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