Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM OscillatorNode.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "AudioScheduledSourceNodeBinding.h"
5 : #include "OscillatorNodeBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "jsapi.h"
8 : #include "mozilla/FloatingPoint.h"
9 : #include "mozilla/OwningNonNull.h"
10 : #include "mozilla/Preferences.h"
11 : #include "mozilla/dom/AudioContext.h"
12 : #include "mozilla/dom/AudioParam.h"
13 : #include "mozilla/dom/BindingUtils.h"
14 : #include "mozilla/dom/DOMJSClass.h"
15 : #include "mozilla/dom/NonRefcountedDOMObject.h"
16 : #include "mozilla/dom/OscillatorNode.h"
17 : #include "mozilla/dom/PeriodicWave.h"
18 : #include "mozilla/dom/PrimitiveConversions.h"
19 : #include "mozilla/dom/ScriptSettings.h"
20 : #include "mozilla/dom/XrayExpandoClass.h"
21 : #include "nsContentUtils.h"
22 :
23 : namespace mozilla {
24 : namespace dom {
25 :
26 : namespace OscillatorTypeValues {
27 : extern const EnumEntry strings[6] = {
28 : {"sine", 4},
29 : {"square", 6},
30 : {"sawtooth", 8},
31 : {"triangle", 8},
32 : {"custom", 6},
33 : { nullptr, 0 }
34 : };
35 : } // namespace OscillatorTypeValues
36 :
37 : bool
38 0 : ToJSValue(JSContext* aCx, OscillatorType aArgument, JS::MutableHandle<JS::Value> aValue)
39 : {
40 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(OscillatorTypeValues::strings));
41 : JSString* resultStr =
42 0 : JS_NewStringCopyN(aCx, OscillatorTypeValues::strings[uint32_t(aArgument)].value,
43 0 : OscillatorTypeValues::strings[uint32_t(aArgument)].length);
44 0 : if (!resultStr) {
45 0 : return false;
46 : }
47 0 : aValue.setString(resultStr);
48 0 : return true;
49 : }
50 :
51 :
52 :
53 0 : OscillatorOptions::OscillatorOptions()
54 0 : : AudioNodeOptions(FastDictionaryInitializer())
55 : {
56 : // Safe to pass a null context if we pass a null value
57 0 : Init(nullptr, JS::NullHandleValue);
58 0 : }
59 :
60 :
61 :
62 : bool
63 0 : OscillatorOptions::InitIds(JSContext* cx, OscillatorOptionsAtoms* atomsCache)
64 : {
65 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
66 :
67 : // Initialize these in reverse order so that any failure leaves the first one
68 : // uninitialized.
69 0 : if (!atomsCache->type_id.init(cx, "type") ||
70 0 : !atomsCache->periodicWave_id.init(cx, "periodicWave") ||
71 0 : !atomsCache->frequency_id.init(cx, "frequency") ||
72 0 : !atomsCache->detune_id.init(cx, "detune")) {
73 0 : return false;
74 : }
75 0 : return true;
76 : }
77 :
78 : bool
79 0 : OscillatorOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
80 : {
81 : // Passing a null JSContext is OK only if we're initing from null,
82 : // Since in that case we will not have to do any property gets
83 : // Also evaluate isNullOrUndefined in order to avoid false-positive
84 : // checkers by static analysis tools
85 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
86 0 : OscillatorOptionsAtoms* atomsCache = nullptr;
87 0 : if (cx) {
88 0 : atomsCache = GetAtomCache<OscillatorOptionsAtoms>(cx);
89 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
90 0 : return false;
91 : }
92 : }
93 :
94 : // Per spec, we init the parent's members first
95 0 : if (!AudioNodeOptions::Init(cx, val)) {
96 0 : return false;
97 : }
98 :
99 0 : bool isNull = val.isNullOrUndefined();
100 : // We only need these if !isNull, in which case we have |cx|.
101 0 : Maybe<JS::Rooted<JSObject *> > object;
102 0 : Maybe<JS::Rooted<JS::Value> > temp;
103 0 : if (!isNull) {
104 0 : MOZ_ASSERT(cx);
105 0 : object.emplace(cx, &val.toObject());
106 0 : temp.emplace(cx);
107 : }
108 0 : if (!isNull) {
109 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->detune_id, temp.ptr())) {
110 0 : return false;
111 : }
112 : }
113 0 : if (!isNull && !temp->isUndefined()) {
114 0 : if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &mDetune)) {
115 0 : return false;
116 0 : } else if (!mozilla::IsFinite(mDetune)) {
117 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'detune' member of OscillatorOptions");
118 0 : return false;
119 : }
120 : } else {
121 0 : mDetune = 0.0F;
122 : }
123 0 : mIsAnyMemberPresent = true;
124 :
125 0 : if (!isNull) {
126 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->frequency_id, temp.ptr())) {
127 0 : return false;
128 : }
129 : }
130 0 : if (!isNull && !temp->isUndefined()) {
131 0 : if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &mFrequency)) {
132 0 : return false;
133 0 : } else if (!mozilla::IsFinite(mFrequency)) {
134 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'frequency' member of OscillatorOptions");
135 0 : return false;
136 : }
137 : } else {
138 0 : mFrequency = 440.0F;
139 : }
140 0 : mIsAnyMemberPresent = true;
141 :
142 0 : if (!isNull) {
143 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->periodicWave_id, temp.ptr())) {
144 0 : return false;
145 : }
146 : }
147 0 : if (!isNull && !temp->isUndefined()) {
148 0 : mPeriodicWave.Construct();
149 0 : if (temp.ref().isObject()) {
150 : static_assert(IsRefcounted<mozilla::dom::PeriodicWave>::value, "We can only store refcounted classes.");{
151 0 : nsresult rv = UnwrapObject<prototypes::id::PeriodicWave, mozilla::dom::PeriodicWave>(temp.ptr(), (mPeriodicWave.Value()));
152 0 : if (NS_FAILED(rv)) {
153 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'periodicWave' member of OscillatorOptions", "PeriodicWave");
154 0 : return false;
155 : }
156 : }
157 : } else {
158 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'periodicWave' member of OscillatorOptions");
159 0 : return false;
160 : }
161 0 : mIsAnyMemberPresent = true;
162 : }
163 :
164 0 : if (!isNull) {
165 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
166 0 : return false;
167 : }
168 : }
169 0 : if (!isNull && !temp->isUndefined()) {
170 : {
171 : int index;
172 0 : if (!FindEnumStringIndex<true>(cx, temp.ref(), OscillatorTypeValues::strings, "OscillatorType", "'type' member of OscillatorOptions", &index)) {
173 0 : return false;
174 : }
175 0 : MOZ_ASSERT(index >= 0);
176 0 : mType = static_cast<OscillatorType>(index);
177 : }
178 : } else {
179 0 : mType = OscillatorType::Sine;
180 : }
181 0 : mIsAnyMemberPresent = true;
182 0 : return true;
183 : }
184 :
185 : bool
186 0 : OscillatorOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
187 : {
188 0 : OscillatorOptionsAtoms* atomsCache = GetAtomCache<OscillatorOptionsAtoms>(cx);
189 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
190 0 : return false;
191 : }
192 :
193 : // Per spec, we define the parent's members first
194 0 : if (!AudioNodeOptions::ToObjectInternal(cx, rval)) {
195 0 : return false;
196 : }
197 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
198 :
199 : do {
200 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
201 0 : JS::Rooted<JS::Value> temp(cx);
202 0 : float const & currentValue = mDetune;
203 0 : temp.set(JS_NumberValue(double(currentValue)));
204 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->detune_id, temp, JSPROP_ENUMERATE)) {
205 0 : return false;
206 : }
207 0 : break;
208 : } while(0);
209 :
210 : do {
211 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
212 0 : JS::Rooted<JS::Value> temp(cx);
213 0 : float const & currentValue = mFrequency;
214 0 : temp.set(JS_NumberValue(double(currentValue)));
215 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->frequency_id, temp, JSPROP_ENUMERATE)) {
216 0 : return false;
217 : }
218 0 : break;
219 : } while(0);
220 :
221 0 : if (mPeriodicWave.WasPassed()) {
222 : do {
223 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
224 0 : JS::Rooted<JS::Value> temp(cx);
225 0 : OwningNonNull<mozilla::dom::PeriodicWave> const & currentValue = mPeriodicWave.InternalValue();
226 0 : if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
227 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
228 0 : return false;
229 : }
230 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->periodicWave_id, temp, JSPROP_ENUMERATE)) {
231 0 : return false;
232 : }
233 0 : break;
234 : } while(0);
235 : }
236 :
237 : do {
238 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
239 0 : JS::Rooted<JS::Value> temp(cx);
240 0 : OscillatorType const & currentValue = mType;
241 0 : if (!ToJSValue(cx, currentValue, &temp)) {
242 0 : return false;
243 : }
244 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
245 0 : return false;
246 : }
247 0 : break;
248 : } while(0);
249 :
250 0 : return true;
251 : }
252 :
253 : void
254 0 : OscillatorOptions::TraceDictionary(JSTracer* trc)
255 : {
256 0 : AudioNodeOptions::TraceDictionary(trc);
257 0 : }
258 :
259 : OscillatorOptions&
260 0 : OscillatorOptions::operator=(const OscillatorOptions& aOther)
261 : {
262 0 : AudioNodeOptions::operator=(aOther);
263 0 : mDetune = aOther.mDetune;
264 0 : mFrequency = aOther.mFrequency;
265 0 : mPeriodicWave.Reset();
266 0 : if (aOther.mPeriodicWave.WasPassed()) {
267 0 : mPeriodicWave.Construct(aOther.mPeriodicWave.Value());
268 : }
269 0 : mType = aOther.mType;
270 0 : return *this;
271 : }
272 :
273 : namespace binding_detail {
274 : } // namespace binding_detail
275 :
276 :
277 : namespace OscillatorNodeBinding {
278 :
279 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<AudioScheduledSourceNodeBinding::NativeType>::value,
280 : "Can't inherit from an interface with a different ownership model.");
281 :
282 : static bool
283 0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OscillatorNode* self, JSJitGetterCallArgs args)
284 : {
285 0 : OscillatorType result(self->Type());
286 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
287 0 : if (!ToJSValue(cx, result, args.rval())) {
288 0 : return false;
289 : }
290 0 : return true;
291 : }
292 :
293 : static bool
294 0 : set_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OscillatorNode* self, JSJitSetterCallArgs args)
295 : {
296 : OscillatorType arg0;
297 : {
298 : int index;
299 0 : if (!FindEnumStringIndex<false>(cx, args[0], OscillatorTypeValues::strings, "OscillatorType", "Value being assigned to OscillatorNode.type", &index)) {
300 0 : return false;
301 : }
302 0 : if (index < 0) {
303 0 : return true;
304 : }
305 0 : arg0 = static_cast<OscillatorType>(index);
306 : }
307 0 : binding_detail::FastErrorResult rv;
308 0 : self->SetType(arg0, rv);
309 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
310 0 : return false;
311 : }
312 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
313 :
314 0 : return true;
315 : }
316 :
317 : static const JSJitInfo type_getterinfo = {
318 : { (JSJitGetterOp)get_type },
319 : { prototypes::id::OscillatorNode },
320 : { PrototypeTraits<prototypes::id::OscillatorNode>::Depth },
321 : JSJitInfo::Getter,
322 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
323 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
324 : false, /* isInfallible. False in setters. */
325 : false, /* isMovable. Not relevant for setters. */
326 : false, /* isEliminatable. Not relevant for setters. */
327 : false, /* isAlwaysInSlot. Only relevant for getters. */
328 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
329 : false, /* isTypedMethod. Only relevant for methods. */
330 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
331 : };
332 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
333 : static_assert(0 < 1, "There is no slot for us");
334 : static const JSJitInfo type_setterinfo = {
335 : { (JSJitGetterOp)set_type },
336 : { prototypes::id::OscillatorNode },
337 : { PrototypeTraits<prototypes::id::OscillatorNode>::Depth },
338 : JSJitInfo::Setter,
339 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
340 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
341 : false, /* isInfallible. False in setters. */
342 : false, /* isMovable. Not relevant for setters. */
343 : false, /* isEliminatable. Not relevant for setters. */
344 : false, /* isAlwaysInSlot. Only relevant for getters. */
345 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
346 : false, /* isTypedMethod. Only relevant for methods. */
347 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
348 : };
349 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
350 : static_assert(0 < 1, "There is no slot for us");
351 :
352 : static bool
353 0 : get_frequency(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OscillatorNode* self, JSJitGetterCallArgs args)
354 : {
355 0 : auto result(StrongOrRawPtr<mozilla::dom::AudioParam>(self->Frequency()));
356 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
357 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
358 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
359 0 : return false;
360 : }
361 0 : return true;
362 : }
363 :
364 : static const JSJitInfo frequency_getterinfo = {
365 : { (JSJitGetterOp)get_frequency },
366 : { prototypes::id::OscillatorNode },
367 : { PrototypeTraits<prototypes::id::OscillatorNode>::Depth },
368 : JSJitInfo::Getter,
369 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
370 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
371 : false, /* isInfallible. False in setters. */
372 : false, /* isMovable. Not relevant for setters. */
373 : false, /* isEliminatable. Not relevant for setters. */
374 : false, /* isAlwaysInSlot. Only relevant for getters. */
375 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
376 : false, /* isTypedMethod. Only relevant for methods. */
377 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
378 : };
379 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
380 : static_assert(0 < 1, "There is no slot for us");
381 :
382 : static bool
383 0 : get_detune(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OscillatorNode* self, JSJitGetterCallArgs args)
384 : {
385 0 : auto result(StrongOrRawPtr<mozilla::dom::AudioParam>(self->Detune()));
386 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
387 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
388 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
389 0 : return false;
390 : }
391 0 : return true;
392 : }
393 :
394 : static const JSJitInfo detune_getterinfo = {
395 : { (JSJitGetterOp)get_detune },
396 : { prototypes::id::OscillatorNode },
397 : { PrototypeTraits<prototypes::id::OscillatorNode>::Depth },
398 : JSJitInfo::Getter,
399 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
400 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
401 : false, /* isInfallible. False in setters. */
402 : false, /* isMovable. Not relevant for setters. */
403 : false, /* isEliminatable. Not relevant for setters. */
404 : false, /* isAlwaysInSlot. Only relevant for getters. */
405 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
406 : false, /* isTypedMethod. Only relevant for methods. */
407 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
408 : };
409 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
410 : static_assert(0 < 1, "There is no slot for us");
411 :
412 : static bool
413 0 : setPeriodicWave(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OscillatorNode* self, const JSJitMethodCallArgs& args)
414 : {
415 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
416 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "OscillatorNode.setPeriodicWave");
417 : }
418 0 : NonNull<mozilla::dom::PeriodicWave> arg0;
419 0 : if (args[0].isObject()) {
420 : {
421 0 : nsresult rv = UnwrapObject<prototypes::id::PeriodicWave, mozilla::dom::PeriodicWave>(args[0], arg0);
422 0 : if (NS_FAILED(rv)) {
423 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of OscillatorNode.setPeriodicWave", "PeriodicWave");
424 0 : return false;
425 : }
426 : }
427 : } else {
428 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of OscillatorNode.setPeriodicWave");
429 0 : return false;
430 : }
431 0 : self->SetPeriodicWave(NonNullHelper(arg0));
432 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
433 0 : args.rval().setUndefined();
434 0 : return true;
435 : }
436 :
437 : static const JSJitInfo setPeriodicWave_methodinfo = {
438 : { (JSJitGetterOp)setPeriodicWave },
439 : { prototypes::id::OscillatorNode },
440 : { PrototypeTraits<prototypes::id::OscillatorNode>::Depth },
441 : JSJitInfo::Method,
442 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
443 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
444 : false, /* isInfallible. False in setters. */
445 : false, /* isMovable. Not relevant for setters. */
446 : false, /* isEliminatable. Not relevant for setters. */
447 : false, /* isAlwaysInSlot. Only relevant for getters. */
448 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
449 : false, /* isTypedMethod. Only relevant for methods. */
450 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
451 : };
452 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
453 : static_assert(0 < 1, "There is no slot for us");
454 :
455 : static bool
456 0 : get_passThrough(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OscillatorNode* self, JSJitGetterCallArgs args)
457 : {
458 0 : bool result(self->PassThrough());
459 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
460 0 : args.rval().setBoolean(result);
461 0 : return true;
462 : }
463 :
464 : static bool
465 0 : set_passThrough(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::OscillatorNode* self, JSJitSetterCallArgs args)
466 : {
467 : bool arg0;
468 0 : if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
469 0 : return false;
470 : }
471 0 : self->SetPassThrough(arg0);
472 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
473 :
474 0 : return true;
475 : }
476 :
477 : static const JSJitInfo passThrough_getterinfo = {
478 : { (JSJitGetterOp)get_passThrough },
479 : { prototypes::id::OscillatorNode },
480 : { PrototypeTraits<prototypes::id::OscillatorNode>::Depth },
481 : JSJitInfo::Getter,
482 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
483 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
484 : true, /* isInfallible. False in setters. */
485 : false, /* isMovable. Not relevant for setters. */
486 : false, /* isEliminatable. Not relevant for setters. */
487 : false, /* isAlwaysInSlot. Only relevant for getters. */
488 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
489 : false, /* isTypedMethod. Only relevant for methods. */
490 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
491 : };
492 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
493 : static_assert(0 < 1, "There is no slot for us");
494 : static const JSJitInfo passThrough_setterinfo = {
495 : { (JSJitGetterOp)set_passThrough },
496 : { prototypes::id::OscillatorNode },
497 : { PrototypeTraits<prototypes::id::OscillatorNode>::Depth },
498 : JSJitInfo::Setter,
499 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
500 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
501 : false, /* isInfallible. False in setters. */
502 : false, /* isMovable. Not relevant for setters. */
503 : false, /* isEliminatable. Not relevant for setters. */
504 : false, /* isAlwaysInSlot. Only relevant for getters. */
505 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
506 : false, /* isTypedMethod. Only relevant for methods. */
507 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
508 : };
509 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
510 : static_assert(0 < 1, "There is no slot for us");
511 :
512 : static bool
513 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
514 : {
515 0 : mozilla::dom::OscillatorNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OscillatorNode>(obj);
516 : // We don't want to preserve if we don't have a wrapper, and we
517 : // obviously can't preserve if we're not initialized.
518 0 : if (self && self->GetWrapperPreserveColor()) {
519 0 : PreserveWrapper(self);
520 : }
521 0 : return true;
522 : }
523 :
524 : static void
525 0 : _finalize(js::FreeOp* fop, JSObject* obj)
526 : {
527 0 : mozilla::dom::OscillatorNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OscillatorNode>(obj);
528 0 : if (self) {
529 0 : ClearWrapper(self, self, obj);
530 0 : AddForDeferredFinalization<mozilla::dom::OscillatorNode>(self);
531 : }
532 0 : }
533 :
534 : static void
535 0 : _objectMoved(JSObject* obj, const JSObject* old)
536 : {
537 0 : mozilla::dom::OscillatorNode* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::OscillatorNode>(obj);
538 0 : if (self) {
539 0 : UpdateWrapper(self, self, obj, old);
540 : }
541 0 : }
542 :
543 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
544 : #if defined(__clang__)
545 : #pragma clang diagnostic push
546 : #pragma clang diagnostic ignored "-Wmissing-braces"
547 : #endif
548 : static const JSFunctionSpec sMethods_specs[] = {
549 : JS_FNSPEC("setPeriodicWave", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setPeriodicWave_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
550 : JS_FS_END
551 : };
552 : #if defined(__clang__)
553 : #pragma clang diagnostic pop
554 : #endif
555 :
556 :
557 : // Can't be const because the pref-enabled boolean needs to be writable
558 : static Prefable<const JSFunctionSpec> sMethods[] = {
559 : { nullptr, &sMethods_specs[0] },
560 : { nullptr, nullptr }
561 : };
562 :
563 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
564 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
565 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
566 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
567 :
568 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
569 : #if defined(__clang__)
570 : #pragma clang diagnostic push
571 : #pragma clang diagnostic ignored "-Wmissing-braces"
572 : #endif
573 : static const JSPropertySpec sAttributes_specs[] = {
574 : { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, GenericBindingSetter, &type_setterinfo },
575 : { "frequency", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &frequency_getterinfo, nullptr, nullptr },
576 : { "detune", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &detune_getterinfo, nullptr, nullptr },
577 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
578 : };
579 : #if defined(__clang__)
580 : #pragma clang diagnostic pop
581 : #endif
582 :
583 :
584 : // Can't be const because the pref-enabled boolean needs to be writable
585 : static Prefable<const JSPropertySpec> sAttributes[] = {
586 : { nullptr, &sAttributes_specs[0] },
587 : { nullptr, nullptr }
588 : };
589 :
590 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
591 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
592 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
593 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
594 :
595 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
596 : #if defined(__clang__)
597 : #pragma clang diagnostic push
598 : #pragma clang diagnostic ignored "-Wmissing-braces"
599 : #endif
600 : static const JSPropertySpec sChromeAttributes_specs[] = {
601 : { "passThrough", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &passThrough_getterinfo, GenericBindingSetter, &passThrough_setterinfo },
602 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
603 : };
604 : #if defined(__clang__)
605 : #pragma clang diagnostic pop
606 : #endif
607 :
608 :
609 : // Can't be const because the pref-enabled boolean needs to be writable
610 : static Prefable<const JSPropertySpec> sChromeAttributes[] = {
611 : { nullptr, &sChromeAttributes_specs[0] },
612 : { nullptr, nullptr }
613 : };
614 :
615 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
616 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
617 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
618 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
619 :
620 :
621 : static uint16_t sNativeProperties_sortedPropertyIndices[4];
622 : static PropertyInfo sNativeProperties_propertyInfos[4];
623 :
624 : static const NativePropertiesN<2> sNativeProperties = {
625 : false, 0,
626 : false, 0,
627 : true, 0 /* sMethods */,
628 : true, 1 /* sAttributes */,
629 : false, 0,
630 : false, 0,
631 : false, 0,
632 : -1,
633 : 4,
634 : sNativeProperties_sortedPropertyIndices,
635 : {
636 : { sMethods, &sNativeProperties_propertyInfos[0] },
637 : { sAttributes, &sNativeProperties_propertyInfos[1] }
638 : }
639 : };
640 : static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
641 : "We have a property info count that is oversized");
642 :
643 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
644 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
645 :
646 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
647 : false, 0,
648 : false, 0,
649 : false, 0,
650 : true, 0 /* sChromeAttributes */,
651 : false, 0,
652 : false, 0,
653 : false, 0,
654 : -1,
655 : 1,
656 : sChromeOnlyNativeProperties_sortedPropertyIndices,
657 : {
658 : { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] }
659 : }
660 : };
661 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
662 : "We have a property info count that is oversized");
663 :
664 : static bool
665 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
666 : {
667 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
668 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
669 0 : if (!args.isConstructing()) {
670 : // XXXbz wish I could get the name from the callee instead of
671 : // Adding more relocations
672 0 : return ThrowConstructorWithoutNew(cx, "OscillatorNode");
673 : }
674 :
675 0 : GlobalObject global(cx, obj);
676 0 : if (global.Failed()) {
677 0 : return false;
678 : }
679 :
680 0 : JS::Rooted<JSObject*> desiredProto(cx);
681 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
682 0 : return false;
683 : }
684 :
685 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
686 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "OscillatorNode");
687 : }
688 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
689 0 : NonNull<mozilla::dom::AudioContext> arg0;
690 0 : if (args[0].isObject()) {
691 : {
692 0 : nsresult rv = UnwrapObject<prototypes::id::BaseAudioContext, mozilla::dom::AudioContext>(args[0], arg0);
693 0 : if (NS_FAILED(rv)) {
694 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of OscillatorNode.constructor", "BaseAudioContext");
695 0 : return false;
696 : }
697 : }
698 : } else {
699 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of OscillatorNode.constructor");
700 0 : return false;
701 : }
702 0 : binding_detail::FastOscillatorOptions arg1;
703 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of OscillatorNode.constructor", false)) {
704 0 : return false;
705 : }
706 0 : Maybe<JSAutoCompartment> ac;
707 0 : if (objIsXray) {
708 0 : obj = js::CheckedUnwrap(obj);
709 0 : if (!obj) {
710 0 : return false;
711 : }
712 0 : ac.emplace(cx, obj);
713 0 : if (!JS_WrapObject(cx, &desiredProto)) {
714 0 : return false;
715 : }
716 : }
717 0 : binding_detail::FastErrorResult rv;
718 0 : auto result(StrongOrRawPtr<mozilla::dom::OscillatorNode>(mozilla::dom::OscillatorNode::Constructor(global, NonNullHelper(arg0), Constify(arg1), rv)));
719 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
720 0 : return false;
721 : }
722 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
723 : static_assert(!IsPointer<decltype(result)>::value,
724 : "NewObject implies that we need to keep the object alive with a strong reference.");
725 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
726 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
727 0 : return false;
728 : }
729 0 : return true;
730 : }
731 :
732 : static const js::ClassOps sInterfaceObjectClassOps = {
733 : nullptr, /* addProperty */
734 : nullptr, /* delProperty */
735 : nullptr, /* getProperty */
736 : nullptr, /* setProperty */
737 : nullptr, /* enumerate */
738 : nullptr, /* newEnumerate */
739 : nullptr, /* resolve */
740 : nullptr, /* mayResolve */
741 : nullptr, /* finalize */
742 : _constructor, /* call */
743 : nullptr, /* hasInstance */
744 : _constructor, /* construct */
745 : nullptr, /* trace */
746 : };
747 :
748 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
749 : {
750 : "Function",
751 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
752 : &sInterfaceObjectClassOps,
753 : JS_NULL_CLASS_SPEC,
754 : JS_NULL_CLASS_EXT,
755 : &sInterfaceObjectClassObjectOps
756 : },
757 : eInterface,
758 : true,
759 : prototypes::id::OscillatorNode,
760 : PrototypeTraits<prototypes::id::OscillatorNode>::Depth,
761 : sNativePropertyHooks,
762 : "function OscillatorNode() {\n [native code]\n}",
763 : AudioScheduledSourceNodeBinding::GetConstructorObject
764 : };
765 :
766 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
767 : {
768 : "OscillatorNodePrototype",
769 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
770 : JS_NULL_CLASS_OPS,
771 : JS_NULL_CLASS_SPEC,
772 : JS_NULL_CLASS_EXT,
773 : JS_NULL_OBJECT_OPS
774 : },
775 : eInterfacePrototype,
776 : false,
777 : prototypes::id::OscillatorNode,
778 : PrototypeTraits<prototypes::id::OscillatorNode>::Depth,
779 : sNativePropertyHooks,
780 : "[object OscillatorNodePrototype]",
781 : AudioScheduledSourceNodeBinding::GetProtoObject
782 : };
783 :
784 : bool
785 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
786 : {
787 : static bool sPrefValue;
788 : static bool sPrefCacheSetUp = false;
789 0 : if (!sPrefCacheSetUp) {
790 0 : sPrefCacheSetUp = true;
791 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.webaudio.enabled");
792 : }
793 :
794 0 : return sPrefValue;
795 : }
796 :
797 : JSObject*
798 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
799 : {
800 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
801 : }
802 :
803 : static const js::ClassOps sClassOps = {
804 : _addProperty, /* addProperty */
805 : nullptr, /* delProperty */
806 : nullptr, /* getProperty */
807 : nullptr, /* setProperty */
808 : nullptr, /* enumerate */
809 : nullptr, /* newEnumerate */
810 : nullptr, /* resolve */
811 : nullptr, /* mayResolve */
812 : _finalize, /* finalize */
813 : nullptr, /* call */
814 : nullptr, /* hasInstance */
815 : nullptr, /* construct */
816 : nullptr, /* trace */
817 : };
818 :
819 : static const js::ClassExtension sClassExtension = {
820 : nullptr, /* weakmapKeyDelegateOp */
821 : _objectMoved /* objectMovedOp */
822 : };
823 :
824 : static const DOMJSClass sClass = {
825 : { "OscillatorNode",
826 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
827 : &sClassOps,
828 : JS_NULL_CLASS_SPEC,
829 : &sClassExtension,
830 : JS_NULL_OBJECT_OPS
831 : },
832 : { prototypes::id::EventTarget, prototypes::id::AudioNode, prototypes::id::AudioScheduledSourceNode, prototypes::id::OscillatorNode, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
833 : IsBaseOf<nsISupports, mozilla::dom::OscillatorNode >::value,
834 : sNativePropertyHooks,
835 : FindAssociatedGlobalForNative<mozilla::dom::OscillatorNode>::Get,
836 : GetProtoObjectHandle,
837 : GetCCParticipant<mozilla::dom::OscillatorNode>::Get()
838 : };
839 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
840 : "Must have the right minimal number of reserved slots.");
841 : static_assert(1 >= 1,
842 : "Must have enough reserved slots.");
843 :
844 : const JSClass*
845 0 : GetJSClass()
846 : {
847 0 : return sClass.ToJSClass();
848 : }
849 :
850 : bool
851 0 : Wrap(JSContext* aCx, mozilla::dom::OscillatorNode* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
852 : {
853 : MOZ_ASSERT(static_cast<mozilla::dom::OscillatorNode*>(aObject) ==
854 : reinterpret_cast<mozilla::dom::OscillatorNode*>(aObject),
855 : "Multiple inheritance for mozilla::dom::OscillatorNode is broken.");
856 : MOZ_ASSERT(static_cast<mozilla::dom::AudioScheduledSourceNode*>(aObject) ==
857 : reinterpret_cast<mozilla::dom::AudioScheduledSourceNode*>(aObject),
858 : "Multiple inheritance for mozilla::dom::AudioScheduledSourceNode is broken.");
859 : MOZ_ASSERT(static_cast<mozilla::dom::AudioNode*>(aObject) ==
860 : reinterpret_cast<mozilla::dom::AudioNode*>(aObject),
861 : "Multiple inheritance for mozilla::dom::AudioNode is broken.");
862 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
863 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
864 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
865 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
866 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
867 0 : MOZ_ASSERT(!aCache->GetWrapper(),
868 : "You should probably not be using Wrap() directly; use "
869 : "GetOrCreateDOMReflector instead");
870 :
871 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
872 : "nsISupports must be on our primary inheritance chain");
873 :
874 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
875 0 : if (!global) {
876 0 : return false;
877 : }
878 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
879 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
880 :
881 : // That might have ended up wrapping us already, due to the wonders
882 : // of XBL. Check for that, and bail out as needed.
883 0 : aReflector.set(aCache->GetWrapper());
884 0 : if (aReflector) {
885 : #ifdef DEBUG
886 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
887 : #endif // DEBUG
888 0 : return true;
889 : }
890 :
891 0 : JSAutoCompartment ac(aCx, global);
892 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
893 0 : if (!canonicalProto) {
894 0 : return false;
895 : }
896 0 : JS::Rooted<JSObject*> proto(aCx);
897 0 : if (aGivenProto) {
898 0 : proto = aGivenProto;
899 : // Unfortunately, while aGivenProto was in the compartment of aCx
900 : // coming in, we changed compartments to that of "parent" so may need
901 : // to wrap the proto here.
902 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
903 0 : if (!JS_WrapObject(aCx, &proto)) {
904 0 : return false;
905 : }
906 : }
907 : } else {
908 0 : proto = canonicalProto;
909 : }
910 :
911 0 : BindingJSObjectCreator<mozilla::dom::OscillatorNode> creator(aCx);
912 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
913 0 : if (!aReflector) {
914 0 : return false;
915 : }
916 :
917 0 : aCache->SetWrapper(aReflector);
918 0 : creator.InitializationSucceeded();
919 :
920 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
921 : aCache->GetWrapperPreserveColor() == aReflector);
922 : // If proto != canonicalProto, we have to preserve our wrapper;
923 : // otherwise we won't be able to properly recreate it later, since
924 : // we won't know what proto to use. Note that we don't check
925 : // aGivenProto here, since it's entirely possible (and even
926 : // somewhat common) to have a non-null aGivenProto which is the
927 : // same as canonicalProto.
928 0 : if (proto != canonicalProto) {
929 0 : PreserveWrapper(aObject);
930 : }
931 :
932 0 : return true;
933 : }
934 :
935 : const NativePropertyHooks sNativePropertyHooks[] = { {
936 : nullptr,
937 : nullptr,
938 : nullptr,
939 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
940 : prototypes::id::OscillatorNode,
941 : constructors::id::OscillatorNode,
942 : AudioScheduledSourceNodeBinding::sNativePropertyHooks,
943 : &DefaultXrayExpandoObjectClass
944 : } };
945 :
946 : void
947 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
948 : {
949 0 : JS::Handle<JSObject*> parentProto(AudioScheduledSourceNodeBinding::GetProtoObjectHandle(aCx));
950 0 : if (!parentProto) {
951 0 : return;
952 : }
953 :
954 0 : JS::Handle<JSObject*> constructorProto(AudioScheduledSourceNodeBinding::GetConstructorObjectHandle(aCx));
955 0 : if (!constructorProto) {
956 0 : return;
957 : }
958 :
959 : static bool sIdsInited = false;
960 0 : if (!sIdsInited && NS_IsMainThread()) {
961 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
962 0 : return;
963 : }
964 0 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
965 0 : return;
966 : }
967 0 : sIdsInited = true;
968 : }
969 :
970 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::OscillatorNode);
971 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::OscillatorNode);
972 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
973 : &sPrototypeClass.mBase, protoCache,
974 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
975 : interfaceCache,
976 : sNativeProperties.Upcast(),
977 0 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
978 : "OscillatorNode", aDefineOnGlobal,
979 : nullptr,
980 0 : false);
981 : }
982 :
983 : JS::Handle<JSObject*>
984 0 : GetProtoObjectHandle(JSContext* aCx)
985 : {
986 : /* Get the interface prototype object for this class. This will create the
987 : object as needed. */
988 0 : bool aDefineOnGlobal = true;
989 :
990 : /* Make sure our global is sane. Hopefully we can remove this sometime */
991 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
992 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
993 0 : return nullptr;
994 : }
995 :
996 : /* Check to see whether the interface objects are already installed */
997 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
998 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::OscillatorNode)) {
999 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1000 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1001 : }
1002 :
1003 : /*
1004 : * The object might _still_ be null, but that's OK.
1005 : *
1006 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1007 : * traced by TraceProtoAndIfaceCache() and its contents are never
1008 : * changed after they have been set.
1009 : *
1010 : * Calling address() avoids the read read barrier that does gray
1011 : * unmarking, but it's not possible for the object to be gray here.
1012 : */
1013 :
1014 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::OscillatorNode);
1015 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1016 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1017 : }
1018 :
1019 : JS::Handle<JSObject*>
1020 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1021 : {
1022 : /* Get the interface object for this class. This will create the object as
1023 : needed. */
1024 :
1025 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1026 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1027 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1028 0 : return nullptr;
1029 : }
1030 :
1031 : /* Check to see whether the interface objects are already installed */
1032 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1033 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::OscillatorNode)) {
1034 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1035 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1036 : }
1037 :
1038 : /*
1039 : * The object might _still_ be null, but that's OK.
1040 : *
1041 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1042 : * traced by TraceProtoAndIfaceCache() and its contents are never
1043 : * changed after they have been set.
1044 : *
1045 : * Calling address() avoids the read read barrier that does gray
1046 : * unmarking, but it's not possible for the object to be gray here.
1047 : */
1048 :
1049 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::OscillatorNode);
1050 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1051 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1052 : }
1053 :
1054 : JSObject*
1055 0 : GetConstructorObject(JSContext* aCx)
1056 : {
1057 0 : return GetConstructorObjectHandle(aCx);
1058 : }
1059 :
1060 : } // namespace OscillatorNodeBinding
1061 :
1062 :
1063 :
1064 : } // namespace dom
1065 : } // namespace mozilla
|