Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/SpeechRecognitionEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM SpeechRecognitionEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "EventBinding.h"
5
#include "SpeechRecognition.h"
6
#include "SpeechRecognitionEventBinding.h"
7
#include "WrapperFactory.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/Preferences.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/SpeechRecognitionEvent.h"
17
#include "mozilla/dom/SpeechRecognitionResultList.h"
18
#include "mozilla/dom/XrayExpandoClass.h"
19
#include "nsIDocument.h"
20
21
namespace mozilla {
22
namespace dom {
23
24
namespace binding_detail {}; // Just to make sure it's known as a namespace
25
using namespace mozilla::dom::binding_detail;
26
27
28
29
SpeechRecognitionEventInit::SpeechRecognitionEventInit()
30
  : EventInit(FastDictionaryInitializer()),
31
    mInterpretation(JS::UndefinedValue())
32
0
{
33
0
  // Safe to pass a null context if we pass a null value
34
0
  Init(nullptr, JS::NullHandleValue);
35
0
}
36
37
38
bool
39
SpeechRecognitionEventInit::InitIds(JSContext* cx, SpeechRecognitionEventInitAtoms* atomsCache)
40
0
{
41
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
42
0
43
0
  // Initialize these in reverse order so that any failure leaves the first one
44
0
  // uninitialized.
45
0
  if (!atomsCache->results_id.init(cx, "results") ||
46
0
      !atomsCache->resultIndex_id.init(cx, "resultIndex") ||
47
0
      !atomsCache->interpretation_id.init(cx, "interpretation") ||
48
0
      !atomsCache->emma_id.init(cx, "emma")) {
49
0
    return false;
50
0
  }
51
0
  return true;
52
0
}
53
54
bool
55
SpeechRecognitionEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
56
0
{
57
0
  // Passing a null JSContext is OK only if we're initing from null,
58
0
  // Since in that case we will not have to do any property gets
59
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
60
0
  // checkers by static analysis tools
61
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
62
0
  SpeechRecognitionEventInitAtoms* atomsCache = nullptr;
63
0
  if (cx) {
64
0
    atomsCache = GetAtomCache<SpeechRecognitionEventInitAtoms>(cx);
65
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
66
0
      return false;
67
0
    }
68
0
  }
69
0
70
0
  // Per spec, we init the parent's members first
71
0
  if (!EventInit::Init(cx, val)) {
72
0
    return false;
73
0
  }
74
0
75
0
  bool isNull = val.isNullOrUndefined();
76
0
  // We only need these if !isNull, in which case we have |cx|.
77
0
  Maybe<JS::Rooted<JSObject *> > object;
78
0
  Maybe<JS::Rooted<JS::Value> > temp;
79
0
  if (!isNull) {
80
0
    MOZ_ASSERT(cx);
81
0
    object.emplace(cx, &val.toObject());
82
0
    temp.emplace(cx);
83
0
  }
84
0
  if (!isNull) {
85
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->emma_id, temp.ptr())) {
86
0
      return false;
87
0
    }
88
0
  }
89
0
  if (!isNull && !temp->isUndefined()) {
90
0
    if (temp.ref().isObject()) {
91
0
      static_assert(IsRefcounted<nsIDocument>::value, "We can only store refcounted classes.");{
92
0
        nsresult rv = UnwrapObject<prototypes::id::Document, nsIDocument>(temp.ptr(), mEmma);
93
0
        if (NS_FAILED(rv)) {
94
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'emma' member of SpeechRecognitionEventInit", "Document");
95
0
          return false;
96
0
        }
97
0
      }
98
0
    } else if (temp.ref().isNullOrUndefined()) {
99
0
      mEmma = nullptr;
100
0
    } else {
101
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'emma' member of SpeechRecognitionEventInit");
102
0
      return false;
103
0
    }
104
0
  } else {
105
0
    mEmma = nullptr;
106
0
  }
107
0
  mIsAnyMemberPresent = true;
108
0
109
0
  if (!isNull) {
110
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->interpretation_id, temp.ptr())) {
111
0
      return false;
112
0
    }
113
0
  }
114
0
  if (!isNull && !temp->isUndefined()) {
115
0
#ifdef __clang__
116
0
#pragma clang diagnostic push
117
0
#pragma clang diagnostic ignored "-Wunreachable-code"
118
0
#pragma clang diagnostic ignored "-Wunreachable-code-return"
119
0
#endif // __clang__
120
0
    if ((passedToJSImpl) && !CallerSubsumes(temp.ref())) {
121
0
      ThrowErrorMessage(cx, MSG_PERMISSION_DENIED_TO_PASS_ARG, "'interpretation' member of SpeechRecognitionEventInit");
122
0
      return false;
123
0
    }
124
0
#ifdef __clang__
125
0
#pragma clang diagnostic pop
126
0
#endif // __clang__
127
0
    mInterpretation = temp.ref();
128
0
  } else {
129
0
    mInterpretation = JS::NullValue();
130
0
  }
131
0
  mIsAnyMemberPresent = true;
132
0
133
0
  if (!isNull) {
134
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->resultIndex_id, temp.ptr())) {
135
0
      return false;
136
0
    }
137
0
  }
138
0
  if (!isNull && !temp->isUndefined()) {
139
0
    if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mResultIndex)) {
140
0
      return false;
141
0
    }
142
0
  } else {
143
0
    mResultIndex = 0U;
144
0
  }
145
0
  mIsAnyMemberPresent = true;
146
0
147
0
  if (!isNull) {
148
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->results_id, temp.ptr())) {
149
0
      return false;
150
0
    }
151
0
  }
152
0
  if (!isNull && !temp->isUndefined()) {
153
0
    if (temp.ref().isObject()) {
154
0
      static_assert(IsRefcounted<mozilla::dom::SpeechRecognitionResultList>::value, "We can only store refcounted classes.");{
155
0
        nsresult rv = UnwrapObject<prototypes::id::SpeechRecognitionResultList, mozilla::dom::SpeechRecognitionResultList>(temp.ptr(), mResults);
156
0
        if (NS_FAILED(rv)) {
157
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'results' member of SpeechRecognitionEventInit", "SpeechRecognitionResultList");
158
0
          return false;
159
0
        }
160
0
      }
161
0
    } else if (temp.ref().isNullOrUndefined()) {
162
0
      mResults = nullptr;
163
0
    } else {
164
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'results' member of SpeechRecognitionEventInit");
165
0
      return false;
166
0
    }
167
0
  } else {
168
0
    mResults = nullptr;
169
0
  }
170
0
  mIsAnyMemberPresent = true;
171
0
  return true;
172
0
}
173
174
bool
175
SpeechRecognitionEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
176
0
{
177
0
  SpeechRecognitionEventInitAtoms* atomsCache = GetAtomCache<SpeechRecognitionEventInitAtoms>(cx);
178
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
179
0
    return false;
180
0
  }
181
0
182
0
  // Per spec, we define the parent's members first
183
0
  if (!EventInit::ToObjectInternal(cx, rval)) {
184
0
    return false;
185
0
  }
186
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
187
0
188
0
  do {
189
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
190
0
    JS::Rooted<JS::Value> temp(cx);
191
0
    RefPtr<nsIDocument> const & currentValue = mEmma;
192
0
    if (!currentValue) {
193
0
      temp.setNull();
194
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->emma_id, temp, JSPROP_ENUMERATE)) {
195
0
        return false;
196
0
      }
197
0
      break;
198
0
    }
199
0
    if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
200
0
      MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing");
201
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
202
0
      return false;
203
0
    }
204
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->emma_id, temp, JSPROP_ENUMERATE)) {
205
0
      return false;
206
0
    }
207
0
    break;
208
0
  } while(false);
209
0
210
0
  do {
211
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
212
0
    JS::Rooted<JS::Value> temp(cx);
213
0
    JS::Value const & currentValue = mInterpretation;
214
0
    JS::ExposeValueToActiveJS(currentValue);
215
0
    temp.set(currentValue);
216
0
    if (!MaybeWrapValue(cx, &temp)) {
217
0
      return false;
218
0
    }
219
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->interpretation_id, temp, JSPROP_ENUMERATE)) {
220
0
      return false;
221
0
    }
222
0
    break;
223
0
  } while(false);
224
0
225
0
  do {
226
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
227
0
    JS::Rooted<JS::Value> temp(cx);
228
0
    uint32_t const & currentValue = mResultIndex;
229
0
    temp.setNumber(currentValue);
230
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->resultIndex_id, temp, JSPROP_ENUMERATE)) {
231
0
      return false;
232
0
    }
233
0
    break;
234
0
  } while(false);
235
0
236
0
  do {
237
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
238
0
    JS::Rooted<JS::Value> temp(cx);
239
0
    RefPtr<mozilla::dom::SpeechRecognitionResultList> const & currentValue = mResults;
240
0
    if (!currentValue) {
241
0
      temp.setNull();
242
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->results_id, temp, JSPROP_ENUMERATE)) {
243
0
        return false;
244
0
      }
245
0
      break;
246
0
    }
247
0
    if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
248
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
249
0
      return false;
250
0
    }
251
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->results_id, temp, JSPROP_ENUMERATE)) {
252
0
      return false;
253
0
    }
254
0
    break;
255
0
  } while(false);
256
0
257
0
  return true;
258
0
}
259
260
void
261
SpeechRecognitionEventInit::TraceDictionary(JSTracer* trc)
262
0
{
263
0
  EventInit::TraceDictionary(trc);
264
0
  JS::UnsafeTraceRoot(trc, &mInterpretation, "SpeechRecognitionEventInit.mInterpretation");
265
0
}
266
267
268
269
namespace binding_detail {
270
} // namespace binding_detail
271
272
273
namespace SpeechRecognitionEvent_Binding {
274
275
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value,
276
              "Can't inherit from an interface with a different ownership model.");
277
278
MOZ_CAN_RUN_SCRIPT static bool
279
get_resultIndex(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionEvent* self, JSJitGetterCallArgs args)
280
0
{
281
0
  AUTO_PROFILER_LABEL_FAST("get SpeechRecognitionEvent.resultIndex", DOM, cx);
282
0
283
0
  uint32_t result(self->ResultIndex());
284
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
285
0
  args.rval().setNumber(result);
286
0
  return true;
287
0
}
288
289
static const JSJitInfo resultIndex_getterinfo = {
290
  { (JSJitGetterOp)get_resultIndex },
291
  { prototypes::id::SpeechRecognitionEvent },
292
  { PrototypeTraits<prototypes::id::SpeechRecognitionEvent>::Depth },
293
  JSJitInfo::Getter,
294
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
295
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
296
  true,  /* isInfallible. False in setters. */
297
  false,  /* isMovable.  Not relevant for setters. */
298
  false, /* isEliminatable.  Not relevant for setters. */
299
  false, /* isAlwaysInSlot.  Only relevant for getters. */
300
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
301
  false,  /* isTypedMethod.  Only relevant for methods. */
302
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
303
};
304
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
305
static_assert(0 < 1, "There is no slot for us");
306
307
MOZ_CAN_RUN_SCRIPT static bool
308
get_results(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionEvent* self, JSJitGetterCallArgs args)
309
0
{
310
0
  AUTO_PROFILER_LABEL_FAST("get SpeechRecognitionEvent.results", DOM, cx);
311
0
312
0
  auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionResultList>(self->GetResults()));
313
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
314
0
  if (!result) {
315
0
    args.rval().setNull();
316
0
    return true;
317
0
  }
318
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
319
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
320
0
    return false;
321
0
  }
322
0
  return true;
323
0
}
324
325
static const JSJitInfo results_getterinfo = {
326
  { (JSJitGetterOp)get_results },
327
  { prototypes::id::SpeechRecognitionEvent },
328
  { PrototypeTraits<prototypes::id::SpeechRecognitionEvent>::Depth },
329
  JSJitInfo::Getter,
330
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
331
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
332
  false,  /* isInfallible. False in setters. */
333
  false,  /* isMovable.  Not relevant for setters. */
334
  false, /* isEliminatable.  Not relevant for setters. */
335
  false, /* isAlwaysInSlot.  Only relevant for getters. */
336
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
337
  false,  /* isTypedMethod.  Only relevant for methods. */
338
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
339
};
340
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
341
static_assert(0 < 1, "There is no slot for us");
342
343
MOZ_CAN_RUN_SCRIPT static bool
344
get_interpretation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionEvent* self, JSJitGetterCallArgs args)
345
0
{
346
0
  AUTO_PROFILER_LABEL_FAST("get SpeechRecognitionEvent.interpretation", DOM, cx);
347
0
348
0
  JS::Rooted<JS::Value> result(cx);
349
0
  self->GetInterpretation(cx, &result);
350
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
351
0
  JS::ExposeValueToActiveJS(result);
352
0
  args.rval().set(result);
353
0
  if (!MaybeWrapValue(cx, args.rval())) {
354
0
    return false;
355
0
  }
356
0
  return true;
357
0
}
358
359
static const JSJitInfo interpretation_getterinfo = {
360
  { (JSJitGetterOp)get_interpretation },
361
  { prototypes::id::SpeechRecognitionEvent },
362
  { PrototypeTraits<prototypes::id::SpeechRecognitionEvent>::Depth },
363
  JSJitInfo::Getter,
364
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
365
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
366
  false,  /* isInfallible. False in setters. */
367
  false,  /* isMovable.  Not relevant for setters. */
368
  false, /* isEliminatable.  Not relevant for setters. */
369
  false, /* isAlwaysInSlot.  Only relevant for getters. */
370
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
371
  false,  /* isTypedMethod.  Only relevant for methods. */
372
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
373
};
374
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
375
static_assert(0 < 1, "There is no slot for us");
376
377
MOZ_CAN_RUN_SCRIPT static bool
378
get_emma(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionEvent* self, JSJitGetterCallArgs args)
379
0
{
380
0
  AUTO_PROFILER_LABEL_FAST("get SpeechRecognitionEvent.emma", DOM, cx);
381
0
382
0
  auto result(StrongOrRawPtr<nsIDocument>(self->GetEmma()));
383
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
384
0
  if (!result) {
385
0
    args.rval().setNull();
386
0
    return true;
387
0
  }
388
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
389
0
    MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing");
390
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
391
0
    return false;
392
0
  }
393
0
  return true;
394
0
}
395
396
static const JSJitInfo emma_getterinfo = {
397
  { (JSJitGetterOp)get_emma },
398
  { prototypes::id::SpeechRecognitionEvent },
399
  { PrototypeTraits<prototypes::id::SpeechRecognitionEvent>::Depth },
400
  JSJitInfo::Getter,
401
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
402
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
403
  false,  /* isInfallible. False in setters. */
404
  false,  /* isMovable.  Not relevant for setters. */
405
  false, /* isEliminatable.  Not relevant for setters. */
406
  false, /* isAlwaysInSlot.  Only relevant for getters. */
407
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
408
  false,  /* isTypedMethod.  Only relevant for methods. */
409
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
410
};
411
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
412
static_assert(0 < 1, "There is no slot for us");
413
414
MOZ_CAN_RUN_SCRIPT static bool
415
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::SpeechRecognitionEvent* self, JSJitGetterCallArgs args)
416
0
{
417
0
  AUTO_PROFILER_LABEL_FAST("get SpeechRecognitionEvent.isTrusted", DOM, cx);
418
0
419
0
  bool result(self->IsTrusted());
420
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
421
0
  args.rval().setBoolean(result);
422
0
  return true;
423
0
}
424
425
static const JSJitInfo isTrusted_getterinfo = {
426
  { (JSJitGetterOp)get_isTrusted },
427
  { prototypes::id::SpeechRecognitionEvent },
428
  { PrototypeTraits<prototypes::id::SpeechRecognitionEvent>::Depth },
429
  JSJitInfo::Getter,
430
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
431
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
432
  true,  /* isInfallible. False in setters. */
433
  true,  /* isMovable.  Not relevant for setters. */
434
  true, /* isEliminatable.  Not relevant for setters. */
435
  false, /* isAlwaysInSlot.  Only relevant for getters. */
436
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
437
  false,  /* isTypedMethod.  Only relevant for methods. */
438
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
439
};
440
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
441
static_assert(0 < 1, "There is no slot for us");
442
443
static bool
444
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
445
0
{
446
0
  mozilla::dom::SpeechRecognitionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionEvent>(obj);
447
0
  // We don't want to preserve if we don't have a wrapper, and we
448
0
  // obviously can't preserve if we're not initialized.
449
0
  if (self && self->GetWrapperPreserveColor()) {
450
0
    PreserveWrapper(self);
451
0
  }
452
0
  return true;
453
0
}
454
455
static void
456
_finalize(js::FreeOp* fop, JSObject* obj)
457
0
{
458
0
  mozilla::dom::SpeechRecognitionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionEvent>(obj);
459
0
  if (self) {
460
0
    ClearWrapper(self, self, obj);
461
0
    AddForDeferredFinalization<mozilla::dom::SpeechRecognitionEvent>(self);
462
0
  }
463
0
}
464
465
static size_t
466
_objectMoved(JSObject* obj, JSObject* old)
467
0
{
468
0
  mozilla::dom::SpeechRecognitionEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::SpeechRecognitionEvent>(obj);
469
0
  if (self) {
470
0
    UpdateWrapper(self, self, obj, old);
471
0
  }
472
0
473
0
  return 0;
474
0
}
475
476
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
477
#if defined(__clang__)
478
#pragma clang diagnostic push
479
#pragma clang diagnostic ignored "-Wmissing-braces"
480
#endif
481
static const JSPropertySpec sAttributes_specs[] = {
482
  { "resultIndex", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &resultIndex_getterinfo, nullptr, nullptr },
483
  { "results", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &results_getterinfo, nullptr, nullptr },
484
  { "interpretation", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &interpretation_getterinfo, nullptr, nullptr },
485
  { "emma", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &emma_getterinfo, nullptr, nullptr },
486
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
487
};
488
#if defined(__clang__)
489
#pragma clang diagnostic pop
490
#endif
491
492
493
static const Prefable<const JSPropertySpec> sAttributes[] = {
494
  { nullptr, &sAttributes_specs[0] },
495
  { nullptr, nullptr }
496
};
497
498
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
499
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
500
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
501
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
502
503
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
504
#if defined(__clang__)
505
#pragma clang diagnostic push
506
#pragma clang diagnostic ignored "-Wmissing-braces"
507
#endif
508
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
509
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
510
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
511
};
512
#if defined(__clang__)
513
#pragma clang diagnostic pop
514
#endif
515
516
517
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
518
  { nullptr, &sUnforgeableAttributes_specs[0] },
519
  { nullptr, nullptr }
520
};
521
522
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
523
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
524
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
525
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
526
527
528
static uint16_t sNativeProperties_sortedPropertyIndices[5];
529
static PropertyInfo sNativeProperties_propertyInfos[5];
530
531
static const NativePropertiesN<2> sNativeProperties = {
532
  false, 0,
533
  false, 0,
534
  false, 0,
535
  true,  0 /* sAttributes */,
536
  false, 0,
537
  true,  1 /* sUnforgeableAttributes */,
538
  false, 0,
539
  -1,
540
  5,
541
  sNativeProperties_sortedPropertyIndices,
542
  {
543
    { sAttributes, &sNativeProperties_propertyInfos[0] },
544
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[4] }
545
  }
546
};
547
static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
548
    "We have a property info count that is oversized");
549
550
static bool
551
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
552
0
{
553
0
  AUTO_PROFILER_LABEL_FAST("SpeechRecognitionEvent constructor", DOM, cx);
554
0
555
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
556
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
557
0
  if (!args.isConstructing()) {
558
0
    // XXXbz wish I could get the name from the callee instead of
559
0
    // Adding more relocations
560
0
    return ThrowConstructorWithoutNew(cx, "SpeechRecognitionEvent");
561
0
  }
562
0
563
0
  JS::Rooted<JSObject*> desiredProto(cx);
564
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
565
0
    return false;
566
0
  }
567
0
568
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
569
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "SpeechRecognitionEvent");
570
0
  }
571
0
  GlobalObject global(cx, obj);
572
0
  if (global.Failed()) {
573
0
    return false;
574
0
  }
575
0
576
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
577
0
  binding_detail::FakeString arg0;
578
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
579
0
    return false;
580
0
  }
581
0
  RootedDictionary<binding_detail::FastSpeechRecognitionEventInit> arg1(cx);
582
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of SpeechRecognitionEvent.constructor", false)) {
583
0
    return false;
584
0
  }
585
0
  Maybe<JSAutoRealm> ar;
586
0
  if (objIsXray) {
587
0
    obj = js::CheckedUnwrap(obj);
588
0
    if (!obj) {
589
0
      return false;
590
0
    }
591
0
    ar.emplace(cx, obj);
592
0
    if (!JS_WrapObject(cx, &desiredProto)) {
593
0
      return false;
594
0
    }
595
0
    if (!JS_WrapValue(cx, JS::MutableHandle<JS::Value>::fromMarkedLocation(&arg1.mInterpretation))) {
596
0
      return false;
597
0
    }
598
0
  }
599
0
  FastErrorResult rv;
600
0
  auto result(StrongOrRawPtr<mozilla::dom::SpeechRecognitionEvent>(mozilla::dom::SpeechRecognitionEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
601
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
602
0
    return false;
603
0
  }
604
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
605
0
  static_assert(!IsPointer<decltype(result)>::value,
606
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
607
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
608
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
609
0
    return false;
610
0
  }
611
0
  return true;
612
0
}
613
614
static const js::ClassOps sInterfaceObjectClassOps = {
615
    nullptr,               /* addProperty */
616
    nullptr,               /* delProperty */
617
    nullptr,               /* enumerate */
618
    nullptr,               /* newEnumerate */
619
    nullptr,               /* resolve */
620
    nullptr,               /* mayResolve */
621
    nullptr,               /* finalize */
622
    _constructor, /* call */
623
    nullptr,               /* hasInstance */
624
    _constructor, /* construct */
625
    nullptr,               /* trace */
626
};
627
628
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
629
  {
630
    "Function",
631
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
632
    &sInterfaceObjectClassOps,
633
    JS_NULL_CLASS_SPEC,
634
    JS_NULL_CLASS_EXT,
635
    &sInterfaceObjectClassObjectOps
636
  },
637
  eInterface,
638
  true,
639
  prototypes::id::SpeechRecognitionEvent,
640
  PrototypeTraits<prototypes::id::SpeechRecognitionEvent>::Depth,
641
  sNativePropertyHooks,
642
  "function SpeechRecognitionEvent() {\n    [native code]\n}",
643
  Event_Binding::GetConstructorObject
644
};
645
646
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
647
  {
648
    "SpeechRecognitionEventPrototype",
649
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
650
    JS_NULL_CLASS_OPS,
651
    JS_NULL_CLASS_SPEC,
652
    JS_NULL_CLASS_EXT,
653
    JS_NULL_OBJECT_OPS
654
  },
655
  eInterfacePrototype,
656
  false,
657
  prototypes::id::SpeechRecognitionEvent,
658
  PrototypeTraits<prototypes::id::SpeechRecognitionEvent>::Depth,
659
  sNativePropertyHooks,
660
  "[object SpeechRecognitionEventPrototype]",
661
  Event_Binding::GetProtoObject
662
};
663
664
bool
665
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
666
0
{
667
0
  static bool sPrefValue;
668
0
  static bool sPrefCacheSetUp = false;
669
0
  if (!sPrefCacheSetUp) {
670
0
    sPrefCacheSetUp = true;
671
0
    Preferences::AddBoolVarCache(&sPrefValue, "media.webspeech.recognition.enable");
672
0
  }
673
0
674
0
  return sPrefValue &&
675
0
         SpeechRecognition::IsAuthorized(aCx, aObj);
676
0
}
677
678
static const js::ClassOps sClassOps = {
679
  _addProperty, /* addProperty */
680
  nullptr,               /* delProperty */
681
  nullptr,               /* enumerate */
682
  nullptr, /* newEnumerate */
683
  nullptr, /* resolve */
684
  nullptr, /* mayResolve */
685
  _finalize, /* finalize */
686
  nullptr, /* call */
687
  nullptr,               /* hasInstance */
688
  nullptr,               /* construct */
689
  nullptr, /* trace */
690
};
691
692
static const js::ClassExtension sClassExtension = {
693
  nullptr, /* weakmapKeyDelegateOp */
694
  _objectMoved /* objectMovedOp */
695
};
696
697
static const DOMJSClass sClass = {
698
  { "SpeechRecognitionEvent",
699
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
700
    &sClassOps,
701
    JS_NULL_CLASS_SPEC,
702
    &sClassExtension,
703
    JS_NULL_OBJECT_OPS
704
  },
705
  { prototypes::id::Event, prototypes::id::SpeechRecognitionEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
706
  IsBaseOf<nsISupports, mozilla::dom::SpeechRecognitionEvent >::value,
707
  sNativePropertyHooks,
708
  FindAssociatedGlobalForNative<mozilla::dom::SpeechRecognitionEvent>::Get,
709
  GetProtoObjectHandle,
710
  GetCCParticipant<mozilla::dom::SpeechRecognitionEvent>::Get()
711
};
712
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
713
              "Must have the right minimal number of reserved slots.");
714
static_assert(1 >= 1,
715
              "Must have enough reserved slots.");
716
717
const JSClass*
718
GetJSClass()
719
0
{
720
0
  return sClass.ToJSClass();
721
0
}
722
723
bool
724
Wrap(JSContext* aCx, mozilla::dom::SpeechRecognitionEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
725
0
{
726
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::SpeechRecognitionEvent>::value,
727
0
                "Shouldn't have wrappercached things that are not refcounted.");
728
0
  MOZ_ASSERT(static_cast<mozilla::dom::SpeechRecognitionEvent*>(aObject) ==
729
0
             reinterpret_cast<mozilla::dom::SpeechRecognitionEvent*>(aObject),
730
0
             "Multiple inheritance for mozilla::dom::SpeechRecognitionEvent is broken.");
731
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
732
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
733
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
734
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
735
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
736
0
  MOZ_ASSERT(!aCache->GetWrapper(),
737
0
             "You should probably not be using Wrap() directly; use "
738
0
             "GetOrCreateDOMReflector instead");
739
0
740
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
741
0
             "nsISupports must be on our primary inheritance chain");
742
0
743
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
744
0
  if (!global) {
745
0
    return false;
746
0
  }
747
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
748
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
749
0
750
0
  // That might have ended up wrapping us already, due to the wonders
751
0
  // of XBL.  Check for that, and bail out as needed.
752
0
  aReflector.set(aCache->GetWrapper());
753
0
  if (aReflector) {
754
#ifdef DEBUG
755
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
756
#endif // DEBUG
757
    return true;
758
0
  }
759
0
760
0
  JSAutoRealm ar(aCx, global);
761
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
762
0
  if (!canonicalProto) {
763
0
    return false;
764
0
  }
765
0
  JS::Rooted<JSObject*> proto(aCx);
766
0
  if (aGivenProto) {
767
0
    proto = aGivenProto;
768
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
769
0
    // coming in, we changed compartments to that of "parent" so may need
770
0
    // to wrap the proto here.
771
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
772
0
      if (!JS_WrapObject(aCx, &proto)) {
773
0
        return false;
774
0
      }
775
0
    }
776
0
  } else {
777
0
    proto = canonicalProto;
778
0
  }
779
0
780
0
  BindingJSObjectCreator<mozilla::dom::SpeechRecognitionEvent> creator(aCx);
781
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
782
0
  if (!aReflector) {
783
0
    return false;
784
0
  }
785
0
786
0
  aCache->SetWrapper(aReflector);
787
0
788
0
  // Important: do unforgeable property setup after we have handed
789
0
  // over ownership of the C++ object to obj as needed, so that if
790
0
  // we fail and it ends up GCed it won't have problems in the
791
0
  // finalizer trying to drop its ownership of the C++ object.
792
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
793
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
794
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
795
0
    aCache->ReleaseWrapper(aObject);
796
0
    aCache->ClearWrapper();
797
0
    return false;
798
0
  }
799
0
  creator.InitializationSucceeded();
800
0
801
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
802
0
             aCache->GetWrapperPreserveColor() == aReflector);
803
0
  // If proto != canonicalProto, we have to preserve our wrapper;
804
0
  // otherwise we won't be able to properly recreate it later, since
805
0
  // we won't know what proto to use.  Note that we don't check
806
0
  // aGivenProto here, since it's entirely possible (and even
807
0
  // somewhat common) to have a non-null aGivenProto which is the
808
0
  // same as canonicalProto.
809
0
  if (proto != canonicalProto) {
810
0
    PreserveWrapper(aObject);
811
0
  }
812
0
813
0
  return true;
814
0
}
815
816
const NativePropertyHooks sNativePropertyHooks[] = { {
817
  nullptr,
818
  nullptr,
819
  nullptr,
820
  { sNativeProperties.Upcast(), nullptr },
821
  prototypes::id::SpeechRecognitionEvent,
822
  constructors::id::SpeechRecognitionEvent,
823
  Event_Binding::sNativePropertyHooks,
824
  &DefaultXrayExpandoObjectClass
825
} };
826
827
void
828
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
829
0
{
830
0
  JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx));
831
0
  if (!parentProto) {
832
0
    return;
833
0
  }
834
0
835
0
  JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx));
836
0
  if (!constructorProto) {
837
0
    return;
838
0
  }
839
0
840
0
  static bool sIdsInited = false;
841
0
  if (!sIdsInited && NS_IsMainThread()) {
842
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
843
0
      return;
844
0
    }
845
0
    sIdsInited = true;
846
0
  }
847
0
848
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::SpeechRecognitionEvent);
849
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::SpeechRecognitionEvent);
850
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
851
0
                              &sPrototypeClass.mBase, protoCache,
852
0
                              nullptr,
853
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
854
0
                              interfaceCache,
855
0
                              sNativeProperties.Upcast(),
856
0
                              nullptr,
857
0
                              "SpeechRecognitionEvent", aDefineOnGlobal,
858
0
                              nullptr,
859
0
                              false);
860
0
861
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
862
0
  {
863
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
864
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
865
0
    if (!unforgeableHolder) {
866
0
      *protoCache = nullptr;
867
0
      if (interfaceCache) {
868
0
        *interfaceCache = nullptr;
869
0
      }
870
0
      return;
871
0
    }
872
0
  }
873
0
874
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
875
0
    *protoCache = nullptr;
876
0
    if (interfaceCache) {
877
0
      *interfaceCache = nullptr;
878
0
    }
879
0
    return;
880
0
  }
881
0
882
0
  if (*protoCache) {
883
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
884
0
                        JS::ObjectValue(*unforgeableHolder));
885
0
  }
886
0
}
887
888
JSObject*
889
GetConstructorObject(JSContext* aCx)
890
0
{
891
0
  return GetConstructorObjectHandle(aCx);
892
0
}
893
894
} // namespace SpeechRecognitionEvent_Binding
895
896
897
898
} // namespace dom
899
} // namespace mozilla