Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/AudioWorkletBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM AudioWorklet.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AudioWorkletBinding.h"
4
#include "WorkletBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/Preferences.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/Worklet.h"
12
#include "mozilla/dom/XrayExpandoClass.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
namespace binding_detail {}; // Just to make sure it's known as a namespace
18
using namespace mozilla::dom::binding_detail;
19
20
21
namespace AudioWorklet_Binding {
22
23
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Worklet_Binding::NativeType>::value,
24
              "Can't inherit from an interface with a different ownership model.");
25
26
static bool
27
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
28
0
{
29
0
  mozilla::dom::Worklet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Worklet>(obj);
30
0
  // We don't want to preserve if we don't have a wrapper, and we
31
0
  // obviously can't preserve if we're not initialized.
32
0
  if (self && self->GetWrapperPreserveColor()) {
33
0
    PreserveWrapper(self);
34
0
  }
35
0
  return true;
36
0
}
37
38
static void
39
_finalize(js::FreeOp* fop, JSObject* obj)
40
0
{
41
0
  mozilla::dom::Worklet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Worklet>(obj);
42
0
  if (self) {
43
0
    ClearWrapper(self, self, obj);
44
0
    AddForDeferredFinalization<mozilla::dom::Worklet>(self);
45
0
  }
46
0
}
47
48
static size_t
49
_objectMoved(JSObject* obj, JSObject* old)
50
0
{
51
0
  mozilla::dom::Worklet* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Worklet>(obj);
52
0
  if (self) {
53
0
    UpdateWrapper(self, self, obj, old);
54
0
  }
55
0
56
0
  return 0;
57
0
}
58
59
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
60
  {
61
    "Function",
62
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
63
    &sBoringInterfaceObjectClassClassOps,
64
    JS_NULL_CLASS_SPEC,
65
    JS_NULL_CLASS_EXT,
66
    &sInterfaceObjectClassObjectOps
67
  },
68
  eInterface,
69
  true,
70
  prototypes::id::AudioWorklet,
71
  PrototypeTraits<prototypes::id::AudioWorklet>::Depth,
72
  sNativePropertyHooks,
73
  "function AudioWorklet() {\n    [native code]\n}",
74
  Worklet_Binding::GetConstructorObject
75
};
76
77
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
78
  {
79
    "AudioWorkletPrototype",
80
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
81
    JS_NULL_CLASS_OPS,
82
    JS_NULL_CLASS_SPEC,
83
    JS_NULL_CLASS_EXT,
84
    JS_NULL_OBJECT_OPS
85
  },
86
  eInterfacePrototype,
87
  false,
88
  prototypes::id::AudioWorklet,
89
  PrototypeTraits<prototypes::id::AudioWorklet>::Depth,
90
  sNativePropertyHooks,
91
  "[object AudioWorkletPrototype]",
92
  Worklet_Binding::GetProtoObject
93
};
94
95
bool
96
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
97
0
{
98
0
  static bool sPrefValue;
99
0
  static bool sPrefCacheSetUp = false;
100
0
  if (!sPrefCacheSetUp) {
101
0
    sPrefCacheSetUp = true;
102
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.audioworklet.enabled");
103
0
  }
104
0
105
0
  return sPrefValue &&
106
0
         mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
107
0
}
108
109
static const js::ClassOps sClassOps = {
110
  _addProperty, /* addProperty */
111
  nullptr,               /* delProperty */
112
  nullptr,               /* enumerate */
113
  nullptr, /* newEnumerate */
114
  nullptr, /* resolve */
115
  nullptr, /* mayResolve */
116
  _finalize, /* finalize */
117
  nullptr, /* call */
118
  nullptr,               /* hasInstance */
119
  nullptr,               /* construct */
120
  nullptr, /* trace */
121
};
122
123
static const js::ClassExtension sClassExtension = {
124
  nullptr, /* weakmapKeyDelegateOp */
125
  _objectMoved /* objectMovedOp */
126
};
127
128
static const DOMJSClass sClass = {
129
  { "AudioWorklet",
130
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
131
    &sClassOps,
132
    JS_NULL_CLASS_SPEC,
133
    &sClassExtension,
134
    JS_NULL_OBJECT_OPS
135
  },
136
  { prototypes::id::Worklet, prototypes::id::AudioWorklet, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
137
  IsBaseOf<nsISupports, mozilla::dom::Worklet >::value,
138
  sNativePropertyHooks,
139
  FindAssociatedGlobalForNative<mozilla::dom::Worklet>::Get,
140
  GetProtoObjectHandle,
141
  GetCCParticipant<mozilla::dom::Worklet>::Get()
142
};
143
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
144
              "Must have the right minimal number of reserved slots.");
145
static_assert(1 >= 1,
146
              "Must have enough reserved slots.");
147
148
const JSClass*
149
GetJSClass()
150
0
{
151
0
  return sClass.ToJSClass();
152
0
}
153
154
bool
155
Wrap(JSContext* aCx, mozilla::dom::Worklet* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
156
0
{
157
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Worklet>::value,
158
0
                "Shouldn't have wrappercached things that are not refcounted.");
159
0
  MOZ_ASSERT(static_cast<mozilla::dom::Worklet*>(aObject) ==
160
0
             reinterpret_cast<mozilla::dom::Worklet*>(aObject),
161
0
             "Multiple inheritance for mozilla::dom::Worklet is broken.");
162
0
  MOZ_ASSERT(static_cast<mozilla::dom::Worklet*>(aObject) ==
163
0
             reinterpret_cast<mozilla::dom::Worklet*>(aObject),
164
0
             "Multiple inheritance for mozilla::dom::Worklet is broken.");
165
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
166
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
167
0
  MOZ_ASSERT(!aCache->GetWrapper(),
168
0
             "You should probably not be using Wrap() directly; use "
169
0
             "GetOrCreateDOMReflector instead");
170
0
171
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
172
0
             "nsISupports must be on our primary inheritance chain");
173
0
174
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
175
0
  if (!global) {
176
0
    return false;
177
0
  }
178
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
179
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
180
0
181
0
  // That might have ended up wrapping us already, due to the wonders
182
0
  // of XBL.  Check for that, and bail out as needed.
183
0
  aReflector.set(aCache->GetWrapper());
184
0
  if (aReflector) {
185
#ifdef DEBUG
186
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
187
#endif // DEBUG
188
    return true;
189
0
  }
190
0
191
0
  JSAutoRealm ar(aCx, global);
192
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
193
0
  if (!canonicalProto) {
194
0
    return false;
195
0
  }
196
0
  JS::Rooted<JSObject*> proto(aCx);
197
0
  if (aGivenProto) {
198
0
    proto = aGivenProto;
199
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
200
0
    // coming in, we changed compartments to that of "parent" so may need
201
0
    // to wrap the proto here.
202
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
203
0
      if (!JS_WrapObject(aCx, &proto)) {
204
0
        return false;
205
0
      }
206
0
    }
207
0
  } else {
208
0
    proto = canonicalProto;
209
0
  }
210
0
211
0
  BindingJSObjectCreator<mozilla::dom::Worklet> creator(aCx);
212
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
213
0
  if (!aReflector) {
214
0
    return false;
215
0
  }
216
0
217
0
  aCache->SetWrapper(aReflector);
218
0
  creator.InitializationSucceeded();
219
0
220
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
221
0
             aCache->GetWrapperPreserveColor() == aReflector);
222
0
  // If proto != canonicalProto, we have to preserve our wrapper;
223
0
  // otherwise we won't be able to properly recreate it later, since
224
0
  // we won't know what proto to use.  Note that we don't check
225
0
  // aGivenProto here, since it's entirely possible (and even
226
0
  // somewhat common) to have a non-null aGivenProto which is the
227
0
  // same as canonicalProto.
228
0
  if (proto != canonicalProto) {
229
0
    PreserveWrapper(aObject);
230
0
  }
231
0
232
0
  return true;
233
0
}
234
235
const NativePropertyHooks sNativePropertyHooks[] = { {
236
  nullptr,
237
  nullptr,
238
  nullptr,
239
  { nullptr, nullptr },
240
  prototypes::id::AudioWorklet,
241
  constructors::id::AudioWorklet,
242
  Worklet_Binding::sNativePropertyHooks,
243
  &DefaultXrayExpandoObjectClass
244
} };
245
246
void
247
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
248
0
{
249
0
  JS::Handle<JSObject*> parentProto(Worklet_Binding::GetProtoObjectHandle(aCx));
250
0
  if (!parentProto) {
251
0
    return;
252
0
  }
253
0
254
0
  JS::Handle<JSObject*> constructorProto(Worklet_Binding::GetConstructorObjectHandle(aCx));
255
0
  if (!constructorProto) {
256
0
    return;
257
0
  }
258
0
259
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::AudioWorklet);
260
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::AudioWorklet);
261
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
262
0
                              &sPrototypeClass.mBase, protoCache,
263
0
                              nullptr,
264
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
265
0
                              interfaceCache,
266
0
                              nullptr,
267
0
                              nullptr,
268
0
                              "AudioWorklet", aDefineOnGlobal,
269
0
                              nullptr,
270
0
                              false);
271
0
}
272
273
JSObject*
274
GetConstructorObject(JSContext* aCx)
275
0
{
276
0
  return GetConstructorObjectHandle(aCx);
277
0
}
278
279
} // namespace AudioWorklet_Binding
280
281
282
283
} // namespace dom
284
} // namespace mozilla