Coverage Report

Created: 2018-09-25 14:53

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