LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - CacheStorageBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 24 265 9.1 %
Date: 2017-07-14 16:53:18 Functions: 4 23 17.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13