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