Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM SpeechRecognitionAlternative.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "SpeechRecognition.h"
4 : #include "SpeechRecognitionAlternativeBinding.h"
5 : #include "WrapperFactory.h"
6 : #include "mozilla/FloatingPoint.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/PrimitiveConversions.h"
13 : #include "mozilla/dom/SpeechRecognitionAlternative.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 :
16 : namespace mozilla {
17 : namespace dom {
18 :
19 : namespace SpeechRecognitionAlternativeBinding {
20 :
21 : static bool
22 0 : get_transcript(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionAlternative* self, JSJitGetterCallArgs args)
23 : {
24 0 : DOMString result;
25 0 : self->GetTranscript(result);
26 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
27 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
28 0 : return false;
29 : }
30 0 : return true;
31 : }
32 :
33 : static const JSJitInfo transcript_getterinfo = {
34 : { (JSJitGetterOp)get_transcript },
35 : { prototypes::id::SpeechRecognitionAlternative },
36 : { PrototypeTraits<prototypes::id::SpeechRecognitionAlternative>::Depth },
37 : JSJitInfo::Getter,
38 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
39 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
40 : false, /* isInfallible. False in setters. */
41 : false, /* isMovable. Not relevant for setters. */
42 : false, /* isEliminatable. Not relevant for setters. */
43 : false, /* isAlwaysInSlot. Only relevant for getters. */
44 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
45 : false, /* isTypedMethod. Only relevant for methods. */
46 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
47 : };
48 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
49 : static_assert(0 < 1, "There is no slot for us");
50 :
51 : static bool
52 0 : get_confidence(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionAlternative* self, JSJitGetterCallArgs args)
53 : {
54 0 : float result(self->Confidence());
55 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
56 0 : args.rval().set(JS_NumberValue(double(result)));
57 0 : return true;
58 : }
59 :
60 : static const JSJitInfo confidence_getterinfo = {
61 : { (JSJitGetterOp)get_confidence },
62 : { prototypes::id::SpeechRecognitionAlternative },
63 : { PrototypeTraits<prototypes::id::SpeechRecognitionAlternative>::Depth },
64 : JSJitInfo::Getter,
65 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
66 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
67 : true, /* isInfallible. False in setters. */
68 : false, /* isMovable. Not relevant for setters. */
69 : false, /* isEliminatable. Not relevant for setters. */
70 : false, /* isAlwaysInSlot. Only relevant for getters. */
71 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
72 : false, /* isTypedMethod. Only relevant for methods. */
73 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
74 : };
75 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
76 : static_assert(0 < 1, "There is no slot for us");
77 :
78 : static bool
79 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
80 : {
81 0 : mozilla::dom::SpeechRecognitionAlternative* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionAlternative>(obj);
82 : // We don't want to preserve if we don't have a wrapper, and we
83 : // obviously can't preserve if we're not initialized.
84 0 : if (self && self->GetWrapperPreserveColor()) {
85 0 : PreserveWrapper(self);
86 : }
87 0 : return true;
88 : }
89 :
90 : static void
91 0 : _finalize(js::FreeOp* fop, JSObject* obj)
92 : {
93 0 : mozilla::dom::SpeechRecognitionAlternative* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionAlternative>(obj);
94 0 : if (self) {
95 0 : ClearWrapper(self, self, obj);
96 0 : AddForDeferredFinalization<mozilla::dom::SpeechRecognitionAlternative>(self);
97 : }
98 0 : }
99 :
100 : static void
101 0 : _objectMoved(JSObject* obj, const JSObject* old)
102 : {
103 0 : mozilla::dom::SpeechRecognitionAlternative* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionAlternative>(obj);
104 0 : if (self) {
105 0 : UpdateWrapper(self, self, obj, old);
106 : }
107 0 : }
108 :
109 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
110 : #if defined(__clang__)
111 : #pragma clang diagnostic push
112 : #pragma clang diagnostic ignored "-Wmissing-braces"
113 : #endif
114 : static const JSPropertySpec sAttributes_specs[] = {
115 : { "transcript", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &transcript_getterinfo, nullptr, nullptr },
116 : { "confidence", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &confidence_getterinfo, nullptr, nullptr },
117 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
118 : };
119 : #if defined(__clang__)
120 : #pragma clang diagnostic pop
121 : #endif
122 :
123 :
124 : // Can't be const because the pref-enabled boolean needs to be writable
125 : static Prefable<const JSPropertySpec> sAttributes[] = {
126 : { nullptr, &sAttributes_specs[0] },
127 : { nullptr, nullptr }
128 : };
129 :
130 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
131 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
132 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
133 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
134 :
135 :
136 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
137 : static PropertyInfo sNativeProperties_propertyInfos[2];
138 :
139 : static const NativePropertiesN<1> sNativeProperties = {
140 : false, 0,
141 : false, 0,
142 : false, 0,
143 : true, 0 /* sAttributes */,
144 : false, 0,
145 : false, 0,
146 : false, 0,
147 : -1,
148 : 2,
149 : sNativeProperties_sortedPropertyIndices,
150 : {
151 : { sAttributes, &sNativeProperties_propertyInfos[0] }
152 : }
153 : };
154 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
155 : "We have a property info count that is oversized");
156 :
157 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
158 : {
159 : "Function",
160 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
161 : &sBoringInterfaceObjectClassClassOps,
162 : JS_NULL_CLASS_SPEC,
163 : JS_NULL_CLASS_EXT,
164 : &sInterfaceObjectClassObjectOps
165 : },
166 : eInterface,
167 : true,
168 : prototypes::id::SpeechRecognitionAlternative,
169 : PrototypeTraits<prototypes::id::SpeechRecognitionAlternative>::Depth,
170 : sNativePropertyHooks,
171 : "function SpeechRecognitionAlternative() {\n [native code]\n}",
172 : JS::GetRealmFunctionPrototype
173 : };
174 :
175 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
176 : {
177 : "SpeechRecognitionAlternativePrototype",
178 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
179 : JS_NULL_CLASS_OPS,
180 : JS_NULL_CLASS_SPEC,
181 : JS_NULL_CLASS_EXT,
182 : JS_NULL_OBJECT_OPS
183 : },
184 : eInterfacePrototype,
185 : false,
186 : prototypes::id::SpeechRecognitionAlternative,
187 : PrototypeTraits<prototypes::id::SpeechRecognitionAlternative>::Depth,
188 : sNativePropertyHooks,
189 : "[object SpeechRecognitionAlternativePrototype]",
190 : JS::GetRealmObjectPrototype
191 : };
192 :
193 : bool
194 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
195 : {
196 : static bool sPrefValue;
197 : static bool sPrefCacheSetUp = false;
198 0 : if (!sPrefCacheSetUp) {
199 0 : sPrefCacheSetUp = true;
200 0 : Preferences::AddBoolVarCache(&sPrefValue, "media.webspeech.recognition.enable");
201 : }
202 :
203 0 : return sPrefValue &&
204 0 : SpeechRecognition::IsAuthorized(aCx, aObj);
205 : }
206 :
207 : JSObject*
208 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
209 : {
210 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
211 : }
212 :
213 : static const js::ClassOps sClassOps = {
214 : _addProperty, /* addProperty */
215 : nullptr, /* delProperty */
216 : nullptr, /* getProperty */
217 : nullptr, /* setProperty */
218 : nullptr, /* enumerate */
219 : nullptr, /* newEnumerate */
220 : nullptr, /* resolve */
221 : nullptr, /* mayResolve */
222 : _finalize, /* finalize */
223 : nullptr, /* call */
224 : nullptr, /* hasInstance */
225 : nullptr, /* construct */
226 : nullptr, /* trace */
227 : };
228 :
229 : static const js::ClassExtension sClassExtension = {
230 : nullptr, /* weakmapKeyDelegateOp */
231 : _objectMoved /* objectMovedOp */
232 : };
233 :
234 : static const DOMJSClass sClass = {
235 : { "SpeechRecognitionAlternative",
236 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
237 : &sClassOps,
238 : JS_NULL_CLASS_SPEC,
239 : &sClassExtension,
240 : JS_NULL_OBJECT_OPS
241 : },
242 : { prototypes::id::SpeechRecognitionAlternative, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
243 : IsBaseOf<nsISupports, mozilla::dom::SpeechRecognitionAlternative >::value,
244 : sNativePropertyHooks,
245 : FindAssociatedGlobalForNative<mozilla::dom::SpeechRecognitionAlternative>::Get,
246 : GetProtoObjectHandle,
247 : GetCCParticipant<mozilla::dom::SpeechRecognitionAlternative>::Get()
248 : };
249 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
250 : "Must have the right minimal number of reserved slots.");
251 : static_assert(1 >= 1,
252 : "Must have enough reserved slots.");
253 :
254 : const JSClass*
255 0 : GetJSClass()
256 : {
257 0 : return sClass.ToJSClass();
258 : }
259 :
260 : bool
261 0 : Wrap(JSContext* aCx, mozilla::dom::SpeechRecognitionAlternative* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
262 : {
263 : MOZ_ASSERT(static_cast<mozilla::dom::SpeechRecognitionAlternative*>(aObject) ==
264 : reinterpret_cast<mozilla::dom::SpeechRecognitionAlternative*>(aObject),
265 : "Multiple inheritance for mozilla::dom::SpeechRecognitionAlternative is broken.");
266 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
267 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
268 0 : MOZ_ASSERT(!aCache->GetWrapper(),
269 : "You should probably not be using Wrap() directly; use "
270 : "GetOrCreateDOMReflector instead");
271 :
272 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
273 : "nsISupports must be on our primary inheritance chain");
274 :
275 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
276 0 : if (!global) {
277 0 : return false;
278 : }
279 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
280 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
281 :
282 : // That might have ended up wrapping us already, due to the wonders
283 : // of XBL. Check for that, and bail out as needed.
284 0 : aReflector.set(aCache->GetWrapper());
285 0 : if (aReflector) {
286 : #ifdef DEBUG
287 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
288 : #endif // DEBUG
289 0 : return true;
290 : }
291 :
292 0 : JSAutoCompartment ac(aCx, global);
293 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
294 0 : if (!canonicalProto) {
295 0 : return false;
296 : }
297 0 : JS::Rooted<JSObject*> proto(aCx);
298 0 : if (aGivenProto) {
299 0 : proto = aGivenProto;
300 : // Unfortunately, while aGivenProto was in the compartment of aCx
301 : // coming in, we changed compartments to that of "parent" so may need
302 : // to wrap the proto here.
303 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
304 0 : if (!JS_WrapObject(aCx, &proto)) {
305 0 : return false;
306 : }
307 : }
308 : } else {
309 0 : proto = canonicalProto;
310 : }
311 :
312 0 : BindingJSObjectCreator<mozilla::dom::SpeechRecognitionAlternative> creator(aCx);
313 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
314 0 : if (!aReflector) {
315 0 : return false;
316 : }
317 :
318 0 : aCache->SetWrapper(aReflector);
319 0 : creator.InitializationSucceeded();
320 :
321 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
322 : aCache->GetWrapperPreserveColor() == aReflector);
323 : // If proto != canonicalProto, we have to preserve our wrapper;
324 : // otherwise we won't be able to properly recreate it later, since
325 : // we won't know what proto to use. Note that we don't check
326 : // aGivenProto here, since it's entirely possible (and even
327 : // somewhat common) to have a non-null aGivenProto which is the
328 : // same as canonicalProto.
329 0 : if (proto != canonicalProto) {
330 0 : PreserveWrapper(aObject);
331 : }
332 :
333 0 : return true;
334 : }
335 :
336 : const NativePropertyHooks sNativePropertyHooks[] = { {
337 : nullptr,
338 : nullptr,
339 : nullptr,
340 : { sNativeProperties.Upcast(), nullptr },
341 : prototypes::id::SpeechRecognitionAlternative,
342 : constructors::id::SpeechRecognitionAlternative,
343 : nullptr,
344 : &DefaultXrayExpandoObjectClass
345 : } };
346 :
347 : void
348 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
349 : {
350 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
351 0 : if (!parentProto) {
352 0 : return;
353 : }
354 :
355 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
356 0 : if (!constructorProto) {
357 0 : return;
358 : }
359 :
360 : static bool sIdsInited = false;
361 0 : if (!sIdsInited && NS_IsMainThread()) {
362 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
363 0 : return;
364 : }
365 0 : sIdsInited = true;
366 : }
367 :
368 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SpeechRecognitionAlternative);
369 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SpeechRecognitionAlternative);
370 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
371 : &sPrototypeClass.mBase, protoCache,
372 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
373 : interfaceCache,
374 : sNativeProperties.Upcast(),
375 : nullptr,
376 : "SpeechRecognitionAlternative", aDefineOnGlobal,
377 : nullptr,
378 0 : false);
379 : }
380 :
381 : JS::Handle<JSObject*>
382 0 : GetProtoObjectHandle(JSContext* aCx)
383 : {
384 : /* Get the interface prototype object for this class. This will create the
385 : object as needed. */
386 0 : bool aDefineOnGlobal = true;
387 :
388 : /* Make sure our global is sane. Hopefully we can remove this sometime */
389 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
390 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
391 0 : return nullptr;
392 : }
393 :
394 : /* Check to see whether the interface objects are already installed */
395 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
396 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::SpeechRecognitionAlternative)) {
397 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
398 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
399 : }
400 :
401 : /*
402 : * The object might _still_ be null, but that's OK.
403 : *
404 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
405 : * traced by TraceProtoAndIfaceCache() and its contents are never
406 : * changed after they have been set.
407 : *
408 : * Calling address() avoids the read read barrier that does gray
409 : * unmarking, but it's not possible for the object to be gray here.
410 : */
411 :
412 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::SpeechRecognitionAlternative);
413 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
414 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
415 : }
416 :
417 : JS::Handle<JSObject*>
418 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
419 : {
420 : /* Get the interface object for this class. This will create the object as
421 : needed. */
422 :
423 : /* Make sure our global is sane. Hopefully we can remove this sometime */
424 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
425 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
426 0 : return nullptr;
427 : }
428 :
429 : /* Check to see whether the interface objects are already installed */
430 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
431 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::SpeechRecognitionAlternative)) {
432 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
433 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
434 : }
435 :
436 : /*
437 : * The object might _still_ be null, but that's OK.
438 : *
439 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
440 : * traced by TraceProtoAndIfaceCache() and its contents are never
441 : * changed after they have been set.
442 : *
443 : * Calling address() avoids the read read barrier that does gray
444 : * unmarking, but it's not possible for the object to be gray here.
445 : */
446 :
447 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::SpeechRecognitionAlternative);
448 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
449 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
450 : }
451 :
452 : JSObject*
453 0 : GetConstructorObject(JSContext* aCx)
454 : {
455 0 : return GetConstructorObjectHandle(aCx);
456 : }
457 :
458 : } // namespace SpeechRecognitionAlternativeBinding
459 :
460 :
461 :
462 : } // namespace dom
463 : } // namespace mozilla
|