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