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