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