Coverage Report

Created: 2018-09-25 14:53

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