/work/obj-fuzz/dom/bindings/SpeechRecognitionResultListBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM SpeechRecognitionResultList.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "SpeechRecognition.h" |
4 | | #include "SpeechRecognitionResultListBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/Preferences.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/DOMJSProxyHandler.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/PrimitiveConversions.h" |
13 | | #include "mozilla/dom/SpeechRecognitionResult.h" |
14 | | #include "mozilla/dom/SpeechRecognitionResultList.h" |
15 | | #include "mozilla/dom/XrayExpandoClass.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
21 | | using namespace mozilla::dom::binding_detail; |
22 | | |
23 | | |
24 | | namespace SpeechRecognitionResultList_Binding { |
25 | | |
26 | | MOZ_CAN_RUN_SCRIPT static bool |
27 | | get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionResultList* self, JSJitGetterCallArgs args) |
28 | 0 | { |
29 | 0 | AUTO_PROFILER_LABEL_FAST("get SpeechRecognitionResultList.length", DOM, cx); |
30 | 0 |
|
31 | 0 | uint32_t result(self->Length()); |
32 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
33 | 0 | args.rval().setNumber(result); |
34 | 0 | return true; |
35 | 0 | } |
36 | | |
37 | | static const JSJitInfo length_getterinfo = { |
38 | | { (JSJitGetterOp)get_length }, |
39 | | { prototypes::id::SpeechRecognitionResultList }, |
40 | | { PrototypeTraits<prototypes::id::SpeechRecognitionResultList>::Depth }, |
41 | | JSJitInfo::Getter, |
42 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
43 | | JSVAL_TYPE_DOUBLE, /* 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 | | MOZ_CAN_RUN_SCRIPT static bool |
56 | | item(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionResultList* self, const JSJitMethodCallArgs& args) |
57 | 0 | { |
58 | 0 | AUTO_PROFILER_LABEL_FAST("SpeechRecognitionResultList.item", DOM, cx); |
59 | 0 |
|
60 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
61 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "SpeechRecognitionResultList.item"); |
62 | 0 | } |
63 | 0 | uint32_t arg0; |
64 | 0 | if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) { |
65 | 0 | return false; |
66 | 0 | } |
67 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionResult>(self->Item(arg0))); |
68 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
69 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
70 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | return true; |
74 | 0 | } |
75 | | |
76 | | static const JSJitInfo item_methodinfo = { |
77 | | { (JSJitGetterOp)item }, |
78 | | { prototypes::id::SpeechRecognitionResultList }, |
79 | | { PrototypeTraits<prototypes::id::SpeechRecognitionResultList>::Depth }, |
80 | | JSJitInfo::Method, |
81 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
82 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
83 | | false, /* isInfallible. False in setters. */ |
84 | | false, /* isMovable. Not relevant for setters. */ |
85 | | false, /* isEliminatable. Not relevant for setters. */ |
86 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
87 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
88 | | false, /* isTypedMethod. Only relevant for methods. */ |
89 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
90 | | }; |
91 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
92 | | static_assert(0 < 1, "There is no slot for us"); |
93 | | |
94 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
95 | | #if defined(__clang__) |
96 | | #pragma clang diagnostic push |
97 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
98 | | #endif |
99 | | static const JSFunctionSpec sMethods_specs[] = { |
100 | | JS_FNSPEC("item", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
101 | | JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"), |
102 | | JS_FS_END |
103 | | }; |
104 | | #if defined(__clang__) |
105 | | #pragma clang diagnostic pop |
106 | | #endif |
107 | | |
108 | | |
109 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
110 | | { nullptr, &sMethods_specs[0] }, |
111 | | { nullptr, nullptr } |
112 | | }; |
113 | | |
114 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
115 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
116 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
117 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
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 | | { "length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr }, |
126 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
127 | | }; |
128 | | #if defined(__clang__) |
129 | | #pragma clang diagnostic pop |
130 | | #endif |
131 | | |
132 | | |
133 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
134 | | { nullptr, &sAttributes_specs[0] }, |
135 | | { nullptr, nullptr } |
136 | | }; |
137 | | |
138 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
139 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
140 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
141 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
142 | | |
143 | | |
144 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
145 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
146 | | |
147 | | static const NativePropertiesN<2> sNativeProperties = { |
148 | | false, 0, |
149 | | false, 0, |
150 | | true, 0 /* sMethods */, |
151 | | true, 1 /* sAttributes */, |
152 | | false, 0, |
153 | | false, 0, |
154 | | false, 0, |
155 | | -1, |
156 | | 3, |
157 | | sNativeProperties_sortedPropertyIndices, |
158 | | { |
159 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
160 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
161 | | } |
162 | | }; |
163 | | static_assert(3 < 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::SpeechRecognitionResultList, |
178 | | PrototypeTraits<prototypes::id::SpeechRecognitionResultList>::Depth, |
179 | | sNativePropertyHooks, |
180 | | "function SpeechRecognitionResultList() {\n [native code]\n}", |
181 | | JS::GetRealmFunctionPrototype |
182 | | }; |
183 | | |
184 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
185 | | { |
186 | | "SpeechRecognitionResultListPrototype", |
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::SpeechRecognitionResultList, |
196 | | PrototypeTraits<prototypes::id::SpeechRecognitionResultList>::Depth, |
197 | | sNativePropertyHooks, |
198 | | "[object SpeechRecognitionResultListPrototype]", |
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_assert(IsBaseOf<nsISupports, mozilla::dom::SpeechRecognitionResultList >::value, |
217 | | "We don't support non-nsISupports native classes for " |
218 | | "proxy-based bindings yet"); |
219 | | |
220 | | |
221 | | class DOMProxyHandler : public mozilla::dom::DOMProxyHandler |
222 | | { |
223 | | public: |
224 | | explicit constexpr DOMProxyHandler() |
225 | 0 | { |
226 | 0 | } |
227 | | |
228 | | virtual bool |
229 | | getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override; |
230 | | |
231 | | virtual bool |
232 | | defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override; |
233 | | |
234 | | using mozilla::dom::DOMProxyHandler::defineProperty; |
235 | | |
236 | | virtual bool |
237 | | ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override; |
238 | | |
239 | | virtual bool |
240 | | hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override; |
241 | | |
242 | | virtual bool |
243 | | get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override; |
244 | | |
245 | | virtual const char* |
246 | | className(JSContext* cx, JS::Handle<JSObject*> proxy) const override; |
247 | | |
248 | | virtual bool |
249 | | finalizeInBackground(const JS::Value& priv) const override; |
250 | | |
251 | | virtual void |
252 | | finalize(JSFreeOp* fop, JSObject* proxy) const override; |
253 | | |
254 | | static const DOMProxyHandler* |
255 | | getInstance(); |
256 | | |
257 | | virtual bool |
258 | | delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override; |
259 | | |
260 | | virtual bool |
261 | | getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override; |
262 | | |
263 | | virtual size_t |
264 | | objectMoved(JSObject* obj, JSObject* old) const override; |
265 | | }; |
266 | | |
267 | | MOZ_ALWAYS_INLINE bool |
268 | | IsProxy(JSObject* obj) |
269 | 0 | { |
270 | 0 | return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance(); |
271 | 0 | } |
272 | | |
273 | | MOZ_ALWAYS_INLINE mozilla::dom::SpeechRecognitionResultList* |
274 | | UnwrapProxy(JSObject* obj) |
275 | 0 | { |
276 | 0 | MOZ_ASSERT(js::IsProxy(obj)); |
277 | 0 | if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) { |
278 | 0 | MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj)); |
279 | 0 | obj = js::UncheckedUnwrap(obj); |
280 | 0 | } |
281 | 0 | MOZ_ASSERT(IsProxy(obj)); |
282 | 0 | return static_cast<mozilla::dom::SpeechRecognitionResultList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); |
283 | 0 | } |
284 | | |
285 | | bool |
286 | | DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const |
287 | 0 | { |
288 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
289 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
290 | 0 | if (IsArrayIndex(index)) { |
291 | 0 | mozilla::dom::SpeechRecognitionResultList* self = UnwrapProxy(proxy); |
292 | 0 | bool found = false; |
293 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionResult>(self->IndexedGetter(index, found))); |
294 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
295 | 0 |
|
296 | 0 | if (found) { |
297 | 0 | if (!GetOrCreateDOMReflector(cx, result, desc.value())) { |
298 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
299 | 0 | return false; |
300 | 0 | } |
301 | 0 | FillPropertyDescriptor(desc, proxy, true); |
302 | 0 | return true; |
303 | 0 | } |
304 | 0 | } |
305 | 0 |
|
306 | 0 | JS::Rooted<JSObject*> expando(cx); |
307 | 0 | if (!isXray && (expando = GetExpandoObject(proxy))) { |
308 | 0 | if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) { |
309 | 0 | return false; |
310 | 0 | } |
311 | 0 | if (desc.object()) { |
312 | 0 | // Pretend the property lives on the wrapper. |
313 | 0 | desc.object().set(proxy); |
314 | 0 | return true; |
315 | 0 | } |
316 | 0 | } |
317 | 0 | |
318 | 0 | desc.object().set(nullptr); |
319 | 0 | return true; |
320 | 0 | } |
321 | | |
322 | | bool |
323 | | DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const |
324 | 0 | { |
325 | 0 | if (IsArrayIndex(GetArrayIndexFromId(cx, id))) { |
326 | 0 | *defined = true; |
327 | 0 | return opresult.failNoIndexedSetter(); |
328 | 0 | } |
329 | 0 | return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined); |
330 | 0 | } |
331 | | |
332 | | |
333 | | bool |
334 | | DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const |
335 | 0 | { |
336 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
337 | 0 |
|
338 | 0 | uint32_t length = UnwrapProxy(proxy)->Length(); |
339 | 0 | MOZ_ASSERT(int32_t(length) >= 0); |
340 | 0 | for (int32_t i = 0; i < int32_t(length); ++i) { |
341 | 0 | if (!props.append(INT_TO_JSID(i))) { |
342 | 0 | return false; |
343 | 0 | } |
344 | 0 | } |
345 | 0 |
|
346 | 0 | JS::Rooted<JSObject*> expando(cx); |
347 | 0 | if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) && |
348 | 0 | !js::GetPropertyKeys(cx, expando, flags, &props)) { |
349 | 0 | return false; |
350 | 0 | } |
351 | 0 | |
352 | 0 | return true; |
353 | 0 | } |
354 | | |
355 | | bool |
356 | | DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const |
357 | 0 | { |
358 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
359 | 0 | "Should not have a XrayWrapper here"); |
360 | 0 |
|
361 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
362 | 0 | if (IsArrayIndex(index)) { |
363 | 0 | bool found = false; |
364 | 0 | mozilla::dom::SpeechRecognitionResultList* self = UnwrapProxy(proxy); |
365 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionResult>(self->IndexedGetter(index, found))); |
366 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
367 | 0 | (void)result; |
368 | 0 |
|
369 | 0 | *bp = found; |
370 | 0 | return true; |
371 | 0 | } |
372 | 0 |
|
373 | 0 |
|
374 | 0 | JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy)); |
375 | 0 | if (expando) { |
376 | 0 | bool b = true; |
377 | 0 | bool ok = JS_HasPropertyById(cx, expando, id, &b); |
378 | 0 | *bp = !!b; |
379 | 0 | if (!ok || *bp) { |
380 | 0 | return ok; |
381 | 0 | } |
382 | 0 | } |
383 | 0 | |
384 | 0 | *bp = false; |
385 | 0 | return true; |
386 | 0 | } |
387 | | |
388 | | bool |
389 | | DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const |
390 | 0 | { |
391 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
392 | 0 | "Should not have a XrayWrapper here"); |
393 | 0 |
|
394 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
395 | 0 | if (IsArrayIndex(index)) { |
396 | 0 | mozilla::dom::SpeechRecognitionResultList* self = UnwrapProxy(proxy); |
397 | 0 | bool found = false; |
398 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionResult>(self->IndexedGetter(index, found))); |
399 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
400 | 0 |
|
401 | 0 | if (found) { |
402 | 0 | if (!GetOrCreateDOMReflector(cx, result, vp)) { |
403 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
404 | 0 | return false; |
405 | 0 | } |
406 | 0 | return true; |
407 | 0 | } |
408 | 0 | // Even if we don't have this index, we don't forward the |
409 | 0 | // get on to our expando object. |
410 | 0 | } else { |
411 | 0 | { // Scope for expando |
412 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
413 | 0 | if (expando) { |
414 | 0 | bool hasProp; |
415 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
416 | 0 | return false; |
417 | 0 | } |
418 | 0 | |
419 | 0 | if (hasProp) { |
420 | 0 | // Forward the get to the expando object, but our receiver is whatever our |
421 | 0 | // receiver is. |
422 | 0 | return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp); |
423 | 0 | } |
424 | 0 | } |
425 | 0 | } |
426 | 0 | } |
427 | 0 | |
428 | 0 | bool foundOnPrototype; |
429 | 0 | if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) { |
430 | 0 | return false; |
431 | 0 | } |
432 | 0 | |
433 | 0 | if (foundOnPrototype) { |
434 | 0 | return true; |
435 | 0 | } |
436 | 0 | |
437 | 0 | vp.setUndefined(); |
438 | 0 | return true; |
439 | 0 | } |
440 | | |
441 | | const char* |
442 | | DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const |
443 | 0 | { |
444 | 0 | return "SpeechRecognitionResultList"; |
445 | 0 | } |
446 | | |
447 | | bool |
448 | | DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const |
449 | 0 | { |
450 | 0 | return false; |
451 | 0 | } |
452 | | |
453 | | void |
454 | | DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const |
455 | 0 | { |
456 | 0 | mozilla::dom::SpeechRecognitionResultList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionResultList>(proxy); |
457 | 0 | if (self) { |
458 | 0 | ClearWrapper(self, self, proxy); |
459 | 0 | AddForDeferredFinalization<mozilla::dom::SpeechRecognitionResultList>(self); |
460 | 0 | } |
461 | 0 | } |
462 | | |
463 | | const DOMProxyHandler* |
464 | | DOMProxyHandler::getInstance() |
465 | 0 | { |
466 | 0 | static const DOMProxyHandler instance; |
467 | 0 | return &instance; |
468 | 0 | } |
469 | | |
470 | | bool |
471 | | DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const |
472 | 0 | { |
473 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
474 | 0 | "Should not have a XrayWrapper here"); |
475 | 0 |
|
476 | 0 | uint32_t index = GetArrayIndexFromId(cx, id); |
477 | 0 | if (IsArrayIndex(index)) { |
478 | 0 | bool deleteSucceeded; |
479 | 0 | bool found = false; |
480 | 0 | mozilla::dom::SpeechRecognitionResultList* self = UnwrapProxy(proxy); |
481 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionResult>(self->IndexedGetter(index, found))); |
482 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
483 | 0 | (void)result; |
484 | 0 | deleteSucceeded = !found; |
485 | 0 | return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); |
486 | 0 | } |
487 | 0 |
|
488 | 0 | return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult); |
489 | 0 | } |
490 | | |
491 | | bool |
492 | | DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const |
493 | 0 | { |
494 | 0 | JS::Rooted<JS::Value> temp(cx); |
495 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
496 | 0 | "Should not have a XrayWrapper here"); |
497 | 0 |
|
498 | 0 | mozilla::dom::SpeechRecognitionResultList* self = UnwrapProxy(proxy); |
499 | 0 | uint32_t length = self->Length(); |
500 | 0 | // Compute the end of the indices we'll get ourselves |
501 | 0 | uint32_t ourEnd = std::max(begin, std::min(end, length)); |
502 | 0 |
|
503 | 0 | for (uint32_t index = begin; index < ourEnd; ++index) { |
504 | 0 | bool found = false; |
505 | 0 | auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionResult>(self->IndexedGetter(index, found))); |
506 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
507 | 0 |
|
508 | 0 | MOZ_ASSERT(found); |
509 | 0 | if (!GetOrCreateDOMReflector(cx, result, &temp)) { |
510 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
511 | 0 | return false; |
512 | 0 | } |
513 | 0 | if (!adder->append(cx, temp)) return false; |
514 | 0 | continue; |
515 | 0 | } |
516 | 0 |
|
517 | 0 | if (end > ourEnd) { |
518 | 0 | JS::Rooted<JSObject*> proto(cx); |
519 | 0 | if (!js::GetObjectProto(cx, proxy, &proto)) { |
520 | 0 | return false; |
521 | 0 | } |
522 | 0 | return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder); |
523 | 0 | } |
524 | 0 | |
525 | 0 | return true; |
526 | 0 | } |
527 | | |
528 | | size_t |
529 | | DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const |
530 | 0 | { |
531 | 0 | mozilla::dom::SpeechRecognitionResultList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionResultList>(obj); |
532 | 0 | if (self) { |
533 | 0 | UpdateWrapper(self, self, obj, old); |
534 | 0 | } |
535 | 0 |
|
536 | 0 | return 0; |
537 | 0 | } |
538 | | |
539 | | static const DOMJSClass sClass = { |
540 | | PROXY_CLASS_DEF("SpeechRecognitionResultList", |
541 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)), |
542 | | { prototypes::id::SpeechRecognitionResultList, 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 }, |
543 | | IsBaseOf<nsISupports, mozilla::dom::SpeechRecognitionResultList >::value, |
544 | | sNativePropertyHooks, |
545 | | FindAssociatedGlobalForNative<mozilla::dom::SpeechRecognitionResultList>::Get, |
546 | | GetProtoObjectHandle, |
547 | | GetCCParticipant<mozilla::dom::SpeechRecognitionResultList>::Get() |
548 | | }; |
549 | | |
550 | | bool |
551 | | Wrap(JSContext* aCx, mozilla::dom::SpeechRecognitionResultList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
552 | 0 | { |
553 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::SpeechRecognitionResultList>::value, |
554 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
555 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::SpeechRecognitionResultList*>(aObject) == |
556 | 0 | reinterpret_cast<mozilla::dom::SpeechRecognitionResultList*>(aObject), |
557 | 0 | "Multiple inheritance for mozilla::dom::SpeechRecognitionResultList is broken."); |
558 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
559 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
560 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
561 | 0 | "You should probably not be using Wrap() directly; use " |
562 | 0 | "GetOrCreateDOMReflector instead"); |
563 | 0 |
|
564 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
565 | 0 | "nsISupports must be on our primary inheritance chain"); |
566 | 0 |
|
567 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
568 | 0 | if (!global) { |
569 | 0 | return false; |
570 | 0 | } |
571 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
572 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
573 | 0 |
|
574 | 0 | // That might have ended up wrapping us already, due to the wonders |
575 | 0 | // of XBL. Check for that, and bail out as needed. |
576 | 0 | aReflector.set(aCache->GetWrapper()); |
577 | 0 | if (aReflector) { |
578 | | #ifdef DEBUG |
579 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
580 | | #endif // DEBUG |
581 | | return true; |
582 | 0 | } |
583 | 0 |
|
584 | 0 | JSAutoRealm ar(aCx, global); |
585 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
586 | 0 | if (!canonicalProto) { |
587 | 0 | return false; |
588 | 0 | } |
589 | 0 | JS::Rooted<JSObject*> proto(aCx); |
590 | 0 | if (aGivenProto) { |
591 | 0 | proto = aGivenProto; |
592 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
593 | 0 | // coming in, we changed compartments to that of "parent" so may need |
594 | 0 | // to wrap the proto here. |
595 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
596 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
597 | 0 | return false; |
598 | 0 | } |
599 | 0 | } |
600 | 0 | } else { |
601 | 0 | proto = canonicalProto; |
602 | 0 | } |
603 | 0 |
|
604 | 0 | BindingJSObjectCreator<mozilla::dom::SpeechRecognitionResultList> creator(aCx); |
605 | 0 | creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(), |
606 | 0 | proto, aObject, JS::UndefinedHandleValue, aReflector); |
607 | 0 | if (!aReflector) { |
608 | 0 | return false; |
609 | 0 | } |
610 | 0 | |
611 | 0 | aCache->SetWrapper(aReflector); |
612 | 0 | creator.InitializationSucceeded(); |
613 | 0 |
|
614 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
615 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
616 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
617 | 0 | // otherwise we won't be able to properly recreate it later, since |
618 | 0 | // we won't know what proto to use. Note that we don't check |
619 | 0 | // aGivenProto here, since it's entirely possible (and even |
620 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
621 | 0 | // same as canonicalProto. |
622 | 0 | if (proto != canonicalProto) { |
623 | 0 | PreserveWrapper(aObject); |
624 | 0 | } |
625 | 0 |
|
626 | 0 | return true; |
627 | 0 | } |
628 | | |
629 | | static bool |
630 | | ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc) |
631 | 0 | { |
632 | 0 | return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc); |
633 | 0 | } |
634 | | |
635 | | static bool |
636 | | EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props) |
637 | 0 | { |
638 | 0 | return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props); |
639 | 0 | } |
640 | | |
641 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
642 | | ResolveOwnProperty, |
643 | | EnumerateOwnProperties, |
644 | | nullptr, |
645 | | { sNativeProperties.Upcast(), nullptr }, |
646 | | prototypes::id::SpeechRecognitionResultList, |
647 | | constructors::id::SpeechRecognitionResultList, |
648 | | nullptr, |
649 | | &DefaultXrayExpandoObjectClass |
650 | | } }; |
651 | | |
652 | | void |
653 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
654 | 0 | { |
655 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
656 | 0 | if (!parentProto) { |
657 | 0 | return; |
658 | 0 | } |
659 | 0 | |
660 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
661 | 0 | if (!constructorProto) { |
662 | 0 | return; |
663 | 0 | } |
664 | 0 | |
665 | 0 | static bool sIdsInited = false; |
666 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
667 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
668 | 0 | return; |
669 | 0 | } |
670 | 0 | sIdsInited = true; |
671 | 0 | } |
672 | 0 |
|
673 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SpeechRecognitionResultList); |
674 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SpeechRecognitionResultList); |
675 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
676 | 0 | &sPrototypeClass.mBase, protoCache, |
677 | 0 | nullptr, |
678 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
679 | 0 | interfaceCache, |
680 | 0 | sNativeProperties.Upcast(), |
681 | 0 | nullptr, |
682 | 0 | "SpeechRecognitionResultList", aDefineOnGlobal, |
683 | 0 | nullptr, |
684 | 0 | false); |
685 | 0 | } |
686 | | |
687 | | JSObject* |
688 | | GetConstructorObject(JSContext* aCx) |
689 | 0 | { |
690 | 0 | return GetConstructorObjectHandle(aCx); |
691 | 0 | } |
692 | | |
693 | | } // namespace SpeechRecognitionResultList_Binding |
694 | | |
695 | | |
696 | | |
697 | | } // namespace dom |
698 | | } // namespace mozilla |