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