Coverage Report

Created: 2018-09-25 14:53

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