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