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