Coverage Report

Created: 2018-09-25 14:53

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