Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM OfflineAudioCompletionEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "OfflineAudioCompletionEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/Preferences.h"
9 : #include "mozilla/dom/AudioBuffer.h"
10 : #include "mozilla/dom/BindingUtils.h"
11 : #include "mozilla/dom/DOMJSClass.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/OfflineAudioCompletionEvent.h"
14 : #include "mozilla/dom/PrimitiveConversions.h"
15 : #include "mozilla/dom/ScriptSettings.h"
16 : #include "mozilla/dom/XrayExpandoClass.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 :
22 0 : OfflineAudioCompletionEventInit::OfflineAudioCompletionEventInit()
23 0 : : EventInit(FastDictionaryInitializer())
24 : {
25 : // Safe to pass a null context if we pass a null value
26 0 : Init(nullptr, JS::NullHandleValue);
27 0 : }
28 :
29 :
30 :
31 : bool
32 0 : OfflineAudioCompletionEventInit::InitIds(JSContext* cx, OfflineAudioCompletionEventInitAtoms* atomsCache)
33 : {
34 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
35 :
36 : // Initialize these in reverse order so that any failure leaves the first one
37 : // uninitialized.
38 0 : if (!atomsCache->renderedBuffer_id.init(cx, "renderedBuffer")) {
39 0 : return false;
40 : }
41 0 : return true;
42 : }
43 :
44 : bool
45 0 : OfflineAudioCompletionEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
46 : {
47 : // Passing a null JSContext is OK only if we're initing from null,
48 : // Since in that case we will not have to do any property gets
49 : // Also evaluate isNullOrUndefined in order to avoid false-positive
50 : // checkers by static analysis tools
51 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
52 0 : OfflineAudioCompletionEventInitAtoms* atomsCache = nullptr;
53 0 : if (cx) {
54 0 : atomsCache = GetAtomCache<OfflineAudioCompletionEventInitAtoms>(cx);
55 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
56 0 : return false;
57 : }
58 : }
59 :
60 : // Per spec, we init the parent's members first
61 0 : if (!EventInit::Init(cx, val)) {
62 0 : return false;
63 : }
64 :
65 0 : bool isNull = val.isNullOrUndefined();
66 : // We only need these if !isNull, in which case we have |cx|.
67 0 : Maybe<JS::Rooted<JSObject *> > object;
68 0 : Maybe<JS::Rooted<JS::Value> > temp;
69 0 : if (!isNull) {
70 0 : MOZ_ASSERT(cx);
71 0 : object.emplace(cx, &val.toObject());
72 0 : temp.emplace(cx);
73 : }
74 0 : if (!isNull) {
75 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->renderedBuffer_id, temp.ptr())) {
76 0 : return false;
77 : }
78 : }
79 0 : if (!isNull && !temp->isUndefined()) {
80 0 : if (temp.ref().isObject()) {
81 : static_assert(IsRefcounted<mozilla::dom::AudioBuffer>::value, "We can only store refcounted classes.");{
82 0 : nsresult rv = UnwrapObject<prototypes::id::AudioBuffer, mozilla::dom::AudioBuffer>(temp.ptr(), mRenderedBuffer);
83 0 : if (NS_FAILED(rv)) {
84 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'renderedBuffer' member of OfflineAudioCompletionEventInit", "AudioBuffer");
85 0 : return false;
86 : }
87 : }
88 : } else {
89 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'renderedBuffer' member of OfflineAudioCompletionEventInit");
90 0 : return false;
91 : }
92 0 : mIsAnyMemberPresent = true;
93 0 : } else if (cx) {
94 : // Don't error out if we have no cx. In that
95 : // situation the caller is default-constructing us and we'll
96 : // just assume they know what they're doing.
97 0 : return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
98 0 : "'renderedBuffer' member of OfflineAudioCompletionEventInit");
99 : }
100 0 : return true;
101 : }
102 :
103 : bool
104 0 : OfflineAudioCompletionEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
105 : {
106 0 : OfflineAudioCompletionEventInitAtoms* atomsCache = GetAtomCache<OfflineAudioCompletionEventInitAtoms>(cx);
107 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
108 0 : return false;
109 : }
110 :
111 : // Per spec, we define the parent's members first
112 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
113 0 : return false;
114 : }
115 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
116 :
117 : do {
118 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
119 0 : JS::Rooted<JS::Value> temp(cx);
120 0 : OwningNonNull<mozilla::dom::AudioBuffer> const & currentValue = mRenderedBuffer;
121 0 : if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
122 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
123 0 : return false;
124 : }
125 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->renderedBuffer_id, temp, JSPROP_ENUMERATE)) {
126 0 : return false;
127 : }
128 0 : break;
129 : } while(0);
130 :
131 0 : return true;
132 : }
133 :
134 : void
135 0 : OfflineAudioCompletionEventInit::TraceDictionary(JSTracer* trc)
136 : {
137 0 : EventInit::TraceDictionary(trc);
138 0 : }
139 :
140 : OfflineAudioCompletionEventInit&
141 0 : OfflineAudioCompletionEventInit::operator=(const OfflineAudioCompletionEventInit& aOther)
142 : {
143 0 : EventInit::operator=(aOther);
144 0 : mRenderedBuffer = aOther.mRenderedBuffer;
145 0 : return *this;
146 : }
147 :
148 : namespace binding_detail {
149 : } // namespace binding_detail
150 :
151 :
152 : namespace OfflineAudioCompletionEventBinding {
153 :
154 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
155 : "Can't inherit from an interface with a different ownership model.");
156 :
157 : static bool
158 0 : get_renderedBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OfflineAudioCompletionEvent* self, JSJitGetterCallArgs args)
159 : {
160 0 : auto result(StrongOrRawPtr<mozilla::dom::AudioBuffer>(self->RenderedBuffer()));
161 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
162 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
163 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
164 0 : return false;
165 : }
166 0 : return true;
167 : }
168 :
169 : static const JSJitInfo renderedBuffer_getterinfo = {
170 : { (JSJitGetterOp)get_renderedBuffer },
171 : { prototypes::id::OfflineAudioCompletionEvent },
172 : { PrototypeTraits<prototypes::id::OfflineAudioCompletionEvent>::Depth },
173 : JSJitInfo::Getter,
174 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
175 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
176 : false, /* isInfallible. False in setters. */
177 : false, /* isMovable. Not relevant for setters. */
178 : false, /* isEliminatable. Not relevant for setters. */
179 : false, /* isAlwaysInSlot. Only relevant for getters. */
180 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
181 : false, /* isTypedMethod. Only relevant for methods. */
182 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
183 : };
184 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
185 : static_assert(0 < 1, "There is no slot for us");
186 :
187 : static bool
188 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OfflineAudioCompletionEvent* self, JSJitGetterCallArgs args)
189 : {
190 0 : bool result(self->IsTrusted());
191 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
192 0 : args.rval().setBoolean(result);
193 0 : return true;
194 : }
195 :
196 : static const JSJitInfo isTrusted_getterinfo = {
197 : { (JSJitGetterOp)get_isTrusted },
198 : { prototypes::id::OfflineAudioCompletionEvent },
199 : { PrototypeTraits<prototypes::id::OfflineAudioCompletionEvent>::Depth },
200 : JSJitInfo::Getter,
201 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
202 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
203 : true, /* isInfallible. False in setters. */
204 : true, /* isMovable. Not relevant for setters. */
205 : true, /* isEliminatable. Not relevant for setters. */
206 : false, /* isAlwaysInSlot. Only relevant for getters. */
207 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
208 : false, /* isTypedMethod. Only relevant for methods. */
209 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
210 : };
211 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
212 : static_assert(0 < 1, "There is no slot for us");
213 :
214 : static bool
215 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
216 : {
217 0 : mozilla::dom::OfflineAudioCompletionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OfflineAudioCompletionEvent>(obj);
218 : // We don't want to preserve if we don't have a wrapper, and we
219 : // obviously can't preserve if we're not initialized.
220 0 : if (self && self->GetWrapperPreserveColor()) {
221 0 : PreserveWrapper(self);
222 : }
223 0 : return true;
224 : }
225 :
226 : static void
227 0 : _finalize(js::FreeOp* fop, JSObject* obj)
228 : {
229 0 : mozilla::dom::OfflineAudioCompletionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OfflineAudioCompletionEvent>(obj);
230 0 : if (self) {
231 0 : ClearWrapper(self, self, obj);
232 0 : AddForDeferredFinalization<mozilla::dom::OfflineAudioCompletionEvent>(self);
233 : }
234 0 : }
235 :
236 : static void
237 0 : _objectMoved(JSObject* obj, const JSObject* old)
238 : {
239 0 : mozilla::dom::OfflineAudioCompletionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OfflineAudioCompletionEvent>(obj);
240 0 : if (self) {
241 0 : UpdateWrapper(self, self, obj, old);
242 : }
243 0 : }
244 :
245 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
246 : #if defined(__clang__)
247 : #pragma clang diagnostic push
248 : #pragma clang diagnostic ignored "-Wmissing-braces"
249 : #endif
250 : static const JSPropertySpec sAttributes_specs[] = {
251 : { "renderedBuffer", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &renderedBuffer_getterinfo, nullptr, nullptr },
252 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
253 : };
254 : #if defined(__clang__)
255 : #pragma clang diagnostic pop
256 : #endif
257 :
258 :
259 : // Can't be const because the pref-enabled boolean needs to be writable
260 : static Prefable<const JSPropertySpec> sAttributes[] = {
261 : { nullptr, &sAttributes_specs[0] },
262 : { nullptr, nullptr }
263 : };
264 :
265 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
266 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
267 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
268 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
269 :
270 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
271 : #if defined(__clang__)
272 : #pragma clang diagnostic push
273 : #pragma clang diagnostic ignored "-Wmissing-braces"
274 : #endif
275 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
276 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
277 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
278 : };
279 : #if defined(__clang__)
280 : #pragma clang diagnostic pop
281 : #endif
282 :
283 :
284 : // Can't be const because the pref-enabled boolean needs to be writable
285 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
286 : { nullptr, &sUnforgeableAttributes_specs[0] },
287 : { nullptr, nullptr }
288 : };
289 :
290 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
291 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
292 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
293 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
294 :
295 :
296 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
297 : static PropertyInfo sNativeProperties_propertyInfos[2];
298 :
299 : static const NativePropertiesN<2> sNativeProperties = {
300 : false, 0,
301 : false, 0,
302 : false, 0,
303 : true, 0 /* sAttributes */,
304 : false, 0,
305 : true, 1 /* sUnforgeableAttributes */,
306 : false, 0,
307 : -1,
308 : 2,
309 : sNativeProperties_sortedPropertyIndices,
310 : {
311 : { sAttributes, &sNativeProperties_propertyInfos[0] },
312 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
313 : }
314 : };
315 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
316 : "We have a property info count that is oversized");
317 :
318 : static bool
319 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
320 : {
321 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
322 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
323 0 : if (!args.isConstructing()) {
324 : // XXXbz wish I could get the name from the callee instead of
325 : // Adding more relocations
326 0 : return ThrowConstructorWithoutNew(cx, "OfflineAudioCompletionEvent");
327 : }
328 :
329 0 : GlobalObject global(cx, obj);
330 0 : if (global.Failed()) {
331 0 : return false;
332 : }
333 :
334 0 : JS::Rooted<JSObject*> desiredProto(cx);
335 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
336 0 : return false;
337 : }
338 :
339 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
340 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "OfflineAudioCompletionEvent");
341 : }
342 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
343 0 : binding_detail::FakeString arg0;
344 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
345 0 : return false;
346 : }
347 0 : binding_detail::FastOfflineAudioCompletionEventInit arg1;
348 0 : if (!arg1.Init(cx, args[1], "Argument 2 of OfflineAudioCompletionEvent.constructor", false)) {
349 0 : return false;
350 : }
351 0 : Maybe<JSAutoCompartment> ac;
352 0 : if (objIsXray) {
353 0 : obj = js::CheckedUnwrap(obj);
354 0 : if (!obj) {
355 0 : return false;
356 : }
357 0 : ac.emplace(cx, obj);
358 0 : if (!JS_WrapObject(cx, &desiredProto)) {
359 0 : return false;
360 : }
361 : }
362 0 : binding_detail::FastErrorResult rv;
363 0 : auto result(StrongOrRawPtr<mozilla::dom::OfflineAudioCompletionEvent>(mozilla::dom::OfflineAudioCompletionEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
364 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
365 0 : return false;
366 : }
367 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
368 : static_assert(!IsPointer<decltype(result)>::value,
369 : "NewObject implies that we need to keep the object alive with a strong reference.");
370 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
371 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
372 0 : return false;
373 : }
374 0 : return true;
375 : }
376 :
377 : static const js::ClassOps sInterfaceObjectClassOps = {
378 : nullptr, /* addProperty */
379 : nullptr, /* delProperty */
380 : nullptr, /* getProperty */
381 : nullptr, /* setProperty */
382 : nullptr, /* enumerate */
383 : nullptr, /* newEnumerate */
384 : nullptr, /* resolve */
385 : nullptr, /* mayResolve */
386 : nullptr, /* finalize */
387 : _constructor, /* call */
388 : nullptr, /* hasInstance */
389 : _constructor, /* construct */
390 : nullptr, /* trace */
391 : };
392 :
393 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
394 : {
395 : "Function",
396 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
397 : &sInterfaceObjectClassOps,
398 : JS_NULL_CLASS_SPEC,
399 : JS_NULL_CLASS_EXT,
400 : &sInterfaceObjectClassObjectOps
401 : },
402 : eInterface,
403 : true,
404 : prototypes::id::OfflineAudioCompletionEvent,
405 : PrototypeTraits<prototypes::id::OfflineAudioCompletionEvent>::Depth,
406 : sNativePropertyHooks,
407 : "function OfflineAudioCompletionEvent() {\n [native code]\n}",
408 : EventBinding::GetConstructorObject
409 : };
410 :
411 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
412 : {
413 : "OfflineAudioCompletionEventPrototype",
414 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
415 : JS_NULL_CLASS_OPS,
416 : JS_NULL_CLASS_SPEC,
417 : JS_NULL_CLASS_EXT,
418 : JS_NULL_OBJECT_OPS
419 : },
420 : eInterfacePrototype,
421 : false,
422 : prototypes::id::OfflineAudioCompletionEvent,
423 : PrototypeTraits<prototypes::id::OfflineAudioCompletionEvent>::Depth,
424 : sNativePropertyHooks,
425 : "[object OfflineAudioCompletionEventPrototype]",
426 : EventBinding::GetProtoObject
427 : };
428 :
429 : bool
430 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
431 : {
432 : static bool sPrefValue;
433 : static bool sPrefCacheSetUp = false;
434 0 : if (!sPrefCacheSetUp) {
435 0 : sPrefCacheSetUp = true;
436 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.webaudio.enabled");
437 : }
438 :
439 0 : return sPrefValue;
440 : }
441 :
442 : JSObject*
443 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
444 : {
445 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
446 : }
447 :
448 : static const js::ClassOps sClassOps = {
449 : _addProperty, /* addProperty */
450 : nullptr, /* delProperty */
451 : nullptr, /* getProperty */
452 : nullptr, /* setProperty */
453 : nullptr, /* enumerate */
454 : nullptr, /* newEnumerate */
455 : nullptr, /* resolve */
456 : nullptr, /* mayResolve */
457 : _finalize, /* finalize */
458 : nullptr, /* call */
459 : nullptr, /* hasInstance */
460 : nullptr, /* construct */
461 : nullptr, /* trace */
462 : };
463 :
464 : static const js::ClassExtension sClassExtension = {
465 : nullptr, /* weakmapKeyDelegateOp */
466 : _objectMoved /* objectMovedOp */
467 : };
468 :
469 : static const DOMJSClass sClass = {
470 : { "OfflineAudioCompletionEvent",
471 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
472 : &sClassOps,
473 : JS_NULL_CLASS_SPEC,
474 : &sClassExtension,
475 : JS_NULL_OBJECT_OPS
476 : },
477 : { prototypes::id::Event, prototypes::id::OfflineAudioCompletionEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
478 : IsBaseOf<nsISupports, mozilla::dom::OfflineAudioCompletionEvent >::value,
479 : sNativePropertyHooks,
480 : FindAssociatedGlobalForNative<mozilla::dom::OfflineAudioCompletionEvent>::Get,
481 : GetProtoObjectHandle,
482 : GetCCParticipant<mozilla::dom::OfflineAudioCompletionEvent>::Get()
483 : };
484 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
485 : "Must have the right minimal number of reserved slots.");
486 : static_assert(1 >= 1,
487 : "Must have enough reserved slots.");
488 :
489 : const JSClass*
490 0 : GetJSClass()
491 : {
492 0 : return sClass.ToJSClass();
493 : }
494 :
495 : bool
496 0 : Wrap(JSContext* aCx, mozilla::dom::OfflineAudioCompletionEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
497 : {
498 : MOZ_ASSERT(static_cast<mozilla::dom::OfflineAudioCompletionEvent*>(aObject) ==
499 : reinterpret_cast<mozilla::dom::OfflineAudioCompletionEvent*>(aObject),
500 : "Multiple inheritance for mozilla::dom::OfflineAudioCompletionEvent is broken.");
501 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
502 : reinterpret_cast<mozilla::dom::Event*>(aObject),
503 : "Multiple inheritance for mozilla::dom::Event is broken.");
504 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
505 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
506 0 : MOZ_ASSERT(!aCache->GetWrapper(),
507 : "You should probably not be using Wrap() directly; use "
508 : "GetOrCreateDOMReflector instead");
509 :
510 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
511 : "nsISupports must be on our primary inheritance chain");
512 :
513 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
514 0 : if (!global) {
515 0 : return false;
516 : }
517 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
518 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
519 :
520 : // That might have ended up wrapping us already, due to the wonders
521 : // of XBL. Check for that, and bail out as needed.
522 0 : aReflector.set(aCache->GetWrapper());
523 0 : if (aReflector) {
524 : #ifdef DEBUG
525 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
526 : #endif // DEBUG
527 0 : return true;
528 : }
529 :
530 0 : JSAutoCompartment ac(aCx, global);
531 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
532 0 : if (!canonicalProto) {
533 0 : return false;
534 : }
535 0 : JS::Rooted<JSObject*> proto(aCx);
536 0 : if (aGivenProto) {
537 0 : proto = aGivenProto;
538 : // Unfortunately, while aGivenProto was in the compartment of aCx
539 : // coming in, we changed compartments to that of "parent" so may need
540 : // to wrap the proto here.
541 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
542 0 : if (!JS_WrapObject(aCx, &proto)) {
543 0 : return false;
544 : }
545 : }
546 : } else {
547 0 : proto = canonicalProto;
548 : }
549 :
550 0 : BindingJSObjectCreator<mozilla::dom::OfflineAudioCompletionEvent> creator(aCx);
551 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
552 0 : if (!aReflector) {
553 0 : return false;
554 : }
555 :
556 0 : aCache->SetWrapper(aReflector);
557 :
558 : // Important: do unforgeable property setup after we have handed
559 : // over ownership of the C++ object to obj as needed, so that if
560 : // we fail and it ends up GCed it won't have problems in the
561 : // finalizer trying to drop its ownership of the C++ object.
562 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
563 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
564 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
565 0 : aCache->ReleaseWrapper(aObject);
566 0 : aCache->ClearWrapper();
567 0 : return false;
568 : }
569 0 : creator.InitializationSucceeded();
570 :
571 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
572 : aCache->GetWrapperPreserveColor() == aReflector);
573 : // If proto != canonicalProto, we have to preserve our wrapper;
574 : // otherwise we won't be able to properly recreate it later, since
575 : // we won't know what proto to use. Note that we don't check
576 : // aGivenProto here, since it's entirely possible (and even
577 : // somewhat common) to have a non-null aGivenProto which is the
578 : // same as canonicalProto.
579 0 : if (proto != canonicalProto) {
580 0 : PreserveWrapper(aObject);
581 : }
582 :
583 0 : return true;
584 : }
585 :
586 : const NativePropertyHooks sNativePropertyHooks[] = { {
587 : nullptr,
588 : nullptr,
589 : nullptr,
590 : { sNativeProperties.Upcast(), nullptr },
591 : prototypes::id::OfflineAudioCompletionEvent,
592 : constructors::id::OfflineAudioCompletionEvent,
593 : EventBinding::sNativePropertyHooks,
594 : &DefaultXrayExpandoObjectClass
595 : } };
596 :
597 : void
598 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
599 : {
600 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
601 0 : if (!parentProto) {
602 0 : return;
603 : }
604 :
605 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
606 0 : if (!constructorProto) {
607 0 : return;
608 : }
609 :
610 : static bool sIdsInited = false;
611 0 : if (!sIdsInited && NS_IsMainThread()) {
612 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
613 0 : return;
614 : }
615 0 : sIdsInited = true;
616 : }
617 :
618 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::OfflineAudioCompletionEvent);
619 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::OfflineAudioCompletionEvent);
620 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
621 : &sPrototypeClass.mBase, protoCache,
622 : constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
623 : interfaceCache,
624 : sNativeProperties.Upcast(),
625 : nullptr,
626 : "OfflineAudioCompletionEvent", aDefineOnGlobal,
627 : nullptr,
628 0 : false);
629 :
630 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
631 : {
632 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
633 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
634 0 : if (!unforgeableHolder) {
635 0 : *protoCache = nullptr;
636 0 : if (interfaceCache) {
637 0 : *interfaceCache = nullptr;
638 : }
639 0 : return;
640 : }
641 : }
642 :
643 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
644 0 : *protoCache = nullptr;
645 0 : if (interfaceCache) {
646 0 : *interfaceCache = nullptr;
647 : }
648 0 : return;
649 : }
650 :
651 0 : if (*protoCache) {
652 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
653 0 : JS::ObjectValue(*unforgeableHolder));
654 : }
655 : }
656 :
657 : JS::Handle<JSObject*>
658 0 : GetProtoObjectHandle(JSContext* aCx)
659 : {
660 : /* Get the interface prototype object for this class. This will create the
661 : object as needed. */
662 0 : bool aDefineOnGlobal = true;
663 :
664 : /* Make sure our global is sane. Hopefully we can remove this sometime */
665 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
666 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
667 0 : return nullptr;
668 : }
669 :
670 : /* Check to see whether the interface objects are already installed */
671 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
672 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::OfflineAudioCompletionEvent)) {
673 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
674 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
675 : }
676 :
677 : /*
678 : * The object might _still_ be null, but that's OK.
679 : *
680 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
681 : * traced by TraceProtoAndIfaceCache() and its contents are never
682 : * changed after they have been set.
683 : *
684 : * Calling address() avoids the read read barrier that does gray
685 : * unmarking, but it's not possible for the object to be gray here.
686 : */
687 :
688 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::OfflineAudioCompletionEvent);
689 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
690 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
691 : }
692 :
693 : JS::Handle<JSObject*>
694 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
695 : {
696 : /* Get the interface object for this class. This will create the object as
697 : needed. */
698 :
699 : /* Make sure our global is sane. Hopefully we can remove this sometime */
700 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
701 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
702 0 : return nullptr;
703 : }
704 :
705 : /* Check to see whether the interface objects are already installed */
706 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
707 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::OfflineAudioCompletionEvent)) {
708 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
709 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
710 : }
711 :
712 : /*
713 : * The object might _still_ be null, but that's OK.
714 : *
715 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
716 : * traced by TraceProtoAndIfaceCache() and its contents are never
717 : * changed after they have been set.
718 : *
719 : * Calling address() avoids the read read barrier that does gray
720 : * unmarking, but it's not possible for the object to be gray here.
721 : */
722 :
723 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::OfflineAudioCompletionEvent);
724 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
725 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
726 : }
727 :
728 : JSObject*
729 0 : GetConstructorObject(JSContext* aCx)
730 : {
731 0 : return GetConstructorObjectHandle(aCx);
732 : }
733 :
734 : } // namespace OfflineAudioCompletionEventBinding
735 :
736 :
737 :
738 : } // namespace dom
739 : } // namespace mozilla
|