Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/PaymentAddressBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM PaymentAddress.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "PaymentAddressBinding.h"
4
#include "WrapperFactory.h"
5
#include "XrayWrapper.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/PaymentAddress.h"
11
#include "mozilla/dom/PaymentRequest.h"
12
#include "mozilla/dom/XrayExpandoClass.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
namespace binding_detail {}; // Just to make sure it's known as a namespace
18
using namespace mozilla::dom::binding_detail;
19
20
21
namespace PaymentAddress_Binding {
22
23
MOZ_CAN_RUN_SCRIPT static bool
24
get_country(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
25
0
{
26
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.country", DOM, cx);
27
0
28
0
  DOMString result;
29
0
  self->GetCountry(result);
30
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
31
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
32
0
    return false;
33
0
  }
34
0
  return true;
35
0
}
36
37
static const JSJitInfo country_getterinfo = {
38
  { (JSJitGetterOp)get_country },
39
  { prototypes::id::PaymentAddress },
40
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
41
  JSJitInfo::Getter,
42
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
43
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
44
  false,  /* isInfallible. False in setters. */
45
  false,  /* isMovable.  Not relevant for setters. */
46
  false, /* isEliminatable.  Not relevant for setters. */
47
  false, /* isAlwaysInSlot.  Only relevant for getters. */
48
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
49
  false,  /* isTypedMethod.  Only relevant for methods. */
50
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
51
};
52
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
53
static_assert(0 < 2, "There is no slot for us");
54
55
MOZ_CAN_RUN_SCRIPT static bool
56
get_addressLine(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
57
0
{
58
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.addressLine", DOM, cx);
59
0
60
0
  // Have to either root across the getter call or reget after.
61
0
  bool isXray;
62
0
  JS::Rooted<JSObject*> slotStorage(cx, GetCachedSlotStorageObject(cx, obj, &isXray));
63
0
  if (!slotStorage) {
64
0
    return false;
65
0
  }
66
0
  const size_t slotIndex = isXray ? (xpc::JSSLOT_EXPANDO_COUNT + 0) : (DOM_INSTANCE_RESERVED_SLOTS + 0);
67
0
  MOZ_ASSERT(JSCLASS_RESERVED_SLOTS(js::GetObjectClass(slotStorage)) > slotIndex);
68
0
  {
69
0
    // Scope for cachedVal
70
0
    JS::Value cachedVal = js::GetReservedSlot(slotStorage, slotIndex);
71
0
    if (!cachedVal.isUndefined()) {
72
0
      args.rval().set(cachedVal);
73
0
      // The cached value is in the compartment of slotStorage,
74
0
      // so wrap into the caller compartment as needed.
75
0
      if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
76
0
        return true;
77
0
      }
78
0
      return false;
79
0
    }
80
0
  }
81
0
82
0
  nsTArray<nsString> result;
83
0
  self->GetAddressLine(result);
84
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
85
0
  {
86
0
    JS::Rooted<JSObject*> conversionScope(cx, isXray ? JS::CurrentGlobalOrNull(cx) : slotStorage);
87
0
    JSAutoRealm ar(cx, conversionScope);
88
0
    do { // block we break out of when done wrapping
89
0
90
0
      uint32_t length = result.Length();
91
0
      JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
92
0
      if (!returnArray) {
93
0
        return false;
94
0
      }
95
0
      // Scope for 'tmp'
96
0
      {
97
0
        JS::Rooted<JS::Value> tmp(cx);
98
0
        for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
99
0
          // Control block to let us common up the JS_DefineElement calls when there
100
0
          // are different ways to succeed at wrapping the object.
101
0
          do {
102
0
            if (!xpc::NonVoidStringToJsval(cx, result[sequenceIdx0], &tmp)) {
103
0
              return false;
104
0
            }
105
0
            break;
106
0
          } while (false);
107
0
          if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
108
0
                                JSPROP_ENUMERATE)) {
109
0
            return false;
110
0
          }
111
0
        }
112
0
      }
113
0
      args.rval().setObject(*returnArray);
114
0
      break;
115
0
    } while (false);
116
0
    JS::Rooted<JSObject*> rvalObj(cx, &args.rval().toObject());
117
0
    if (!JS_FreezeObject(cx, rvalObj)) {
118
0
      return false;
119
0
    }
120
0
  }
121
0
  { // And now store things in the realm of our slotStorage.
122
0
    JSAutoRealm ar(cx, slotStorage);
123
0
    // Make a copy so that we don't do unnecessary wrapping on args.rval().
124
0
    JS::Rooted<JS::Value> storedVal(cx, args.rval());
125
0
    if (!MaybeWrapNonDOMObjectValue(cx, &storedVal)) {
126
0
      return false;
127
0
    }
128
0
    js::SetReservedSlot(slotStorage, slotIndex, storedVal);
129
0
    if (!isXray) {
130
0
      // In the Xray case we don't need to do this, because getting the
131
0
      // expando object already preserved our wrapper.
132
0
      PreserveWrapper(self);
133
0
    }
134
0
  }
135
0
  // And now make sure args.rval() is in the caller realm.
136
0
  if (MaybeWrapNonDOMObjectValue(cx, args.rval())) {
137
0
    return true;
138
0
  }
139
0
  return false;
140
0
}
141
142
static const JSJitInfo addressLine_getterinfo = {
143
  { (JSJitGetterOp)get_addressLine },
144
  { prototypes::id::PaymentAddress },
145
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
146
  JSJitInfo::Getter,
147
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
148
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
149
  false,  /* isInfallible. False in setters. */
150
  true,  /* isMovable.  Not relevant for setters. */
151
  true, /* isEliminatable.  Not relevant for setters. */
152
  false, /* isAlwaysInSlot.  Only relevant for getters. */
153
  true, /* isLazilyCachedInSlot.  Only relevant for getters. */
154
  false,  /* isTypedMethod.  Only relevant for methods. */
155
  (DOM_INSTANCE_RESERVED_SLOTS + 0)   /* Reserved slot index, if we're stored in a slot, else 0. */
156
};
157
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) <= JSJitInfo::maxSlotIndex, "We won't fit");
158
static_assert((DOM_INSTANCE_RESERVED_SLOTS + 0) < 2, "There is no slot for us");
159
160
MOZ_CAN_RUN_SCRIPT static bool
161
get_region(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
162
0
{
163
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.region", DOM, cx);
164
0
165
0
  DOMString result;
166
0
  self->GetRegion(result);
167
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
168
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
169
0
    return false;
170
0
  }
171
0
  return true;
172
0
}
173
174
static const JSJitInfo region_getterinfo = {
175
  { (JSJitGetterOp)get_region },
176
  { prototypes::id::PaymentAddress },
177
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
178
  JSJitInfo::Getter,
179
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
180
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
181
  false,  /* isInfallible. False in setters. */
182
  false,  /* isMovable.  Not relevant for setters. */
183
  false, /* isEliminatable.  Not relevant for setters. */
184
  false, /* isAlwaysInSlot.  Only relevant for getters. */
185
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
186
  false,  /* isTypedMethod.  Only relevant for methods. */
187
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
188
};
189
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
190
static_assert(0 < 2, "There is no slot for us");
191
192
MOZ_CAN_RUN_SCRIPT static bool
193
get_city(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
194
0
{
195
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.city", DOM, cx);
196
0
197
0
  DOMString result;
198
0
  self->GetCity(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 city_getterinfo = {
207
  { (JSJitGetterOp)get_city },
208
  { prototypes::id::PaymentAddress },
209
  { PrototypeTraits<prototypes::id::PaymentAddress>::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 < 2, "There is no slot for us");
223
224
MOZ_CAN_RUN_SCRIPT static bool
225
get_dependentLocality(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
226
0
{
227
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.dependentLocality", DOM, cx);
228
0
229
0
  DOMString result;
230
0
  self->GetDependentLocality(result);
231
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
232
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
233
0
    return false;
234
0
  }
235
0
  return true;
236
0
}
237
238
static const JSJitInfo dependentLocality_getterinfo = {
239
  { (JSJitGetterOp)get_dependentLocality },
240
  { prototypes::id::PaymentAddress },
241
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
242
  JSJitInfo::Getter,
243
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
244
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
245
  false,  /* isInfallible. False in setters. */
246
  false,  /* isMovable.  Not relevant for setters. */
247
  false, /* isEliminatable.  Not relevant for setters. */
248
  false, /* isAlwaysInSlot.  Only relevant for getters. */
249
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
250
  false,  /* isTypedMethod.  Only relevant for methods. */
251
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
252
};
253
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
254
static_assert(0 < 2, "There is no slot for us");
255
256
MOZ_CAN_RUN_SCRIPT static bool
257
get_postalCode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
258
0
{
259
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.postalCode", DOM, cx);
260
0
261
0
  DOMString result;
262
0
  self->GetPostalCode(result);
263
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
264
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
265
0
    return false;
266
0
  }
267
0
  return true;
268
0
}
269
270
static const JSJitInfo postalCode_getterinfo = {
271
  { (JSJitGetterOp)get_postalCode },
272
  { prototypes::id::PaymentAddress },
273
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
274
  JSJitInfo::Getter,
275
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
276
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
277
  false,  /* isInfallible. False in setters. */
278
  false,  /* isMovable.  Not relevant for setters. */
279
  false, /* isEliminatable.  Not relevant for setters. */
280
  false, /* isAlwaysInSlot.  Only relevant for getters. */
281
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
282
  false,  /* isTypedMethod.  Only relevant for methods. */
283
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
284
};
285
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
286
static_assert(0 < 2, "There is no slot for us");
287
288
MOZ_CAN_RUN_SCRIPT static bool
289
get_sortingCode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
290
0
{
291
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.sortingCode", DOM, cx);
292
0
293
0
  DOMString result;
294
0
  self->GetSortingCode(result);
295
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
296
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
297
0
    return false;
298
0
  }
299
0
  return true;
300
0
}
301
302
static const JSJitInfo sortingCode_getterinfo = {
303
  { (JSJitGetterOp)get_sortingCode },
304
  { prototypes::id::PaymentAddress },
305
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
306
  JSJitInfo::Getter,
307
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
308
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
309
  false,  /* isInfallible. False in setters. */
310
  false,  /* isMovable.  Not relevant for setters. */
311
  false, /* isEliminatable.  Not relevant for setters. */
312
  false, /* isAlwaysInSlot.  Only relevant for getters. */
313
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
314
  false,  /* isTypedMethod.  Only relevant for methods. */
315
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
316
};
317
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
318
static_assert(0 < 2, "There is no slot for us");
319
320
MOZ_CAN_RUN_SCRIPT static bool
321
get_organization(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
322
0
{
323
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.organization", DOM, cx);
324
0
325
0
  DOMString result;
326
0
  self->GetOrganization(result);
327
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
328
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
329
0
    return false;
330
0
  }
331
0
  return true;
332
0
}
333
334
static const JSJitInfo organization_getterinfo = {
335
  { (JSJitGetterOp)get_organization },
336
  { prototypes::id::PaymentAddress },
337
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
338
  JSJitInfo::Getter,
339
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
340
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
341
  false,  /* isInfallible. False in setters. */
342
  false,  /* isMovable.  Not relevant for setters. */
343
  false, /* isEliminatable.  Not relevant for setters. */
344
  false, /* isAlwaysInSlot.  Only relevant for getters. */
345
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
346
  false,  /* isTypedMethod.  Only relevant for methods. */
347
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
348
};
349
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
350
static_assert(0 < 2, "There is no slot for us");
351
352
MOZ_CAN_RUN_SCRIPT static bool
353
get_recipient(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
354
0
{
355
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.recipient", DOM, cx);
356
0
357
0
  DOMString result;
358
0
  self->GetRecipient(result);
359
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
360
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
361
0
    return false;
362
0
  }
363
0
  return true;
364
0
}
365
366
static const JSJitInfo recipient_getterinfo = {
367
  { (JSJitGetterOp)get_recipient },
368
  { prototypes::id::PaymentAddress },
369
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
370
  JSJitInfo::Getter,
371
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
372
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
373
  false,  /* isInfallible. False in setters. */
374
  false,  /* isMovable.  Not relevant for setters. */
375
  false, /* isEliminatable.  Not relevant for setters. */
376
  false, /* isAlwaysInSlot.  Only relevant for getters. */
377
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
378
  false,  /* isTypedMethod.  Only relevant for methods. */
379
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
380
};
381
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
382
static_assert(0 < 2, "There is no slot for us");
383
384
MOZ_CAN_RUN_SCRIPT static bool
385
get_phone(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JSJitGetterCallArgs args)
386
0
{
387
0
  AUTO_PROFILER_LABEL_FAST("get PaymentAddress.phone", DOM, cx);
388
0
389
0
  DOMString result;
390
0
  self->GetPhone(result);
391
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
392
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
393
0
    return false;
394
0
  }
395
0
  return true;
396
0
}
397
398
static const JSJitInfo phone_getterinfo = {
399
  { (JSJitGetterOp)get_phone },
400
  { prototypes::id::PaymentAddress },
401
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
402
  JSJitInfo::Getter,
403
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
404
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
405
  false,  /* isInfallible. False in setters. */
406
  false,  /* isMovable.  Not relevant for setters. */
407
  false, /* isEliminatable.  Not relevant for setters. */
408
  false, /* isAlwaysInSlot.  Only relevant for getters. */
409
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
410
  false,  /* isTypedMethod.  Only relevant for methods. */
411
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
412
};
413
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
414
static_assert(0 < 2, "There is no slot for us");
415
416
MOZ_CAN_RUN_SCRIPT static bool
417
toJSON(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, const JSJitMethodCallArgs& args)
418
0
{
419
0
  AUTO_PROFILER_LABEL_FAST("PaymentAddress.toJSON", DOM, cx);
420
0
421
0
  JS::Rooted<JSObject*> result(cx, JS_NewPlainObject(cx));
422
0
  if (!result) {
423
0
    return false;
424
0
  }
425
0
  if (!PaymentAddress_Binding::CollectJSONAttributes(cx, obj, self, result)) {
426
0
    return false;
427
0
  }
428
0
  args.rval().setObject(*result);
429
0
  return true;
430
0
}
431
432
static const JSJitInfo toJSON_methodinfo = {
433
  { (JSJitGetterOp)toJSON },
434
  { prototypes::id::PaymentAddress },
435
  { PrototypeTraits<prototypes::id::PaymentAddress>::Depth },
436
  JSJitInfo::Method,
437
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
438
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
439
  false,  /* isInfallible. False in setters. */
440
  false,  /* isMovable.  Not relevant for setters. */
441
  false, /* isEliminatable.  Not relevant for setters. */
442
  false, /* isAlwaysInSlot.  Only relevant for getters. */
443
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
444
  false,  /* isTypedMethod.  Only relevant for methods. */
445
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
446
};
447
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
448
static_assert(0 < 2, "There is no slot for us");
449
450
static bool
451
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
452
0
{
453
0
  mozilla::dom::PaymentAddress* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentAddress>(obj);
454
0
  // We don't want to preserve if we don't have a wrapper, and we
455
0
  // obviously can't preserve if we're not initialized.
456
0
  if (self && self->GetWrapperPreserveColor()) {
457
0
    PreserveWrapper(self);
458
0
  }
459
0
  return true;
460
0
}
461
462
static void
463
_finalize(js::FreeOp* fop, JSObject* obj)
464
0
{
465
0
  mozilla::dom::PaymentAddress* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentAddress>(obj);
466
0
  if (self) {
467
0
    ClearWrapper(self, self, obj);
468
0
    AddForDeferredFinalization<mozilla::dom::PaymentAddress>(self);
469
0
  }
470
0
}
471
472
static size_t
473
_objectMoved(JSObject* obj, JSObject* old)
474
0
{
475
0
  mozilla::dom::PaymentAddress* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PaymentAddress>(obj);
476
0
  if (self) {
477
0
    UpdateWrapper(self, self, obj, old);
478
0
  }
479
0
480
0
  return 0;
481
0
}
482
483
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
484
#if defined(__clang__)
485
#pragma clang diagnostic push
486
#pragma clang diagnostic ignored "-Wmissing-braces"
487
#endif
488
static const JSFunctionSpec sMethods_specs[] = {
489
  JS_FNSPEC("toJSON", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&toJSON_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
490
  JS_FS_END
491
};
492
#if defined(__clang__)
493
#pragma clang diagnostic pop
494
#endif
495
496
// Can't be const because the pref-enabled boolean needs to be writable
497
static PrefableDisablers sMethods_disablers0 = {
498
  true, true, 0, nullptr
499
};
500
501
static const Prefable<const JSFunctionSpec> sMethods[] = {
502
  { &sMethods_disablers0, &sMethods_specs[0] },
503
  { nullptr, nullptr }
504
};
505
506
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
507
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
508
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
509
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
510
511
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
512
#if defined(__clang__)
513
#pragma clang diagnostic push
514
#pragma clang diagnostic ignored "-Wmissing-braces"
515
#endif
516
static const JSPropertySpec sAttributes_specs[] = {
517
  { "country", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &country_getterinfo, nullptr, nullptr },
518
  { "addressLine", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &addressLine_getterinfo, nullptr, nullptr },
519
  { "region", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &region_getterinfo, nullptr, nullptr },
520
  { "city", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &city_getterinfo, nullptr, nullptr },
521
  { "dependentLocality", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &dependentLocality_getterinfo, nullptr, nullptr },
522
  { "postalCode", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &postalCode_getterinfo, nullptr, nullptr },
523
  { "sortingCode", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &sortingCode_getterinfo, nullptr, nullptr },
524
  { "organization", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &organization_getterinfo, nullptr, nullptr },
525
  { "recipient", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &recipient_getterinfo, nullptr, nullptr },
526
  { "phone", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &phone_getterinfo, nullptr, nullptr },
527
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
528
};
529
#if defined(__clang__)
530
#pragma clang diagnostic pop
531
#endif
532
533
// Can't be const because the pref-enabled boolean needs to be writable
534
static PrefableDisablers sAttributes_disablers0 = {
535
  true, true, 0, nullptr
536
};
537
538
static const Prefable<const JSPropertySpec> sAttributes[] = {
539
  { &sAttributes_disablers0, &sAttributes_specs[0] },
540
  { nullptr, nullptr }
541
};
542
543
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
544
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
545
static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
546
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
547
548
549
static uint16_t sNativeProperties_sortedPropertyIndices[11];
550
static PropertyInfo sNativeProperties_propertyInfos[11];
551
552
static const NativePropertiesN<2> sNativeProperties = {
553
  false, 0,
554
  false, 0,
555
  true,  0 /* sMethods */,
556
  true,  1 /* sAttributes */,
557
  false, 0,
558
  false, 0,
559
  false, 0,
560
  -1,
561
  11,
562
  sNativeProperties_sortedPropertyIndices,
563
  {
564
    { sMethods, &sNativeProperties_propertyInfos[0] },
565
    { sAttributes, &sNativeProperties_propertyInfos[1] }
566
  }
567
};
568
static_assert(11 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
569
    "We have a property info count that is oversized");
570
571
MOZ_CAN_RUN_SCRIPT bool
572
CollectJSONAttributes(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PaymentAddress* self, JS::Rooted<JSObject*>& result)
573
0
{
574
0
  { // scope for "temp"
575
0
    JS::Rooted<JS::Value> temp(cx);
576
0
    if (!get_country(cx, obj, self, JSJitGetterCallArgs(&temp))) {
577
0
      return false;
578
0
    }
579
0
    if (!JS_DefineProperty(cx, result, "country", temp, JSPROP_ENUMERATE)) {
580
0
      return false;
581
0
    }
582
0
  }
583
0
  { // scope for "temp"
584
0
    JS::Rooted<JS::Value> temp(cx);
585
0
    if (!get_addressLine(cx, obj, self, JSJitGetterCallArgs(&temp))) {
586
0
      return false;
587
0
    }
588
0
    if (!JS_DefineProperty(cx, result, "addressLine", temp, JSPROP_ENUMERATE)) {
589
0
      return false;
590
0
    }
591
0
  }
592
0
  { // scope for "temp"
593
0
    JS::Rooted<JS::Value> temp(cx);
594
0
    if (!get_region(cx, obj, self, JSJitGetterCallArgs(&temp))) {
595
0
      return false;
596
0
    }
597
0
    if (!JS_DefineProperty(cx, result, "region", temp, JSPROP_ENUMERATE)) {
598
0
      return false;
599
0
    }
600
0
  }
601
0
  { // scope for "temp"
602
0
    JS::Rooted<JS::Value> temp(cx);
603
0
    if (!get_city(cx, obj, self, JSJitGetterCallArgs(&temp))) {
604
0
      return false;
605
0
    }
606
0
    if (!JS_DefineProperty(cx, result, "city", temp, JSPROP_ENUMERATE)) {
607
0
      return false;
608
0
    }
609
0
  }
610
0
  { // scope for "temp"
611
0
    JS::Rooted<JS::Value> temp(cx);
612
0
    if (!get_dependentLocality(cx, obj, self, JSJitGetterCallArgs(&temp))) {
613
0
      return false;
614
0
    }
615
0
    if (!JS_DefineProperty(cx, result, "dependentLocality", temp, JSPROP_ENUMERATE)) {
616
0
      return false;
617
0
    }
618
0
  }
619
0
  { // scope for "temp"
620
0
    JS::Rooted<JS::Value> temp(cx);
621
0
    if (!get_postalCode(cx, obj, self, JSJitGetterCallArgs(&temp))) {
622
0
      return false;
623
0
    }
624
0
    if (!JS_DefineProperty(cx, result, "postalCode", temp, JSPROP_ENUMERATE)) {
625
0
      return false;
626
0
    }
627
0
  }
628
0
  { // scope for "temp"
629
0
    JS::Rooted<JS::Value> temp(cx);
630
0
    if (!get_sortingCode(cx, obj, self, JSJitGetterCallArgs(&temp))) {
631
0
      return false;
632
0
    }
633
0
    if (!JS_DefineProperty(cx, result, "sortingCode", temp, JSPROP_ENUMERATE)) {
634
0
      return false;
635
0
    }
636
0
  }
637
0
  { // scope for "temp"
638
0
    JS::Rooted<JS::Value> temp(cx);
639
0
    if (!get_organization(cx, obj, self, JSJitGetterCallArgs(&temp))) {
640
0
      return false;
641
0
    }
642
0
    if (!JS_DefineProperty(cx, result, "organization", temp, JSPROP_ENUMERATE)) {
643
0
      return false;
644
0
    }
645
0
  }
646
0
  { // scope for "temp"
647
0
    JS::Rooted<JS::Value> temp(cx);
648
0
    if (!get_recipient(cx, obj, self, JSJitGetterCallArgs(&temp))) {
649
0
      return false;
650
0
    }
651
0
    if (!JS_DefineProperty(cx, result, "recipient", temp, JSPROP_ENUMERATE)) {
652
0
      return false;
653
0
    }
654
0
  }
655
0
  { // scope for "temp"
656
0
    JS::Rooted<JS::Value> temp(cx);
657
0
    if (!get_phone(cx, obj, self, JSJitGetterCallArgs(&temp))) {
658
0
      return false;
659
0
    }
660
0
    if (!JS_DefineProperty(cx, result, "phone", temp, JSPROP_ENUMERATE)) {
661
0
      return false;
662
0
    }
663
0
  }
664
0
  return true;
665
0
}
666
667
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
668
  {
669
    "Function",
670
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
671
    &sBoringInterfaceObjectClassClassOps,
672
    JS_NULL_CLASS_SPEC,
673
    JS_NULL_CLASS_EXT,
674
    &sInterfaceObjectClassObjectOps
675
  },
676
  eInterface,
677
  true,
678
  prototypes::id::PaymentAddress,
679
  PrototypeTraits<prototypes::id::PaymentAddress>::Depth,
680
  sNativePropertyHooks,
681
  "function PaymentAddress() {\n    [native code]\n}",
682
  JS::GetRealmFunctionPrototype
683
};
684
685
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
686
  {
687
    "PaymentAddressPrototype",
688
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
689
    JS_NULL_CLASS_OPS,
690
    JS_NULL_CLASS_SPEC,
691
    JS_NULL_CLASS_EXT,
692
    JS_NULL_OBJECT_OPS
693
  },
694
  eInterfacePrototype,
695
  false,
696
  prototypes::id::PaymentAddress,
697
  PrototypeTraits<prototypes::id::PaymentAddress>::Depth,
698
  sNativePropertyHooks,
699
  "[object PaymentAddressPrototype]",
700
  JS::GetRealmObjectPrototype
701
};
702
703
bool
704
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
705
0
{
706
0
  return mozilla::dom::PaymentRequest::PrefEnabled(aCx, aObj) &&
707
0
         mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
708
0
}
709
710
static const js::ClassOps sClassOps = {
711
  _addProperty, /* addProperty */
712
  nullptr,               /* delProperty */
713
  nullptr,               /* enumerate */
714
  nullptr, /* newEnumerate */
715
  nullptr, /* resolve */
716
  nullptr, /* mayResolve */
717
  _finalize, /* finalize */
718
  nullptr, /* call */
719
  nullptr,               /* hasInstance */
720
  nullptr,               /* construct */
721
  nullptr, /* trace */
722
};
723
724
static const js::ClassExtension sClassExtension = {
725
  nullptr, /* weakmapKeyDelegateOp */
726
  _objectMoved /* objectMovedOp */
727
};
728
729
static const DOMJSClass sClass = {
730
  { "PaymentAddress",
731
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(2),
732
    &sClassOps,
733
    JS_NULL_CLASS_SPEC,
734
    &sClassExtension,
735
    JS_NULL_OBJECT_OPS
736
  },
737
  { prototypes::id::PaymentAddress, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
738
  IsBaseOf<nsISupports, mozilla::dom::PaymentAddress >::value,
739
  sNativePropertyHooks,
740
  FindAssociatedGlobalForNative<mozilla::dom::PaymentAddress>::Get,
741
  GetProtoObjectHandle,
742
  GetCCParticipant<mozilla::dom::PaymentAddress>::Get()
743
};
744
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
745
              "Must have the right minimal number of reserved slots.");
746
static_assert(2 >= 2,
747
              "Must have enough reserved slots.");
748
749
const JSClass*
750
GetJSClass()
751
0
{
752
0
  return sClass.ToJSClass();
753
0
}
754
755
bool
756
Wrap(JSContext* aCx, mozilla::dom::PaymentAddress* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
757
0
{
758
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::PaymentAddress>::value,
759
0
                "Shouldn't have wrappercached things that are not refcounted.");
760
0
  MOZ_ASSERT(static_cast<mozilla::dom::PaymentAddress*>(aObject) ==
761
0
             reinterpret_cast<mozilla::dom::PaymentAddress*>(aObject),
762
0
             "Multiple inheritance for mozilla::dom::PaymentAddress is broken.");
763
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
764
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
765
0
  MOZ_ASSERT(!aCache->GetWrapper(),
766
0
             "You should probably not be using Wrap() directly; use "
767
0
             "GetOrCreateDOMReflector instead");
768
0
769
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
770
0
             "nsISupports must be on our primary inheritance chain");
771
0
772
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
773
0
  if (!global) {
774
0
    return false;
775
0
  }
776
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
777
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
778
0
779
0
  // That might have ended up wrapping us already, due to the wonders
780
0
  // of XBL.  Check for that, and bail out as needed.
781
0
  aReflector.set(aCache->GetWrapper());
782
0
  if (aReflector) {
783
#ifdef DEBUG
784
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
785
#endif // DEBUG
786
    return true;
787
0
  }
788
0
789
0
  JSAutoRealm ar(aCx, global);
790
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
791
0
  if (!canonicalProto) {
792
0
    return false;
793
0
  }
794
0
  JS::Rooted<JSObject*> proto(aCx);
795
0
  if (aGivenProto) {
796
0
    proto = aGivenProto;
797
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
798
0
    // coming in, we changed compartments to that of "parent" so may need
799
0
    // to wrap the proto here.
800
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
801
0
      if (!JS_WrapObject(aCx, &proto)) {
802
0
        return false;
803
0
      }
804
0
    }
805
0
  } else {
806
0
    proto = canonicalProto;
807
0
  }
808
0
809
0
  BindingJSObjectCreator<mozilla::dom::PaymentAddress> creator(aCx);
810
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
811
0
  if (!aReflector) {
812
0
    return false;
813
0
  }
814
0
815
0
  aCache->SetWrapper(aReflector);
816
0
  creator.InitializationSucceeded();
817
0
818
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
819
0
             aCache->GetWrapperPreserveColor() == aReflector);
820
0
  // If proto != canonicalProto, we have to preserve our wrapper;
821
0
  // otherwise we won't be able to properly recreate it later, since
822
0
  // we won't know what proto to use.  Note that we don't check
823
0
  // aGivenProto here, since it's entirely possible (and even
824
0
  // somewhat common) to have a non-null aGivenProto which is the
825
0
  // same as canonicalProto.
826
0
  if (proto != canonicalProto) {
827
0
    PreserveWrapper(aObject);
828
0
  }
829
0
830
0
  return true;
831
0
}
832
833
// This may allocate too many slots, because we only really need
834
// slots for our non-interface-typed members that we cache.  But
835
// allocating slots only for those would make the slot index
836
// computations much more complicated, so let's do this the simple
837
// way for now.
838
DEFINE_XRAY_EXPANDO_CLASS(static, sXrayExpandoObjectClass, 1);
839
840
const NativePropertyHooks sNativePropertyHooks[] = { {
841
  nullptr,
842
  nullptr,
843
  nullptr,
844
  { sNativeProperties.Upcast(), nullptr },
845
  prototypes::id::PaymentAddress,
846
  constructors::id::PaymentAddress,
847
  nullptr,
848
  &sXrayExpandoObjectClass
849
} };
850
851
void
852
ClearCachedAddressLineValue(mozilla::dom::PaymentAddress* aObject)
853
0
{
854
0
  JSObject* obj;
855
0
  obj = aObject->GetWrapper();
856
0
  if (!obj) {
857
0
    return;
858
0
  }
859
0
  js::SetReservedSlot(obj, (DOM_INSTANCE_RESERVED_SLOTS + 0), JS::UndefinedValue());
860
0
  xpc::ClearXrayExpandoSlots(obj, (xpc::JSSLOT_EXPANDO_COUNT + 0));
861
0
}
862
863
void
864
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
865
0
{
866
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
867
0
  if (!parentProto) {
868
0
    return;
869
0
  }
870
0
871
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
872
0
  if (!constructorProto) {
873
0
    return;
874
0
  }
875
0
876
0
  static bool sIdsInited = false;
877
0
  if (!sIdsInited && NS_IsMainThread()) {
878
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
879
0
      return;
880
0
    }
881
0
    sIdsInited = true;
882
0
  }
883
0
884
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PaymentAddress);
885
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PaymentAddress);
886
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
887
0
                              &sPrototypeClass.mBase, protoCache,
888
0
                              nullptr,
889
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
890
0
                              interfaceCache,
891
0
                              sNativeProperties.Upcast(),
892
0
                              nullptr,
893
0
                              "PaymentAddress", aDefineOnGlobal,
894
0
                              nullptr,
895
0
                              false);
896
0
}
897
898
JSObject*
899
GetConstructorObject(JSContext* aCx)
900
0
{
901
0
  return GetConstructorObjectHandle(aCx);
902
0
}
903
904
} // namespace PaymentAddress_Binding
905
906
907
908
} // namespace dom
909
} // namespace mozilla