Coverage Report

Created: 2018-09-25 14:53

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