/work/obj-fuzz/dom/bindings/SpeechSynthesisBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM SpeechSynthesis.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "SpeechSynthesisBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/Preferences.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/Nullable.h" |
13 | | #include "mozilla/dom/PrimitiveConversions.h" |
14 | | #include "mozilla/dom/SpeechSynthesis.h" |
15 | | #include "mozilla/dom/SpeechSynthesisUtterance.h" |
16 | | #include "mozilla/dom/SpeechSynthesisVoice.h" |
17 | | #include "mozilla/dom/XrayExpandoClass.h" |
18 | | #include "nsContentUtils.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 SpeechSynthesis_Binding { |
28 | | |
29 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
30 | | "Can't inherit from an interface with a different ownership model."); |
31 | | |
32 | | MOZ_CAN_RUN_SCRIPT static bool |
33 | | get_pending(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, JSJitGetterCallArgs args) |
34 | 0 | { |
35 | 0 | AUTO_PROFILER_LABEL_FAST("get SpeechSynthesis.pending", DOM, cx); |
36 | 0 |
|
37 | 0 | bool result(self->Pending()); |
38 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
39 | 0 | args.rval().setBoolean(result); |
40 | 0 | return true; |
41 | 0 | } |
42 | | |
43 | | static const JSJitInfo pending_getterinfo = { |
44 | | { (JSJitGetterOp)get_pending }, |
45 | | { prototypes::id::SpeechSynthesis }, |
46 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
47 | | JSJitInfo::Getter, |
48 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
49 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
50 | | true, /* isInfallible. False in setters. */ |
51 | | false, /* isMovable. Not relevant for setters. */ |
52 | | false, /* isEliminatable. Not relevant for setters. */ |
53 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
54 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
55 | | false, /* isTypedMethod. Only relevant for methods. */ |
56 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
57 | | }; |
58 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
59 | | static_assert(0 < 1, "There is no slot for us"); |
60 | | |
61 | | MOZ_CAN_RUN_SCRIPT static bool |
62 | | get_speaking(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, JSJitGetterCallArgs args) |
63 | 0 | { |
64 | 0 | AUTO_PROFILER_LABEL_FAST("get SpeechSynthesis.speaking", DOM, cx); |
65 | 0 |
|
66 | 0 | bool result(self->Speaking()); |
67 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
68 | 0 | args.rval().setBoolean(result); |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | | static const JSJitInfo speaking_getterinfo = { |
73 | | { (JSJitGetterOp)get_speaking }, |
74 | | { prototypes::id::SpeechSynthesis }, |
75 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
76 | | JSJitInfo::Getter, |
77 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
78 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
79 | | true, /* isInfallible. False in setters. */ |
80 | | false, /* isMovable. Not relevant for setters. */ |
81 | | false, /* isEliminatable. Not relevant for setters. */ |
82 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
83 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
84 | | false, /* isTypedMethod. Only relevant for methods. */ |
85 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
86 | | }; |
87 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
88 | | static_assert(0 < 1, "There is no slot for us"); |
89 | | |
90 | | MOZ_CAN_RUN_SCRIPT static bool |
91 | | get_paused(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, JSJitGetterCallArgs args) |
92 | 0 | { |
93 | 0 | AUTO_PROFILER_LABEL_FAST("get SpeechSynthesis.paused", DOM, cx); |
94 | 0 |
|
95 | 0 | bool result(self->Paused()); |
96 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
97 | 0 | args.rval().setBoolean(result); |
98 | 0 | return true; |
99 | 0 | } |
100 | | |
101 | | static const JSJitInfo paused_getterinfo = { |
102 | | { (JSJitGetterOp)get_paused }, |
103 | | { prototypes::id::SpeechSynthesis }, |
104 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
105 | | JSJitInfo::Getter, |
106 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
107 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
108 | | true, /* isInfallible. False in setters. */ |
109 | | false, /* isMovable. Not relevant for setters. */ |
110 | | false, /* isEliminatable. Not relevant for setters. */ |
111 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
112 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
113 | | false, /* isTypedMethod. Only relevant for methods. */ |
114 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
115 | | }; |
116 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
117 | | static_assert(0 < 1, "There is no slot for us"); |
118 | | |
119 | | MOZ_CAN_RUN_SCRIPT static bool |
120 | | speak(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, const JSJitMethodCallArgs& args) |
121 | 0 | { |
122 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechSynthesis.speak", DOM, cx); |
123 | 0 |
|
124 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
125 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "SpeechSynthesis.speak"); |
126 | 0 | } |
127 | 0 | NonNull<mozilla::dom::SpeechSynthesisUtterance> arg0; |
128 | 0 | if (args[0].isObject()) { |
129 | 0 | { |
130 | 0 | nsresult rv = UnwrapObject<prototypes::id::SpeechSynthesisUtterance, mozilla::dom::SpeechSynthesisUtterance>(args[0], arg0); |
131 | 0 | if (NS_FAILED(rv)) { |
132 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of SpeechSynthesis.speak", "SpeechSynthesisUtterance"); |
133 | 0 | return false; |
134 | 0 | } |
135 | 0 | } |
136 | 0 | } else { |
137 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of SpeechSynthesis.speak"); |
138 | 0 | return false; |
139 | 0 | } |
140 | 0 | self->Speak(MOZ_KnownLive(NonNullHelper(arg0))); |
141 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
142 | 0 | args.rval().setUndefined(); |
143 | 0 | return true; |
144 | 0 | } |
145 | | |
146 | | static const JSJitInfo speak_methodinfo = { |
147 | | { (JSJitGetterOp)speak }, |
148 | | { prototypes::id::SpeechSynthesis }, |
149 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
150 | | JSJitInfo::Method, |
151 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
152 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
153 | | false, /* isInfallible. False in setters. */ |
154 | | false, /* isMovable. Not relevant for setters. */ |
155 | | false, /* isEliminatable. Not relevant for setters. */ |
156 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
157 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
158 | | false, /* isTypedMethod. Only relevant for methods. */ |
159 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
160 | | }; |
161 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
162 | | static_assert(0 < 1, "There is no slot for us"); |
163 | | |
164 | | MOZ_CAN_RUN_SCRIPT static bool |
165 | | cancel(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, const JSJitMethodCallArgs& args) |
166 | 0 | { |
167 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechSynthesis.cancel", DOM, cx); |
168 | 0 |
|
169 | 0 | self->Cancel(); |
170 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
171 | 0 | args.rval().setUndefined(); |
172 | 0 | return true; |
173 | 0 | } |
174 | | |
175 | | static const JSJitInfo cancel_methodinfo = { |
176 | | { (JSJitGetterOp)cancel }, |
177 | | { prototypes::id::SpeechSynthesis }, |
178 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
179 | | JSJitInfo::Method, |
180 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
181 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
182 | | true, /* isInfallible. False in setters. */ |
183 | | false, /* isMovable. Not relevant for setters. */ |
184 | | false, /* isEliminatable. Not relevant for setters. */ |
185 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
186 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
187 | | false, /* isTypedMethod. Only relevant for methods. */ |
188 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
189 | | }; |
190 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
191 | | static_assert(0 < 1, "There is no slot for us"); |
192 | | |
193 | | MOZ_CAN_RUN_SCRIPT static bool |
194 | | pause(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, const JSJitMethodCallArgs& args) |
195 | 0 | { |
196 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechSynthesis.pause", DOM, cx); |
197 | 0 |
|
198 | 0 | self->Pause(); |
199 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
200 | 0 | args.rval().setUndefined(); |
201 | 0 | return true; |
202 | 0 | } |
203 | | |
204 | | static const JSJitInfo pause_methodinfo = { |
205 | | { (JSJitGetterOp)pause }, |
206 | | { prototypes::id::SpeechSynthesis }, |
207 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
208 | | JSJitInfo::Method, |
209 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
210 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
211 | | true, /* isInfallible. False in setters. */ |
212 | | false, /* isMovable. Not relevant for setters. */ |
213 | | false, /* isEliminatable. Not relevant for setters. */ |
214 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
215 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
216 | | false, /* isTypedMethod. Only relevant for methods. */ |
217 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
218 | | }; |
219 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
220 | | static_assert(0 < 1, "There is no slot for us"); |
221 | | |
222 | | MOZ_CAN_RUN_SCRIPT static bool |
223 | | resume(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, const JSJitMethodCallArgs& args) |
224 | 0 | { |
225 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechSynthesis.resume", DOM, cx); |
226 | 0 |
|
227 | 0 | self->Resume(); |
228 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
229 | 0 | args.rval().setUndefined(); |
230 | 0 | return true; |
231 | 0 | } |
232 | | |
233 | | static const JSJitInfo resume_methodinfo = { |
234 | | { (JSJitGetterOp)resume }, |
235 | | { prototypes::id::SpeechSynthesis }, |
236 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
237 | | JSJitInfo::Method, |
238 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
239 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
240 | | true, /* isInfallible. False in setters. */ |
241 | | false, /* isMovable. Not relevant for setters. */ |
242 | | false, /* isEliminatable. Not relevant for setters. */ |
243 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
244 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
245 | | false, /* isTypedMethod. Only relevant for methods. */ |
246 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
247 | | }; |
248 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
249 | | static_assert(0 < 1, "There is no slot for us"); |
250 | | |
251 | | MOZ_CAN_RUN_SCRIPT static bool |
252 | | getVoices(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, const JSJitMethodCallArgs& args) |
253 | 0 | { |
254 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechSynthesis.getVoices", DOM, cx); |
255 | 0 |
|
256 | 0 | nsTArray<StrongPtrForMember<mozilla::dom::SpeechSynthesisVoice>::Type> result; |
257 | 0 | self->GetVoices(result); |
258 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
259 | 0 |
|
260 | 0 | uint32_t length = result.Length(); |
261 | 0 | JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length)); |
262 | 0 | if (!returnArray) { |
263 | 0 | return false; |
264 | 0 | } |
265 | 0 | // Scope for 'tmp' |
266 | 0 | { |
267 | 0 | JS::Rooted<JS::Value> tmp(cx); |
268 | 0 | for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) { |
269 | 0 | // Control block to let us common up the JS_DefineElement calls when there |
270 | 0 | // are different ways to succeed at wrapping the object. |
271 | 0 | do { |
272 | 0 | if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) { |
273 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
274 | 0 | return false; |
275 | 0 | } |
276 | 0 | break; |
277 | 0 | } while (false); |
278 | 0 | if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp, |
279 | 0 | JSPROP_ENUMERATE)) { |
280 | 0 | return false; |
281 | 0 | } |
282 | 0 | } |
283 | 0 | } |
284 | 0 | args.rval().setObject(*returnArray); |
285 | 0 | return true; |
286 | 0 | } |
287 | | |
288 | | static const JSJitInfo getVoices_methodinfo = { |
289 | | { (JSJitGetterOp)getVoices }, |
290 | | { prototypes::id::SpeechSynthesis }, |
291 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
292 | | JSJitInfo::Method, |
293 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
294 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
295 | | false, /* isInfallible. False in setters. */ |
296 | | false, /* isMovable. Not relevant for setters. */ |
297 | | false, /* isEliminatable. Not relevant for setters. */ |
298 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
299 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
300 | | false, /* isTypedMethod. Only relevant for methods. */ |
301 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
302 | | }; |
303 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
304 | | static_assert(0 < 1, "There is no slot for us"); |
305 | | |
306 | | MOZ_CAN_RUN_SCRIPT static bool |
307 | | get_onvoiceschanged(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, JSJitGetterCallArgs args) |
308 | 0 | { |
309 | 0 | AUTO_PROFILER_LABEL_FAST("get SpeechSynthesis.onvoiceschanged", DOM, cx); |
310 | 0 |
|
311 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnvoiceschanged()); |
312 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
313 | 0 | if (result) { |
314 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
315 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
316 | 0 | return false; |
317 | 0 | } |
318 | 0 | return true; |
319 | 0 | } else { |
320 | 0 | args.rval().setNull(); |
321 | 0 | return true; |
322 | 0 | } |
323 | 0 | } |
324 | | |
325 | | MOZ_CAN_RUN_SCRIPT static bool |
326 | | set_onvoiceschanged(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, JSJitSetterCallArgs args) |
327 | 0 | { |
328 | 0 | AUTO_PROFILER_LABEL_FAST("set SpeechSynthesis.onvoiceschanged", DOM, cx); |
329 | 0 |
|
330 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
331 | 0 | if (args[0].isObject()) { |
332 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
333 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
334 | 0 | } |
335 | 0 | } else { |
336 | 0 | arg0 = nullptr; |
337 | 0 | } |
338 | 0 | self->SetOnvoiceschanged(Constify(arg0)); |
339 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
340 | 0 |
|
341 | 0 | return true; |
342 | 0 | } |
343 | | |
344 | | static const JSJitInfo onvoiceschanged_getterinfo = { |
345 | | { (JSJitGetterOp)get_onvoiceschanged }, |
346 | | { prototypes::id::SpeechSynthesis }, |
347 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
348 | | JSJitInfo::Getter, |
349 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
350 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
351 | | false, /* isInfallible. False in setters. */ |
352 | | false, /* isMovable. Not relevant for setters. */ |
353 | | false, /* isEliminatable. Not relevant for setters. */ |
354 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
355 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
356 | | false, /* isTypedMethod. Only relevant for methods. */ |
357 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
358 | | }; |
359 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
360 | | static_assert(0 < 1, "There is no slot for us"); |
361 | | static const JSJitInfo onvoiceschanged_setterinfo = { |
362 | | { (JSJitGetterOp)set_onvoiceschanged }, |
363 | | { prototypes::id::SpeechSynthesis }, |
364 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
365 | | JSJitInfo::Setter, |
366 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
367 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
368 | | false, /* isInfallible. False in setters. */ |
369 | | false, /* isMovable. Not relevant for setters. */ |
370 | | false, /* isEliminatable. Not relevant for setters. */ |
371 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
372 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
373 | | false, /* isTypedMethod. Only relevant for methods. */ |
374 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
375 | | }; |
376 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
377 | | static_assert(0 < 1, "There is no slot for us"); |
378 | | |
379 | | MOZ_CAN_RUN_SCRIPT static bool |
380 | | forceEnd(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechSynthesis* self, const JSJitMethodCallArgs& args) |
381 | 0 | { |
382 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechSynthesis.forceEnd", DOM, cx); |
383 | 0 |
|
384 | 0 | self->ForceEnd(); |
385 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
386 | 0 | args.rval().setUndefined(); |
387 | 0 | return true; |
388 | 0 | } |
389 | | |
390 | | static const JSJitInfo forceEnd_methodinfo = { |
391 | | { (JSJitGetterOp)forceEnd }, |
392 | | { prototypes::id::SpeechSynthesis }, |
393 | | { PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth }, |
394 | | JSJitInfo::Method, |
395 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
396 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
397 | | true, /* isInfallible. False in setters. */ |
398 | | false, /* isMovable. Not relevant for setters. */ |
399 | | false, /* isEliminatable. Not relevant for setters. */ |
400 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
401 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
402 | | false, /* isTypedMethod. Only relevant for methods. */ |
403 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
404 | | }; |
405 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
406 | | static_assert(0 < 1, "There is no slot for us"); |
407 | | |
408 | | static bool |
409 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
410 | 0 | { |
411 | 0 | mozilla::dom::SpeechSynthesis* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechSynthesis>(obj); |
412 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
413 | 0 | // obviously can't preserve if we're not initialized. |
414 | 0 | if (self && self->GetWrapperPreserveColor()) { |
415 | 0 | PreserveWrapper(self); |
416 | 0 | } |
417 | 0 | return true; |
418 | 0 | } |
419 | | |
420 | | static void |
421 | | _finalize(js::FreeOp* fop, JSObject* obj) |
422 | 0 | { |
423 | 0 | mozilla::dom::SpeechSynthesis* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechSynthesis>(obj); |
424 | 0 | if (self) { |
425 | 0 | ClearWrapper(self, self, obj); |
426 | 0 | AddForDeferredFinalization<mozilla::dom::SpeechSynthesis>(self); |
427 | 0 | } |
428 | 0 | } |
429 | | |
430 | | static size_t |
431 | | _objectMoved(JSObject* obj, JSObject* old) |
432 | 0 | { |
433 | 0 | mozilla::dom::SpeechSynthesis* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechSynthesis>(obj); |
434 | 0 | if (self) { |
435 | 0 | UpdateWrapper(self, self, obj, old); |
436 | 0 | } |
437 | 0 |
|
438 | 0 | return 0; |
439 | 0 | } |
440 | | |
441 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
442 | | #if defined(__clang__) |
443 | | #pragma clang diagnostic push |
444 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
445 | | #endif |
446 | | static const JSFunctionSpec sMethods_specs[] = { |
447 | | JS_FNSPEC("speak", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&speak_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
448 | | JS_FNSPEC("cancel", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&cancel_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
449 | | JS_FNSPEC("pause", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&pause_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
450 | | JS_FNSPEC("resume", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&resume_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
451 | | JS_FNSPEC("getVoices", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getVoices_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
452 | | JS_FS_END |
453 | | }; |
454 | | #if defined(__clang__) |
455 | | #pragma clang diagnostic pop |
456 | | #endif |
457 | | |
458 | | |
459 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
460 | | { nullptr, &sMethods_specs[0] }, |
461 | | { nullptr, nullptr } |
462 | | }; |
463 | | |
464 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
465 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
466 | | static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
467 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
468 | | |
469 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
470 | | #if defined(__clang__) |
471 | | #pragma clang diagnostic push |
472 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
473 | | #endif |
474 | | static const JSFunctionSpec sChromeMethods_specs[] = { |
475 | | JS_FNSPEC("forceEnd", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&forceEnd_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
476 | | JS_FS_END |
477 | | }; |
478 | | #if defined(__clang__) |
479 | | #pragma clang diagnostic pop |
480 | | #endif |
481 | | |
482 | | |
483 | | static const Prefable<const JSFunctionSpec> sChromeMethods[] = { |
484 | | { nullptr, &sChromeMethods_specs[0] }, |
485 | | { nullptr, nullptr } |
486 | | }; |
487 | | |
488 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
489 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
490 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
491 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
492 | | |
493 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
494 | | #if defined(__clang__) |
495 | | #pragma clang diagnostic push |
496 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
497 | | #endif |
498 | | static const JSPropertySpec sAttributes_specs[] = { |
499 | | { "pending", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pending_getterinfo, nullptr, nullptr }, |
500 | | { "speaking", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &speaking_getterinfo, nullptr, nullptr }, |
501 | | { "paused", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &paused_getterinfo, nullptr, nullptr }, |
502 | | { "onvoiceschanged", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onvoiceschanged_getterinfo, GenericSetter<NormalThisPolicy>, &onvoiceschanged_setterinfo }, |
503 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
504 | | }; |
505 | | #if defined(__clang__) |
506 | | #pragma clang diagnostic pop |
507 | | #endif |
508 | | |
509 | | |
510 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
511 | | { nullptr, &sAttributes_specs[0] }, |
512 | | { nullptr, nullptr } |
513 | | }; |
514 | | |
515 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
516 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
517 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
518 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
519 | | |
520 | | |
521 | | static uint16_t sNativeProperties_sortedPropertyIndices[9]; |
522 | | static PropertyInfo sNativeProperties_propertyInfos[9]; |
523 | | |
524 | | static const NativePropertiesN<2> sNativeProperties = { |
525 | | false, 0, |
526 | | false, 0, |
527 | | true, 0 /* sMethods */, |
528 | | true, 1 /* sAttributes */, |
529 | | false, 0, |
530 | | false, 0, |
531 | | false, 0, |
532 | | -1, |
533 | | 9, |
534 | | sNativeProperties_sortedPropertyIndices, |
535 | | { |
536 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
537 | | { sAttributes, &sNativeProperties_propertyInfos[5] } |
538 | | } |
539 | | }; |
540 | | static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
541 | | "We have a property info count that is oversized"); |
542 | | |
543 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1]; |
544 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1]; |
545 | | |
546 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
547 | | false, 0, |
548 | | false, 0, |
549 | | true, 0 /* sChromeMethods */, |
550 | | false, 0, |
551 | | false, 0, |
552 | | false, 0, |
553 | | false, 0, |
554 | | -1, |
555 | | 1, |
556 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
557 | | { |
558 | | { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] } |
559 | | } |
560 | | }; |
561 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
562 | | "We have a property info count that is oversized"); |
563 | | |
564 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
565 | | { |
566 | | "Function", |
567 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
568 | | &sBoringInterfaceObjectClassClassOps, |
569 | | JS_NULL_CLASS_SPEC, |
570 | | JS_NULL_CLASS_EXT, |
571 | | &sInterfaceObjectClassObjectOps |
572 | | }, |
573 | | eInterface, |
574 | | true, |
575 | | prototypes::id::SpeechSynthesis, |
576 | | PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth, |
577 | | sNativePropertyHooks, |
578 | | "function SpeechSynthesis() {\n [native code]\n}", |
579 | | EventTarget_Binding::GetConstructorObject |
580 | | }; |
581 | | |
582 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
583 | | { |
584 | | "SpeechSynthesisPrototype", |
585 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
586 | | JS_NULL_CLASS_OPS, |
587 | | JS_NULL_CLASS_SPEC, |
588 | | JS_NULL_CLASS_EXT, |
589 | | JS_NULL_OBJECT_OPS |
590 | | }, |
591 | | eInterfacePrototype, |
592 | | false, |
593 | | prototypes::id::SpeechSynthesis, |
594 | | PrototypeTraits<prototypes::id::SpeechSynthesis>::Depth, |
595 | | sNativePropertyHooks, |
596 | | "[object SpeechSynthesisPrototype]", |
597 | | EventTarget_Binding::GetProtoObject |
598 | | }; |
599 | | |
600 | | bool |
601 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
602 | 0 | { |
603 | 0 | static bool sPrefValue; |
604 | 0 | static bool sPrefCacheSetUp = false; |
605 | 0 | if (!sPrefCacheSetUp) { |
606 | 0 | sPrefCacheSetUp = true; |
607 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "media.webspeech.synth.enabled"); |
608 | 0 | } |
609 | 0 |
|
610 | 0 | return sPrefValue; |
611 | 0 | } |
612 | | |
613 | | static const js::ClassOps sClassOps = { |
614 | | _addProperty, /* addProperty */ |
615 | | nullptr, /* delProperty */ |
616 | | nullptr, /* enumerate */ |
617 | | nullptr, /* newEnumerate */ |
618 | | nullptr, /* resolve */ |
619 | | nullptr, /* mayResolve */ |
620 | | _finalize, /* finalize */ |
621 | | nullptr, /* call */ |
622 | | nullptr, /* hasInstance */ |
623 | | nullptr, /* construct */ |
624 | | nullptr, /* trace */ |
625 | | }; |
626 | | |
627 | | static const js::ClassExtension sClassExtension = { |
628 | | nullptr, /* weakmapKeyDelegateOp */ |
629 | | _objectMoved /* objectMovedOp */ |
630 | | }; |
631 | | |
632 | | static const DOMJSClass sClass = { |
633 | | { "SpeechSynthesis", |
634 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
635 | | &sClassOps, |
636 | | JS_NULL_CLASS_SPEC, |
637 | | &sClassExtension, |
638 | | JS_NULL_OBJECT_OPS |
639 | | }, |
640 | | { prototypes::id::EventTarget, prototypes::id::SpeechSynthesis, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
641 | | IsBaseOf<nsISupports, mozilla::dom::SpeechSynthesis >::value, |
642 | | sNativePropertyHooks, |
643 | | FindAssociatedGlobalForNative<mozilla::dom::SpeechSynthesis>::Get, |
644 | | GetProtoObjectHandle, |
645 | | GetCCParticipant<mozilla::dom::SpeechSynthesis>::Get() |
646 | | }; |
647 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
648 | | "Must have the right minimal number of reserved slots."); |
649 | | static_assert(1 >= 1, |
650 | | "Must have enough reserved slots."); |
651 | | |
652 | | const JSClass* |
653 | | GetJSClass() |
654 | 0 | { |
655 | 0 | return sClass.ToJSClass(); |
656 | 0 | } |
657 | | |
658 | | bool |
659 | | Wrap(JSContext* aCx, mozilla::dom::SpeechSynthesis* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
660 | 0 | { |
661 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::SpeechSynthesis>::value, |
662 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
663 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::SpeechSynthesis*>(aObject) == |
664 | 0 | reinterpret_cast<mozilla::dom::SpeechSynthesis*>(aObject), |
665 | 0 | "Multiple inheritance for mozilla::dom::SpeechSynthesis is broken."); |
666 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
667 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
668 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
669 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
670 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
671 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
672 | 0 | "You should probably not be using Wrap() directly; use " |
673 | 0 | "GetOrCreateDOMReflector instead"); |
674 | 0 |
|
675 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
676 | 0 | "nsISupports must be on our primary inheritance chain"); |
677 | 0 |
|
678 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
679 | 0 | if (!global) { |
680 | 0 | return false; |
681 | 0 | } |
682 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
683 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
684 | 0 |
|
685 | 0 | // That might have ended up wrapping us already, due to the wonders |
686 | 0 | // of XBL. Check for that, and bail out as needed. |
687 | 0 | aReflector.set(aCache->GetWrapper()); |
688 | 0 | if (aReflector) { |
689 | | #ifdef DEBUG |
690 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
691 | | #endif // DEBUG |
692 | | return true; |
693 | 0 | } |
694 | 0 |
|
695 | 0 | JSAutoRealm ar(aCx, global); |
696 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
697 | 0 | if (!canonicalProto) { |
698 | 0 | return false; |
699 | 0 | } |
700 | 0 | JS::Rooted<JSObject*> proto(aCx); |
701 | 0 | if (aGivenProto) { |
702 | 0 | proto = aGivenProto; |
703 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
704 | 0 | // coming in, we changed compartments to that of "parent" so may need |
705 | 0 | // to wrap the proto here. |
706 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
707 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
708 | 0 | return false; |
709 | 0 | } |
710 | 0 | } |
711 | 0 | } else { |
712 | 0 | proto = canonicalProto; |
713 | 0 | } |
714 | 0 |
|
715 | 0 | BindingJSObjectCreator<mozilla::dom::SpeechSynthesis> creator(aCx); |
716 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
717 | 0 | if (!aReflector) { |
718 | 0 | return false; |
719 | 0 | } |
720 | 0 | |
721 | 0 | aCache->SetWrapper(aReflector); |
722 | 0 | creator.InitializationSucceeded(); |
723 | 0 |
|
724 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
725 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
726 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
727 | 0 | // otherwise we won't be able to properly recreate it later, since |
728 | 0 | // we won't know what proto to use. Note that we don't check |
729 | 0 | // aGivenProto here, since it's entirely possible (and even |
730 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
731 | 0 | // same as canonicalProto. |
732 | 0 | if (proto != canonicalProto) { |
733 | 0 | PreserveWrapper(aObject); |
734 | 0 | } |
735 | 0 |
|
736 | 0 | return true; |
737 | 0 | } |
738 | | |
739 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
740 | | nullptr, |
741 | | nullptr, |
742 | | nullptr, |
743 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
744 | | prototypes::id::SpeechSynthesis, |
745 | | constructors::id::SpeechSynthesis, |
746 | | EventTarget_Binding::sNativePropertyHooks, |
747 | | &DefaultXrayExpandoObjectClass |
748 | | } }; |
749 | | |
750 | | void |
751 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
752 | 0 | { |
753 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
754 | 0 | if (!parentProto) { |
755 | 0 | return; |
756 | 0 | } |
757 | 0 | |
758 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
759 | 0 | if (!constructorProto) { |
760 | 0 | return; |
761 | 0 | } |
762 | 0 | |
763 | 0 | static bool sIdsInited = false; |
764 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
765 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
766 | 0 | return; |
767 | 0 | } |
768 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
769 | 0 | return; |
770 | 0 | } |
771 | 0 | sIdsInited = true; |
772 | 0 | } |
773 | 0 |
|
774 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SpeechSynthesis); |
775 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SpeechSynthesis); |
776 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
777 | 0 | &sPrototypeClass.mBase, protoCache, |
778 | 0 | nullptr, |
779 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
780 | 0 | interfaceCache, |
781 | 0 | sNativeProperties.Upcast(), |
782 | 0 | sChromeOnlyNativeProperties.Upcast(), |
783 | 0 | "SpeechSynthesis", aDefineOnGlobal, |
784 | 0 | nullptr, |
785 | 0 | false); |
786 | 0 | } |
787 | | |
788 | | JSObject* |
789 | | GetConstructorObject(JSContext* aCx) |
790 | 0 | { |
791 | 0 | return GetConstructorObjectHandle(aCx); |
792 | 0 | } |
793 | | |
794 | | } // namespace SpeechSynthesis_Binding |
795 | | |
796 | | |
797 | | |
798 | | } // namespace dom |
799 | | } // namespace mozilla |