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