Coverage Report

Created: 2018-09-25 14:53

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