Coverage Report

Created: 2018-09-25 14:53

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