Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/CacheBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Cache.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "CacheBinding.h"
5
#include "RequestBinding.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/DOMPrefs.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/Promise.h"
14
#include "mozilla/dom/Response.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/SimpleGlobalObject.h"
17
#include "mozilla/dom/ToJSValue.h"
18
#include "mozilla/dom/UnionConversions.h"
19
#include "mozilla/dom/XrayExpandoClass.h"
20
#include "mozilla/dom/cache/Cache.h"
21
#include "nsContentUtils.h"
22
23
namespace mozilla {
24
namespace dom {
25
26
namespace binding_detail {}; // Just to make sure it's known as a namespace
27
using namespace mozilla::dom::binding_detail;
28
29
30
31
CacheQueryOptions::CacheQueryOptions()
32
0
{
33
0
  // Safe to pass a null context if we pass a null value
34
0
  Init(nullptr, JS::NullHandleValue);
35
0
}
36
37
38
39
bool
40
CacheQueryOptions::InitIds(JSContext* cx, CacheQueryOptionsAtoms* atomsCache)
41
0
{
42
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
43
0
44
0
  // Initialize these in reverse order so that any failure leaves the first one
45
0
  // uninitialized.
46
0
  if (!atomsCache->ignoreVary_id.init(cx, "ignoreVary") ||
47
0
      !atomsCache->ignoreSearch_id.init(cx, "ignoreSearch") ||
48
0
      !atomsCache->ignoreMethod_id.init(cx, "ignoreMethod") ||
49
0
      !atomsCache->cacheName_id.init(cx, "cacheName")) {
50
0
    return false;
51
0
  }
52
0
  return true;
53
0
}
54
55
bool
56
CacheQueryOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
57
0
{
58
0
  // Passing a null JSContext is OK only if we're initing from null,
59
0
  // Since in that case we will not have to do any property gets
60
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
61
0
  // checkers by static analysis tools
62
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
63
0
  CacheQueryOptionsAtoms* atomsCache = nullptr;
64
0
  if (cx) {
65
0
    atomsCache = GetAtomCache<CacheQueryOptionsAtoms>(cx);
66
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
67
0
      return false;
68
0
    }
69
0
  }
70
0
71
0
  if (!IsConvertibleToDictionary(val)) {
72
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
73
0
  }
74
0
75
0
  bool isNull = val.isNullOrUndefined();
76
0
  // We only need these if !isNull, in which case we have |cx|.
77
0
  Maybe<JS::Rooted<JSObject *> > object;
78
0
  Maybe<JS::Rooted<JS::Value> > temp;
79
0
  if (!isNull) {
80
0
    MOZ_ASSERT(cx);
81
0
    object.emplace(cx, &val.toObject());
82
0
    temp.emplace(cx);
83
0
  }
84
0
  if (!isNull) {
85
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->cacheName_id, temp.ptr())) {
86
0
      return false;
87
0
    }
88
0
  }
89
0
  if (!isNull && !temp->isUndefined()) {
90
0
    mCacheName.Construct();
91
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mCacheName.Value()))) {
92
0
      return false;
93
0
    }
94
0
    mIsAnyMemberPresent = true;
95
0
  }
96
0
97
0
  if (!isNull) {
98
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->ignoreMethod_id, temp.ptr())) {
99
0
      return false;
100
0
    }
101
0
  }
102
0
  if (!isNull && !temp->isUndefined()) {
103
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIgnoreMethod)) {
104
0
      return false;
105
0
    }
106
0
  } else {
107
0
    mIgnoreMethod = false;
108
0
  }
109
0
  mIsAnyMemberPresent = true;
110
0
111
0
  if (!isNull) {
112
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->ignoreSearch_id, temp.ptr())) {
113
0
      return false;
114
0
    }
115
0
  }
116
0
  if (!isNull && !temp->isUndefined()) {
117
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIgnoreSearch)) {
118
0
      return false;
119
0
    }
120
0
  } else {
121
0
    mIgnoreSearch = false;
122
0
  }
123
0
  mIsAnyMemberPresent = true;
124
0
125
0
  if (!isNull) {
126
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->ignoreVary_id, temp.ptr())) {
127
0
      return false;
128
0
    }
129
0
  }
130
0
  if (!isNull && !temp->isUndefined()) {
131
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIgnoreVary)) {
132
0
      return false;
133
0
    }
134
0
  } else {
135
0
    mIgnoreVary = false;
136
0
  }
137
0
  mIsAnyMemberPresent = true;
138
0
  return true;
139
0
}
140
141
bool
142
CacheQueryOptions::Init(const nsAString& aJSON)
143
0
{
144
0
  AutoJSAPI jsapi;
145
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
146
0
  if (!cleanGlobal) {
147
0
    return false;
148
0
  }
149
0
  if (!jsapi.Init(cleanGlobal)) {
150
0
    return false;
151
0
  }
152
0
  JSContext* cx = jsapi.cx();
153
0
  JS::Rooted<JS::Value> json(cx);
154
0
  bool ok = ParseJSON(cx, aJSON, &json);
155
0
  NS_ENSURE_TRUE(ok, false);
156
0
  return Init(cx, json);
157
0
}
158
159
bool
160
CacheQueryOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
161
0
{
162
0
  CacheQueryOptionsAtoms* atomsCache = GetAtomCache<CacheQueryOptionsAtoms>(cx);
163
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
164
0
    return false;
165
0
  }
166
0
167
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
168
0
  if (!obj) {
169
0
    return false;
170
0
  }
171
0
  rval.set(JS::ObjectValue(*obj));
172
0
173
0
  if (mCacheName.WasPassed()) {
174
0
    do {
175
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
176
0
      JS::Rooted<JS::Value> temp(cx);
177
0
      nsString const & currentValue = mCacheName.InternalValue();
178
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
179
0
        return false;
180
0
      }
181
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->cacheName_id, temp, JSPROP_ENUMERATE)) {
182
0
        return false;
183
0
      }
184
0
      break;
185
0
    } while(false);
186
0
  }
187
0
188
0
  do {
189
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
190
0
    JS::Rooted<JS::Value> temp(cx);
191
0
    bool const & currentValue = mIgnoreMethod;
192
0
    temp.setBoolean(currentValue);
193
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->ignoreMethod_id, temp, JSPROP_ENUMERATE)) {
194
0
      return false;
195
0
    }
196
0
    break;
197
0
  } while(false);
198
0
199
0
  do {
200
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
201
0
    JS::Rooted<JS::Value> temp(cx);
202
0
    bool const & currentValue = mIgnoreSearch;
203
0
    temp.setBoolean(currentValue);
204
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->ignoreSearch_id, temp, JSPROP_ENUMERATE)) {
205
0
      return false;
206
0
    }
207
0
    break;
208
0
  } while(false);
209
0
210
0
  do {
211
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
212
0
    JS::Rooted<JS::Value> temp(cx);
213
0
    bool const & currentValue = mIgnoreVary;
214
0
    temp.setBoolean(currentValue);
215
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->ignoreVary_id, temp, JSPROP_ENUMERATE)) {
216
0
      return false;
217
0
    }
218
0
    break;
219
0
  } while(false);
220
0
221
0
  return true;
222
0
}
223
224
bool
225
CacheQueryOptions::ToJSON(nsAString& aJSON) const
226
0
{
227
0
  AutoJSAPI jsapi;
228
0
  jsapi.Init();
229
0
  JSContext *cx = jsapi.cx();
230
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
231
0
  // because we'll only be creating objects, in ways that have no
232
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
233
0
  // which likewise guarantees no side-effects for the sorts of
234
0
  // things we will pass it.
235
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
236
0
  JS::Rooted<JS::Value> val(cx);
237
0
  if (!ToObjectInternal(cx, &val)) {
238
0
    return false;
239
0
  }
240
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
241
0
  return StringifyToJSON(cx, obj, aJSON);
242
0
}
243
244
void
245
CacheQueryOptions::TraceDictionary(JSTracer* trc)
246
0
{
247
0
}
248
249
CacheQueryOptions&
250
CacheQueryOptions::operator=(const CacheQueryOptions& aOther)
251
0
{
252
0
  DictionaryBase::operator=(aOther);
253
0
  mCacheName.Reset();
254
0
  if (aOther.mCacheName.WasPassed()) {
255
0
    mCacheName.Construct(aOther.mCacheName.Value());
256
0
  }
257
0
  mIgnoreMethod = aOther.mIgnoreMethod;
258
0
  mIgnoreSearch = aOther.mIgnoreSearch;
259
0
  mIgnoreVary = aOther.mIgnoreVary;
260
0
  return *this;
261
0
}
262
263
namespace binding_detail {
264
} // namespace binding_detail
265
266
267
268
CacheBatchOperation::CacheBatchOperation()
269
  : mOptions(FastDictionaryInitializer())
270
0
{
271
0
  // Safe to pass a null context if we pass a null value
272
0
  Init(nullptr, JS::NullHandleValue);
273
0
}
274
275
276
277
bool
278
CacheBatchOperation::InitIds(JSContext* cx, CacheBatchOperationAtoms* atomsCache)
279
0
{
280
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
281
0
282
0
  // Initialize these in reverse order so that any failure leaves the first one
283
0
  // uninitialized.
284
0
  if (!atomsCache->type_id.init(cx, "type") ||
285
0
      !atomsCache->response_id.init(cx, "response") ||
286
0
      !atomsCache->request_id.init(cx, "request") ||
287
0
      !atomsCache->options_id.init(cx, "options")) {
288
0
    return false;
289
0
  }
290
0
  return true;
291
0
}
292
293
bool
294
CacheBatchOperation::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
295
0
{
296
0
  // Passing a null JSContext is OK only if we're initing from null,
297
0
  // Since in that case we will not have to do any property gets
298
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
299
0
  // checkers by static analysis tools
300
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
301
0
  CacheBatchOperationAtoms* atomsCache = nullptr;
302
0
  if (cx) {
303
0
    atomsCache = GetAtomCache<CacheBatchOperationAtoms>(cx);
304
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
305
0
      return false;
306
0
    }
307
0
  }
308
0
309
0
  if (!IsConvertibleToDictionary(val)) {
310
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
311
0
  }
312
0
313
0
  bool isNull = val.isNullOrUndefined();
314
0
  // We only need these if !isNull, in which case we have |cx|.
315
0
  Maybe<JS::Rooted<JSObject *> > object;
316
0
  Maybe<JS::Rooted<JS::Value> > temp;
317
0
  if (!isNull) {
318
0
    MOZ_ASSERT(cx);
319
0
    object.emplace(cx, &val.toObject());
320
0
    temp.emplace(cx);
321
0
  }
322
0
  if (!isNull) {
323
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->options_id, temp.ptr())) {
324
0
      return false;
325
0
    }
326
0
  }
327
0
  if (!mOptions.Init(cx, (!isNull && !temp->isUndefined()) ? temp.ref() : JS::NullHandleValue,  "'options' member of CacheBatchOperation", passedToJSImpl)) {
328
0
    return false;
329
0
  }
330
0
  mIsAnyMemberPresent = true;
331
0
332
0
  if (!isNull) {
333
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->request_id, temp.ptr())) {
334
0
      return false;
335
0
    }
336
0
  }
337
0
  if (!isNull && !temp->isUndefined()) {
338
0
    mRequest.Construct();
339
0
    if (temp.ref().isObject()) {
340
0
      static_assert(IsRefcounted<mozilla::dom::Request>::value, "We can only store refcounted classes.");{
341
0
        nsresult rv = UnwrapObject<prototypes::id::Request, mozilla::dom::Request>(temp.ptr(), (mRequest.Value()));
342
0
        if (NS_FAILED(rv)) {
343
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'request' member of CacheBatchOperation", "Request");
344
0
          return false;
345
0
        }
346
0
      }
347
0
    } else {
348
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'request' member of CacheBatchOperation");
349
0
      return false;
350
0
    }
351
0
    mIsAnyMemberPresent = true;
352
0
  }
353
0
354
0
  if (!isNull) {
355
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->response_id, temp.ptr())) {
356
0
      return false;
357
0
    }
358
0
  }
359
0
  if (!isNull && !temp->isUndefined()) {
360
0
    mResponse.Construct();
361
0
    if (temp.ref().isObject()) {
362
0
      static_assert(IsRefcounted<mozilla::dom::Response>::value, "We can only store refcounted classes.");{
363
0
        nsresult rv = UnwrapObject<prototypes::id::Response, mozilla::dom::Response>(temp.ptr(), (mResponse.Value()));
364
0
        if (NS_FAILED(rv)) {
365
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'response' member of CacheBatchOperation", "Response");
366
0
          return false;
367
0
        }
368
0
      }
369
0
    } else {
370
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'response' member of CacheBatchOperation");
371
0
      return false;
372
0
    }
373
0
    mIsAnyMemberPresent = true;
374
0
  }
375
0
376
0
  if (!isNull) {
377
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
378
0
      return false;
379
0
    }
380
0
  }
381
0
  if (!isNull && !temp->isUndefined()) {
382
0
    mType.Construct();
383
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mType.Value()))) {
384
0
      return false;
385
0
    }
386
0
    mIsAnyMemberPresent = true;
387
0
  }
388
0
  return true;
389
0
}
390
391
bool
392
CacheBatchOperation::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
393
0
{
394
0
  CacheBatchOperationAtoms* atomsCache = GetAtomCache<CacheBatchOperationAtoms>(cx);
395
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
396
0
    return false;
397
0
  }
398
0
399
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
400
0
  if (!obj) {
401
0
    return false;
402
0
  }
403
0
  rval.set(JS::ObjectValue(*obj));
404
0
405
0
  do {
406
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
407
0
    JS::Rooted<JS::Value> temp(cx);
408
0
    CacheQueryOptions const & currentValue = mOptions;
409
0
    if (!currentValue.ToObjectInternal(cx, &temp)) {
410
0
      return false;
411
0
    }
412
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->options_id, temp, JSPROP_ENUMERATE)) {
413
0
      return false;
414
0
    }
415
0
    break;
416
0
  } while(false);
417
0
418
0
  if (mRequest.WasPassed()) {
419
0
    do {
420
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
421
0
      JS::Rooted<JS::Value> temp(cx);
422
0
      OwningNonNull<mozilla::dom::Request> const & currentValue = mRequest.InternalValue();
423
0
      if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
424
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
425
0
        return false;
426
0
      }
427
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->request_id, temp, JSPROP_ENUMERATE)) {
428
0
        return false;
429
0
      }
430
0
      break;
431
0
    } while(false);
432
0
  }
433
0
434
0
  if (mResponse.WasPassed()) {
435
0
    do {
436
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
437
0
      JS::Rooted<JS::Value> temp(cx);
438
0
      OwningNonNull<mozilla::dom::Response> const & currentValue = mResponse.InternalValue();
439
0
      if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
440
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
441
0
        return false;
442
0
      }
443
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->response_id, temp, JSPROP_ENUMERATE)) {
444
0
        return false;
445
0
      }
446
0
      break;
447
0
    } while(false);
448
0
  }
449
0
450
0
  if (mType.WasPassed()) {
451
0
    do {
452
0
      // block for our 'break' successCode and scope for 'temp' and 'currentValue'
453
0
      JS::Rooted<JS::Value> temp(cx);
454
0
      nsString const & currentValue = mType.InternalValue();
455
0
      if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
456
0
        return false;
457
0
      }
458
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
459
0
        return false;
460
0
      }
461
0
      break;
462
0
    } while(false);
463
0
  }
464
0
465
0
  return true;
466
0
}
467
468
void
469
CacheBatchOperation::TraceDictionary(JSTracer* trc)
470
0
{
471
0
}
472
473
474
475
CacheBatchOperation&
476
CacheBatchOperation::operator=(const CacheBatchOperation& aOther)
477
0
{
478
0
  DictionaryBase::operator=(aOther);
479
0
  mOptions = aOther.mOptions;
480
0
  mRequest.Reset();
481
0
  if (aOther.mRequest.WasPassed()) {
482
0
    mRequest.Construct(aOther.mRequest.Value());
483
0
  }
484
0
  mResponse.Reset();
485
0
  if (aOther.mResponse.WasPassed()) {
486
0
    mResponse.Construct(aOther.mResponse.Value());
487
0
  }
488
0
  mType.Reset();
489
0
  if (aOther.mType.WasPassed()) {
490
0
    mType.Construct(aOther.mType.Value());
491
0
  }
492
0
  return *this;
493
0
}
494
495
namespace binding_detail {
496
} // namespace binding_detail
497
498
499
namespace Cache_Binding {
500
501
MOZ_CAN_RUN_SCRIPT static bool
502
match(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
503
0
{
504
0
  AUTO_PROFILER_LABEL_FAST("Cache.match", DOM, cx);
505
0
506
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
507
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Cache.match");
508
0
  }
509
0
  RequestOrUSVString arg0;
510
0
  RequestOrUSVStringArgument arg0_holder(arg0);
511
0
  {
512
0
    bool done = false, failed = false, tryNext;
513
0
    if (args[0].isObject()) {
514
0
      done = (failed = !arg0_holder.TrySetToRequest(cx, args[0], tryNext, false)) || !tryNext;
515
0
516
0
    }
517
0
    if (!done) {
518
0
      do {
519
0
        done = (failed = !arg0_holder.TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
520
0
        break;
521
0
      } while (false);
522
0
    }
523
0
    if (failed) {
524
0
      return false;
525
0
    }
526
0
    if (!done) {
527
0
      ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Cache.match", "Request");
528
0
      return false;
529
0
    }
530
0
  }
531
0
  binding_detail::FastCacheQueryOptions arg1;
532
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of Cache.match", false)) {
533
0
    return false;
534
0
  }
535
0
  FastErrorResult rv;
536
0
  auto result(StrongOrRawPtr<Promise>(self->Match(cx, Constify(arg0), Constify(arg1), rv)));
537
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
538
0
    return false;
539
0
  }
540
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
541
0
  static_assert(!IsPointer<decltype(result)>::value,
542
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
543
0
  if (!ToJSValue(cx, result, args.rval())) {
544
0
    return false;
545
0
  }
546
0
  return true;
547
0
}
548
549
MOZ_CAN_RUN_SCRIPT static bool
550
match_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
551
0
{
552
0
  bool ok = match(cx, obj, self, args);
553
0
  if (ok) {
554
0
    return true;
555
0
  }
556
0
  return ConvertExceptionToPromise(cx, args.rval());
557
0
}
558
559
static const JSJitInfo match_methodinfo = {
560
  { (JSJitGetterOp)match_promiseWrapper },
561
  { prototypes::id::Cache },
562
  { PrototypeTraits<prototypes::id::Cache>::Depth },
563
  JSJitInfo::Method,
564
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
565
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
566
  false,  /* isInfallible. False in setters. */
567
  false,  /* isMovable.  Not relevant for setters. */
568
  false, /* isEliminatable.  Not relevant for setters. */
569
  false, /* isAlwaysInSlot.  Only relevant for getters. */
570
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
571
  false,  /* isTypedMethod.  Only relevant for methods. */
572
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
573
};
574
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
575
static_assert(0 < 1, "There is no slot for us");
576
577
MOZ_CAN_RUN_SCRIPT static bool
578
matchAll(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
579
0
{
580
0
  AUTO_PROFILER_LABEL_FAST("Cache.matchAll", DOM, cx);
581
0
582
0
  Optional<RequestOrUSVString> arg0;
583
0
  Maybe<RequestOrUSVStringArgument> arg0_holder;
584
0
  if (args.hasDefined(0)) {
585
0
    arg0.Construct();
586
0
    arg0_holder.emplace(arg0.Value());
587
0
    {
588
0
      bool done = false, failed = false, tryNext;
589
0
      if (args[0].isObject()) {
590
0
        done = (failed = !arg0_holder.ref().TrySetToRequest(cx, args[0], tryNext, false)) || !tryNext;
591
0
592
0
      }
593
0
      if (!done) {
594
0
        do {
595
0
          done = (failed = !arg0_holder.ref().TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
596
0
          break;
597
0
        } while (false);
598
0
      }
599
0
      if (failed) {
600
0
        return false;
601
0
      }
602
0
      if (!done) {
603
0
        ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Cache.matchAll", "Request");
604
0
        return false;
605
0
      }
606
0
    }
607
0
  }
608
0
  binding_detail::FastCacheQueryOptions arg1;
609
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of Cache.matchAll", false)) {
610
0
    return false;
611
0
  }
612
0
  FastErrorResult rv;
613
0
  auto result(StrongOrRawPtr<Promise>(self->MatchAll(cx, Constify(arg0), Constify(arg1), rv)));
614
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
615
0
    return false;
616
0
  }
617
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
618
0
  static_assert(!IsPointer<decltype(result)>::value,
619
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
620
0
  if (!ToJSValue(cx, result, args.rval())) {
621
0
    return false;
622
0
  }
623
0
  return true;
624
0
}
625
626
MOZ_CAN_RUN_SCRIPT static bool
627
matchAll_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
628
0
{
629
0
  bool ok = matchAll(cx, obj, self, args);
630
0
  if (ok) {
631
0
    return true;
632
0
  }
633
0
  return ConvertExceptionToPromise(cx, args.rval());
634
0
}
635
636
static const JSJitInfo matchAll_methodinfo = {
637
  { (JSJitGetterOp)matchAll_promiseWrapper },
638
  { prototypes::id::Cache },
639
  { PrototypeTraits<prototypes::id::Cache>::Depth },
640
  JSJitInfo::Method,
641
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
642
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
643
  false,  /* isInfallible. False in setters. */
644
  false,  /* isMovable.  Not relevant for setters. */
645
  false, /* isEliminatable.  Not relevant for setters. */
646
  false, /* isAlwaysInSlot.  Only relevant for getters. */
647
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
648
  false,  /* isTypedMethod.  Only relevant for methods. */
649
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
650
};
651
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
652
static_assert(0 < 1, "There is no slot for us");
653
654
MOZ_CAN_RUN_SCRIPT static bool
655
add(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
656
0
{
657
0
  AUTO_PROFILER_LABEL_FAST("Cache.add", DOM, cx);
658
0
659
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
660
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Cache.add");
661
0
  }
662
0
  RequestOrUSVString arg0;
663
0
  RequestOrUSVStringArgument arg0_holder(arg0);
664
0
  {
665
0
    bool done = false, failed = false, tryNext;
666
0
    if (args[0].isObject()) {
667
0
      done = (failed = !arg0_holder.TrySetToRequest(cx, args[0], tryNext, false)) || !tryNext;
668
0
669
0
    }
670
0
    if (!done) {
671
0
      do {
672
0
        done = (failed = !arg0_holder.TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
673
0
        break;
674
0
      } while (false);
675
0
    }
676
0
    if (failed) {
677
0
      return false;
678
0
    }
679
0
    if (!done) {
680
0
      ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Cache.add", "Request");
681
0
      return false;
682
0
    }
683
0
  }
684
0
  FastErrorResult rv;
685
0
  auto result(StrongOrRawPtr<Promise>(self->Add(cx, Constify(arg0), nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv)));
686
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
687
0
    return false;
688
0
  }
689
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
690
0
  static_assert(!IsPointer<decltype(result)>::value,
691
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
692
0
  if (!ToJSValue(cx, result, args.rval())) {
693
0
    return false;
694
0
  }
695
0
  return true;
696
0
}
697
698
MOZ_CAN_RUN_SCRIPT static bool
699
add_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
700
0
{
701
0
  bool ok = add(cx, obj, self, args);
702
0
  if (ok) {
703
0
    return true;
704
0
  }
705
0
  return ConvertExceptionToPromise(cx, args.rval());
706
0
}
707
708
static const JSJitInfo add_methodinfo = {
709
  { (JSJitGetterOp)add_promiseWrapper },
710
  { prototypes::id::Cache },
711
  { PrototypeTraits<prototypes::id::Cache>::Depth },
712
  JSJitInfo::Method,
713
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
714
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
715
  false,  /* isInfallible. False in setters. */
716
  false,  /* isMovable.  Not relevant for setters. */
717
  false, /* isEliminatable.  Not relevant for setters. */
718
  false, /* isAlwaysInSlot.  Only relevant for getters. */
719
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
720
  false,  /* isTypedMethod.  Only relevant for methods. */
721
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
722
};
723
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
724
static_assert(0 < 1, "There is no slot for us");
725
726
MOZ_CAN_RUN_SCRIPT static bool
727
addAll(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
728
0
{
729
0
  AUTO_PROFILER_LABEL_FAST("Cache.addAll", DOM, cx);
730
0
731
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
732
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Cache.addAll");
733
0
  }
734
0
  binding_detail::AutoSequence<OwningRequestOrUSVString> arg0;
735
0
  if (args[0].isObject()) {
736
0
    JS::ForOfIterator iter(cx);
737
0
    if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
738
0
      return false;
739
0
    }
740
0
    if (!iter.valueIsIterable()) {
741
0
      ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of Cache.addAll");
742
0
      return false;
743
0
    }
744
0
    binding_detail::AutoSequence<OwningRequestOrUSVString> &arr = arg0;
745
0
    JS::Rooted<JS::Value> temp(cx);
746
0
    while (true) {
747
0
      bool done;
748
0
      if (!iter.next(&temp, &done)) {
749
0
        return false;
750
0
      }
751
0
      if (done) {
752
0
        break;
753
0
      }
754
0
      OwningRequestOrUSVString* slotPtr = arr.AppendElement(mozilla::fallible);
755
0
      if (!slotPtr) {
756
0
        JS_ReportOutOfMemory(cx);
757
0
        return false;
758
0
      }
759
0
      OwningRequestOrUSVString& slot = *slotPtr;
760
0
      {
761
0
        bool done = false, failed = false, tryNext;
762
0
        if (temp.isObject()) {
763
0
          done = (failed = !slot.TrySetToRequest(cx, temp, tryNext, false)) || !tryNext;
764
0
765
0
        }
766
0
        if (!done) {
767
0
          do {
768
0
            done = (failed = !slot.TrySetToUSVString(cx, temp, tryNext)) || !tryNext;
769
0
            break;
770
0
          } while (false);
771
0
        }
772
0
        if (failed) {
773
0
          return false;
774
0
        }
775
0
        if (!done) {
776
0
          ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Element of argument 1 of Cache.addAll", "Request");
777
0
          return false;
778
0
        }
779
0
      }
780
0
    }
781
0
  } else {
782
0
    ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of Cache.addAll");
783
0
    return false;
784
0
  }
785
0
  FastErrorResult rv;
786
0
  auto result(StrongOrRawPtr<Promise>(self->AddAll(cx, Constify(arg0), nsContentUtils::ThreadsafeIsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv)));
787
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
788
0
    return false;
789
0
  }
790
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
791
0
  static_assert(!IsPointer<decltype(result)>::value,
792
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
793
0
  if (!ToJSValue(cx, result, args.rval())) {
794
0
    return false;
795
0
  }
796
0
  return true;
797
0
}
798
799
MOZ_CAN_RUN_SCRIPT static bool
800
addAll_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
801
0
{
802
0
  bool ok = addAll(cx, obj, self, args);
803
0
  if (ok) {
804
0
    return true;
805
0
  }
806
0
  return ConvertExceptionToPromise(cx, args.rval());
807
0
}
808
809
static const JSJitInfo addAll_methodinfo = {
810
  { (JSJitGetterOp)addAll_promiseWrapper },
811
  { prototypes::id::Cache },
812
  { PrototypeTraits<prototypes::id::Cache>::Depth },
813
  JSJitInfo::Method,
814
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
815
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
816
  false,  /* isInfallible. False in setters. */
817
  false,  /* isMovable.  Not relevant for setters. */
818
  false, /* isEliminatable.  Not relevant for setters. */
819
  false, /* isAlwaysInSlot.  Only relevant for getters. */
820
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
821
  false,  /* isTypedMethod.  Only relevant for methods. */
822
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
823
};
824
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
825
static_assert(0 < 1, "There is no slot for us");
826
827
MOZ_CAN_RUN_SCRIPT static bool
828
put(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
829
0
{
830
0
  AUTO_PROFILER_LABEL_FAST("Cache.put", DOM, cx);
831
0
832
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
833
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Cache.put");
834
0
  }
835
0
  RequestOrUSVString arg0;
836
0
  RequestOrUSVStringArgument arg0_holder(arg0);
837
0
  {
838
0
    bool done = false, failed = false, tryNext;
839
0
    if (args[0].isObject()) {
840
0
      done = (failed = !arg0_holder.TrySetToRequest(cx, args[0], tryNext, false)) || !tryNext;
841
0
842
0
    }
843
0
    if (!done) {
844
0
      do {
845
0
        done = (failed = !arg0_holder.TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
846
0
        break;
847
0
      } while (false);
848
0
    }
849
0
    if (failed) {
850
0
      return false;
851
0
    }
852
0
    if (!done) {
853
0
      ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Cache.put", "Request");
854
0
      return false;
855
0
    }
856
0
  }
857
0
  NonNull<mozilla::dom::Response> arg1;
858
0
  if (args[1].isObject()) {
859
0
    {
860
0
      nsresult rv = UnwrapObject<prototypes::id::Response, mozilla::dom::Response>(args[1], arg1);
861
0
      if (NS_FAILED(rv)) {
862
0
        ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of Cache.put", "Response");
863
0
        return false;
864
0
      }
865
0
    }
866
0
  } else {
867
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of Cache.put");
868
0
    return false;
869
0
  }
870
0
  FastErrorResult rv;
871
0
  auto result(StrongOrRawPtr<Promise>(self->Put(cx, Constify(arg0), MOZ_KnownLive(NonNullHelper(arg1)), rv)));
872
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
873
0
    return false;
874
0
  }
875
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
876
0
  static_assert(!IsPointer<decltype(result)>::value,
877
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
878
0
  if (!ToJSValue(cx, result, args.rval())) {
879
0
    return false;
880
0
  }
881
0
  return true;
882
0
}
883
884
MOZ_CAN_RUN_SCRIPT static bool
885
put_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
886
0
{
887
0
  bool ok = put(cx, obj, self, args);
888
0
  if (ok) {
889
0
    return true;
890
0
  }
891
0
  return ConvertExceptionToPromise(cx, args.rval());
892
0
}
893
894
static const JSJitInfo put_methodinfo = {
895
  { (JSJitGetterOp)put_promiseWrapper },
896
  { prototypes::id::Cache },
897
  { PrototypeTraits<prototypes::id::Cache>::Depth },
898
  JSJitInfo::Method,
899
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
900
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
901
  false,  /* isInfallible. False in setters. */
902
  false,  /* isMovable.  Not relevant for setters. */
903
  false, /* isEliminatable.  Not relevant for setters. */
904
  false, /* isAlwaysInSlot.  Only relevant for getters. */
905
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
906
  false,  /* isTypedMethod.  Only relevant for methods. */
907
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
908
};
909
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
910
static_assert(0 < 1, "There is no slot for us");
911
912
MOZ_CAN_RUN_SCRIPT static bool
913
_delete_(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
914
0
{
915
0
  AUTO_PROFILER_LABEL_FAST("Cache.delete", DOM, cx);
916
0
917
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
918
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Cache.delete");
919
0
  }
920
0
  RequestOrUSVString arg0;
921
0
  RequestOrUSVStringArgument arg0_holder(arg0);
922
0
  {
923
0
    bool done = false, failed = false, tryNext;
924
0
    if (args[0].isObject()) {
925
0
      done = (failed = !arg0_holder.TrySetToRequest(cx, args[0], tryNext, false)) || !tryNext;
926
0
927
0
    }
928
0
    if (!done) {
929
0
      do {
930
0
        done = (failed = !arg0_holder.TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
931
0
        break;
932
0
      } while (false);
933
0
    }
934
0
    if (failed) {
935
0
      return false;
936
0
    }
937
0
    if (!done) {
938
0
      ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Cache.delete", "Request");
939
0
      return false;
940
0
    }
941
0
  }
942
0
  binding_detail::FastCacheQueryOptions arg1;
943
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of Cache.delete", false)) {
944
0
    return false;
945
0
  }
946
0
  FastErrorResult rv;
947
0
  auto result(StrongOrRawPtr<Promise>(self->Delete(cx, Constify(arg0), Constify(arg1), rv)));
948
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
949
0
    return false;
950
0
  }
951
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
952
0
  static_assert(!IsPointer<decltype(result)>::value,
953
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
954
0
  if (!ToJSValue(cx, result, args.rval())) {
955
0
    return false;
956
0
  }
957
0
  return true;
958
0
}
959
960
MOZ_CAN_RUN_SCRIPT static bool
961
_delete__promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
962
0
{
963
0
  bool ok = _delete_(cx, obj, self, args);
964
0
  if (ok) {
965
0
    return true;
966
0
  }
967
0
  return ConvertExceptionToPromise(cx, args.rval());
968
0
}
969
970
static const JSJitInfo delete_methodinfo = {
971
  { (JSJitGetterOp)_delete__promiseWrapper },
972
  { prototypes::id::Cache },
973
  { PrototypeTraits<prototypes::id::Cache>::Depth },
974
  JSJitInfo::Method,
975
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
976
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
977
  false,  /* isInfallible. False in setters. */
978
  false,  /* isMovable.  Not relevant for setters. */
979
  false, /* isEliminatable.  Not relevant for setters. */
980
  false, /* isAlwaysInSlot.  Only relevant for getters. */
981
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
982
  false,  /* isTypedMethod.  Only relevant for methods. */
983
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
984
};
985
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
986
static_assert(0 < 1, "There is no slot for us");
987
988
MOZ_CAN_RUN_SCRIPT static bool
989
keys(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
990
0
{
991
0
  AUTO_PROFILER_LABEL_FAST("Cache.keys", DOM, cx);
992
0
993
0
  Optional<RequestOrUSVString> arg0;
994
0
  Maybe<RequestOrUSVStringArgument> arg0_holder;
995
0
  if (args.hasDefined(0)) {
996
0
    arg0.Construct();
997
0
    arg0_holder.emplace(arg0.Value());
998
0
    {
999
0
      bool done = false, failed = false, tryNext;
1000
0
      if (args[0].isObject()) {
1001
0
        done = (failed = !arg0_holder.ref().TrySetToRequest(cx, args[0], tryNext, false)) || !tryNext;
1002
0
1003
0
      }
1004
0
      if (!done) {
1005
0
        do {
1006
0
          done = (failed = !arg0_holder.ref().TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
1007
0
          break;
1008
0
        } while (false);
1009
0
      }
1010
0
      if (failed) {
1011
0
        return false;
1012
0
      }
1013
0
      if (!done) {
1014
0
        ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Cache.keys", "Request");
1015
0
        return false;
1016
0
      }
1017
0
    }
1018
0
  }
1019
0
  binding_detail::FastCacheQueryOptions arg1;
1020
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of Cache.keys", false)) {
1021
0
    return false;
1022
0
  }
1023
0
  FastErrorResult rv;
1024
0
  auto result(StrongOrRawPtr<Promise>(self->Keys(cx, Constify(arg0), Constify(arg1), rv)));
1025
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1026
0
    return false;
1027
0
  }
1028
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
1029
0
  static_assert(!IsPointer<decltype(result)>::value,
1030
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
1031
0
  if (!ToJSValue(cx, result, args.rval())) {
1032
0
    return false;
1033
0
  }
1034
0
  return true;
1035
0
}
1036
1037
MOZ_CAN_RUN_SCRIPT static bool
1038
keys_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::cache::Cache* self, const JSJitMethodCallArgs& args)
1039
0
{
1040
0
  bool ok = keys(cx, obj, self, args);
1041
0
  if (ok) {
1042
0
    return true;
1043
0
  }
1044
0
  return ConvertExceptionToPromise(cx, args.rval());
1045
0
}
1046
1047
static const JSJitInfo keys_methodinfo = {
1048
  { (JSJitGetterOp)keys_promiseWrapper },
1049
  { prototypes::id::Cache },
1050
  { PrototypeTraits<prototypes::id::Cache>::Depth },
1051
  JSJitInfo::Method,
1052
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
1053
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
1054
  false,  /* isInfallible. False in setters. */
1055
  false,  /* isMovable.  Not relevant for setters. */
1056
  false, /* isEliminatable.  Not relevant for setters. */
1057
  false, /* isAlwaysInSlot.  Only relevant for getters. */
1058
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
1059
  false,  /* isTypedMethod.  Only relevant for methods. */
1060
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
1061
};
1062
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
1063
static_assert(0 < 1, "There is no slot for us");
1064
1065
static bool
1066
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
1067
0
{
1068
0
  mozilla::dom::cache::Cache* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::cache::Cache>(obj);
1069
0
  // We don't want to preserve if we don't have a wrapper, and we
1070
0
  // obviously can't preserve if we're not initialized.
1071
0
  if (self && self->GetWrapperPreserveColor()) {
1072
0
    PreserveWrapper(self);
1073
0
  }
1074
0
  return true;
1075
0
}
1076
1077
static void
1078
_finalize(js::FreeOp* fop, JSObject* obj)
1079
0
{
1080
0
  mozilla::dom::cache::Cache* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::cache::Cache>(obj);
1081
0
  if (self) {
1082
0
    ClearWrapper(self, self, obj);
1083
0
    AddForDeferredFinalization<mozilla::dom::cache::Cache>(self);
1084
0
  }
1085
0
}
1086
1087
static size_t
1088
_objectMoved(JSObject* obj, JSObject* old)
1089
0
{
1090
0
  mozilla::dom::cache::Cache* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::cache::Cache>(obj);
1091
0
  if (self) {
1092
0
    UpdateWrapper(self, self, obj, old);
1093
0
  }
1094
0
1095
0
  return 0;
1096
0
}
1097
1098
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1099
#if defined(__clang__)
1100
#pragma clang diagnostic push
1101
#pragma clang diagnostic ignored "-Wmissing-braces"
1102
#endif
1103
static const JSFunctionSpec sMethods_specs[] = {
1104
  JS_FNSPEC("match", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&match_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1105
  JS_FNSPEC("matchAll", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&matchAll_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1106
  JS_FNSPEC("add", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&add_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1107
  JS_FNSPEC("addAll", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&addAll_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1108
  JS_FNSPEC("put", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&put_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
1109
  JS_FNSPEC("delete", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&delete_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
1110
  JS_FNSPEC("keys", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&keys_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
1111
  JS_FS_END
1112
};
1113
#if defined(__clang__)
1114
#pragma clang diagnostic pop
1115
#endif
1116
1117
1118
static const Prefable<const JSFunctionSpec> sMethods[] = {
1119
  { nullptr, &sMethods_specs[0] },
1120
  { nullptr, nullptr }
1121
};
1122
1123
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1124
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1125
static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1126
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1127
1128
1129
static uint16_t sNativeProperties_sortedPropertyIndices[7];
1130
static PropertyInfo sNativeProperties_propertyInfos[7];
1131
1132
static const NativePropertiesN<1> sNativeProperties = {
1133
  false, 0,
1134
  false, 0,
1135
  true,  0 /* sMethods */,
1136
  false, 0,
1137
  false, 0,
1138
  false, 0,
1139
  false, 0,
1140
  -1,
1141
  7,
1142
  sNativeProperties_sortedPropertyIndices,
1143
  {
1144
    { sMethods, &sNativeProperties_propertyInfos[0] }
1145
  }
1146
};
1147
static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1148
    "We have a property info count that is oversized");
1149
1150
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1151
  {
1152
    "Function",
1153
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1154
    &sBoringInterfaceObjectClassClassOps,
1155
    JS_NULL_CLASS_SPEC,
1156
    JS_NULL_CLASS_EXT,
1157
    &sInterfaceObjectClassObjectOps
1158
  },
1159
  eInterface,
1160
  true,
1161
  prototypes::id::Cache,
1162
  PrototypeTraits<prototypes::id::Cache>::Depth,
1163
  sNativePropertyHooks,
1164
  "function Cache() {\n    [native code]\n}",
1165
  JS::GetRealmFunctionPrototype
1166
};
1167
1168
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1169
  {
1170
    "CachePrototype",
1171
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1172
    JS_NULL_CLASS_OPS,
1173
    JS_NULL_CLASS_SPEC,
1174
    JS_NULL_CLASS_EXT,
1175
    JS_NULL_OBJECT_OPS
1176
  },
1177
  eInterfacePrototype,
1178
  false,
1179
  prototypes::id::Cache,
1180
  PrototypeTraits<prototypes::id::Cache>::Depth,
1181
  sNativePropertyHooks,
1182
  "[object CachePrototype]",
1183
  JS::GetRealmObjectPrototype
1184
};
1185
1186
bool
1187
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
1188
0
{
1189
0
  return mozilla::dom::DOMPrefs::dom_caches_enabled(aCx, aObj);
1190
0
}
1191
1192
static const js::ClassOps sClassOps = {
1193
  _addProperty, /* addProperty */
1194
  nullptr,               /* delProperty */
1195
  nullptr,               /* enumerate */
1196
  nullptr, /* newEnumerate */
1197
  nullptr, /* resolve */
1198
  nullptr, /* mayResolve */
1199
  _finalize, /* finalize */
1200
  nullptr, /* call */
1201
  nullptr,               /* hasInstance */
1202
  nullptr,               /* construct */
1203
  nullptr, /* trace */
1204
};
1205
1206
static const js::ClassExtension sClassExtension = {
1207
  nullptr, /* weakmapKeyDelegateOp */
1208
  _objectMoved /* objectMovedOp */
1209
};
1210
1211
static const DOMJSClass sClass = {
1212
  { "Cache",
1213
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1214
    &sClassOps,
1215
    JS_NULL_CLASS_SPEC,
1216
    &sClassExtension,
1217
    JS_NULL_OBJECT_OPS
1218
  },
1219
  { prototypes::id::Cache, 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 },
1220
  IsBaseOf<nsISupports, mozilla::dom::cache::Cache >::value,
1221
  sNativePropertyHooks,
1222
  FindAssociatedGlobalForNative<mozilla::dom::cache::Cache>::Get,
1223
  GetProtoObjectHandle,
1224
  GetCCParticipant<mozilla::dom::cache::Cache>::Get()
1225
};
1226
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1227
              "Must have the right minimal number of reserved slots.");
1228
static_assert(1 >= 1,
1229
              "Must have enough reserved slots.");
1230
1231
const JSClass*
1232
GetJSClass()
1233
0
{
1234
0
  return sClass.ToJSClass();
1235
0
}
1236
1237
bool
1238
Wrap(JSContext* aCx, mozilla::dom::cache::Cache* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1239
0
{
1240
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::cache::Cache>::value,
1241
0
                "Shouldn't have wrappercached things that are not refcounted.");
1242
0
  MOZ_ASSERT(static_cast<mozilla::dom::cache::Cache*>(aObject) ==
1243
0
             reinterpret_cast<mozilla::dom::cache::Cache*>(aObject),
1244
0
             "Multiple inheritance for mozilla::dom::cache::Cache is broken.");
1245
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1246
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1247
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1248
0
             "You should probably not be using Wrap() directly; use "
1249
0
             "GetOrCreateDOMReflector instead");
1250
0
1251
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1252
0
             "nsISupports must be on our primary inheritance chain");
1253
0
1254
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1255
0
  if (!global) {
1256
0
    return false;
1257
0
  }
1258
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1259
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1260
0
1261
0
  // That might have ended up wrapping us already, due to the wonders
1262
0
  // of XBL.  Check for that, and bail out as needed.
1263
0
  aReflector.set(aCache->GetWrapper());
1264
0
  if (aReflector) {
1265
#ifdef DEBUG
1266
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1267
#endif // DEBUG
1268
    return true;
1269
0
  }
1270
0
1271
0
  JSAutoRealm ar(aCx, global);
1272
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1273
0
  if (!canonicalProto) {
1274
0
    return false;
1275
0
  }
1276
0
  JS::Rooted<JSObject*> proto(aCx);
1277
0
  if (aGivenProto) {
1278
0
    proto = aGivenProto;
1279
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1280
0
    // coming in, we changed compartments to that of "parent" so may need
1281
0
    // to wrap the proto here.
1282
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1283
0
      if (!JS_WrapObject(aCx, &proto)) {
1284
0
        return false;
1285
0
      }
1286
0
    }
1287
0
  } else {
1288
0
    proto = canonicalProto;
1289
0
  }
1290
0
1291
0
  BindingJSObjectCreator<mozilla::dom::cache::Cache> creator(aCx);
1292
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1293
0
  if (!aReflector) {
1294
0
    return false;
1295
0
  }
1296
0
1297
0
  aCache->SetWrapper(aReflector);
1298
0
  creator.InitializationSucceeded();
1299
0
1300
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1301
0
             aCache->GetWrapperPreserveColor() == aReflector);
1302
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1303
0
  // otherwise we won't be able to properly recreate it later, since
1304
0
  // we won't know what proto to use.  Note that we don't check
1305
0
  // aGivenProto here, since it's entirely possible (and even
1306
0
  // somewhat common) to have a non-null aGivenProto which is the
1307
0
  // same as canonicalProto.
1308
0
  if (proto != canonicalProto) {
1309
0
    PreserveWrapper(aObject);
1310
0
  }
1311
0
1312
0
  return true;
1313
0
}
1314
1315
const NativePropertyHooks sNativePropertyHooks[] = { {
1316
  nullptr,
1317
  nullptr,
1318
  nullptr,
1319
  { sNativeProperties.Upcast(), nullptr },
1320
  prototypes::id::Cache,
1321
  constructors::id::Cache,
1322
  nullptr,
1323
  &DefaultXrayExpandoObjectClass
1324
} };
1325
1326
void
1327
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1328
0
{
1329
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1330
0
  if (!parentProto) {
1331
0
    return;
1332
0
  }
1333
0
1334
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1335
0
  if (!constructorProto) {
1336
0
    return;
1337
0
  }
1338
0
1339
0
  static bool sIdsInited = false;
1340
0
  if (!sIdsInited && NS_IsMainThread()) {
1341
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1342
0
      return;
1343
0
    }
1344
0
    sIdsInited = true;
1345
0
  }
1346
0
1347
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Cache);
1348
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Cache);
1349
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1350
0
                              &sPrototypeClass.mBase, protoCache,
1351
0
                              nullptr,
1352
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1353
0
                              interfaceCache,
1354
0
                              sNativeProperties.Upcast(),
1355
0
                              nullptr,
1356
0
                              "Cache", aDefineOnGlobal,
1357
0
                              nullptr,
1358
0
                              false);
1359
0
}
1360
1361
JSObject*
1362
GetConstructorObject(JSContext* aCx)
1363
0
{
1364
0
  return GetConstructorObjectHandle(aCx);
1365
0
}
1366
1367
} // namespace Cache_Binding
1368
1369
1370
1371
} // namespace dom
1372
} // namespace mozilla