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