Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/PointerEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM PointerEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "MouseEventBinding.h"
5
#include "PointerEventBinding.h"
6
#include "WrapperFactory.h"
7
#include "mozilla/FloatingPoint.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/Preferences.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/PointerEvent.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
namespace binding_detail {}; // Just to make sure it's known as a namespace
22
using namespace mozilla::dom::binding_detail;
23
24
25
26
PointerEventInit::PointerEventInit()
27
  : MouseEventInit(FastDictionaryInitializer())
28
0
{
29
0
  // Safe to pass a null context if we pass a null value
30
0
  Init(nullptr, JS::NullHandleValue);
31
0
}
32
33
34
35
bool
36
PointerEventInit::InitIds(JSContext* cx, PointerEventInitAtoms* atomsCache)
37
0
{
38
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
39
0
40
0
  // Initialize these in reverse order so that any failure leaves the first one
41
0
  // uninitialized.
42
0
  if (!atomsCache->width_id.init(cx, "width") ||
43
0
      !atomsCache->twist_id.init(cx, "twist") ||
44
0
      !atomsCache->tiltY_id.init(cx, "tiltY") ||
45
0
      !atomsCache->tiltX_id.init(cx, "tiltX") ||
46
0
      !atomsCache->tangentialPressure_id.init(cx, "tangentialPressure") ||
47
0
      !atomsCache->pressure_id.init(cx, "pressure") ||
48
0
      !atomsCache->pointerType_id.init(cx, "pointerType") ||
49
0
      !atomsCache->pointerId_id.init(cx, "pointerId") ||
50
0
      !atomsCache->isPrimary_id.init(cx, "isPrimary") ||
51
0
      !atomsCache->height_id.init(cx, "height") ||
52
0
      !atomsCache->coalescedEvents_id.init(cx, "coalescedEvents")) {
53
0
    return false;
54
0
  }
55
0
  return true;
56
0
}
57
58
bool
59
PointerEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
60
0
{
61
0
  // Passing a null JSContext is OK only if we're initing from null,
62
0
  // Since in that case we will not have to do any property gets
63
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
64
0
  // checkers by static analysis tools
65
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
66
0
  PointerEventInitAtoms* atomsCache = nullptr;
67
0
  if (cx) {
68
0
    atomsCache = GetAtomCache<PointerEventInitAtoms>(cx);
69
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
70
0
      return false;
71
0
    }
72
0
  }
73
0
74
0
  // Per spec, we init the parent's members first
75
0
  if (!MouseEventInit::Init(cx, val)) {
76
0
    return false;
77
0
  }
78
0
79
0
  bool isNull = val.isNullOrUndefined();
80
0
  // We only need these if !isNull, in which case we have |cx|.
81
0
  Maybe<JS::Rooted<JSObject *> > object;
82
0
  Maybe<JS::Rooted<JS::Value> > temp;
83
0
  if (!isNull) {
84
0
    MOZ_ASSERT(cx);
85
0
    object.emplace(cx, &val.toObject());
86
0
    temp.emplace(cx);
87
0
  }
88
0
  if (!isNull) {
89
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->coalescedEvents_id, temp.ptr())) {
90
0
      return false;
91
0
    }
92
0
  }
93
0
  if (!isNull && !temp->isUndefined()) {
94
0
    if (temp.ref().isObject()) {
95
0
      JS::ForOfIterator iter(cx);
96
0
      if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
97
0
        return false;
98
0
      }
99
0
      if (!iter.valueIsIterable()) {
100
0
        ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'coalescedEvents' member of PointerEventInit");
101
0
        return false;
102
0
      }
103
0
      Sequence<OwningNonNull<mozilla::dom::PointerEvent>> &arr = mCoalescedEvents;
104
0
      JS::Rooted<JS::Value> temp(cx);
105
0
      while (true) {
106
0
        bool done;
107
0
        if (!iter.next(&temp, &done)) {
108
0
          return false;
109
0
        }
110
0
        if (done) {
111
0
          break;
112
0
        }
113
0
        OwningNonNull<mozilla::dom::PointerEvent>* slotPtr = arr.AppendElement(mozilla::fallible);
114
0
        if (!slotPtr) {
115
0
          JS_ReportOutOfMemory(cx);
116
0
          return false;
117
0
        }
118
0
        OwningNonNull<mozilla::dom::PointerEvent>& slot = *slotPtr;
119
0
        if (temp.isObject()) {
120
0
          static_assert(IsRefcounted<mozilla::dom::PointerEvent>::value, "We can only store refcounted classes.");{
121
0
            nsresult rv = UnwrapObject<prototypes::id::PointerEvent, mozilla::dom::PointerEvent>(&temp, slot);
122
0
            if (NS_FAILED(rv)) {
123
0
              ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Element of 'coalescedEvents' member of PointerEventInit", "PointerEvent");
124
0
              return false;
125
0
            }
126
0
          }
127
0
        } else {
128
0
          ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Element of 'coalescedEvents' member of PointerEventInit");
129
0
          return false;
130
0
        }
131
0
      }
132
0
    } else {
133
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'coalescedEvents' member of PointerEventInit");
134
0
      return false;
135
0
    }
136
0
  } else {
137
0
    /* Array is already empty; nothing to do */
138
0
  }
139
0
  mIsAnyMemberPresent = true;
140
0
141
0
  if (!isNull) {
142
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) {
143
0
      return false;
144
0
    }
145
0
  }
146
0
  if (!isNull && !temp->isUndefined()) {
147
0
    if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mHeight)) {
148
0
      return false;
149
0
    }
150
0
  } else {
151
0
    mHeight = 1;
152
0
  }
153
0
  mIsAnyMemberPresent = true;
154
0
155
0
  if (!isNull) {
156
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->isPrimary_id, temp.ptr())) {
157
0
      return false;
158
0
    }
159
0
  }
160
0
  if (!isNull && !temp->isUndefined()) {
161
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIsPrimary)) {
162
0
      return false;
163
0
    }
164
0
  } else {
165
0
    mIsPrimary = false;
166
0
  }
167
0
  mIsAnyMemberPresent = true;
168
0
169
0
  if (!isNull) {
170
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->pointerId_id, temp.ptr())) {
171
0
      return false;
172
0
    }
173
0
  }
174
0
  if (!isNull && !temp->isUndefined()) {
175
0
    if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mPointerId)) {
176
0
      return false;
177
0
    }
178
0
  } else {
179
0
    mPointerId = 0;
180
0
  }
181
0
  mIsAnyMemberPresent = true;
182
0
183
0
  if (!isNull) {
184
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->pointerType_id, temp.ptr())) {
185
0
      return false;
186
0
    }
187
0
  }
188
0
  if (!isNull && !temp->isUndefined()) {
189
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mPointerType)) {
190
0
      return false;
191
0
    }
192
0
  } else {
193
0
    static const char16_t data[] = { 0 };
194
0
    mPointerType.Rebind(data, ArrayLength(data) - 1);
195
0
  }
196
0
  mIsAnyMemberPresent = true;
197
0
198
0
  if (!isNull) {
199
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->pressure_id, temp.ptr())) {
200
0
      return false;
201
0
    }
202
0
  }
203
0
  if (!isNull && !temp->isUndefined()) {
204
0
    if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &mPressure)) {
205
0
      return false;
206
0
    } else if (!mozilla::IsFinite(mPressure)) {
207
0
      ThrowErrorMessage(cx, MSG_NOT_FINITE, "'pressure' member of PointerEventInit");
208
0
      return false;
209
0
    }
210
0
  } else {
211
0
    mPressure = 0.0F;
212
0
  }
213
0
  mIsAnyMemberPresent = true;
214
0
215
0
  if (!isNull) {
216
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->tangentialPressure_id, temp.ptr())) {
217
0
      return false;
218
0
    }
219
0
  }
220
0
  if (!isNull && !temp->isUndefined()) {
221
0
    if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &mTangentialPressure)) {
222
0
      return false;
223
0
    } else if (!mozilla::IsFinite(mTangentialPressure)) {
224
0
      ThrowErrorMessage(cx, MSG_NOT_FINITE, "'tangentialPressure' member of PointerEventInit");
225
0
      return false;
226
0
    }
227
0
  } else {
228
0
    mTangentialPressure = 0.0F;
229
0
  }
230
0
  mIsAnyMemberPresent = true;
231
0
232
0
  if (!isNull) {
233
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->tiltX_id, temp.ptr())) {
234
0
      return false;
235
0
    }
236
0
  }
237
0
  if (!isNull && !temp->isUndefined()) {
238
0
    if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mTiltX)) {
239
0
      return false;
240
0
    }
241
0
  } else {
242
0
    mTiltX = 0;
243
0
  }
244
0
  mIsAnyMemberPresent = true;
245
0
246
0
  if (!isNull) {
247
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->tiltY_id, temp.ptr())) {
248
0
      return false;
249
0
    }
250
0
  }
251
0
  if (!isNull && !temp->isUndefined()) {
252
0
    if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mTiltY)) {
253
0
      return false;
254
0
    }
255
0
  } else {
256
0
    mTiltY = 0;
257
0
  }
258
0
  mIsAnyMemberPresent = true;
259
0
260
0
  if (!isNull) {
261
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->twist_id, temp.ptr())) {
262
0
      return false;
263
0
    }
264
0
  }
265
0
  if (!isNull && !temp->isUndefined()) {
266
0
    if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mTwist)) {
267
0
      return false;
268
0
    }
269
0
  } else {
270
0
    mTwist = 0;
271
0
  }
272
0
  mIsAnyMemberPresent = true;
273
0
274
0
  if (!isNull) {
275
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) {
276
0
      return false;
277
0
    }
278
0
  }
279
0
  if (!isNull && !temp->isUndefined()) {
280
0
    if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mWidth)) {
281
0
      return false;
282
0
    }
283
0
  } else {
284
0
    mWidth = 1;
285
0
  }
286
0
  mIsAnyMemberPresent = true;
287
0
  return true;
288
0
}
289
290
bool
291
PointerEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
292
0
{
293
0
  PointerEventInitAtoms* atomsCache = GetAtomCache<PointerEventInitAtoms>(cx);
294
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
295
0
    return false;
296
0
  }
297
0
298
0
  // Per spec, we define the parent's members first
299
0
  if (!MouseEventInit::ToObjectInternal(cx, rval)) {
300
0
    return false;
301
0
  }
302
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
303
0
304
0
  do {
305
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
306
0
    JS::Rooted<JS::Value> temp(cx);
307
0
    Sequence<OwningNonNull<mozilla::dom::PointerEvent>> const & currentValue = mCoalescedEvents;
308
0
309
0
    uint32_t length = currentValue.Length();
310
0
    JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
311
0
    if (!returnArray) {
312
0
      return false;
313
0
    }
314
0
    // Scope for 'tmp'
315
0
    {
316
0
      JS::Rooted<JS::Value> tmp(cx);
317
0
      for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
318
0
        // Control block to let us common up the JS_DefineElement calls when there
319
0
        // are different ways to succeed at wrapping the object.
320
0
        do {
321
0
          if (!GetOrCreateDOMReflector(cx, currentValue[sequenceIdx0], &tmp)) {
322
0
            MOZ_ASSERT(JS_IsExceptionPending(cx));
323
0
            return false;
324
0
          }
325
0
          break;
326
0
        } while (false);
327
0
        if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
328
0
                              JSPROP_ENUMERATE)) {
329
0
          return false;
330
0
        }
331
0
      }
332
0
    }
333
0
    temp.setObject(*returnArray);
334
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->coalescedEvents_id, temp, JSPROP_ENUMERATE)) {
335
0
      return false;
336
0
    }
337
0
    break;
338
0
  } while(false);
339
0
340
0
  do {
341
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
342
0
    JS::Rooted<JS::Value> temp(cx);
343
0
    int32_t const & currentValue = mHeight;
344
0
    temp.setInt32(int32_t(currentValue));
345
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) {
346
0
      return false;
347
0
    }
348
0
    break;
349
0
  } while(false);
350
0
351
0
  do {
352
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
353
0
    JS::Rooted<JS::Value> temp(cx);
354
0
    bool const & currentValue = mIsPrimary;
355
0
    temp.setBoolean(currentValue);
356
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->isPrimary_id, temp, JSPROP_ENUMERATE)) {
357
0
      return false;
358
0
    }
359
0
    break;
360
0
  } while(false);
361
0
362
0
  do {
363
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
364
0
    JS::Rooted<JS::Value> temp(cx);
365
0
    int32_t const & currentValue = mPointerId;
366
0
    temp.setInt32(int32_t(currentValue));
367
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->pointerId_id, temp, JSPROP_ENUMERATE)) {
368
0
      return false;
369
0
    }
370
0
    break;
371
0
  } while(false);
372
0
373
0
  do {
374
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
375
0
    JS::Rooted<JS::Value> temp(cx);
376
0
    nsString const & currentValue = mPointerType;
377
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
378
0
      return false;
379
0
    }
380
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->pointerType_id, temp, JSPROP_ENUMERATE)) {
381
0
      return false;
382
0
    }
383
0
    break;
384
0
  } while(false);
385
0
386
0
  do {
387
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
388
0
    JS::Rooted<JS::Value> temp(cx);
389
0
    float const & currentValue = mPressure;
390
0
    temp.set(JS_NumberValue(double(currentValue)));
391
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->pressure_id, temp, JSPROP_ENUMERATE)) {
392
0
      return false;
393
0
    }
394
0
    break;
395
0
  } while(false);
396
0
397
0
  do {
398
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
399
0
    JS::Rooted<JS::Value> temp(cx);
400
0
    float const & currentValue = mTangentialPressure;
401
0
    temp.set(JS_NumberValue(double(currentValue)));
402
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->tangentialPressure_id, temp, JSPROP_ENUMERATE)) {
403
0
      return false;
404
0
    }
405
0
    break;
406
0
  } while(false);
407
0
408
0
  do {
409
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
410
0
    JS::Rooted<JS::Value> temp(cx);
411
0
    int32_t const & currentValue = mTiltX;
412
0
    temp.setInt32(int32_t(currentValue));
413
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->tiltX_id, temp, JSPROP_ENUMERATE)) {
414
0
      return false;
415
0
    }
416
0
    break;
417
0
  } while(false);
418
0
419
0
  do {
420
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
421
0
    JS::Rooted<JS::Value> temp(cx);
422
0
    int32_t const & currentValue = mTiltY;
423
0
    temp.setInt32(int32_t(currentValue));
424
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->tiltY_id, temp, JSPROP_ENUMERATE)) {
425
0
      return false;
426
0
    }
427
0
    break;
428
0
  } while(false);
429
0
430
0
  do {
431
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
432
0
    JS::Rooted<JS::Value> temp(cx);
433
0
    int32_t const & currentValue = mTwist;
434
0
    temp.setInt32(int32_t(currentValue));
435
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->twist_id, temp, JSPROP_ENUMERATE)) {
436
0
      return false;
437
0
    }
438
0
    break;
439
0
  } while(false);
440
0
441
0
  do {
442
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
443
0
    JS::Rooted<JS::Value> temp(cx);
444
0
    int32_t const & currentValue = mWidth;
445
0
    temp.setInt32(int32_t(currentValue));
446
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) {
447
0
      return false;
448
0
    }
449
0
    break;
450
0
  } while(false);
451
0
452
0
  return true;
453
0
}
454
455
void
456
PointerEventInit::TraceDictionary(JSTracer* trc)
457
0
{
458
0
  MouseEventInit::TraceDictionary(trc);
459
0
}
460
461
462
463
PointerEventInit&
464
PointerEventInit::operator=(const PointerEventInit& aOther)
465
0
{
466
0
  MouseEventInit::operator=(aOther);
467
0
  mCoalescedEvents = aOther.mCoalescedEvents;
468
0
  mHeight = aOther.mHeight;
469
0
  mIsPrimary = aOther.mIsPrimary;
470
0
  mPointerId = aOther.mPointerId;
471
0
  mPointerType = aOther.mPointerType;
472
0
  mPressure = aOther.mPressure;
473
0
  mTangentialPressure = aOther.mTangentialPressure;
474
0
  mTiltX = aOther.mTiltX;
475
0
  mTiltY = aOther.mTiltY;
476
0
  mTwist = aOther.mTwist;
477
0
  mWidth = aOther.mWidth;
478
0
  return *this;
479
0
}
480
481
namespace binding_detail {
482
} // namespace binding_detail
483
484
485
namespace PointerEvent_Binding {
486
487
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MouseEvent_Binding::NativeType>::value,
488
              "Can't inherit from an interface with a different ownership model.");
489
490
MOZ_CAN_RUN_SCRIPT static bool
491
get_pointerId(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
492
0
{
493
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.pointerId", DOM, cx);
494
0
495
0
  int32_t result(self->PointerId());
496
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
497
0
  args.rval().setInt32(int32_t(result));
498
0
  return true;
499
0
}
500
501
static const JSJitInfo pointerId_getterinfo = {
502
  { (JSJitGetterOp)get_pointerId },
503
  { prototypes::id::PointerEvent },
504
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
505
  JSJitInfo::Getter,
506
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
507
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
508
  true,  /* isInfallible. False in setters. */
509
  false,  /* isMovable.  Not relevant for setters. */
510
  false, /* isEliminatable.  Not relevant for setters. */
511
  false, /* isAlwaysInSlot.  Only relevant for getters. */
512
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
513
  false,  /* isTypedMethod.  Only relevant for methods. */
514
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
515
};
516
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
517
static_assert(0 < 1, "There is no slot for us");
518
519
MOZ_CAN_RUN_SCRIPT static bool
520
get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
521
0
{
522
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.width", DOM, cx);
523
0
524
0
  int32_t result(self->Width());
525
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
526
0
  args.rval().setInt32(int32_t(result));
527
0
  return true;
528
0
}
529
530
static const JSJitInfo width_getterinfo = {
531
  { (JSJitGetterOp)get_width },
532
  { prototypes::id::PointerEvent },
533
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
534
  JSJitInfo::Getter,
535
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
536
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
537
  true,  /* isInfallible. False in setters. */
538
  false,  /* isMovable.  Not relevant for setters. */
539
  false, /* isEliminatable.  Not relevant for setters. */
540
  false, /* isAlwaysInSlot.  Only relevant for getters. */
541
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
542
  false,  /* isTypedMethod.  Only relevant for methods. */
543
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
544
};
545
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
546
static_assert(0 < 1, "There is no slot for us");
547
548
MOZ_CAN_RUN_SCRIPT static bool
549
get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
550
0
{
551
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.height", DOM, cx);
552
0
553
0
  int32_t result(self->Height());
554
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
555
0
  args.rval().setInt32(int32_t(result));
556
0
  return true;
557
0
}
558
559
static const JSJitInfo height_getterinfo = {
560
  { (JSJitGetterOp)get_height },
561
  { prototypes::id::PointerEvent },
562
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
563
  JSJitInfo::Getter,
564
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
565
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
566
  true,  /* isInfallible. False in setters. */
567
  false,  /* isMovable.  Not relevant for setters. */
568
  false, /* isEliminatable.  Not relevant for setters. */
569
  false, /* isAlwaysInSlot.  Only relevant for getters. */
570
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
571
  false,  /* isTypedMethod.  Only relevant for methods. */
572
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
573
};
574
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
575
static_assert(0 < 1, "There is no slot for us");
576
577
MOZ_CAN_RUN_SCRIPT static bool
578
get_pressure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
579
0
{
580
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.pressure", DOM, cx);
581
0
582
0
  float result(self->Pressure());
583
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
584
0
  args.rval().set(JS_NumberValue(double(result)));
585
0
  return true;
586
0
}
587
588
static const JSJitInfo pressure_getterinfo = {
589
  { (JSJitGetterOp)get_pressure },
590
  { prototypes::id::PointerEvent },
591
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
592
  JSJitInfo::Getter,
593
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
594
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
595
  true,  /* isInfallible. False in setters. */
596
  false,  /* isMovable.  Not relevant for setters. */
597
  false, /* isEliminatable.  Not relevant for setters. */
598
  false, /* isAlwaysInSlot.  Only relevant for getters. */
599
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
600
  false,  /* isTypedMethod.  Only relevant for methods. */
601
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
602
};
603
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
604
static_assert(0 < 1, "There is no slot for us");
605
606
MOZ_CAN_RUN_SCRIPT static bool
607
get_tangentialPressure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
608
0
{
609
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.tangentialPressure", DOM, cx);
610
0
611
0
  float result(self->TangentialPressure());
612
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
613
0
  args.rval().set(JS_NumberValue(double(result)));
614
0
  return true;
615
0
}
616
617
static const JSJitInfo tangentialPressure_getterinfo = {
618
  { (JSJitGetterOp)get_tangentialPressure },
619
  { prototypes::id::PointerEvent },
620
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
621
  JSJitInfo::Getter,
622
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
623
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
624
  true,  /* isInfallible. False in setters. */
625
  false,  /* isMovable.  Not relevant for setters. */
626
  false, /* isEliminatable.  Not relevant for setters. */
627
  false, /* isAlwaysInSlot.  Only relevant for getters. */
628
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
629
  false,  /* isTypedMethod.  Only relevant for methods. */
630
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
631
};
632
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
633
static_assert(0 < 1, "There is no slot for us");
634
635
MOZ_CAN_RUN_SCRIPT static bool
636
get_tiltX(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
637
0
{
638
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.tiltX", DOM, cx);
639
0
640
0
  int32_t result(self->TiltX());
641
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
642
0
  args.rval().setInt32(int32_t(result));
643
0
  return true;
644
0
}
645
646
static const JSJitInfo tiltX_getterinfo = {
647
  { (JSJitGetterOp)get_tiltX },
648
  { prototypes::id::PointerEvent },
649
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
650
  JSJitInfo::Getter,
651
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
652
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
653
  true,  /* isInfallible. False in setters. */
654
  false,  /* isMovable.  Not relevant for setters. */
655
  false, /* isEliminatable.  Not relevant for setters. */
656
  false, /* isAlwaysInSlot.  Only relevant for getters. */
657
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
658
  false,  /* isTypedMethod.  Only relevant for methods. */
659
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
660
};
661
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
662
static_assert(0 < 1, "There is no slot for us");
663
664
MOZ_CAN_RUN_SCRIPT static bool
665
get_tiltY(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
666
0
{
667
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.tiltY", DOM, cx);
668
0
669
0
  int32_t result(self->TiltY());
670
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
671
0
  args.rval().setInt32(int32_t(result));
672
0
  return true;
673
0
}
674
675
static const JSJitInfo tiltY_getterinfo = {
676
  { (JSJitGetterOp)get_tiltY },
677
  { prototypes::id::PointerEvent },
678
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
679
  JSJitInfo::Getter,
680
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
681
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
682
  true,  /* isInfallible. False in setters. */
683
  false,  /* isMovable.  Not relevant for setters. */
684
  false, /* isEliminatable.  Not relevant for setters. */
685
  false, /* isAlwaysInSlot.  Only relevant for getters. */
686
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
687
  false,  /* isTypedMethod.  Only relevant for methods. */
688
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
689
};
690
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
691
static_assert(0 < 1, "There is no slot for us");
692
693
MOZ_CAN_RUN_SCRIPT static bool
694
get_twist(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
695
0
{
696
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.twist", DOM, cx);
697
0
698
0
  int32_t result(self->Twist());
699
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
700
0
  args.rval().setInt32(int32_t(result));
701
0
  return true;
702
0
}
703
704
static const JSJitInfo twist_getterinfo = {
705
  { (JSJitGetterOp)get_twist },
706
  { prototypes::id::PointerEvent },
707
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
708
  JSJitInfo::Getter,
709
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
710
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
711
  true,  /* isInfallible. False in setters. */
712
  false,  /* isMovable.  Not relevant for setters. */
713
  false, /* isEliminatable.  Not relevant for setters. */
714
  false, /* isAlwaysInSlot.  Only relevant for getters. */
715
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
716
  false,  /* isTypedMethod.  Only relevant for methods. */
717
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
718
};
719
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
720
static_assert(0 < 1, "There is no slot for us");
721
722
MOZ_CAN_RUN_SCRIPT static bool
723
get_pointerType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
724
0
{
725
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.pointerType", DOM, cx);
726
0
727
0
  DOMString result;
728
0
  self->GetPointerType(result);
729
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
730
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
731
0
    return false;
732
0
  }
733
0
  return true;
734
0
}
735
736
static const JSJitInfo pointerType_getterinfo = {
737
  { (JSJitGetterOp)get_pointerType },
738
  { prototypes::id::PointerEvent },
739
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
740
  JSJitInfo::Getter,
741
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
742
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
743
  false,  /* isInfallible. False in setters. */
744
  false,  /* isMovable.  Not relevant for setters. */
745
  false, /* isEliminatable.  Not relevant for setters. */
746
  false, /* isAlwaysInSlot.  Only relevant for getters. */
747
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
748
  false,  /* isTypedMethod.  Only relevant for methods. */
749
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
750
};
751
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
752
static_assert(0 < 1, "There is no slot for us");
753
754
MOZ_CAN_RUN_SCRIPT static bool
755
get_isPrimary(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
756
0
{
757
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.isPrimary", DOM, cx);
758
0
759
0
  bool result(self->IsPrimary());
760
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
761
0
  args.rval().setBoolean(result);
762
0
  return true;
763
0
}
764
765
static const JSJitInfo isPrimary_getterinfo = {
766
  { (JSJitGetterOp)get_isPrimary },
767
  { prototypes::id::PointerEvent },
768
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
769
  JSJitInfo::Getter,
770
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
771
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
772
  true,  /* isInfallible. False in setters. */
773
  false,  /* isMovable.  Not relevant for setters. */
774
  false, /* isEliminatable.  Not relevant for setters. */
775
  false, /* isAlwaysInSlot.  Only relevant for getters. */
776
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
777
  false,  /* isTypedMethod.  Only relevant for methods. */
778
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
779
};
780
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
781
static_assert(0 < 1, "There is no slot for us");
782
783
MOZ_CAN_RUN_SCRIPT static bool
784
getCoalescedEvents(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, const JSJitMethodCallArgs& args)
785
0
{
786
0
  AUTO_PROFILER_LABEL_FAST("PointerEvent.getCoalescedEvents", DOM, cx);
787
0
788
0
  nsTArray<StrongPtrForMember<mozilla::dom::PointerEvent>::Type> result;
789
0
  self->GetCoalescedEvents(result);
790
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
791
0
792
0
  uint32_t length = result.Length();
793
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
794
0
  if (!returnArray) {
795
0
    return false;
796
0
  }
797
0
  // Scope for 'tmp'
798
0
  {
799
0
    JS::Rooted<JS::Value> tmp(cx);
800
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
801
0
      // Control block to let us common up the JS_DefineElement calls when there
802
0
      // are different ways to succeed at wrapping the object.
803
0
      do {
804
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
805
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
806
0
          return false;
807
0
        }
808
0
        break;
809
0
      } while (false);
810
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
811
0
                            JSPROP_ENUMERATE)) {
812
0
        return false;
813
0
      }
814
0
    }
815
0
  }
816
0
  args.rval().setObject(*returnArray);
817
0
  return true;
818
0
}
819
820
static const JSJitInfo getCoalescedEvents_methodinfo = {
821
  { (JSJitGetterOp)getCoalescedEvents },
822
  { prototypes::id::PointerEvent },
823
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
824
  JSJitInfo::Method,
825
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
826
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
827
  false,  /* isInfallible. False in setters. */
828
  false,  /* isMovable.  Not relevant for setters. */
829
  false, /* isEliminatable.  Not relevant for setters. */
830
  false, /* isAlwaysInSlot.  Only relevant for getters. */
831
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
832
  false,  /* isTypedMethod.  Only relevant for methods. */
833
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
834
};
835
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
836
static_assert(0 < 1, "There is no slot for us");
837
838
MOZ_CAN_RUN_SCRIPT static bool
839
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
840
0
{
841
0
  AUTO_PROFILER_LABEL_FAST("get PointerEvent.isTrusted", DOM, cx);
842
0
843
0
  bool result(self->IsTrusted());
844
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
845
0
  args.rval().setBoolean(result);
846
0
  return true;
847
0
}
848
849
static const JSJitInfo isTrusted_getterinfo = {
850
  { (JSJitGetterOp)get_isTrusted },
851
  { prototypes::id::PointerEvent },
852
  { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
853
  JSJitInfo::Getter,
854
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
855
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
856
  true,  /* isInfallible. False in setters. */
857
  true,  /* isMovable.  Not relevant for setters. */
858
  true, /* isEliminatable.  Not relevant for setters. */
859
  false, /* isAlwaysInSlot.  Only relevant for getters. */
860
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
861
  false,  /* isTypedMethod.  Only relevant for methods. */
862
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
863
};
864
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
865
static_assert(0 < 1, "There is no slot for us");
866
867
static bool
868
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
869
0
{
870
0
  mozilla::dom::PointerEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PointerEvent>(obj);
871
0
  // We don't want to preserve if we don't have a wrapper, and we
872
0
  // obviously can't preserve if we're not initialized.
873
0
  if (self && self->GetWrapperPreserveColor()) {
874
0
    PreserveWrapper(self);
875
0
  }
876
0
  return true;
877
0
}
878
879
static void
880
_finalize(js::FreeOp* fop, JSObject* obj)
881
0
{
882
0
  mozilla::dom::PointerEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PointerEvent>(obj);
883
0
  if (self) {
884
0
    ClearWrapper(self, self, obj);
885
0
    AddForDeferredFinalization<mozilla::dom::PointerEvent>(self);
886
0
  }
887
0
}
888
889
static size_t
890
_objectMoved(JSObject* obj, JSObject* old)
891
0
{
892
0
  mozilla::dom::PointerEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PointerEvent>(obj);
893
0
  if (self) {
894
0
    UpdateWrapper(self, self, obj, old);
895
0
  }
896
0
897
0
  return 0;
898
0
}
899
900
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
901
#if defined(__clang__)
902
#pragma clang diagnostic push
903
#pragma clang diagnostic ignored "-Wmissing-braces"
904
#endif
905
static const JSFunctionSpec sMethods_specs[] = {
906
  JS_FNSPEC("getCoalescedEvents", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getCoalescedEvents_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
907
  JS_FS_END
908
};
909
#if defined(__clang__)
910
#pragma clang diagnostic pop
911
#endif
912
913
914
static const Prefable<const JSFunctionSpec> sMethods[] = {
915
  { nullptr, &sMethods_specs[0] },
916
  { nullptr, nullptr }
917
};
918
919
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
920
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
921
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
922
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
923
924
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
925
#if defined(__clang__)
926
#pragma clang diagnostic push
927
#pragma clang diagnostic ignored "-Wmissing-braces"
928
#endif
929
static const JSPropertySpec sAttributes_specs[] = {
930
  { "pointerId", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pointerId_getterinfo, nullptr, nullptr },
931
  { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, nullptr, nullptr },
932
  { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, nullptr, nullptr },
933
  { "pressure", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pressure_getterinfo, nullptr, nullptr },
934
  { "tangentialPressure", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &tangentialPressure_getterinfo, nullptr, nullptr },
935
  { "tiltX", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &tiltX_getterinfo, nullptr, nullptr },
936
  { "tiltY", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &tiltY_getterinfo, nullptr, nullptr },
937
  { "twist", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &twist_getterinfo, nullptr, nullptr },
938
  { "pointerType", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pointerType_getterinfo, nullptr, nullptr },
939
  { "isPrimary", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isPrimary_getterinfo, nullptr, nullptr },
940
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
941
};
942
#if defined(__clang__)
943
#pragma clang diagnostic pop
944
#endif
945
946
947
static const Prefable<const JSPropertySpec> sAttributes[] = {
948
  { nullptr, &sAttributes_specs[0] },
949
  { nullptr, nullptr }
950
};
951
952
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
953
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
954
static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
955
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
956
957
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
958
#if defined(__clang__)
959
#pragma clang diagnostic push
960
#pragma clang diagnostic ignored "-Wmissing-braces"
961
#endif
962
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
963
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
964
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
965
};
966
#if defined(__clang__)
967
#pragma clang diagnostic pop
968
#endif
969
970
971
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
972
  { nullptr, &sUnforgeableAttributes_specs[0] },
973
  { nullptr, nullptr }
974
};
975
976
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
977
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
978
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
979
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
980
981
982
static uint16_t sNativeProperties_sortedPropertyIndices[12];
983
static PropertyInfo sNativeProperties_propertyInfos[12];
984
985
static const NativePropertiesN<3> sNativeProperties = {
986
  false, 0,
987
  false, 0,
988
  true,  0 /* sMethods */,
989
  true,  1 /* sAttributes */,
990
  false, 0,
991
  true,  2 /* sUnforgeableAttributes */,
992
  false, 0,
993
  -1,
994
  12,
995
  sNativeProperties_sortedPropertyIndices,
996
  {
997
    { sMethods, &sNativeProperties_propertyInfos[0] },
998
    { sAttributes, &sNativeProperties_propertyInfos[1] },
999
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[11] }
1000
  }
1001
};
1002
static_assert(12 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1003
    "We have a property info count that is oversized");
1004
1005
static bool
1006
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1007
0
{
1008
0
  AUTO_PROFILER_LABEL_FAST("PointerEvent constructor", DOM, cx);
1009
0
1010
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1011
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
1012
0
  if (!args.isConstructing()) {
1013
0
    // XXXbz wish I could get the name from the callee instead of
1014
0
    // Adding more relocations
1015
0
    return ThrowConstructorWithoutNew(cx, "PointerEvent");
1016
0
  }
1017
0
1018
0
  JS::Rooted<JSObject*> desiredProto(cx);
1019
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
1020
0
    return false;
1021
0
  }
1022
0
1023
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
1024
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PointerEvent");
1025
0
  }
1026
0
  GlobalObject global(cx, obj);
1027
0
  if (global.Failed()) {
1028
0
    return false;
1029
0
  }
1030
0
1031
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1032
0
  binding_detail::FakeString arg0;
1033
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
1034
0
    return false;
1035
0
  }
1036
0
  binding_detail::FastPointerEventInit arg1;
1037
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of PointerEvent.constructor", false)) {
1038
0
    return false;
1039
0
  }
1040
0
  Maybe<JSAutoRealm> ar;
1041
0
  if (objIsXray) {
1042
0
    obj = js::CheckedUnwrap(obj);
1043
0
    if (!obj) {
1044
0
      return false;
1045
0
    }
1046
0
    ar.emplace(cx, obj);
1047
0
    if (!JS_WrapObject(cx, &desiredProto)) {
1048
0
      return false;
1049
0
    }
1050
0
  }
1051
0
  FastErrorResult rv;
1052
0
  auto result(StrongOrRawPtr<mozilla::dom::PointerEvent>(mozilla::dom::PointerEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
1053
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1054
0
    return false;
1055
0
  }
1056
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1057
0
  static_assert(!IsPointer<decltype(result)>::value,
1058
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1059
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1060
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
1061
0
    return false;
1062
0
  }
1063
0
  return true;
1064
0
}
1065
1066
static const js::ClassOps sInterfaceObjectClassOps = {
1067
    nullptr,               /* addProperty */
1068
    nullptr,               /* delProperty */
1069
    nullptr,               /* enumerate */
1070
    nullptr,               /* newEnumerate */
1071
    nullptr,               /* resolve */
1072
    nullptr,               /* mayResolve */
1073
    nullptr,               /* finalize */
1074
    _constructor, /* call */
1075
    nullptr,               /* hasInstance */
1076
    _constructor, /* construct */
1077
    nullptr,               /* trace */
1078
};
1079
1080
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1081
  {
1082
    "Function",
1083
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1084
    &sInterfaceObjectClassOps,
1085
    JS_NULL_CLASS_SPEC,
1086
    JS_NULL_CLASS_EXT,
1087
    &sInterfaceObjectClassObjectOps
1088
  },
1089
  eInterface,
1090
  true,
1091
  prototypes::id::PointerEvent,
1092
  PrototypeTraits<prototypes::id::PointerEvent>::Depth,
1093
  sNativePropertyHooks,
1094
  "function PointerEvent() {\n    [native code]\n}",
1095
  MouseEvent_Binding::GetConstructorObject
1096
};
1097
1098
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1099
  {
1100
    "PointerEventPrototype",
1101
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
1102
    JS_NULL_CLASS_OPS,
1103
    JS_NULL_CLASS_SPEC,
1104
    JS_NULL_CLASS_EXT,
1105
    JS_NULL_OBJECT_OPS
1106
  },
1107
  eInterfacePrototype,
1108
  false,
1109
  prototypes::id::PointerEvent,
1110
  PrototypeTraits<prototypes::id::PointerEvent>::Depth,
1111
  sNativePropertyHooks,
1112
  "[object PointerEventPrototype]",
1113
  MouseEvent_Binding::GetProtoObject
1114
};
1115
1116
bool
1117
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1118
0
{
1119
0
  static bool sPrefValue;
1120
0
  static bool sPrefCacheSetUp = false;
1121
0
  if (!sPrefCacheSetUp) {
1122
0
    sPrefCacheSetUp = true;
1123
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.w3c_pointer_events.enabled");
1124
0
  }
1125
0
1126
0
  return sPrefValue;
1127
0
}
1128
1129
static const js::ClassOps sClassOps = {
1130
  _addProperty, /* addProperty */
1131
  nullptr,               /* delProperty */
1132
  nullptr,               /* enumerate */
1133
  nullptr, /* newEnumerate */
1134
  nullptr, /* resolve */
1135
  nullptr, /* mayResolve */
1136
  _finalize, /* finalize */
1137
  nullptr, /* call */
1138
  nullptr,               /* hasInstance */
1139
  nullptr,               /* construct */
1140
  nullptr, /* trace */
1141
};
1142
1143
static const js::ClassExtension sClassExtension = {
1144
  nullptr, /* weakmapKeyDelegateOp */
1145
  _objectMoved /* objectMovedOp */
1146
};
1147
1148
static const DOMJSClass sClass = {
1149
  { "PointerEvent",
1150
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
1151
    &sClassOps,
1152
    JS_NULL_CLASS_SPEC,
1153
    &sClassExtension,
1154
    JS_NULL_OBJECT_OPS
1155
  },
1156
  { prototypes::id::Event, prototypes::id::UIEvent, prototypes::id::MouseEvent, prototypes::id::PointerEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1157
  IsBaseOf<nsISupports, mozilla::dom::PointerEvent >::value,
1158
  sNativePropertyHooks,
1159
  FindAssociatedGlobalForNative<mozilla::dom::PointerEvent>::Get,
1160
  GetProtoObjectHandle,
1161
  GetCCParticipant<mozilla::dom::PointerEvent>::Get()
1162
};
1163
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1164
              "Must have the right minimal number of reserved slots.");
1165
static_assert(1 >= 1,
1166
              "Must have enough reserved slots.");
1167
1168
const JSClass*
1169
GetJSClass()
1170
0
{
1171
0
  return sClass.ToJSClass();
1172
0
}
1173
1174
bool
1175
Wrap(JSContext* aCx, mozilla::dom::PointerEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1176
0
{
1177
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::PointerEvent>::value,
1178
0
                "Shouldn't have wrappercached things that are not refcounted.");
1179
0
  MOZ_ASSERT(static_cast<mozilla::dom::PointerEvent*>(aObject) ==
1180
0
             reinterpret_cast<mozilla::dom::PointerEvent*>(aObject),
1181
0
             "Multiple inheritance for mozilla::dom::PointerEvent is broken.");
1182
0
  MOZ_ASSERT(static_cast<mozilla::dom::MouseEvent*>(aObject) ==
1183
0
             reinterpret_cast<mozilla::dom::MouseEvent*>(aObject),
1184
0
             "Multiple inheritance for mozilla::dom::MouseEvent is broken.");
1185
0
  MOZ_ASSERT(static_cast<mozilla::dom::UIEvent*>(aObject) ==
1186
0
             reinterpret_cast<mozilla::dom::UIEvent*>(aObject),
1187
0
             "Multiple inheritance for mozilla::dom::UIEvent is broken.");
1188
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
1189
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
1190
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
1191
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1192
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1193
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1194
0
             "You should probably not be using Wrap() directly; use "
1195
0
             "GetOrCreateDOMReflector instead");
1196
0
1197
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1198
0
             "nsISupports must be on our primary inheritance chain");
1199
0
1200
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1201
0
  if (!global) {
1202
0
    return false;
1203
0
  }
1204
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1205
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1206
0
1207
0
  // That might have ended up wrapping us already, due to the wonders
1208
0
  // of XBL.  Check for that, and bail out as needed.
1209
0
  aReflector.set(aCache->GetWrapper());
1210
0
  if (aReflector) {
1211
#ifdef DEBUG
1212
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1213
#endif // DEBUG
1214
    return true;
1215
0
  }
1216
0
1217
0
  JSAutoRealm ar(aCx, global);
1218
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1219
0
  if (!canonicalProto) {
1220
0
    return false;
1221
0
  }
1222
0
  JS::Rooted<JSObject*> proto(aCx);
1223
0
  if (aGivenProto) {
1224
0
    proto = aGivenProto;
1225
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1226
0
    // coming in, we changed compartments to that of "parent" so may need
1227
0
    // to wrap the proto here.
1228
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1229
0
      if (!JS_WrapObject(aCx, &proto)) {
1230
0
        return false;
1231
0
      }
1232
0
    }
1233
0
  } else {
1234
0
    proto = canonicalProto;
1235
0
  }
1236
0
1237
0
  BindingJSObjectCreator<mozilla::dom::PointerEvent> creator(aCx);
1238
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1239
0
  if (!aReflector) {
1240
0
    return false;
1241
0
  }
1242
0
1243
0
  aCache->SetWrapper(aReflector);
1244
0
1245
0
  // Important: do unforgeable property setup after we have handed
1246
0
  // over ownership of the C++ object to obj as needed, so that if
1247
0
  // we fail and it ends up GCed it won't have problems in the
1248
0
  // finalizer trying to drop its ownership of the C++ object.
1249
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
1250
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
1251
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
1252
0
    aCache->ReleaseWrapper(aObject);
1253
0
    aCache->ClearWrapper();
1254
0
    return false;
1255
0
  }
1256
0
  creator.InitializationSucceeded();
1257
0
1258
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1259
0
             aCache->GetWrapperPreserveColor() == aReflector);
1260
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1261
0
  // otherwise we won't be able to properly recreate it later, since
1262
0
  // we won't know what proto to use.  Note that we don't check
1263
0
  // aGivenProto here, since it's entirely possible (and even
1264
0
  // somewhat common) to have a non-null aGivenProto which is the
1265
0
  // same as canonicalProto.
1266
0
  if (proto != canonicalProto) {
1267
0
    PreserveWrapper(aObject);
1268
0
  }
1269
0
1270
0
  return true;
1271
0
}
1272
1273
const NativePropertyHooks sNativePropertyHooks[] = { {
1274
  nullptr,
1275
  nullptr,
1276
  nullptr,
1277
  { sNativeProperties.Upcast(), nullptr },
1278
  prototypes::id::PointerEvent,
1279
  constructors::id::PointerEvent,
1280
  MouseEvent_Binding::sNativePropertyHooks,
1281
  &DefaultXrayExpandoObjectClass
1282
} };
1283
1284
void
1285
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1286
0
{
1287
0
  JS::Handle<JSObject*> parentProto(MouseEvent_Binding::GetProtoObjectHandle(aCx));
1288
0
  if (!parentProto) {
1289
0
    return;
1290
0
  }
1291
0
1292
0
  JS::Handle<JSObject*> constructorProto(MouseEvent_Binding::GetConstructorObjectHandle(aCx));
1293
0
  if (!constructorProto) {
1294
0
    return;
1295
0
  }
1296
0
1297
0
  static bool sIdsInited = false;
1298
0
  if (!sIdsInited && NS_IsMainThread()) {
1299
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1300
0
      return;
1301
0
    }
1302
0
    sIdsInited = true;
1303
0
  }
1304
0
1305
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PointerEvent);
1306
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PointerEvent);
1307
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1308
0
                              &sPrototypeClass.mBase, protoCache,
1309
0
                              nullptr,
1310
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
1311
0
                              interfaceCache,
1312
0
                              sNativeProperties.Upcast(),
1313
0
                              nullptr,
1314
0
                              "PointerEvent", aDefineOnGlobal,
1315
0
                              nullptr,
1316
0
                              false);
1317
0
1318
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
1319
0
  {
1320
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1321
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1322
0
    if (!unforgeableHolder) {
1323
0
      *protoCache = nullptr;
1324
0
      if (interfaceCache) {
1325
0
        *interfaceCache = nullptr;
1326
0
      }
1327
0
      return;
1328
0
    }
1329
0
  }
1330
0
1331
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1332
0
    *protoCache = nullptr;
1333
0
    if (interfaceCache) {
1334
0
      *interfaceCache = nullptr;
1335
0
    }
1336
0
    return;
1337
0
  }
1338
0
1339
0
  if (*protoCache) {
1340
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1341
0
                        JS::ObjectValue(*unforgeableHolder));
1342
0
  }
1343
0
}
1344
1345
JSObject*
1346
GetConstructorObject(JSContext* aCx)
1347
0
{
1348
0
  return GetConstructorObjectHandle(aCx);
1349
0
}
1350
1351
} // namespace PointerEvent_Binding
1352
1353
1354
1355
} // namespace dom
1356
} // namespace mozilla