Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/HTMLAudioElementBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM HTMLAudioElement.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "HTMLAudioElementBinding.h"
4
#include "HTMLMediaElementBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/HTMLAudioElement.h"
10
#include "mozilla/dom/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/XrayExpandoClass.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
namespace binding_detail {}; // Just to make sure it's known as a namespace
17
using namespace mozilla::dom::binding_detail;
18
19
20
namespace HTMLAudioElement_Binding {
21
22
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLMediaElement_Binding::NativeType>::value,
23
              "Can't inherit from an interface with a different ownership model.");
24
25
static bool
26
_Audio(JSContext* cx, unsigned argc, JS::Value* vp)
27
0
{
28
0
  AUTO_PROFILER_LABEL_FAST("Audio constructor", DOM, cx);
29
0
30
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
31
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
32
0
  if (!args.isConstructing()) {
33
0
    // XXXbz wish I could get the name from the callee instead of
34
0
    // Adding more relocations
35
0
    return ThrowConstructorWithoutNew(cx, "Audio");
36
0
  }
37
0
38
0
  JS::Rooted<JSObject*> desiredProto(cx);
39
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
40
0
    return false;
41
0
  }
42
0
43
0
  GlobalObject global(cx, obj);
44
0
  if (global.Failed()) {
45
0
    return false;
46
0
  }
47
0
48
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
49
0
  Optional<nsAString> arg0;
50
0
  binding_detail::FakeString arg0_holder;
51
0
  if (args.hasDefined(0)) {
52
0
    if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0_holder)) {
53
0
      return false;
54
0
    }
55
0
    arg0 = &arg0_holder;
56
0
  }
57
0
  Maybe<JSAutoRealm> ar;
58
0
  if (objIsXray) {
59
0
    obj = js::CheckedUnwrap(obj);
60
0
    if (!obj) {
61
0
      return false;
62
0
    }
63
0
    ar.emplace(cx, obj);
64
0
    if (!JS_WrapObject(cx, &desiredProto)) {
65
0
      return false;
66
0
    }
67
0
  }
68
0
  FastErrorResult rv;
69
0
  auto result(StrongOrRawPtr<mozilla::dom::HTMLAudioElement>(mozilla::dom::HTMLAudioElement::Audio(global, NonNullHelper(Constify(arg0)), rv)));
70
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
71
0
    return false;
72
0
  }
73
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
74
0
  static_assert(!IsPointer<decltype(result)>::value,
75
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
76
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
77
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
78
0
    return false;
79
0
  }
80
0
  return true;
81
0
}
82
83
static bool
84
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
85
0
{
86
0
  mozilla::dom::HTMLAudioElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLAudioElement>(obj);
87
0
  // We don't want to preserve if we don't have a wrapper, and we
88
0
  // obviously can't preserve if we're not initialized.
89
0
  if (self && self->GetWrapperPreserveColor()) {
90
0
    PreserveWrapper(self);
91
0
  }
92
0
  return true;
93
0
}
94
95
static void
96
_finalize(js::FreeOp* fop, JSObject* obj)
97
0
{
98
0
  mozilla::dom::HTMLAudioElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLAudioElement>(obj);
99
0
  if (self) {
100
0
    ClearWrapper(self, self, obj);
101
0
    AddForDeferredFinalization<mozilla::dom::HTMLAudioElement>(self);
102
0
  }
103
0
}
104
105
static size_t
106
_objectMoved(JSObject* obj, JSObject* old)
107
0
{
108
0
  mozilla::dom::HTMLAudioElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLAudioElement>(obj);
109
0
  if (self) {
110
0
    UpdateWrapper(self, self, obj, old);
111
0
  }
112
0
113
0
  return 0;
114
0
}
115
116
static bool
117
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
118
0
{
119
0
  AUTO_PROFILER_LABEL_FAST("HTMLAudioElement constructor", DOM, cx);
120
0
121
0
  return HTMLConstructor(cx, argc, vp,
122
0
                         constructors::id::HTMLAudioElement,
123
0
                         prototypes::id::HTMLAudioElement,
124
0
                         CreateInterfaceObjects);
125
0
}
126
127
static const js::ClassOps sInterfaceObjectClassOps = {
128
    nullptr,               /* addProperty */
129
    nullptr,               /* delProperty */
130
    nullptr,               /* enumerate */
131
    nullptr,               /* newEnumerate */
132
    nullptr,               /* resolve */
133
    nullptr,               /* mayResolve */
134
    nullptr,               /* finalize */
135
    _constructor, /* call */
136
    nullptr,               /* hasInstance */
137
    _constructor, /* construct */
138
    nullptr,               /* trace */
139
};
140
141
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
142
  {
143
    "Function",
144
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE + 1 /* slots for the named constructors */),
145
    &sInterfaceObjectClassOps,
146
    JS_NULL_CLASS_SPEC,
147
    JS_NULL_CLASS_EXT,
148
    &sInterfaceObjectClassObjectOps
149
  },
150
  eInterface,
151
  true,
152
  prototypes::id::HTMLAudioElement,
153
  PrototypeTraits<prototypes::id::HTMLAudioElement>::Depth,
154
  sNativePropertyHooks,
155
  "function HTMLAudioElement() {\n    [native code]\n}",
156
  HTMLMediaElement_Binding::GetConstructorObject
157
};
158
159
const NativePropertyHooks sNamedConstructorNativePropertyHooks = {
160
    nullptr,
161
    nullptr,
162
    nullptr,
163
    { nullptr, nullptr },
164
    prototypes::id::HTMLAudioElement,
165
    constructors::id::HTMLAudioElement,
166
    nullptr
167
};
168
169
static const NamedConstructor namedConstructors[] = {
170
  { "Audio", { _Audio, &sNamedConstructorNativePropertyHooks }, 0 },
171
  { nullptr, { nullptr, nullptr }, 0 }
172
};
173
174
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
175
  {
176
    "HTMLAudioElementPrototype",
177
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
178
    JS_NULL_CLASS_OPS,
179
    JS_NULL_CLASS_SPEC,
180
    JS_NULL_CLASS_EXT,
181
    JS_NULL_OBJECT_OPS
182
  },
183
  eInterfacePrototype,
184
  false,
185
  prototypes::id::HTMLAudioElement,
186
  PrototypeTraits<prototypes::id::HTMLAudioElement>::Depth,
187
  sNativePropertyHooks,
188
  "[object HTMLAudioElementPrototype]",
189
  HTMLMediaElement_Binding::GetProtoObject
190
};
191
192
static const js::ClassOps sClassOps = {
193
  _addProperty, /* addProperty */
194
  nullptr,               /* delProperty */
195
  nullptr,               /* enumerate */
196
  nullptr, /* newEnumerate */
197
  nullptr, /* resolve */
198
  nullptr, /* mayResolve */
199
  _finalize, /* finalize */
200
  nullptr, /* call */
201
  nullptr,               /* hasInstance */
202
  nullptr,               /* construct */
203
  nullptr, /* trace */
204
};
205
206
static const js::ClassExtension sClassExtension = {
207
  nullptr, /* weakmapKeyDelegateOp */
208
  _objectMoved /* objectMovedOp */
209
};
210
211
static const DOMJSClass sClass = {
212
  { "HTMLAudioElement",
213
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
214
    &sClassOps,
215
    JS_NULL_CLASS_SPEC,
216
    &sClassExtension,
217
    JS_NULL_OBJECT_OPS
218
  },
219
  { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLMediaElement, prototypes::id::HTMLAudioElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
220
  IsBaseOf<nsISupports, mozilla::dom::HTMLAudioElement >::value,
221
  sNativePropertyHooks,
222
  FindAssociatedGlobalForNative<mozilla::dom::HTMLAudioElement>::Get,
223
  GetProtoObjectHandle,
224
  GetCCParticipant<mozilla::dom::HTMLAudioElement>::Get()
225
};
226
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
227
              "Must have the right minimal number of reserved slots.");
228
static_assert(1 >= 1,
229
              "Must have enough reserved slots.");
230
231
const JSClass*
232
GetJSClass()
233
0
{
234
0
  return sClass.ToJSClass();
235
0
}
236
237
bool
238
Wrap(JSContext* aCx, mozilla::dom::HTMLAudioElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
239
0
{
240
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::HTMLAudioElement>::value,
241
0
                "Shouldn't have wrappercached things that are not refcounted.");
242
0
  MOZ_ASSERT(static_cast<mozilla::dom::HTMLAudioElement*>(aObject) ==
243
0
             reinterpret_cast<mozilla::dom::HTMLAudioElement*>(aObject),
244
0
             "Multiple inheritance for mozilla::dom::HTMLAudioElement is broken.");
245
0
  MOZ_ASSERT(static_cast<mozilla::dom::HTMLMediaElement*>(aObject) ==
246
0
             reinterpret_cast<mozilla::dom::HTMLMediaElement*>(aObject),
247
0
             "Multiple inheritance for mozilla::dom::HTMLMediaElement is broken.");
248
0
  MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) ==
249
0
             reinterpret_cast<nsGenericHTMLElement*>(aObject),
250
0
             "Multiple inheritance for nsGenericHTMLElement is broken.");
251
0
  MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) ==
252
0
             reinterpret_cast<mozilla::dom::Element*>(aObject),
253
0
             "Multiple inheritance for mozilla::dom::Element is broken.");
254
0
  MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
255
0
             reinterpret_cast<nsINode*>(aObject),
256
0
             "Multiple inheritance for nsINode is broken.");
257
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
258
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
259
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
260
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
261
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
262
0
  MOZ_ASSERT(!aCache->GetWrapper(),
263
0
             "You should probably not be using Wrap() directly; use "
264
0
             "GetOrCreateDOMReflector instead");
265
0
266
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
267
0
             "nsISupports must be on our primary inheritance chain");
268
0
269
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
270
0
  if (!global) {
271
0
    return false;
272
0
  }
273
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
274
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
275
0
276
0
  // That might have ended up wrapping us already, due to the wonders
277
0
  // of XBL.  Check for that, and bail out as needed.
278
0
  aReflector.set(aCache->GetWrapper());
279
0
  if (aReflector) {
280
#ifdef DEBUG
281
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
282
#endif // DEBUG
283
    return true;
284
0
  }
285
0
286
0
  JSAutoRealm ar(aCx, global);
287
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
288
0
  if (!canonicalProto) {
289
0
    return false;
290
0
  }
291
0
  JS::Rooted<JSObject*> proto(aCx);
292
0
  if (aGivenProto) {
293
0
    proto = aGivenProto;
294
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
295
0
    // coming in, we changed compartments to that of "parent" so may need
296
0
    // to wrap the proto here.
297
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
298
0
      if (!JS_WrapObject(aCx, &proto)) {
299
0
        return false;
300
0
      }
301
0
    }
302
0
  } else {
303
0
    proto = canonicalProto;
304
0
  }
305
0
306
0
  BindingJSObjectCreator<mozilla::dom::HTMLAudioElement> creator(aCx);
307
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
308
0
  if (!aReflector) {
309
0
    return false;
310
0
  }
311
0
312
0
  aCache->SetWrapper(aReflector);
313
0
  creator.InitializationSucceeded();
314
0
315
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
316
0
             aCache->GetWrapperPreserveColor() == aReflector);
317
0
  // If proto != canonicalProto, we have to preserve our wrapper;
318
0
  // otherwise we won't be able to properly recreate it later, since
319
0
  // we won't know what proto to use.  Note that we don't check
320
0
  // aGivenProto here, since it's entirely possible (and even
321
0
  // somewhat common) to have a non-null aGivenProto which is the
322
0
  // same as canonicalProto.
323
0
  if (proto != canonicalProto) {
324
0
    PreserveWrapper(aObject);
325
0
  }
326
0
327
0
  return true;
328
0
}
329
330
const NativePropertyHooks sNativePropertyHooks[] = { {
331
  nullptr,
332
  nullptr,
333
  nullptr,
334
  { nullptr, nullptr },
335
  prototypes::id::HTMLAudioElement,
336
  constructors::id::HTMLAudioElement,
337
  HTMLMediaElement_Binding::sNativePropertyHooks,
338
  &DefaultXrayExpandoObjectClass
339
} };
340
341
void
342
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
343
0
{
344
0
  JS::Handle<JSObject*> parentProto(HTMLMediaElement_Binding::GetProtoObjectHandle(aCx));
345
0
  if (!parentProto) {
346
0
    return;
347
0
  }
348
0
349
0
  JS::Handle<JSObject*> constructorProto(HTMLMediaElement_Binding::GetConstructorObjectHandle(aCx));
350
0
  if (!constructorProto) {
351
0
    return;
352
0
  }
353
0
354
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLAudioElement);
355
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLAudioElement);
356
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
357
0
                              &sPrototypeClass.mBase, protoCache,
358
0
                              nullptr,
359
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, namedConstructors,
360
0
                              interfaceCache,
361
0
                              nullptr,
362
0
                              nullptr,
363
0
                              "HTMLAudioElement", aDefineOnGlobal,
364
0
                              nullptr,
365
0
                              false);
366
0
}
367
368
JSObject*
369
GetConstructorObject(JSContext* aCx)
370
0
{
371
0
  return GetConstructorObjectHandle(aCx);
372
0
}
373
374
} // namespace HTMLAudioElement_Binding
375
376
377
378
} // namespace dom
379
} // namespace mozilla