/work/obj-fuzz/dom/bindings/SpeechGrammarBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM SpeechGrammar.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "SpeechGrammarBinding.h" |
4 | | #include "SpeechRecognition.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/SpeechGrammar.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 SpeechGrammar_Binding { |
24 | | |
25 | | MOZ_CAN_RUN_SCRIPT static bool |
26 | | get_src(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechGrammar* self, JSJitGetterCallArgs args) |
27 | 0 | { |
28 | 0 | AUTO_PROFILER_LABEL_FAST("get SpeechGrammar.src", DOM, cx); |
29 | 0 |
|
30 | 0 | FastErrorResult rv; |
31 | 0 | DOMString result; |
32 | 0 | self->GetSrc(result, rv); |
33 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
34 | 0 | return false; |
35 | 0 | } |
36 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
37 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
38 | 0 | return false; |
39 | 0 | } |
40 | 0 | return true; |
41 | 0 | } |
42 | | |
43 | | MOZ_CAN_RUN_SCRIPT static bool |
44 | | set_src(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechGrammar* self, JSJitSetterCallArgs args) |
45 | 0 | { |
46 | 0 | AUTO_PROFILER_LABEL_FAST("set SpeechGrammar.src", DOM, cx); |
47 | 0 |
|
48 | 0 | binding_detail::FakeString arg0; |
49 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
50 | 0 | return false; |
51 | 0 | } |
52 | 0 | FastErrorResult rv; |
53 | 0 | self->SetSrc(NonNullHelper(Constify(arg0)), rv); |
54 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
55 | 0 | return false; |
56 | 0 | } |
57 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
58 | 0 |
|
59 | 0 | return true; |
60 | 0 | } |
61 | | |
62 | | static const JSJitInfo src_getterinfo = { |
63 | | { (JSJitGetterOp)get_src }, |
64 | | { prototypes::id::SpeechGrammar }, |
65 | | { PrototypeTraits<prototypes::id::SpeechGrammar>::Depth }, |
66 | | JSJitInfo::Getter, |
67 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
68 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
69 | | false, /* isInfallible. False in setters. */ |
70 | | false, /* isMovable. Not relevant for setters. */ |
71 | | false, /* isEliminatable. Not relevant for setters. */ |
72 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
73 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
74 | | false, /* isTypedMethod. Only relevant for methods. */ |
75 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
76 | | }; |
77 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
78 | | static_assert(0 < 1, "There is no slot for us"); |
79 | | static const JSJitInfo src_setterinfo = { |
80 | | { (JSJitGetterOp)set_src }, |
81 | | { prototypes::id::SpeechGrammar }, |
82 | | { PrototypeTraits<prototypes::id::SpeechGrammar>::Depth }, |
83 | | JSJitInfo::Setter, |
84 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
85 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
86 | | false, /* isInfallible. False in setters. */ |
87 | | false, /* isMovable. Not relevant for setters. */ |
88 | | false, /* isEliminatable. Not relevant for setters. */ |
89 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
90 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
91 | | false, /* isTypedMethod. Only relevant for methods. */ |
92 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
93 | | }; |
94 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
95 | | static_assert(0 < 1, "There is no slot for us"); |
96 | | |
97 | | MOZ_CAN_RUN_SCRIPT static bool |
98 | | get_weight(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechGrammar* self, JSJitGetterCallArgs args) |
99 | 0 | { |
100 | 0 | AUTO_PROFILER_LABEL_FAST("get SpeechGrammar.weight", DOM, cx); |
101 | 0 |
|
102 | 0 | FastErrorResult rv; |
103 | 0 | float result(self->GetWeight(rv)); |
104 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
105 | 0 | return false; |
106 | 0 | } |
107 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
108 | 0 | args.rval().set(JS_NumberValue(double(result))); |
109 | 0 | return true; |
110 | 0 | } |
111 | | |
112 | | MOZ_CAN_RUN_SCRIPT static bool |
113 | | set_weight(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechGrammar* self, JSJitSetterCallArgs args) |
114 | 0 | { |
115 | 0 | AUTO_PROFILER_LABEL_FAST("set SpeechGrammar.weight", DOM, cx); |
116 | 0 |
|
117 | 0 | float arg0; |
118 | 0 | if (!ValueToPrimitive<float, eDefault>(cx, args[0], &arg0)) { |
119 | 0 | return false; |
120 | 0 | } else if (!mozilla::IsFinite(arg0)) { |
121 | 0 | ThrowErrorMessage(cx, MSG_NOT_FINITE, "Value being assigned to SpeechGrammar.weight"); |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 | FastErrorResult rv; |
125 | 0 | self->SetWeight(arg0, rv); |
126 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
127 | 0 | return false; |
128 | 0 | } |
129 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
130 | 0 |
|
131 | 0 | return true; |
132 | 0 | } |
133 | | |
134 | | static const JSJitInfo weight_getterinfo = { |
135 | | { (JSJitGetterOp)get_weight }, |
136 | | { prototypes::id::SpeechGrammar }, |
137 | | { PrototypeTraits<prototypes::id::SpeechGrammar>::Depth }, |
138 | | JSJitInfo::Getter, |
139 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
140 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
141 | | false, /* isInfallible. False in setters. */ |
142 | | false, /* isMovable. Not relevant for setters. */ |
143 | | false, /* isEliminatable. Not relevant for setters. */ |
144 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
145 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
146 | | false, /* isTypedMethod. Only relevant for methods. */ |
147 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
148 | | }; |
149 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
150 | | static_assert(0 < 1, "There is no slot for us"); |
151 | | static const JSJitInfo weight_setterinfo = { |
152 | | { (JSJitGetterOp)set_weight }, |
153 | | { prototypes::id::SpeechGrammar }, |
154 | | { PrototypeTraits<prototypes::id::SpeechGrammar>::Depth }, |
155 | | JSJitInfo::Setter, |
156 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
157 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
158 | | false, /* isInfallible. False in setters. */ |
159 | | false, /* isMovable. Not relevant for setters. */ |
160 | | false, /* isEliminatable. Not relevant for setters. */ |
161 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
162 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
163 | | false, /* isTypedMethod. Only relevant for methods. */ |
164 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
165 | | }; |
166 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
167 | | static_assert(0 < 1, "There is no slot for us"); |
168 | | |
169 | | static bool |
170 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
171 | 0 | { |
172 | 0 | mozilla::dom::SpeechGrammar* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechGrammar>(obj); |
173 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
174 | 0 | // obviously can't preserve if we're not initialized. |
175 | 0 | if (self && self->GetWrapperPreserveColor()) { |
176 | 0 | PreserveWrapper(self); |
177 | 0 | } |
178 | 0 | return true; |
179 | 0 | } |
180 | | |
181 | | static void |
182 | | _finalize(js::FreeOp* fop, JSObject* obj) |
183 | 0 | { |
184 | 0 | mozilla::dom::SpeechGrammar* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechGrammar>(obj); |
185 | 0 | if (self) { |
186 | 0 | ClearWrapper(self, self, obj); |
187 | 0 | AddForDeferredFinalization<mozilla::dom::SpeechGrammar>(self); |
188 | 0 | } |
189 | 0 | } |
190 | | |
191 | | static size_t |
192 | | _objectMoved(JSObject* obj, JSObject* old) |
193 | 0 | { |
194 | 0 | mozilla::dom::SpeechGrammar* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechGrammar>(obj); |
195 | 0 | if (self) { |
196 | 0 | UpdateWrapper(self, self, obj, old); |
197 | 0 | } |
198 | 0 |
|
199 | 0 | return 0; |
200 | 0 | } |
201 | | |
202 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
203 | | #if defined(__clang__) |
204 | | #pragma clang diagnostic push |
205 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
206 | | #endif |
207 | | static const JSPropertySpec sAttributes_specs[] = { |
208 | | { "src", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &src_getterinfo, GenericSetter<NormalThisPolicy>, &src_setterinfo }, |
209 | | { "weight", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &weight_getterinfo, GenericSetter<NormalThisPolicy>, &weight_setterinfo }, |
210 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
211 | | }; |
212 | | #if defined(__clang__) |
213 | | #pragma clang diagnostic pop |
214 | | #endif |
215 | | |
216 | | |
217 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
218 | | { nullptr, &sAttributes_specs[0] }, |
219 | | { nullptr, nullptr } |
220 | | }; |
221 | | |
222 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
223 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
224 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
225 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
226 | | |
227 | | |
228 | | static uint16_t sNativeProperties_sortedPropertyIndices[2]; |
229 | | static PropertyInfo sNativeProperties_propertyInfos[2]; |
230 | | |
231 | | static const NativePropertiesN<1> sNativeProperties = { |
232 | | false, 0, |
233 | | false, 0, |
234 | | false, 0, |
235 | | true, 0 /* sAttributes */, |
236 | | false, 0, |
237 | | false, 0, |
238 | | false, 0, |
239 | | -1, |
240 | | 2, |
241 | | sNativeProperties_sortedPropertyIndices, |
242 | | { |
243 | | { sAttributes, &sNativeProperties_propertyInfos[0] } |
244 | | } |
245 | | }; |
246 | | static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
247 | | "We have a property info count that is oversized"); |
248 | | |
249 | | static bool |
250 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
251 | 0 | { |
252 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechGrammar constructor", DOM, cx); |
253 | 0 |
|
254 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
255 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
256 | 0 | if (!args.isConstructing()) { |
257 | 0 | // XXXbz wish I could get the name from the callee instead of |
258 | 0 | // Adding more relocations |
259 | 0 | return ThrowConstructorWithoutNew(cx, "SpeechGrammar"); |
260 | 0 | } |
261 | 0 | |
262 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
263 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
264 | 0 | return false; |
265 | 0 | } |
266 | 0 | |
267 | 0 | GlobalObject global(cx, obj); |
268 | 0 | if (global.Failed()) { |
269 | 0 | return false; |
270 | 0 | } |
271 | 0 | |
272 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
273 | 0 | Maybe<JSAutoRealm> ar; |
274 | 0 | if (objIsXray) { |
275 | 0 | obj = js::CheckedUnwrap(obj); |
276 | 0 | if (!obj) { |
277 | 0 | return false; |
278 | 0 | } |
279 | 0 | ar.emplace(cx, obj); |
280 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
281 | 0 | return false; |
282 | 0 | } |
283 | 0 | } |
284 | 0 | FastErrorResult rv; |
285 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SpeechGrammar>(mozilla::dom::SpeechGrammar::Constructor(global, rv))); |
286 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
287 | 0 | return false; |
288 | 0 | } |
289 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
290 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
291 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
292 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
293 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
294 | 0 | return false; |
295 | 0 | } |
296 | 0 | return true; |
297 | 0 | } |
298 | | |
299 | | static const js::ClassOps sInterfaceObjectClassOps = { |
300 | | nullptr, /* addProperty */ |
301 | | nullptr, /* delProperty */ |
302 | | nullptr, /* enumerate */ |
303 | | nullptr, /* newEnumerate */ |
304 | | nullptr, /* resolve */ |
305 | | nullptr, /* mayResolve */ |
306 | | nullptr, /* finalize */ |
307 | | _constructor, /* call */ |
308 | | nullptr, /* hasInstance */ |
309 | | _constructor, /* construct */ |
310 | | nullptr, /* trace */ |
311 | | }; |
312 | | |
313 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
314 | | { |
315 | | "Function", |
316 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
317 | | &sInterfaceObjectClassOps, |
318 | | JS_NULL_CLASS_SPEC, |
319 | | JS_NULL_CLASS_EXT, |
320 | | &sInterfaceObjectClassObjectOps |
321 | | }, |
322 | | eInterface, |
323 | | true, |
324 | | prototypes::id::SpeechGrammar, |
325 | | PrototypeTraits<prototypes::id::SpeechGrammar>::Depth, |
326 | | sNativePropertyHooks, |
327 | | "function SpeechGrammar() {\n [native code]\n}", |
328 | | JS::GetRealmFunctionPrototype |
329 | | }; |
330 | | |
331 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
332 | | { |
333 | | "SpeechGrammarPrototype", |
334 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
335 | | JS_NULL_CLASS_OPS, |
336 | | JS_NULL_CLASS_SPEC, |
337 | | JS_NULL_CLASS_EXT, |
338 | | JS_NULL_OBJECT_OPS |
339 | | }, |
340 | | eInterfacePrototype, |
341 | | false, |
342 | | prototypes::id::SpeechGrammar, |
343 | | PrototypeTraits<prototypes::id::SpeechGrammar>::Depth, |
344 | | sNativePropertyHooks, |
345 | | "[object SpeechGrammarPrototype]", |
346 | | JS::GetRealmObjectPrototype |
347 | | }; |
348 | | |
349 | | bool |
350 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
351 | 0 | { |
352 | 0 | static bool sPrefValue; |
353 | 0 | static bool sPrefCacheSetUp = false; |
354 | 0 | if (!sPrefCacheSetUp) { |
355 | 0 | sPrefCacheSetUp = true; |
356 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "media.webspeech.recognition.enable"); |
357 | 0 | } |
358 | 0 |
|
359 | 0 | return sPrefValue && |
360 | 0 | SpeechRecognition::IsAuthorized(aCx, aObj); |
361 | 0 | } |
362 | | |
363 | | static const js::ClassOps sClassOps = { |
364 | | _addProperty, /* addProperty */ |
365 | | nullptr, /* delProperty */ |
366 | | nullptr, /* enumerate */ |
367 | | nullptr, /* newEnumerate */ |
368 | | nullptr, /* resolve */ |
369 | | nullptr, /* mayResolve */ |
370 | | _finalize, /* finalize */ |
371 | | nullptr, /* call */ |
372 | | nullptr, /* hasInstance */ |
373 | | nullptr, /* construct */ |
374 | | nullptr, /* trace */ |
375 | | }; |
376 | | |
377 | | static const js::ClassExtension sClassExtension = { |
378 | | nullptr, /* weakmapKeyDelegateOp */ |
379 | | _objectMoved /* objectMovedOp */ |
380 | | }; |
381 | | |
382 | | static const DOMJSClass sClass = { |
383 | | { "SpeechGrammar", |
384 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
385 | | &sClassOps, |
386 | | JS_NULL_CLASS_SPEC, |
387 | | &sClassExtension, |
388 | | JS_NULL_OBJECT_OPS |
389 | | }, |
390 | | { prototypes::id::SpeechGrammar, 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 }, |
391 | | IsBaseOf<nsISupports, mozilla::dom::SpeechGrammar >::value, |
392 | | sNativePropertyHooks, |
393 | | FindAssociatedGlobalForNative<mozilla::dom::SpeechGrammar>::Get, |
394 | | GetProtoObjectHandle, |
395 | | GetCCParticipant<mozilla::dom::SpeechGrammar>::Get() |
396 | | }; |
397 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
398 | | "Must have the right minimal number of reserved slots."); |
399 | | static_assert(1 >= 1, |
400 | | "Must have enough reserved slots."); |
401 | | |
402 | | const JSClass* |
403 | | GetJSClass() |
404 | 0 | { |
405 | 0 | return sClass.ToJSClass(); |
406 | 0 | } |
407 | | |
408 | | bool |
409 | | Wrap(JSContext* aCx, mozilla::dom::SpeechGrammar* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
410 | 0 | { |
411 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::SpeechGrammar>::value, |
412 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
413 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::SpeechGrammar*>(aObject) == |
414 | 0 | reinterpret_cast<mozilla::dom::SpeechGrammar*>(aObject), |
415 | 0 | "Multiple inheritance for mozilla::dom::SpeechGrammar is broken."); |
416 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
417 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
418 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
419 | 0 | "You should probably not be using Wrap() directly; use " |
420 | 0 | "GetOrCreateDOMReflector instead"); |
421 | 0 |
|
422 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
423 | 0 | "nsISupports must be on our primary inheritance chain"); |
424 | 0 |
|
425 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
426 | 0 | if (!global) { |
427 | 0 | return false; |
428 | 0 | } |
429 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
430 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
431 | 0 |
|
432 | 0 | // That might have ended up wrapping us already, due to the wonders |
433 | 0 | // of XBL. Check for that, and bail out as needed. |
434 | 0 | aReflector.set(aCache->GetWrapper()); |
435 | 0 | if (aReflector) { |
436 | | #ifdef DEBUG |
437 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
438 | | #endif // DEBUG |
439 | | return true; |
440 | 0 | } |
441 | 0 |
|
442 | 0 | JSAutoRealm ar(aCx, global); |
443 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
444 | 0 | if (!canonicalProto) { |
445 | 0 | return false; |
446 | 0 | } |
447 | 0 | JS::Rooted<JSObject*> proto(aCx); |
448 | 0 | if (aGivenProto) { |
449 | 0 | proto = aGivenProto; |
450 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
451 | 0 | // coming in, we changed compartments to that of "parent" so may need |
452 | 0 | // to wrap the proto here. |
453 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
454 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
455 | 0 | return false; |
456 | 0 | } |
457 | 0 | } |
458 | 0 | } else { |
459 | 0 | proto = canonicalProto; |
460 | 0 | } |
461 | 0 |
|
462 | 0 | BindingJSObjectCreator<mozilla::dom::SpeechGrammar> creator(aCx); |
463 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
464 | 0 | if (!aReflector) { |
465 | 0 | return false; |
466 | 0 | } |
467 | 0 | |
468 | 0 | aCache->SetWrapper(aReflector); |
469 | 0 | creator.InitializationSucceeded(); |
470 | 0 |
|
471 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
472 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
473 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
474 | 0 | // otherwise we won't be able to properly recreate it later, since |
475 | 0 | // we won't know what proto to use. Note that we don't check |
476 | 0 | // aGivenProto here, since it's entirely possible (and even |
477 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
478 | 0 | // same as canonicalProto. |
479 | 0 | if (proto != canonicalProto) { |
480 | 0 | PreserveWrapper(aObject); |
481 | 0 | } |
482 | 0 |
|
483 | 0 | return true; |
484 | 0 | } |
485 | | |
486 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
487 | | nullptr, |
488 | | nullptr, |
489 | | nullptr, |
490 | | { sNativeProperties.Upcast(), nullptr }, |
491 | | prototypes::id::SpeechGrammar, |
492 | | constructors::id::SpeechGrammar, |
493 | | nullptr, |
494 | | &DefaultXrayExpandoObjectClass |
495 | | } }; |
496 | | |
497 | | void |
498 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
499 | 0 | { |
500 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
501 | 0 | if (!parentProto) { |
502 | 0 | return; |
503 | 0 | } |
504 | 0 | |
505 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
506 | 0 | if (!constructorProto) { |
507 | 0 | return; |
508 | 0 | } |
509 | 0 | |
510 | 0 | static bool sIdsInited = false; |
511 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
512 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
513 | 0 | return; |
514 | 0 | } |
515 | 0 | sIdsInited = true; |
516 | 0 | } |
517 | 0 |
|
518 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SpeechGrammar); |
519 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SpeechGrammar); |
520 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
521 | 0 | &sPrototypeClass.mBase, protoCache, |
522 | 0 | nullptr, |
523 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
524 | 0 | interfaceCache, |
525 | 0 | sNativeProperties.Upcast(), |
526 | 0 | nullptr, |
527 | 0 | "SpeechGrammar", aDefineOnGlobal, |
528 | 0 | nullptr, |
529 | 0 | false); |
530 | 0 | } |
531 | | |
532 | | JSObject* |
533 | | GetConstructorObject(JSContext* aCx) |
534 | 0 | { |
535 | 0 | return GetConstructorObjectHandle(aCx); |
536 | 0 | } |
537 | | |
538 | | } // namespace SpeechGrammar_Binding |
539 | | |
540 | | |
541 | | |
542 | | } // namespace dom |
543 | | } // namespace mozilla |