Coverage Report

Created: 2018-09-25 14:53

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