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