Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/EventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Event.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "EventBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/FloatingPoint.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/Event.h"
11
#include "mozilla/dom/EventTarget.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/SimpleGlobalObject.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
#include "nsContentUtils.h"
19
#include "nsISupports.h"
20
#include "xpcjsid.h"
21
22
namespace mozilla {
23
namespace dom {
24
25
namespace binding_detail {}; // Just to make sure it's known as a namespace
26
using namespace mozilla::dom::binding_detail;
27
28
29
30
EventInit::EventInit()
31
0
{
32
0
  // Safe to pass a null context if we pass a null value
33
0
  Init(nullptr, JS::NullHandleValue);
34
0
}
35
36
37
38
bool
39
EventInit::InitIds(JSContext* cx, EventInitAtoms* 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->composed_id.init(cx, "composed") ||
46
0
      !atomsCache->cancelable_id.init(cx, "cancelable") ||
47
0
      !atomsCache->bubbles_id.init(cx, "bubbles")) {
48
0
    return false;
49
0
  }
50
0
  return true;
51
0
}
52
53
bool
54
EventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
55
0
{
56
0
  // Passing a null JSContext is OK only if we're initing from null,
57
0
  // Since in that case we will not have to do any property gets
58
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
59
0
  // checkers by static analysis tools
60
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
61
0
  EventInitAtoms* atomsCache = nullptr;
62
0
  if (cx) {
63
0
    atomsCache = GetAtomCache<EventInitAtoms>(cx);
64
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
65
0
      return false;
66
0
    }
67
0
  }
68
0
69
0
  if (!IsConvertibleToDictionary(val)) {
70
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
71
0
  }
72
0
73
0
  bool isNull = val.isNullOrUndefined();
74
0
  // We only need these if !isNull, in which case we have |cx|.
75
0
  Maybe<JS::Rooted<JSObject *> > object;
76
0
  Maybe<JS::Rooted<JS::Value> > temp;
77
0
  if (!isNull) {
78
0
    MOZ_ASSERT(cx);
79
0
    object.emplace(cx, &val.toObject());
80
0
    temp.emplace(cx);
81
0
  }
82
0
  if (!isNull) {
83
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->bubbles_id, temp.ptr())) {
84
0
      return false;
85
0
    }
86
0
  }
87
0
  if (!isNull && !temp->isUndefined()) {
88
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mBubbles)) {
89
0
      return false;
90
0
    }
91
0
  } else {
92
0
    mBubbles = false;
93
0
  }
94
0
  mIsAnyMemberPresent = true;
95
0
96
0
  if (!isNull) {
97
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->cancelable_id, temp.ptr())) {
98
0
      return false;
99
0
    }
100
0
  }
101
0
  if (!isNull && !temp->isUndefined()) {
102
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mCancelable)) {
103
0
      return false;
104
0
    }
105
0
  } else {
106
0
    mCancelable = false;
107
0
  }
108
0
  mIsAnyMemberPresent = true;
109
0
110
0
  if (!isNull) {
111
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->composed_id, temp.ptr())) {
112
0
      return false;
113
0
    }
114
0
  }
115
0
  if (!isNull && !temp->isUndefined()) {
116
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mComposed)) {
117
0
      return false;
118
0
    }
119
0
  } else {
120
0
    mComposed = false;
121
0
  }
122
0
  mIsAnyMemberPresent = true;
123
0
  return true;
124
0
}
125
126
bool
127
EventInit::Init(const nsAString& aJSON)
128
0
{
129
0
  AutoJSAPI jsapi;
130
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
131
0
  if (!cleanGlobal) {
132
0
    return false;
133
0
  }
134
0
  if (!jsapi.Init(cleanGlobal)) {
135
0
    return false;
136
0
  }
137
0
  JSContext* cx = jsapi.cx();
138
0
  JS::Rooted<JS::Value> json(cx);
139
0
  bool ok = ParseJSON(cx, aJSON, &json);
140
0
  NS_ENSURE_TRUE(ok, false);
141
0
  return Init(cx, json);
142
0
}
143
144
bool
145
EventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
146
0
{
147
0
  EventInitAtoms* atomsCache = GetAtomCache<EventInitAtoms>(cx);
148
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
149
0
    return false;
150
0
  }
151
0
152
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
153
0
  if (!obj) {
154
0
    return false;
155
0
  }
156
0
  rval.set(JS::ObjectValue(*obj));
157
0
158
0
  do {
159
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
160
0
    JS::Rooted<JS::Value> temp(cx);
161
0
    bool const & currentValue = mBubbles;
162
0
    temp.setBoolean(currentValue);
163
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->bubbles_id, temp, JSPROP_ENUMERATE)) {
164
0
      return false;
165
0
    }
166
0
    break;
167
0
  } while(false);
168
0
169
0
  do {
170
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
171
0
    JS::Rooted<JS::Value> temp(cx);
172
0
    bool const & currentValue = mCancelable;
173
0
    temp.setBoolean(currentValue);
174
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->cancelable_id, temp, JSPROP_ENUMERATE)) {
175
0
      return false;
176
0
    }
177
0
    break;
178
0
  } while(false);
179
0
180
0
  do {
181
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
182
0
    JS::Rooted<JS::Value> temp(cx);
183
0
    bool const & currentValue = mComposed;
184
0
    temp.setBoolean(currentValue);
185
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->composed_id, temp, JSPROP_ENUMERATE)) {
186
0
      return false;
187
0
    }
188
0
    break;
189
0
  } while(false);
190
0
191
0
  return true;
192
0
}
193
194
bool
195
EventInit::ToJSON(nsAString& aJSON) const
196
0
{
197
0
  AutoJSAPI jsapi;
198
0
  jsapi.Init();
199
0
  JSContext *cx = jsapi.cx();
200
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
201
0
  // because we'll only be creating objects, in ways that have no
202
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
203
0
  // which likewise guarantees no side-effects for the sorts of
204
0
  // things we will pass it.
205
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
206
0
  JS::Rooted<JS::Value> val(cx);
207
0
  if (!ToObjectInternal(cx, &val)) {
208
0
    return false;
209
0
  }
210
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
211
0
  return StringifyToJSON(cx, obj, aJSON);
212
0
}
213
214
void
215
EventInit::TraceDictionary(JSTracer* trc)
216
0
{
217
0
}
218
219
EventInit&
220
EventInit::operator=(const EventInit& aOther)
221
0
{
222
0
  DictionaryBase::operator=(aOther);
223
0
  mBubbles = aOther.mBubbles;
224
0
  mCancelable = aOther.mCancelable;
225
0
  mComposed = aOther.mComposed;
226
0
  return *this;
227
0
}
228
229
namespace binding_detail {
230
} // namespace binding_detail
231
232
233
namespace Event_Binding {
234
235
MOZ_CAN_RUN_SCRIPT static bool
236
get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
237
0
{
238
0
  AUTO_PROFILER_LABEL_FAST("get Event.type", DOM, cx);
239
0
240
0
  DOMString result;
241
0
  self->GetType(result);
242
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
243
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
244
0
    return false;
245
0
  }
246
0
  return true;
247
0
}
248
249
static const JSJitInfo type_getterinfo = {
250
  { (JSJitGetterOp)get_type },
251
  { prototypes::id::Event },
252
  { PrototypeTraits<prototypes::id::Event>::Depth },
253
  JSJitInfo::Getter,
254
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
255
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
256
  false,  /* isInfallible. False in setters. */
257
  true,  /* isMovable.  Not relevant for setters. */
258
  true, /* isEliminatable.  Not relevant for setters. */
259
  false, /* isAlwaysInSlot.  Only relevant for getters. */
260
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
261
  false,  /* isTypedMethod.  Only relevant for methods. */
262
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
263
};
264
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
265
static_assert(0 < 1, "There is no slot for us");
266
267
MOZ_CAN_RUN_SCRIPT static bool
268
get_target(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
269
0
{
270
0
  AUTO_PROFILER_LABEL_FAST("get Event.target", DOM, cx);
271
0
272
0
  auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetTarget()));
273
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
274
0
  if (!result) {
275
0
    args.rval().setNull();
276
0
    return true;
277
0
  }
278
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
279
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
280
0
    return false;
281
0
  }
282
0
  return true;
283
0
}
284
285
static const JSJitInfo target_getterinfo = {
286
  { (JSJitGetterOp)get_target },
287
  { prototypes::id::Event },
288
  { PrototypeTraits<prototypes::id::Event>::Depth },
289
  JSJitInfo::Getter,
290
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
291
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
292
  false,  /* isInfallible. False in setters. */
293
  true,  /* isMovable.  Not relevant for setters. */
294
  true, /* isEliminatable.  Not relevant for setters. */
295
  false, /* isAlwaysInSlot.  Only relevant for getters. */
296
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
297
  false,  /* isTypedMethod.  Only relevant for methods. */
298
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
299
};
300
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
301
static_assert(0 < 1, "There is no slot for us");
302
303
MOZ_CAN_RUN_SCRIPT static bool
304
get_currentTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
305
0
{
306
0
  AUTO_PROFILER_LABEL_FAST("get Event.currentTarget", DOM, cx);
307
0
308
0
  auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetCurrentTarget()));
309
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
310
0
  if (!result) {
311
0
    args.rval().setNull();
312
0
    return true;
313
0
  }
314
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
315
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
316
0
    return false;
317
0
  }
318
0
  return true;
319
0
}
320
321
static const JSJitInfo currentTarget_getterinfo = {
322
  { (JSJitGetterOp)get_currentTarget },
323
  { prototypes::id::Event },
324
  { PrototypeTraits<prototypes::id::Event>::Depth },
325
  JSJitInfo::Getter,
326
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
327
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
328
  false,  /* isInfallible. False in setters. */
329
  true,  /* isMovable.  Not relevant for setters. */
330
  true, /* isEliminatable.  Not relevant for setters. */
331
  false, /* isAlwaysInSlot.  Only relevant for getters. */
332
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
333
  false,  /* isTypedMethod.  Only relevant for methods. */
334
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
335
};
336
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
337
static_assert(0 < 1, "There is no slot for us");
338
339
MOZ_CAN_RUN_SCRIPT static bool
340
composedPath(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
341
0
{
342
0
  AUTO_PROFILER_LABEL_FAST("Event.composedPath", DOM, cx);
343
0
344
0
  nsTArray<StrongPtrForMember<mozilla::dom::EventTarget>::Type> result;
345
0
  self->ComposedPath(result);
346
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
347
0
348
0
  uint32_t length = result.Length();
349
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
350
0
  if (!returnArray) {
351
0
    return false;
352
0
  }
353
0
  // Scope for 'tmp'
354
0
  {
355
0
    JS::Rooted<JS::Value> tmp(cx);
356
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
357
0
      // Control block to let us common up the JS_DefineElement calls when there
358
0
      // are different ways to succeed at wrapping the object.
359
0
      do {
360
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
361
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
362
0
          return false;
363
0
        }
364
0
        break;
365
0
      } while (false);
366
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
367
0
                            JSPROP_ENUMERATE)) {
368
0
        return false;
369
0
      }
370
0
    }
371
0
  }
372
0
  args.rval().setObject(*returnArray);
373
0
  return true;
374
0
}
375
376
static const JSJitInfo composedPath_methodinfo = {
377
  { (JSJitGetterOp)composedPath },
378
  { prototypes::id::Event },
379
  { PrototypeTraits<prototypes::id::Event>::Depth },
380
  JSJitInfo::Method,
381
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
382
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
383
  false,  /* isInfallible. False in setters. */
384
  false,  /* isMovable.  Not relevant for setters. */
385
  false, /* isEliminatable.  Not relevant for setters. */
386
  false, /* isAlwaysInSlot.  Only relevant for getters. */
387
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
388
  false,  /* isTypedMethod.  Only relevant for methods. */
389
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
390
};
391
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
392
static_assert(0 < 1, "There is no slot for us");
393
394
MOZ_CAN_RUN_SCRIPT static bool
395
get_eventPhase(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
396
0
{
397
0
  AUTO_PROFILER_LABEL_FAST("get Event.eventPhase", DOM, cx);
398
0
399
0
  uint16_t result(self->EventPhase());
400
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
401
0
  args.rval().setInt32(int32_t(result));
402
0
  return true;
403
0
}
404
405
static const JSJitInfo eventPhase_getterinfo = {
406
  { (JSJitGetterOp)get_eventPhase },
407
  { prototypes::id::Event },
408
  { PrototypeTraits<prototypes::id::Event>::Depth },
409
  JSJitInfo::Getter,
410
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
411
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
412
  true,  /* isInfallible. False in setters. */
413
  true,  /* isMovable.  Not relevant for setters. */
414
  true, /* isEliminatable.  Not relevant for setters. */
415
  false, /* isAlwaysInSlot.  Only relevant for getters. */
416
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
417
  false,  /* isTypedMethod.  Only relevant for methods. */
418
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
419
};
420
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
421
static_assert(0 < 1, "There is no slot for us");
422
423
MOZ_CAN_RUN_SCRIPT static bool
424
stopPropagation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
425
0
{
426
0
  AUTO_PROFILER_LABEL_FAST("Event.stopPropagation", DOM, cx);
427
0
428
0
  self->StopPropagation();
429
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
430
0
  args.rval().setUndefined();
431
0
  return true;
432
0
}
433
434
static const JSJitInfo stopPropagation_methodinfo = {
435
  { (JSJitGetterOp)stopPropagation },
436
  { prototypes::id::Event },
437
  { PrototypeTraits<prototypes::id::Event>::Depth },
438
  JSJitInfo::Method,
439
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
440
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
441
  true,  /* isInfallible. False in setters. */
442
  false,  /* isMovable.  Not relevant for setters. */
443
  false, /* isEliminatable.  Not relevant for setters. */
444
  false, /* isAlwaysInSlot.  Only relevant for getters. */
445
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
446
  false,  /* isTypedMethod.  Only relevant for methods. */
447
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
448
};
449
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
450
static_assert(0 < 1, "There is no slot for us");
451
452
MOZ_CAN_RUN_SCRIPT static bool
453
stopImmediatePropagation(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
454
0
{
455
0
  AUTO_PROFILER_LABEL_FAST("Event.stopImmediatePropagation", DOM, cx);
456
0
457
0
  self->StopImmediatePropagation();
458
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
459
0
  args.rval().setUndefined();
460
0
  return true;
461
0
}
462
463
static const JSJitInfo stopImmediatePropagation_methodinfo = {
464
  { (JSJitGetterOp)stopImmediatePropagation },
465
  { prototypes::id::Event },
466
  { PrototypeTraits<prototypes::id::Event>::Depth },
467
  JSJitInfo::Method,
468
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
469
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
470
  true,  /* isInfallible. False in setters. */
471
  false,  /* isMovable.  Not relevant for setters. */
472
  false, /* isEliminatable.  Not relevant for setters. */
473
  false, /* isAlwaysInSlot.  Only relevant for getters. */
474
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
475
  false,  /* isTypedMethod.  Only relevant for methods. */
476
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
477
};
478
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
479
static_assert(0 < 1, "There is no slot for us");
480
481
MOZ_CAN_RUN_SCRIPT static bool
482
get_bubbles(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
483
0
{
484
0
  AUTO_PROFILER_LABEL_FAST("get Event.bubbles", DOM, cx);
485
0
486
0
  bool result(self->Bubbles());
487
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
488
0
  args.rval().setBoolean(result);
489
0
  return true;
490
0
}
491
492
static const JSJitInfo bubbles_getterinfo = {
493
  { (JSJitGetterOp)get_bubbles },
494
  { prototypes::id::Event },
495
  { PrototypeTraits<prototypes::id::Event>::Depth },
496
  JSJitInfo::Getter,
497
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
498
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
499
  true,  /* isInfallible. False in setters. */
500
  true,  /* isMovable.  Not relevant for setters. */
501
  true, /* isEliminatable.  Not relevant for setters. */
502
  false, /* isAlwaysInSlot.  Only relevant for getters. */
503
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
504
  false,  /* isTypedMethod.  Only relevant for methods. */
505
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
506
};
507
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
508
static_assert(0 < 1, "There is no slot for us");
509
510
MOZ_CAN_RUN_SCRIPT static bool
511
get_cancelable(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
512
0
{
513
0
  AUTO_PROFILER_LABEL_FAST("get Event.cancelable", DOM, cx);
514
0
515
0
  bool result(self->Cancelable());
516
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
517
0
  args.rval().setBoolean(result);
518
0
  return true;
519
0
}
520
521
static const JSJitInfo cancelable_getterinfo = {
522
  { (JSJitGetterOp)get_cancelable },
523
  { prototypes::id::Event },
524
  { PrototypeTraits<prototypes::id::Event>::Depth },
525
  JSJitInfo::Getter,
526
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
527
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
528
  true,  /* isInfallible. False in setters. */
529
  true,  /* isMovable.  Not relevant for setters. */
530
  true, /* isEliminatable.  Not relevant for setters. */
531
  false, /* isAlwaysInSlot.  Only relevant for getters. */
532
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
533
  false,  /* isTypedMethod.  Only relevant for methods. */
534
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
535
};
536
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
537
static_assert(0 < 1, "There is no slot for us");
538
539
MOZ_CAN_RUN_SCRIPT static bool
540
get_returnValue(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
541
0
{
542
0
  AUTO_PROFILER_LABEL_FAST("get Event.returnValue", DOM, cx);
543
0
544
0
  bool result(self->ReturnValue(nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem));
545
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
546
0
  args.rval().setBoolean(result);
547
0
  return true;
548
0
}
549
550
MOZ_CAN_RUN_SCRIPT static bool
551
set_returnValue(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitSetterCallArgs args)
552
0
{
553
0
  AUTO_PROFILER_LABEL_FAST("set Event.returnValue", DOM, cx);
554
0
555
0
  bool arg0;
556
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
557
0
    return false;
558
0
  }
559
0
  self->SetReturnValue(arg0, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem);
560
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
561
0
562
0
  return true;
563
0
}
564
565
static const JSJitInfo returnValue_getterinfo = {
566
  { (JSJitGetterOp)get_returnValue },
567
  { prototypes::id::Event },
568
  { PrototypeTraits<prototypes::id::Event>::Depth },
569
  JSJitInfo::Getter,
570
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
571
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
572
  true,  /* isInfallible. False in setters. */
573
  false,  /* isMovable.  Not relevant for setters. */
574
  false, /* isEliminatable.  Not relevant for setters. */
575
  false, /* isAlwaysInSlot.  Only relevant for getters. */
576
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
577
  false,  /* isTypedMethod.  Only relevant for methods. */
578
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
579
};
580
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
581
static_assert(0 < 1, "There is no slot for us");
582
static const JSJitInfo returnValue_setterinfo = {
583
  { (JSJitGetterOp)set_returnValue },
584
  { prototypes::id::Event },
585
  { PrototypeTraits<prototypes::id::Event>::Depth },
586
  JSJitInfo::Setter,
587
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
588
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
589
  false,  /* isInfallible. False in setters. */
590
  false,  /* isMovable.  Not relevant for setters. */
591
  false, /* isEliminatable.  Not relevant for setters. */
592
  false, /* isAlwaysInSlot.  Only relevant for getters. */
593
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
594
  false,  /* isTypedMethod.  Only relevant for methods. */
595
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
596
};
597
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
598
static_assert(0 < 1, "There is no slot for us");
599
600
MOZ_CAN_RUN_SCRIPT static bool
601
preventDefault(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
602
0
{
603
0
  AUTO_PROFILER_LABEL_FAST("Event.preventDefault", DOM, cx);
604
0
605
0
  self->PreventDefault(cx, nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem);
606
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
607
0
  args.rval().setUndefined();
608
0
  return true;
609
0
}
610
611
static const JSJitInfo preventDefault_methodinfo = {
612
  { (JSJitGetterOp)preventDefault },
613
  { prototypes::id::Event },
614
  { PrototypeTraits<prototypes::id::Event>::Depth },
615
  JSJitInfo::Method,
616
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
617
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
618
  true,  /* isInfallible. False in setters. */
619
  false,  /* isMovable.  Not relevant for setters. */
620
  false, /* isEliminatable.  Not relevant for setters. */
621
  false, /* isAlwaysInSlot.  Only relevant for getters. */
622
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
623
  false,  /* isTypedMethod.  Only relevant for methods. */
624
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
625
};
626
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
627
static_assert(0 < 1, "There is no slot for us");
628
629
MOZ_CAN_RUN_SCRIPT static bool
630
get_defaultPrevented(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
631
0
{
632
0
  AUTO_PROFILER_LABEL_FAST("get Event.defaultPrevented", DOM, cx);
633
0
634
0
  bool result(self->DefaultPrevented(nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem));
635
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
636
0
  args.rval().setBoolean(result);
637
0
  return true;
638
0
}
639
640
static const JSJitInfo defaultPrevented_getterinfo = {
641
  { (JSJitGetterOp)get_defaultPrevented },
642
  { prototypes::id::Event },
643
  { PrototypeTraits<prototypes::id::Event>::Depth },
644
  JSJitInfo::Getter,
645
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
646
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
647
  true,  /* isInfallible. False in setters. */
648
  true,  /* isMovable.  Not relevant for setters. */
649
  true, /* isEliminatable.  Not relevant for setters. */
650
  false, /* isAlwaysInSlot.  Only relevant for getters. */
651
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
652
  false,  /* isTypedMethod.  Only relevant for methods. */
653
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
654
};
655
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
656
static_assert(0 < 1, "There is no slot for us");
657
658
MOZ_CAN_RUN_SCRIPT static bool
659
get_defaultPreventedByChrome(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
660
0
{
661
0
  AUTO_PROFILER_LABEL_FAST("get Event.defaultPreventedByChrome", DOM, cx);
662
0
663
0
  bool result(self->DefaultPreventedByChrome());
664
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
665
0
  args.rval().setBoolean(result);
666
0
  return true;
667
0
}
668
669
static const JSJitInfo defaultPreventedByChrome_getterinfo = {
670
  { (JSJitGetterOp)get_defaultPreventedByChrome },
671
  { prototypes::id::Event },
672
  { PrototypeTraits<prototypes::id::Event>::Depth },
673
  JSJitInfo::Getter,
674
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
675
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
676
  true,  /* isInfallible. False in setters. */
677
  true,  /* isMovable.  Not relevant for setters. */
678
  true, /* isEliminatable.  Not relevant for setters. */
679
  false, /* isAlwaysInSlot.  Only relevant for getters. */
680
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
681
  false,  /* isTypedMethod.  Only relevant for methods. */
682
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
683
};
684
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
685
static_assert(0 < 1, "There is no slot for us");
686
687
MOZ_CAN_RUN_SCRIPT static bool
688
get_defaultPreventedByContent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
689
0
{
690
0
  AUTO_PROFILER_LABEL_FAST("get Event.defaultPreventedByContent", DOM, cx);
691
0
692
0
  bool result(self->DefaultPreventedByContent());
693
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
694
0
  args.rval().setBoolean(result);
695
0
  return true;
696
0
}
697
698
static const JSJitInfo defaultPreventedByContent_getterinfo = {
699
  { (JSJitGetterOp)get_defaultPreventedByContent },
700
  { prototypes::id::Event },
701
  { PrototypeTraits<prototypes::id::Event>::Depth },
702
  JSJitInfo::Getter,
703
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
704
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
705
  true,  /* isInfallible. False in setters. */
706
  true,  /* isMovable.  Not relevant for setters. */
707
  true, /* isEliminatable.  Not relevant for setters. */
708
  false, /* isAlwaysInSlot.  Only relevant for getters. */
709
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
710
  false,  /* isTypedMethod.  Only relevant for methods. */
711
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
712
};
713
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
714
static_assert(0 < 1, "There is no slot for us");
715
716
MOZ_CAN_RUN_SCRIPT static bool
717
get_composed(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
718
0
{
719
0
  AUTO_PROFILER_LABEL_FAST("get Event.composed", DOM, cx);
720
0
721
0
  bool result(self->Composed());
722
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
723
0
  args.rval().setBoolean(result);
724
0
  return true;
725
0
}
726
727
static const JSJitInfo composed_getterinfo = {
728
  { (JSJitGetterOp)get_composed },
729
  { prototypes::id::Event },
730
  { PrototypeTraits<prototypes::id::Event>::Depth },
731
  JSJitInfo::Getter,
732
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
733
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
734
  true,  /* isInfallible. False in setters. */
735
  true,  /* isMovable.  Not relevant for setters. */
736
  true, /* isEliminatable.  Not relevant for setters. */
737
  false, /* isAlwaysInSlot.  Only relevant for getters. */
738
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
739
  false,  /* isTypedMethod.  Only relevant for methods. */
740
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
741
};
742
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
743
static_assert(0 < 1, "There is no slot for us");
744
745
MOZ_CAN_RUN_SCRIPT static bool
746
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
747
0
{
748
0
  AUTO_PROFILER_LABEL_FAST("get Event.isTrusted", DOM, cx);
749
0
750
0
  bool result(self->IsTrusted());
751
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
752
0
  args.rval().setBoolean(result);
753
0
  return true;
754
0
}
755
756
static const JSJitInfo isTrusted_getterinfo = {
757
  { (JSJitGetterOp)get_isTrusted },
758
  { prototypes::id::Event },
759
  { PrototypeTraits<prototypes::id::Event>::Depth },
760
  JSJitInfo::Getter,
761
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
762
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
763
  true,  /* isInfallible. False in setters. */
764
  true,  /* isMovable.  Not relevant for setters. */
765
  true, /* isEliminatable.  Not relevant for setters. */
766
  false, /* isAlwaysInSlot.  Only relevant for getters. */
767
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
768
  false,  /* isTypedMethod.  Only relevant for methods. */
769
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
770
};
771
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
772
static_assert(0 < 1, "There is no slot for us");
773
774
MOZ_CAN_RUN_SCRIPT static bool
775
get_timeStamp(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
776
0
{
777
0
  AUTO_PROFILER_LABEL_FAST("get Event.timeStamp", DOM, cx);
778
0
779
0
  double result(self->TimeStamp());
780
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
781
0
  args.rval().set(JS_NumberValue(double(result)));
782
0
  return true;
783
0
}
784
785
static const JSJitInfo timeStamp_getterinfo = {
786
  { (JSJitGetterOp)get_timeStamp },
787
  { prototypes::id::Event },
788
  { PrototypeTraits<prototypes::id::Event>::Depth },
789
  JSJitInfo::Getter,
790
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
791
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
792
  true,  /* isInfallible. False in setters. */
793
  true,  /* isMovable.  Not relevant for setters. */
794
  true, /* isEliminatable.  Not relevant for setters. */
795
  false, /* isAlwaysInSlot.  Only relevant for getters. */
796
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
797
  false,  /* isTypedMethod.  Only relevant for methods. */
798
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
799
};
800
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
801
static_assert(0 < 1, "There is no slot for us");
802
803
MOZ_CAN_RUN_SCRIPT static bool
804
initEvent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, const JSJitMethodCallArgs& args)
805
0
{
806
0
  AUTO_PROFILER_LABEL_FAST("Event.initEvent", DOM, cx);
807
0
808
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
809
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Event.initEvent");
810
0
  }
811
0
  binding_detail::FakeString arg0;
812
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
813
0
    return false;
814
0
  }
815
0
  bool arg1;
816
0
  if (args.hasDefined(1)) {
817
0
    if (!ValueToPrimitive<bool, eDefault>(cx, args[1], &arg1)) {
818
0
      return false;
819
0
    }
820
0
  } else {
821
0
    arg1 = false;
822
0
  }
823
0
  bool arg2;
824
0
  if (args.hasDefined(2)) {
825
0
    if (!ValueToPrimitive<bool, eDefault>(cx, args[2], &arg2)) {
826
0
      return false;
827
0
    }
828
0
  } else {
829
0
    arg2 = false;
830
0
  }
831
0
  self->InitEvent(NonNullHelper(Constify(arg0)), arg1, arg2);
832
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
833
0
  args.rval().setUndefined();
834
0
  return true;
835
0
}
836
837
static const JSJitInfo initEvent_methodinfo = {
838
  { (JSJitGetterOp)initEvent },
839
  { prototypes::id::Event },
840
  { PrototypeTraits<prototypes::id::Event>::Depth },
841
  JSJitInfo::Method,
842
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
843
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
844
  false,  /* isInfallible. False in setters. */
845
  false,  /* isMovable.  Not relevant for setters. */
846
  false, /* isEliminatable.  Not relevant for setters. */
847
  false, /* isAlwaysInSlot.  Only relevant for getters. */
848
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
849
  false,  /* isTypedMethod.  Only relevant for methods. */
850
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
851
};
852
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
853
static_assert(0 < 1, "There is no slot for us");
854
855
MOZ_CAN_RUN_SCRIPT static bool
856
get_cancelBubble(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
857
0
{
858
0
  AUTO_PROFILER_LABEL_FAST("get Event.cancelBubble", DOM, cx);
859
0
860
0
  bool result(self->CancelBubble());
861
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
862
0
  args.rval().setBoolean(result);
863
0
  return true;
864
0
}
865
866
MOZ_CAN_RUN_SCRIPT static bool
867
set_cancelBubble(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitSetterCallArgs args)
868
0
{
869
0
  AUTO_PROFILER_LABEL_FAST("set Event.cancelBubble", DOM, cx);
870
0
871
0
  bool arg0;
872
0
  if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) {
873
0
    return false;
874
0
  }
875
0
  self->SetCancelBubble(arg0);
876
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
877
0
878
0
  return true;
879
0
}
880
881
static const JSJitInfo cancelBubble_getterinfo = {
882
  { (JSJitGetterOp)get_cancelBubble },
883
  { prototypes::id::Event },
884
  { PrototypeTraits<prototypes::id::Event>::Depth },
885
  JSJitInfo::Getter,
886
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
887
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
888
  true,  /* isInfallible. False in setters. */
889
  false,  /* isMovable.  Not relevant for setters. */
890
  false, /* isEliminatable.  Not relevant for setters. */
891
  false, /* isAlwaysInSlot.  Only relevant for getters. */
892
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
893
  false,  /* isTypedMethod.  Only relevant for methods. */
894
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
895
};
896
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
897
static_assert(0 < 1, "There is no slot for us");
898
static const JSJitInfo cancelBubble_setterinfo = {
899
  { (JSJitGetterOp)set_cancelBubble },
900
  { prototypes::id::Event },
901
  { PrototypeTraits<prototypes::id::Event>::Depth },
902
  JSJitInfo::Setter,
903
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
904
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
905
  false,  /* isInfallible. False in setters. */
906
  false,  /* isMovable.  Not relevant for setters. */
907
  false, /* isEliminatable.  Not relevant for setters. */
908
  false, /* isAlwaysInSlot.  Only relevant for getters. */
909
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
910
  false,  /* isTypedMethod.  Only relevant for methods. */
911
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
912
};
913
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
914
static_assert(0 < 1, "There is no slot for us");
915
916
MOZ_CAN_RUN_SCRIPT static bool
917
get_originalTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
918
0
{
919
0
  AUTO_PROFILER_LABEL_FAST("get Event.originalTarget", DOM, cx);
920
0
921
0
  auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetOriginalTarget()));
922
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
923
0
  if (!result) {
924
0
    args.rval().setNull();
925
0
    return true;
926
0
  }
927
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
928
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
929
0
    return false;
930
0
  }
931
0
  return true;
932
0
}
933
934
static const JSJitInfo originalTarget_getterinfo = {
935
  { (JSJitGetterOp)get_originalTarget },
936
  { prototypes::id::Event },
937
  { PrototypeTraits<prototypes::id::Event>::Depth },
938
  JSJitInfo::Getter,
939
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
940
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
941
  false,  /* isInfallible. False in setters. */
942
  false,  /* isMovable.  Not relevant for setters. */
943
  false, /* isEliminatable.  Not relevant for setters. */
944
  false, /* isAlwaysInSlot.  Only relevant for getters. */
945
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
946
  false,  /* isTypedMethod.  Only relevant for methods. */
947
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
948
};
949
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
950
static_assert(0 < 1, "There is no slot for us");
951
952
MOZ_CAN_RUN_SCRIPT static bool
953
get_explicitOriginalTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
954
0
{
955
0
  AUTO_PROFILER_LABEL_FAST("get Event.explicitOriginalTarget", DOM, cx);
956
0
957
0
  auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetExplicitOriginalTarget()));
958
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
959
0
  if (!result) {
960
0
    args.rval().setNull();
961
0
    return true;
962
0
  }
963
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
964
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
965
0
    return false;
966
0
  }
967
0
  return true;
968
0
}
969
970
static const JSJitInfo explicitOriginalTarget_getterinfo = {
971
  { (JSJitGetterOp)get_explicitOriginalTarget },
972
  { prototypes::id::Event },
973
  { PrototypeTraits<prototypes::id::Event>::Depth },
974
  JSJitInfo::Getter,
975
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
976
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
977
  false,  /* isInfallible. False in setters. */
978
  false,  /* isMovable.  Not relevant for setters. */
979
  false, /* isEliminatable.  Not relevant for setters. */
980
  false, /* isAlwaysInSlot.  Only relevant for getters. */
981
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
982
  false,  /* isTypedMethod.  Only relevant for methods. */
983
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
984
};
985
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
986
static_assert(0 < 1, "There is no slot for us");
987
988
MOZ_CAN_RUN_SCRIPT static bool
989
get_composedTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
990
0
{
991
0
  AUTO_PROFILER_LABEL_FAST("get Event.composedTarget", DOM, cx);
992
0
993
0
  auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetComposedTarget()));
994
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
995
0
  if (!result) {
996
0
    args.rval().setNull();
997
0
    return true;
998
0
  }
999
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
1000
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1001
0
    return false;
1002
0
  }
1003
0
  return true;
1004
0
}
1005
1006
static const JSJitInfo composedTarget_getterinfo = {
1007
  { (JSJitGetterOp)get_composedTarget },
1008
  { prototypes::id::Event },
1009
  { PrototypeTraits<prototypes::id::Event>::Depth },
1010
  JSJitInfo::Getter,
1011
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1012
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
1013
  false,  /* isInfallible. False in setters. */
1014
  false,  /* isMovable.  Not relevant for setters. */
1015
  false, /* isEliminatable.  Not relevant for setters. */
1016
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1017
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1018
  false,  /* isTypedMethod.  Only relevant for methods. */
1019
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1020
};
1021
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1022
static_assert(0 < 1, "There is no slot for us");
1023
1024
MOZ_CAN_RUN_SCRIPT static bool
1025
get_multipleActionsPrevented(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
1026
0
{
1027
0
  AUTO_PROFILER_LABEL_FAST("get Event.multipleActionsPrevented", DOM, cx);
1028
0
1029
0
  bool result(self->MultipleActionsPrevented());
1030
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1031
0
  args.rval().setBoolean(result);
1032
0
  return true;
1033
0
}
1034
1035
static const JSJitInfo multipleActionsPrevented_getterinfo = {
1036
  { (JSJitGetterOp)get_multipleActionsPrevented },
1037
  { prototypes::id::Event },
1038
  { PrototypeTraits<prototypes::id::Event>::Depth },
1039
  JSJitInfo::Getter,
1040
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1041
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1042
  true,  /* isInfallible. False in setters. */
1043
  false,  /* isMovable.  Not relevant for setters. */
1044
  false, /* isEliminatable.  Not relevant for setters. */
1045
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1046
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1047
  false,  /* isTypedMethod.  Only relevant for methods. */
1048
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1049
};
1050
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1051
static_assert(0 < 1, "There is no slot for us");
1052
1053
MOZ_CAN_RUN_SCRIPT static bool
1054
get_isSynthesized(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Event* self, JSJitGetterCallArgs args)
1055
0
{
1056
0
  AUTO_PROFILER_LABEL_FAST("get Event.isSynthesized", DOM, cx);
1057
0
1058
0
  bool result(self->IsSynthesized());
1059
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1060
0
  args.rval().setBoolean(result);
1061
0
  return true;
1062
0
}
1063
1064
static const JSJitInfo isSynthesized_getterinfo = {
1065
  { (JSJitGetterOp)get_isSynthesized },
1066
  { prototypes::id::Event },
1067
  { PrototypeTraits<prototypes::id::Event>::Depth },
1068
  JSJitInfo::Getter,
1069
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1070
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
1071
  true,  /* isInfallible. False in setters. */
1072
  false,  /* isMovable.  Not relevant for setters. */
1073
  false, /* isEliminatable.  Not relevant for setters. */
1074
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1075
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1076
  false,  /* isTypedMethod.  Only relevant for methods. */
1077
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1078
};
1079
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1080
static_assert(0 < 1, "There is no slot for us");
1081
1082
static bool
1083
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1084
0
{
1085
0
  mozilla::dom::Event* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Event>(obj);
1086
0
  // We don't want to preserve if we don't have a wrapper, and we
1087
0
  // obviously can't preserve if we're not initialized.
1088
0
  if (self && self->GetWrapperPreserveColor()) {
1089
0
    PreserveWrapper(self);
1090
0
  }
1091
0
  return true;
1092
0
}
1093
1094
static void
1095
_finalize(js::FreeOp* fop, JSObject* obj)
1096
0
{
1097
0
  mozilla::dom::Event* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Event>(obj);
1098
0
  if (self) {
1099
0
    ClearWrapper(self, self, obj);
1100
0
    AddForDeferredFinalization<mozilla::dom::Event>(self);
1101
0
  }
1102
0
}
1103
1104
static size_t
1105
_objectMoved(JSObject* obj, JSObject* old)
1106
0
{
1107
0
  mozilla::dom::Event* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Event>(obj);
1108
0
  if (self) {
1109
0
    UpdateWrapper(self, self, obj, old);
1110
0
  }
1111
0
1112
0
  return 0;
1113
0
}
1114
1115
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1116
#if defined(__clang__)
1117
#pragma clang diagnostic push
1118
#pragma clang diagnostic ignored "-Wmissing-braces"
1119
#endif
1120
static const JSFunctionSpec sMethods_specs[] = {
1121
  JS_FNSPEC("composedPath", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&composedPath_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1122
  JS_FNSPEC("stopPropagation", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&stopPropagation_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1123
  JS_FNSPEC("stopImmediatePropagation", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&stopImmediatePropagation_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1124
  JS_FNSPEC("preventDefault", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&preventDefault_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1125
  JS_FNSPEC("initEvent", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&initEvent_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1126
  JS_FS_END
1127
};
1128
#if defined(__clang__)
1129
#pragma clang diagnostic pop
1130
#endif
1131
1132
1133
static const Prefable<const JSFunctionSpec> sMethods[] = {
1134
  { nullptr, &sMethods_specs[0] },
1135
  { nullptr, nullptr }
1136
};
1137
1138
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1139
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1140
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1141
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1142
1143
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1144
#if defined(__clang__)
1145
#pragma clang diagnostic push
1146
#pragma clang diagnostic ignored "-Wmissing-braces"
1147
#endif
1148
static const JSFunctionSpec sChromeMethods_specs[] = {
1149
  JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
1150
  JS_FS_END
1151
};
1152
#if defined(__clang__)
1153
#pragma clang diagnostic pop
1154
#endif
1155
1156
// Can't be const because the pref-enabled boolean needs to be writable
1157
static PrefableDisablers sChromeMethods_disablers0 = {
1158
  true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
1159
};
1160
1161
static const Prefable<const JSFunctionSpec> sChromeMethods[] = {
1162
  { &sChromeMethods_disablers0, &sChromeMethods_specs[0] },
1163
  { nullptr, nullptr }
1164
};
1165
1166
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1167
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1168
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1169
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1170
1171
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1172
#if defined(__clang__)
1173
#pragma clang diagnostic push
1174
#pragma clang diagnostic ignored "-Wmissing-braces"
1175
#endif
1176
static const JSPropertySpec sAttributes_specs[] = {
1177
  { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr },
1178
  { "target", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &target_getterinfo, nullptr, nullptr },
1179
  { "srcElement", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &target_getterinfo, nullptr, nullptr },
1180
  { "currentTarget", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &currentTarget_getterinfo, nullptr, nullptr },
1181
  { "eventPhase", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &eventPhase_getterinfo, nullptr, nullptr },
1182
  { "bubbles", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &bubbles_getterinfo, nullptr, nullptr },
1183
  { "cancelable", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &cancelable_getterinfo, nullptr, nullptr },
1184
  { "returnValue", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &returnValue_getterinfo, GenericSetter<NormalThisPolicy>, &returnValue_setterinfo },
1185
  { "defaultPrevented", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &defaultPrevented_getterinfo, nullptr, nullptr },
1186
  { "composed", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &composed_getterinfo, nullptr, nullptr },
1187
  { "timeStamp", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &timeStamp_getterinfo, nullptr, nullptr },
1188
  { "cancelBubble", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &cancelBubble_getterinfo, GenericSetter<NormalThisPolicy>, &cancelBubble_setterinfo },
1189
  { "originalTarget", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &originalTarget_getterinfo, nullptr, nullptr },
1190
  { "explicitOriginalTarget", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &explicitOriginalTarget_getterinfo, nullptr, nullptr },
1191
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1192
};
1193
#if defined(__clang__)
1194
#pragma clang diagnostic pop
1195
#endif
1196
1197
1198
static const Prefable<const JSPropertySpec> sAttributes[] = {
1199
  { nullptr, &sAttributes_specs[0] },
1200
  { nullptr, nullptr }
1201
};
1202
1203
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1204
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1205
static_assert(14 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1206
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1207
1208
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1209
#if defined(__clang__)
1210
#pragma clang diagnostic push
1211
#pragma clang diagnostic ignored "-Wmissing-braces"
1212
#endif
1213
static const JSPropertySpec sChromeAttributes_specs[] = {
1214
  { "defaultPreventedByChrome", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &defaultPreventedByChrome_getterinfo, nullptr, nullptr },
1215
  { "defaultPreventedByContent", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &defaultPreventedByContent_getterinfo, nullptr, nullptr },
1216
  { "composedTarget", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &composedTarget_getterinfo, nullptr, nullptr },
1217
  { "multipleActionsPrevented", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &multipleActionsPrevented_getterinfo, nullptr, nullptr },
1218
  { "isSynthesized", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isSynthesized_getterinfo, nullptr, nullptr },
1219
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1220
};
1221
#if defined(__clang__)
1222
#pragma clang diagnostic pop
1223
#endif
1224
1225
1226
static const Prefable<const JSPropertySpec> sChromeAttributes[] = {
1227
  { nullptr, &sChromeAttributes_specs[0] },
1228
  { nullptr, nullptr }
1229
};
1230
1231
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1232
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1233
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1234
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1235
1236
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1237
#if defined(__clang__)
1238
#pragma clang diagnostic push
1239
#pragma clang diagnostic ignored "-Wmissing-braces"
1240
#endif
1241
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
1242
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
1243
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1244
};
1245
#if defined(__clang__)
1246
#pragma clang diagnostic pop
1247
#endif
1248
1249
1250
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
1251
  { nullptr, &sUnforgeableAttributes_specs[0] },
1252
  { nullptr, nullptr }
1253
};
1254
1255
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1256
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1257
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1258
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1259
1260
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1261
#if defined(__clang__)
1262
#pragma clang diagnostic push
1263
#pragma clang diagnostic ignored "-Wmissing-braces"
1264
#endif
1265
static const ConstantSpec sConstants_specs[] = {
1266
  { "NONE", JS::Int32Value(0) },
1267
  { "CAPTURING_PHASE", JS::Int32Value(1) },
1268
  { "AT_TARGET", JS::Int32Value(2) },
1269
  { "BUBBLING_PHASE", JS::Int32Value(3) },
1270
  { "ALT_MASK", JS::Int32Value(1) },
1271
  { "CONTROL_MASK", JS::Int32Value(2) },
1272
  { "SHIFT_MASK", JS::Int32Value(4) },
1273
  { "META_MASK", JS::Int32Value(8) },
1274
  { 0, JS::UndefinedValue() }
1275
};
1276
#if defined(__clang__)
1277
#pragma clang diagnostic pop
1278
#endif
1279
1280
1281
static const Prefable<const ConstantSpec> sConstants[] = {
1282
  { nullptr, &sConstants_specs[0] },
1283
  { nullptr, nullptr }
1284
};
1285
1286
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1287
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1288
static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1289
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1290
1291
1292
static uint16_t sNativeProperties_sortedPropertyIndices[28];
1293
static PropertyInfo sNativeProperties_propertyInfos[28];
1294
1295
static const NativePropertiesN<4> sNativeProperties = {
1296
  false, 0,
1297
  false, 0,
1298
  true,  0 /* sMethods */,
1299
  true,  1 /* sAttributes */,
1300
  false, 0,
1301
  true,  2 /* sUnforgeableAttributes */,
1302
  true,  3 /* sConstants */,
1303
  -1,
1304
  28,
1305
  sNativeProperties_sortedPropertyIndices,
1306
  {
1307
    { sMethods, &sNativeProperties_propertyInfos[0] },
1308
    { sAttributes, &sNativeProperties_propertyInfos[5] },
1309
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[19] },
1310
    { sConstants, &sNativeProperties_propertyInfos[20] }
1311
  }
1312
};
1313
static_assert(28 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1314
    "We have a property info count that is oversized");
1315
1316
static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[6];
1317
static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[6];
1318
1319
static const NativePropertiesN<2> sChromeOnlyNativeProperties = {
1320
  false, 0,
1321
  false, 0,
1322
  true,  0 /* sChromeMethods */,
1323
  true,  1 /* sChromeAttributes */,
1324
  false, 0,
1325
  false, 0,
1326
  false, 0,
1327
  -1,
1328
  6,
1329
  sChromeOnlyNativeProperties_sortedPropertyIndices,
1330
  {
1331
    { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] },
1332
    { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[1] }
1333
  }
1334
};
1335
static_assert(6 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
1336
    "We have a property info count that is oversized");
1337
1338
static bool
1339
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1340
0
{
1341
0
  AUTO_PROFILER_LABEL_FAST("Event constructor", DOM, cx);
1342
0
1343
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1344
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1345
0
  if (!args.isConstructing()) {
1346
0
    // XXXbz wish I could get the name from the callee instead of
1347
0
    // Adding more relocations
1348
0
    return ThrowConstructorWithoutNew(cx, "Event");
1349
0
  }
1350
0
1351
0
  JS::Rooted<JSObject*> desiredProto(cx);
1352
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
1353
0
    return false;
1354
0
  }
1355
0
1356
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1357
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Event");
1358
0
  }
1359
0
  GlobalObject global(cx, obj);
1360
0
  if (global.Failed()) {
1361
0
    return false;
1362
0
  }
1363
0
1364
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1365
0
  binding_detail::FakeString arg0;
1366
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1367
0
    return false;
1368
0
  }
1369
0
  binding_detail::FastEventInit arg1;
1370
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of Event.constructor", false)) {
1371
0
    return false;
1372
0
  }
1373
0
  Maybe<JSAutoRealm> ar;
1374
0
  if (objIsXray) {
1375
0
    obj = js::CheckedUnwrap(obj);
1376
0
    if (!obj) {
1377
0
      return false;
1378
0
    }
1379
0
    ar.emplace(cx, obj);
1380
0
    if (!JS_WrapObject(cx, &desiredProto)) {
1381
0
      return false;
1382
0
    }
1383
0
  }
1384
0
  FastErrorResult rv;
1385
0
  auto result(StrongOrRawPtr<mozilla::dom::Event>(mozilla::dom::Event::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
1386
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1387
0
    return false;
1388
0
  }
1389
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1390
0
  static_assert(!IsPointer<decltype(result)>::value,
1391
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1392
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1393
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1394
0
    return false;
1395
0
  }
1396
0
  return true;
1397
0
}
1398
1399
static const js::ClassOps sInterfaceObjectClassOps = {
1400
    nullptr,               /* addProperty */
1401
    nullptr,               /* delProperty */
1402
    nullptr,               /* enumerate */
1403
    nullptr,               /* newEnumerate */
1404
    nullptr,               /* resolve */
1405
    nullptr,               /* mayResolve */
1406
    nullptr,               /* finalize */
1407
    _constructor, /* call */
1408
    nullptr,               /* hasInstance */
1409
    _constructor, /* construct */
1410
    nullptr,               /* trace */
1411
};
1412
1413
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1414
  {
1415
    "Function",
1416
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1417
    &sInterfaceObjectClassOps,
1418
    JS_NULL_CLASS_SPEC,
1419
    JS_NULL_CLASS_EXT,
1420
    &sInterfaceObjectClassObjectOps
1421
  },
1422
  eInterface,
1423
  true,
1424
  prototypes::id::Event,
1425
  PrototypeTraits<prototypes::id::Event>::Depth,
1426
  sNativePropertyHooks,
1427
  "function Event() {\n    [native code]\n}",
1428
  JS::GetRealmFunctionPrototype
1429
};
1430
1431
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1432
  {
1433
    "EventPrototype",
1434
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
1435
    JS_NULL_CLASS_OPS,
1436
    JS_NULL_CLASS_SPEC,
1437
    JS_NULL_CLASS_EXT,
1438
    JS_NULL_OBJECT_OPS
1439
  },
1440
  eInterfacePrototype,
1441
  false,
1442
  prototypes::id::Event,
1443
  PrototypeTraits<prototypes::id::Event>::Depth,
1444
  sNativePropertyHooks,
1445
  "[object EventPrototype]",
1446
  JS::GetRealmObjectPrototype
1447
};
1448
1449
static const js::ClassOps sClassOps = {
1450
  _addProperty, /* addProperty */
1451
  nullptr,               /* delProperty */
1452
  nullptr,               /* enumerate */
1453
  nullptr, /* newEnumerate */
1454
  nullptr, /* resolve */
1455
  nullptr, /* mayResolve */
1456
  _finalize, /* finalize */
1457
  nullptr, /* call */
1458
  nullptr,               /* hasInstance */
1459
  nullptr,               /* construct */
1460
  nullptr, /* trace */
1461
};
1462
1463
static const js::ClassExtension sClassExtension = {
1464
  nullptr, /* weakmapKeyDelegateOp */
1465
  _objectMoved /* objectMovedOp */
1466
};
1467
1468
static const DOMJSClass sClass = {
1469
  { "Event",
1470
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
1471
    &sClassOps,
1472
    JS_NULL_CLASS_SPEC,
1473
    &sClassExtension,
1474
    JS_NULL_OBJECT_OPS
1475
  },
1476
  { prototypes::id::Event, 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 },
1477
  IsBaseOf<nsISupports, mozilla::dom::Event >::value,
1478
  sNativePropertyHooks,
1479
  FindAssociatedGlobalForNative<mozilla::dom::Event>::Get,
1480
  GetProtoObjectHandle,
1481
  GetCCParticipant<mozilla::dom::Event>::Get()
1482
};
1483
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1484
              "Must have the right minimal number of reserved slots.");
1485
static_assert(1 >= 1,
1486
              "Must have enough reserved slots.");
1487
1488
const JSClass*
1489
GetJSClass()
1490
0
{
1491
0
  return sClass.ToJSClass();
1492
0
}
1493
1494
bool
1495
Wrap(JSContext* aCx, mozilla::dom::Event* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1496
0
{
1497
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Event>::value,
1498
0
                "Shouldn't have wrappercached things that are not refcounted.");
1499
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
1500
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
1501
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
1502
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1503
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1504
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1505
0
             "You should probably not be using Wrap() directly; use "
1506
0
             "GetOrCreateDOMReflector instead");
1507
0
1508
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1509
0
             "nsISupports must be on our primary inheritance chain");
1510
0
1511
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1512
0
  if (!global) {
1513
0
    return false;
1514
0
  }
1515
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1516
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1517
0
1518
0
  // That might have ended up wrapping us already, due to the wonders
1519
0
  // of XBL.  Check for that, and bail out as needed.
1520
0
  aReflector.set(aCache->GetWrapper());
1521
0
  if (aReflector) {
1522
#ifdef DEBUG
1523
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1524
#endif // DEBUG
1525
    return true;
1526
0
  }
1527
0
1528
0
  JSAutoRealm ar(aCx, global);
1529
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1530
0
  if (!canonicalProto) {
1531
0
    return false;
1532
0
  }
1533
0
  JS::Rooted<JSObject*> proto(aCx);
1534
0
  if (aGivenProto) {
1535
0
    proto = aGivenProto;
1536
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1537
0
    // coming in, we changed compartments to that of "parent" so may need
1538
0
    // to wrap the proto here.
1539
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1540
0
      if (!JS_WrapObject(aCx, &proto)) {
1541
0
        return false;
1542
0
      }
1543
0
    }
1544
0
  } else {
1545
0
    proto = canonicalProto;
1546
0
  }
1547
0
1548
0
  BindingJSObjectCreator<mozilla::dom::Event> creator(aCx);
1549
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1550
0
  if (!aReflector) {
1551
0
    return false;
1552
0
  }
1553
0
1554
0
  aCache->SetWrapper(aReflector);
1555
0
1556
0
  // Important: do unforgeable property setup after we have handed
1557
0
  // over ownership of the C++ object to obj as needed, so that if
1558
0
  // we fail and it ends up GCed it won't have problems in the
1559
0
  // finalizer trying to drop its ownership of the C++ object.
1560
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
1561
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
1562
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
1563
0
    aCache->ReleaseWrapper(aObject);
1564
0
    aCache->ClearWrapper();
1565
0
    return false;
1566
0
  }
1567
0
  creator.InitializationSucceeded();
1568
0
1569
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1570
0
             aCache->GetWrapperPreserveColor() == aReflector);
1571
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1572
0
  // otherwise we won't be able to properly recreate it later, since
1573
0
  // we won't know what proto to use.  Note that we don't check
1574
0
  // aGivenProto here, since it's entirely possible (and even
1575
0
  // somewhat common) to have a non-null aGivenProto which is the
1576
0
  // same as canonicalProto.
1577
0
  if (proto != canonicalProto) {
1578
0
    PreserveWrapper(aObject);
1579
0
  }
1580
0
1581
0
  return true;
1582
0
}
1583
1584
const NativePropertyHooks sNativePropertyHooks[] = { {
1585
  nullptr,
1586
  nullptr,
1587
  nullptr,
1588
  { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1589
  prototypes::id::Event,
1590
  constructors::id::Event,
1591
  nullptr,
1592
  &DefaultXrayExpandoObjectClass
1593
} };
1594
1595
void
1596
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1597
0
{
1598
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1599
0
  if (!parentProto) {
1600
0
    return;
1601
0
  }
1602
0
1603
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1604
0
  if (!constructorProto) {
1605
0
    return;
1606
0
  }
1607
0
1608
0
  static bool sIdsInited = false;
1609
0
  if (!sIdsInited && NS_IsMainThread()) {
1610
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1611
0
      return;
1612
0
    }
1613
0
    if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1614
0
      return;
1615
0
    }
1616
0
    sIdsInited = true;
1617
0
  }
1618
0
1619
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Event);
1620
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Event);
1621
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1622
0
                              &sPrototypeClass.mBase, protoCache,
1623
0
                              nullptr,
1624
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
1625
0
                              interfaceCache,
1626
0
                              sNativeProperties.Upcast(),
1627
0
                              sChromeOnlyNativeProperties.Upcast(),
1628
0
                              "Event", aDefineOnGlobal,
1629
0
                              nullptr,
1630
0
                              false);
1631
0
1632
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
1633
0
  {
1634
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1635
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1636
0
    if (!unforgeableHolder) {
1637
0
      *protoCache = nullptr;
1638
0
      if (interfaceCache) {
1639
0
        *interfaceCache = nullptr;
1640
0
      }
1641
0
      return;
1642
0
    }
1643
0
  }
1644
0
1645
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1646
0
    *protoCache = nullptr;
1647
0
    if (interfaceCache) {
1648
0
      *interfaceCache = nullptr;
1649
0
    }
1650
0
    return;
1651
0
  }
1652
0
1653
0
  if (*protoCache) {
1654
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1655
0
                        JS::ObjectValue(*unforgeableHolder));
1656
0
  }
1657
0
}
1658
1659
JSObject*
1660
GetProtoObject(JSContext* aCx)
1661
0
{
1662
0
  return GetProtoObjectHandle(aCx);
1663
0
}
1664
1665
JSObject*
1666
GetConstructorObject(JSContext* aCx)
1667
0
{
1668
0
  return GetConstructorObjectHandle(aCx);
1669
0
}
1670
1671
} // namespace Event_Binding
1672
1673
1674
1675
} // namespace dom
1676
} // namespace mozilla