Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM SpeechRecognitionResult.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "SpeechRecognition.h"
4 : #include "SpeechRecognitionResultBinding.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/SpeechRecognitionAlternative.h"
14 : #include "mozilla/dom/SpeechRecognitionResult.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : namespace SpeechRecognitionResultBinding {
21 :
22 : static bool
23 0 : get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionResult* self, JSJitGetterCallArgs args)
24 : {
25 0 : uint32_t result(self->Length());
26 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
27 0 : args.rval().setNumber(result);
28 0 : return true;
29 : }
30 :
31 : static const JSJitInfo length_getterinfo = {
32 : { (JSJitGetterOp)get_length },
33 : { prototypes::id::SpeechRecognitionResult },
34 : { PrototypeTraits<prototypes::id::SpeechRecognitionResult>::Depth },
35 : JSJitInfo::Getter,
36 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
37 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
38 : true, /* isInfallible. False in setters. */
39 : false, /* isMovable. Not relevant for setters. */
40 : false, /* isEliminatable. Not relevant for setters. */
41 : false, /* isAlwaysInSlot. Only relevant for getters. */
42 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
43 : false, /* isTypedMethod. Only relevant for methods. */
44 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
45 : };
46 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
47 : static_assert(0 < 1, "There is no slot for us");
48 :
49 : static bool
50 0 : item(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionResult* self, const JSJitMethodCallArgs& args)
51 : {
52 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
53 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "SpeechRecognitionResult.item");
54 : }
55 : uint32_t arg0;
56 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
57 0 : return false;
58 : }
59 0 : auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionAlternative>(self->Item(arg0)));
60 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
61 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
62 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
63 0 : return false;
64 : }
65 0 : return true;
66 : }
67 :
68 : static const JSJitInfo item_methodinfo = {
69 : { (JSJitGetterOp)item },
70 : { prototypes::id::SpeechRecognitionResult },
71 : { PrototypeTraits<prototypes::id::SpeechRecognitionResult>::Depth },
72 : JSJitInfo::Method,
73 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
74 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
75 : false, /* 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 0 : get_isFinal(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionResult* self, JSJitGetterCallArgs args)
88 : {
89 0 : bool result(self->IsFinal());
90 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
91 0 : args.rval().setBoolean(result);
92 0 : return true;
93 : }
94 :
95 : static const JSJitInfo isFinal_getterinfo = {
96 : { (JSJitGetterOp)get_isFinal },
97 : { prototypes::id::SpeechRecognitionResult },
98 : { PrototypeTraits<prototypes::id::SpeechRecognitionResult>::Depth },
99 : JSJitInfo::Getter,
100 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
101 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
102 : true, /* isInfallible. False in setters. */
103 : false, /* isMovable. Not relevant for setters. */
104 : false, /* isEliminatable. Not relevant for setters. */
105 : false, /* isAlwaysInSlot. Only relevant for getters. */
106 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
107 : false, /* isTypedMethod. Only relevant for methods. */
108 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
109 : };
110 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
111 : static_assert(0 < 1, "There is no slot for us");
112 :
113 : static void
114 0 : _objectMoved(JSObject* obj, const JSObject* old)
115 : {
116 0 : mozilla::dom::SpeechRecognitionResult* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionResult>(obj);
117 0 : if (self) {
118 0 : UpdateWrapper(self, self, obj, old);
119 : }
120 0 : }
121 :
122 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
123 : #if defined(__clang__)
124 : #pragma clang diagnostic push
125 : #pragma clang diagnostic ignored "-Wmissing-braces"
126 : #endif
127 : static const JSFunctionSpec sMethods_specs[] = {
128 : JS_FNSPEC("item", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
129 : JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
130 : JS_FS_END
131 : };
132 : #if defined(__clang__)
133 : #pragma clang diagnostic pop
134 : #endif
135 :
136 :
137 : // Can't be const because the pref-enabled boolean needs to be writable
138 : static Prefable<const JSFunctionSpec> sMethods[] = {
139 : { nullptr, &sMethods_specs[0] },
140 : { nullptr, nullptr }
141 : };
142 :
143 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
144 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
145 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
146 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
147 :
148 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
149 : #if defined(__clang__)
150 : #pragma clang diagnostic push
151 : #pragma clang diagnostic ignored "-Wmissing-braces"
152 : #endif
153 : static const JSPropertySpec sAttributes_specs[] = {
154 : { "length", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &length_getterinfo, nullptr, nullptr },
155 : { "isFinal", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &isFinal_getterinfo, nullptr, nullptr },
156 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
157 : };
158 : #if defined(__clang__)
159 : #pragma clang diagnostic pop
160 : #endif
161 :
162 :
163 : // Can't be const because the pref-enabled boolean needs to be writable
164 : static Prefable<const JSPropertySpec> sAttributes[] = {
165 : { nullptr, &sAttributes_specs[0] },
166 : { nullptr, nullptr }
167 : };
168 :
169 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
170 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
171 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
172 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
173 :
174 :
175 : static uint16_t sNativeProperties_sortedPropertyIndices[4];
176 : static PropertyInfo sNativeProperties_propertyInfos[4];
177 :
178 : static const NativePropertiesN<2> sNativeProperties = {
179 : false, 0,
180 : false, 0,
181 : true, 0 /* sMethods */,
182 : true, 1 /* sAttributes */,
183 : false, 0,
184 : false, 0,
185 : false, 0,
186 : -1,
187 : 4,
188 : sNativeProperties_sortedPropertyIndices,
189 : {
190 : { sMethods, &sNativeProperties_propertyInfos[0] },
191 : { sAttributes, &sNativeProperties_propertyInfos[2] }
192 : }
193 : };
194 : static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
195 : "We have a property info count that is oversized");
196 :
197 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
198 : {
199 : "Function",
200 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
201 : &sBoringInterfaceObjectClassClassOps,
202 : JS_NULL_CLASS_SPEC,
203 : JS_NULL_CLASS_EXT,
204 : &sInterfaceObjectClassObjectOps
205 : },
206 : eInterface,
207 : true,
208 : prototypes::id::SpeechRecognitionResult,
209 : PrototypeTraits<prototypes::id::SpeechRecognitionResult>::Depth,
210 : sNativePropertyHooks,
211 : "function SpeechRecognitionResult() {\n [native code]\n}",
212 : JS::GetRealmFunctionPrototype
213 : };
214 :
215 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
216 : {
217 : "SpeechRecognitionResultPrototype",
218 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
219 : JS_NULL_CLASS_OPS,
220 : JS_NULL_CLASS_SPEC,
221 : JS_NULL_CLASS_EXT,
222 : JS_NULL_OBJECT_OPS
223 : },
224 : eInterfacePrototype,
225 : false,
226 : prototypes::id::SpeechRecognitionResult,
227 : PrototypeTraits<prototypes::id::SpeechRecognitionResult>::Depth,
228 : sNativePropertyHooks,
229 : "[object SpeechRecognitionResultPrototype]",
230 : JS::GetRealmObjectPrototype
231 : };
232 :
233 : bool
234 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
235 : {
236 : static bool sPrefValue;
237 : static bool sPrefCacheSetUp = false;
238 0 : if (!sPrefCacheSetUp) {
239 0 : sPrefCacheSetUp = true;
240 0 : Preferences::AddBoolVarCache(&sPrefValue, "media.webspeech.recognition.enable");
241 : }
242 :
243 0 : return sPrefValue &&
244 0 : SpeechRecognition::IsAuthorized(aCx, aObj);
245 : }
246 :
247 : JSObject*
248 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
249 : {
250 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
251 : }
252 :
253 : static_assert(IsBaseOf<nsISupports, mozilla::dom::SpeechRecognitionResult >::value,
254 : "We don't support non-nsISupports native classes for "
255 : "proxy-based bindings yet");
256 :
257 :
258 : class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
259 : {
260 : public:
261 : explicit constexpr DOMProxyHandler()
262 : {
263 : }
264 :
265 : virtual bool
266 : getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
267 :
268 : virtual bool
269 : defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
270 :
271 : using mozilla::dom::DOMProxyHandler::defineProperty;
272 :
273 : virtual bool
274 : ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
275 :
276 : virtual bool
277 : hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
278 :
279 : virtual bool
280 : get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
281 :
282 : virtual const char*
283 : className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
284 :
285 : virtual bool
286 : finalizeInBackground(const JS::Value& priv) const override;
287 :
288 : virtual void
289 : finalize(JSFreeOp* fop, JSObject* proxy) const override;
290 :
291 : static const DOMProxyHandler*
292 : getInstance();
293 :
294 : virtual bool
295 : delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
296 :
297 : virtual bool
298 : getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
299 : };
300 :
301 : MOZ_ALWAYS_INLINE bool
302 0 : IsProxy(JSObject* obj)
303 : {
304 0 : return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
305 : }
306 :
307 : MOZ_ALWAYS_INLINE mozilla::dom::SpeechRecognitionResult*
308 0 : UnwrapProxy(JSObject* obj)
309 : {
310 0 : MOZ_ASSERT(js::IsProxy(obj));
311 0 : if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
312 0 : MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
313 0 : obj = js::UncheckedUnwrap(obj);
314 : }
315 0 : MOZ_ASSERT(IsProxy(obj));
316 0 : return static_cast<mozilla::dom::SpeechRecognitionResult*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
317 : }
318 :
319 : bool
320 0 : DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
321 : {
322 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
323 0 : uint32_t index = GetArrayIndexFromId(cx, id);
324 0 : if (IsArrayIndex(index)) {
325 0 : mozilla::dom::SpeechRecognitionResult* self = UnwrapProxy(proxy);
326 0 : bool found = false;
327 0 : auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionAlternative>(self->IndexedGetter(index, found)));
328 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
329 :
330 0 : if (found) {
331 0 : if (!GetOrCreateDOMReflector(cx, result, desc.value())) {
332 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
333 0 : return false;
334 : }
335 0 : FillPropertyDescriptor(desc, proxy, true);
336 0 : return true;
337 : }
338 : }
339 :
340 0 : JS::Rooted<JSObject*> expando(cx);
341 0 : if (!isXray && (expando = GetExpandoObject(proxy))) {
342 0 : if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
343 0 : return false;
344 : }
345 0 : if (desc.object()) {
346 : // Pretend the property lives on the wrapper.
347 0 : desc.object().set(proxy);
348 0 : return true;
349 : }
350 : }
351 :
352 0 : desc.object().set(nullptr);
353 0 : return true;
354 : }
355 :
356 : bool
357 0 : DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
358 : {
359 0 : if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
360 0 : *defined = true;
361 0 : return opresult.failNoIndexedSetter();
362 : }
363 0 : return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined);
364 : }
365 :
366 :
367 : bool
368 0 : DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
369 : {
370 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
371 :
372 0 : uint32_t length = UnwrapProxy(proxy)->Length();
373 0 : MOZ_ASSERT(int32_t(length) >= 0);
374 0 : for (int32_t i = 0; i < int32_t(length); ++i) {
375 0 : if (!props.append(INT_TO_JSID(i))) {
376 0 : return false;
377 : }
378 : }
379 :
380 0 : JS::Rooted<JSObject*> expando(cx);
381 0 : if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
382 0 : !js::GetPropertyKeys(cx, expando, flags, &props)) {
383 0 : return false;
384 : }
385 :
386 0 : return true;
387 : }
388 :
389 : bool
390 0 : DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
391 : {
392 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
393 : "Should not have a XrayWrapper here");
394 :
395 0 : uint32_t index = GetArrayIndexFromId(cx, id);
396 0 : if (IsArrayIndex(index)) {
397 0 : bool found = false;
398 0 : mozilla::dom::SpeechRecognitionResult* self = UnwrapProxy(proxy);
399 0 : auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionAlternative>(self->IndexedGetter(index, found)));
400 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
401 : (void)result;
402 :
403 0 : *bp = found;
404 0 : return true;
405 : }
406 :
407 :
408 0 : JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
409 0 : if (expando) {
410 0 : bool b = true;
411 0 : bool ok = JS_HasPropertyById(cx, expando, id, &b);
412 0 : *bp = !!b;
413 0 : if (!ok || *bp) {
414 0 : return ok;
415 : }
416 : }
417 :
418 0 : *bp = false;
419 0 : return true;
420 : }
421 :
422 : bool
423 0 : DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
424 : {
425 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
426 : "Should not have a XrayWrapper here");
427 :
428 0 : uint32_t index = GetArrayIndexFromId(cx, id);
429 0 : if (IsArrayIndex(index)) {
430 0 : mozilla::dom::SpeechRecognitionResult* self = UnwrapProxy(proxy);
431 0 : bool found = false;
432 0 : auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionAlternative>(self->IndexedGetter(index, found)));
433 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
434 :
435 0 : if (found) {
436 0 : if (!GetOrCreateDOMReflector(cx, result, vp)) {
437 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
438 0 : return false;
439 : }
440 0 : return true;
441 : }
442 : // Even if we don't have this index, we don't forward the
443 : // get on to our expando object.
444 : } else {
445 : { // Scope for expando
446 0 : JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
447 0 : if (expando) {
448 : bool hasProp;
449 0 : if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
450 0 : return false;
451 : }
452 :
453 0 : if (hasProp) {
454 : // Forward the get to the expando object, but our receiver is whatever our
455 : // receiver is.
456 0 : return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp);
457 : }
458 : }
459 : }
460 : }
461 :
462 : bool foundOnPrototype;
463 0 : if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
464 0 : return false;
465 : }
466 :
467 0 : if (foundOnPrototype) {
468 0 : return true;
469 : }
470 :
471 0 : vp.setUndefined();
472 0 : return true;
473 : }
474 :
475 : const char*
476 0 : DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
477 : {
478 0 : return "SpeechRecognitionResult";
479 : }
480 :
481 : bool
482 0 : DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
483 : {
484 0 : return false;
485 : }
486 :
487 : void
488 0 : DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
489 : {
490 0 : mozilla::dom::SpeechRecognitionResult* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionResult>(proxy);
491 0 : if (self) {
492 0 : ClearWrapper(self, self, proxy);
493 0 : AddForDeferredFinalization<mozilla::dom::SpeechRecognitionResult>(self);
494 : }
495 0 : }
496 :
497 : const DOMProxyHandler*
498 0 : DOMProxyHandler::getInstance()
499 : {
500 : static const DOMProxyHandler instance;
501 0 : return &instance;
502 : }
503 :
504 : bool
505 0 : DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
506 : {
507 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
508 : "Should not have a XrayWrapper here");
509 :
510 0 : uint32_t index = GetArrayIndexFromId(cx, id);
511 0 : if (IsArrayIndex(index)) {
512 : bool deleteSucceeded;
513 0 : bool found = false;
514 0 : mozilla::dom::SpeechRecognitionResult* self = UnwrapProxy(proxy);
515 0 : auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionAlternative>(self->IndexedGetter(index, found)));
516 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
517 : (void)result;
518 0 : deleteSucceeded = !found;
519 0 : return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
520 : }
521 :
522 0 : return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
523 : }
524 :
525 : bool
526 0 : DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
527 : {
528 0 : JS::Rooted<JS::Value> temp(cx);
529 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
530 : "Should not have a XrayWrapper here");
531 :
532 0 : mozilla::dom::SpeechRecognitionResult* self = UnwrapProxy(proxy);
533 0 : uint32_t length = self->Length();
534 : // Compute the end of the indices we'll get ourselves
535 0 : uint32_t ourEnd = std::max(begin, std::min(end, length));
536 :
537 0 : for (uint32_t index = begin; index < ourEnd; ++index) {
538 0 : bool found = false;
539 0 : auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionAlternative>(self->IndexedGetter(index, found)));
540 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
541 :
542 0 : MOZ_ASSERT(found);
543 0 : if (!GetOrCreateDOMReflector(cx, result, &temp)) {
544 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
545 0 : return false;
546 : }
547 0 : if (!adder->append(cx, temp)) return false;
548 0 : continue;
549 : }
550 :
551 0 : if (end > ourEnd) {
552 0 : JS::Rooted<JSObject*> proto(cx);
553 0 : if (!js::GetObjectProto(cx, proxy, &proto)) {
554 0 : return false;
555 : }
556 0 : return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
557 : }
558 :
559 0 : return true;
560 : }
561 :
562 : static const js::ClassExtension sClassExtension = PROXY_MAKE_EXT(
563 : _objectMoved
564 : );
565 :
566 : static const DOMJSClass sClass = {
567 : PROXY_CLASS_WITH_EXT("SpeechRecognitionResult",
568 : JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
569 : &sClassExtension),
570 : { prototypes::id::SpeechRecognitionResult, 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 },
571 : IsBaseOf<nsISupports, mozilla::dom::SpeechRecognitionResult >::value,
572 : sNativePropertyHooks,
573 : FindAssociatedGlobalForNative<mozilla::dom::SpeechRecognitionResult>::Get,
574 : GetProtoObjectHandle,
575 : GetCCParticipant<mozilla::dom::SpeechRecognitionResult>::Get()
576 : };
577 :
578 : bool
579 0 : Wrap(JSContext* aCx, mozilla::dom::SpeechRecognitionResult* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
580 : {
581 : MOZ_ASSERT(static_cast<mozilla::dom::SpeechRecognitionResult*>(aObject) ==
582 : reinterpret_cast<mozilla::dom::SpeechRecognitionResult*>(aObject),
583 : "Multiple inheritance for mozilla::dom::SpeechRecognitionResult is broken.");
584 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
585 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
586 0 : MOZ_ASSERT(!aCache->GetWrapper(),
587 : "You should probably not be using Wrap() directly; use "
588 : "GetOrCreateDOMReflector instead");
589 :
590 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
591 : "nsISupports must be on our primary inheritance chain");
592 :
593 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
594 0 : if (!global) {
595 0 : return false;
596 : }
597 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
598 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
599 :
600 : // That might have ended up wrapping us already, due to the wonders
601 : // of XBL. Check for that, and bail out as needed.
602 0 : aReflector.set(aCache->GetWrapper());
603 0 : if (aReflector) {
604 : #ifdef DEBUG
605 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
606 : #endif // DEBUG
607 0 : return true;
608 : }
609 :
610 0 : JSAutoCompartment ac(aCx, global);
611 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
612 0 : if (!canonicalProto) {
613 0 : return false;
614 : }
615 0 : JS::Rooted<JSObject*> proto(aCx);
616 0 : if (aGivenProto) {
617 0 : proto = aGivenProto;
618 : // Unfortunately, while aGivenProto was in the compartment of aCx
619 : // coming in, we changed compartments to that of "parent" so may need
620 : // to wrap the proto here.
621 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
622 0 : if (!JS_WrapObject(aCx, &proto)) {
623 0 : return false;
624 : }
625 : }
626 : } else {
627 0 : proto = canonicalProto;
628 : }
629 :
630 0 : BindingJSObjectCreator<mozilla::dom::SpeechRecognitionResult> creator(aCx);
631 0 : JS::Rooted<JS::Value> expandoValue(aCx, JS::UndefinedValue());
632 0 : creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
633 0 : proto, aObject, expandoValue, aReflector);
634 0 : if (!aReflector) {
635 0 : return false;
636 : }
637 :
638 :
639 0 : aCache->SetWrapper(aReflector);
640 0 : creator.InitializationSucceeded();
641 :
642 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
643 : aCache->GetWrapperPreserveColor() == aReflector);
644 : // If proto != canonicalProto, we have to preserve our wrapper;
645 : // otherwise we won't be able to properly recreate it later, since
646 : // we won't know what proto to use. Note that we don't check
647 : // aGivenProto here, since it's entirely possible (and even
648 : // somewhat common) to have a non-null aGivenProto which is the
649 : // same as canonicalProto.
650 0 : if (proto != canonicalProto) {
651 0 : PreserveWrapper(aObject);
652 : }
653 :
654 0 : return true;
655 : }
656 :
657 : static bool
658 0 : ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
659 : {
660 0 : return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
661 : }
662 :
663 : static bool
664 0 : EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
665 : {
666 0 : return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
667 : }
668 :
669 : const NativePropertyHooks sNativePropertyHooks[] = { {
670 : ResolveOwnProperty,
671 : EnumerateOwnProperties,
672 : nullptr,
673 : { sNativeProperties.Upcast(), nullptr },
674 : prototypes::id::SpeechRecognitionResult,
675 : constructors::id::SpeechRecognitionResult,
676 : nullptr,
677 : &DefaultXrayExpandoObjectClass
678 : } };
679 :
680 : void
681 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
682 : {
683 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
684 0 : if (!parentProto) {
685 0 : return;
686 : }
687 :
688 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
689 0 : if (!constructorProto) {
690 0 : return;
691 : }
692 :
693 : static bool sIdsInited = false;
694 0 : if (!sIdsInited && NS_IsMainThread()) {
695 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
696 0 : return;
697 : }
698 0 : sIdsInited = true;
699 : }
700 :
701 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SpeechRecognitionResult);
702 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SpeechRecognitionResult);
703 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
704 : &sPrototypeClass.mBase, protoCache,
705 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
706 : interfaceCache,
707 : sNativeProperties.Upcast(),
708 : nullptr,
709 : "SpeechRecognitionResult", aDefineOnGlobal,
710 : nullptr,
711 0 : false);
712 : }
713 :
714 : JS::Handle<JSObject*>
715 0 : GetProtoObjectHandle(JSContext* aCx)
716 : {
717 : /* Get the interface prototype object for this class. This will create the
718 : object as needed. */
719 0 : bool aDefineOnGlobal = true;
720 :
721 : /* Make sure our global is sane. Hopefully we can remove this sometime */
722 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
723 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
724 0 : return nullptr;
725 : }
726 :
727 : /* Check to see whether the interface objects are already installed */
728 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
729 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::SpeechRecognitionResult)) {
730 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
731 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
732 : }
733 :
734 : /*
735 : * The object might _still_ be null, but that's OK.
736 : *
737 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
738 : * traced by TraceProtoAndIfaceCache() and its contents are never
739 : * changed after they have been set.
740 : *
741 : * Calling address() avoids the read read barrier that does gray
742 : * unmarking, but it's not possible for the object to be gray here.
743 : */
744 :
745 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::SpeechRecognitionResult);
746 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
747 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
748 : }
749 :
750 : JS::Handle<JSObject*>
751 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
752 : {
753 : /* Get the interface object for this class. This will create the object as
754 : needed. */
755 :
756 : /* Make sure our global is sane. Hopefully we can remove this sometime */
757 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
758 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
759 0 : return nullptr;
760 : }
761 :
762 : /* Check to see whether the interface objects are already installed */
763 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
764 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::SpeechRecognitionResult)) {
765 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
766 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
767 : }
768 :
769 : /*
770 : * The object might _still_ be null, but that's OK.
771 : *
772 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
773 : * traced by TraceProtoAndIfaceCache() and its contents are never
774 : * changed after they have been set.
775 : *
776 : * Calling address() avoids the read read barrier that does gray
777 : * unmarking, but it's not possible for the object to be gray here.
778 : */
779 :
780 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::SpeechRecognitionResult);
781 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
782 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
783 : }
784 :
785 : JSObject*
786 0 : GetConstructorObject(JSContext* aCx)
787 : {
788 0 : return GetConstructorObjectHandle(aCx);
789 : }
790 :
791 : } // namespace SpeechRecognitionResultBinding
792 :
793 :
794 :
795 : } // namespace dom
796 : } // namespace mozilla
|