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