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