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