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