LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - TestFunctionsBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 245 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM TestFunctions.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "TestFunctionsBinding.h"
       4             : #include "WrapperFactory.h"
       5             : #include "mozilla/OwningNonNull.h"
       6             : #include "mozilla/Preferences.h"
       7             : #include "mozilla/dom/BindingUtils.h"
       8             : #include "mozilla/dom/DOMJSClass.h"
       9             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      10             : #include "mozilla/dom/PrimitiveConversions.h"
      11             : #include "mozilla/dom/Promise.h"
      12             : #include "mozilla/dom/TestFunctions.h"
      13             : #include "mozilla/dom/ToJSValue.h"
      14             : #include "mozilla/dom/XrayExpandoClass.h"
      15             : 
      16             : namespace mozilla {
      17             : namespace dom {
      18             : 
      19             : already_AddRefed<Promise>
      20           0 : PromiseReturner::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
      21             : {
      22           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
      23             : 
      24           0 :   JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
      25           0 :   if (!JS::Call(cx, aThisVal, callable,
      26           0 :                 JS::HandleValueArray::empty(), &rval)) {
      27           0 :     aRv.NoteJSContextException(cx);
      28           0 :     return nullptr;
      29             :   }
      30           0 :   RefPtr<Promise> rvalDecl;
      31             :   { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
      32             :     // etc.
      33             : 
      34           0 :     JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
      35             :     // We basically want our entry global here.  Play it safe
      36             :     // and use GetEntryGlobal() to get it, with whatever
      37             :     // principal-clamping it ends up doing.
      38           0 :     globalObj = GetEntryGlobal()->GetGlobalJSObject();
      39           0 :     JSAutoCompartment ac(cx, globalObj);
      40           0 :     GlobalObject promiseGlobal(cx, globalObj);
      41           0 :     if (promiseGlobal.Failed()) {
      42           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
      43           0 :       return nullptr;
      44             :     }
      45             : 
      46           0 :     JS::Rooted<JS::Value> valueToResolve(cx, rval);
      47           0 :     if (!JS_WrapValue(cx, &valueToResolve)) {
      48           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
      49           0 :       return nullptr;
      50             :     }
      51           0 :     binding_detail::FastErrorResult promiseRv;
      52             :     nsCOMPtr<nsIGlobalObject> global =
      53           0 :       do_QueryInterface(promiseGlobal.GetAsSupports());
      54           0 :     if (!global) {
      55           0 :       promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
      56           0 :       MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
      57           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
      58           0 :       return nullptr;
      59             :     }
      60           0 :     rvalDecl = Promise::Resolve(global, cx, valueToResolve,
      61           0 :                                     promiseRv);
      62           0 :     if (promiseRv.MaybeSetPendingException(cx)) {
      63           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
      64           0 :       return nullptr;
      65             :     }
      66             :   }
      67           0 :   return rvalDecl.forget();
      68             : }
      69             : 
      70             : 
      71             : 
      72             : namespace binding_detail {
      73             : } // namespace binding_detail
      74             : 
      75             : 
      76             : namespace TestFunctionsBinding {
      77             : 
      78             : static bool
      79           0 : throwUncatchableException(JSContext* cx, unsigned argc, JS::Value* vp)
      80             : {
      81           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
      82           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
      83             : 
      84           0 :   GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
      85           0 :   if (global.Failed()) {
      86           0 :     return false;
      87             :   }
      88             : 
      89           0 :   binding_detail::FastErrorResult rv;
      90           0 :   mozilla::dom::TestFunctions::ThrowUncatchableException(global, rv);
      91           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
      92           0 :     return false;
      93             :   }
      94           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      95           0 :   args.rval().setUndefined();
      96           0 :   return true;
      97             : }
      98             : 
      99             : static bool
     100           0 : passThroughPromise(JSContext* cx, unsigned argc, JS::Value* vp)
     101             : {
     102           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     103           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     104             : 
     105           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     106           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TestFunctions.passThroughPromise");
     107             :   }
     108           0 :   GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
     109           0 :   if (global.Failed()) {
     110           0 :     return false;
     111             :   }
     112             : 
     113           0 :   OwningNonNull<Promise> arg0;
     114             :   { // Scope for our GlobalObject, FastErrorResult, JSAutoCompartment,
     115             :     // etc.
     116             : 
     117           0 :     JS::Rooted<JSObject*> globalObj(cx, JS::CurrentGlobalOrNull(cx));
     118           0 :     JSAutoCompartment ac(cx, globalObj);
     119           0 :     GlobalObject promiseGlobal(cx, globalObj);
     120           0 :     if (promiseGlobal.Failed()) {
     121           0 :       return false;
     122             :     }
     123             : 
     124           0 :     JS::Rooted<JS::Value> valueToResolve(cx, args[0]);
     125           0 :     if (!JS_WrapValue(cx, &valueToResolve)) {
     126           0 :       return false;
     127             :     }
     128           0 :     binding_detail::FastErrorResult promiseRv;
     129             :     nsCOMPtr<nsIGlobalObject> global =
     130           0 :       do_QueryInterface(promiseGlobal.GetAsSupports());
     131           0 :     if (!global) {
     132           0 :       promiseRv.ThrowWithCustomCleanup(NS_ERROR_UNEXPECTED);
     133           0 :       MOZ_ALWAYS_TRUE(promiseRv.MaybeSetPendingException(cx));
     134           0 :       return false;
     135             :     }
     136           0 :     arg0 = Promise::Resolve(global, cx, valueToResolve,
     137           0 :                                     promiseRv);
     138           0 :     if (promiseRv.MaybeSetPendingException(cx)) {
     139           0 :       return false;
     140             :     }
     141             :   }
     142           0 :   auto result(StrongOrRawPtr<Promise>(mozilla::dom::TestFunctions::PassThroughPromise(global, NonNullHelper(arg0))));
     143           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     144           0 :   if (!ToJSValue(cx, result, args.rval())) {
     145           0 :     return false;
     146             :   }
     147           0 :   return true;
     148             : }
     149             : 
     150             : 
     151             : static const JSJitInfo passThroughPromise_methodinfo = {
     152             :   { (JSJitGetterOp)passThroughPromise },
     153             :   { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
     154             :   JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
     155             :   false, false, 0
     156             : };
     157             : 
     158             : static bool
     159           0 : passThroughCallbackPromise(JSContext* cx, unsigned argc, JS::Value* vp)
     160             : {
     161           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     162           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     163             : 
     164           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     165           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TestFunctions.passThroughCallbackPromise");
     166             :   }
     167           0 :   GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
     168           0 :   if (global.Failed()) {
     169           0 :     return false;
     170             :   }
     171             : 
     172           0 :   RootedCallback<OwningNonNull<binding_detail::FastPromiseReturner>> arg0(cx);
     173           0 :   if (args[0].isObject()) {
     174           0 :     if (JS::IsCallable(&args[0].toObject())) {
     175             :     { // scope for tempRoot
     176           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     177           0 :       arg0 = new binding_detail::FastPromiseReturner(tempRoot);
     178             :     }
     179             :     } else {
     180           0 :       ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of TestFunctions.passThroughCallbackPromise");
     181           0 :       return false;
     182             :     }
     183             :   } else {
     184           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of TestFunctions.passThroughCallbackPromise");
     185           0 :     return false;
     186             :   }
     187           0 :   binding_detail::FastErrorResult rv;
     188           0 :   auto result(StrongOrRawPtr<Promise>(mozilla::dom::TestFunctions::PassThroughCallbackPromise(global, NonNullHelper(arg0), rv)));
     189           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     190           0 :     return false;
     191             :   }
     192           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     193           0 :   if (!ToJSValue(cx, result, args.rval())) {
     194           0 :     return false;
     195             :   }
     196           0 :   return true;
     197             : }
     198             : 
     199             : 
     200             : static const JSJitInfo passThroughCallbackPromise_methodinfo = {
     201             :   { (JSJitGetterOp)passThroughCallbackPromise },
     202             :   { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
     203             :   JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
     204             :   false, false, 0
     205             : };
     206             : 
     207             : static bool
     208           0 : setStringData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TestFunctions* self, const JSJitMethodCallArgs& args)
     209             : {
     210           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     211           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TestFunctions.setStringData");
     212             :   }
     213           0 :   binding_detail::FakeString arg0;
     214           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     215           0 :     return false;
     216             :   }
     217           0 :   self->SetStringData(NonNullHelper(Constify(arg0)));
     218           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     219           0 :   args.rval().setUndefined();
     220           0 :   return true;
     221             : }
     222             : 
     223             : static const JSJitInfo setStringData_methodinfo = {
     224             :   { (JSJitGetterOp)setStringData },
     225             :   { prototypes::id::TestFunctions },
     226             :   { PrototypeTraits<prototypes::id::TestFunctions>::Depth },
     227             :   JSJitInfo::Method,
     228             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     229             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     230             :   false,  /* isInfallible. False in setters. */
     231             :   false,  /* isMovable.  Not relevant for setters. */
     232             :   false, /* isEliminatable.  Not relevant for setters. */
     233             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     234             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     235             :   false,  /* isTypedMethod.  Only relevant for methods. */
     236             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     237             : };
     238             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     239             : static_assert(0 < 1, "There is no slot for us");
     240             : 
     241             : static bool
     242           0 : getStringDataAsAString(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TestFunctions* self, const JSJitMethodCallArgs& args)
     243             : {
     244           0 :   unsigned argcount = std::min(args.length(), 1u);
     245           0 :   switch (argcount) {
     246             :     case 0: {
     247           0 :       DOMString result;
     248           0 :       self->GetStringDataAsAString(result);
     249           0 :       MOZ_ASSERT(!JS_IsExceptionPending(cx));
     250           0 :       if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     251           0 :         return false;
     252             :       }
     253           0 :       return true;
     254             :       break;
     255             :     }
     256             :     case 1: {
     257             :       uint32_t arg0;
     258           0 :       if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
     259           0 :         return false;
     260             :       }
     261           0 :       DOMString result;
     262           0 :       self->GetStringDataAsAString(arg0, result);
     263           0 :       MOZ_ASSERT(!JS_IsExceptionPending(cx));
     264           0 :       if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     265           0 :         return false;
     266             :       }
     267           0 :       return true;
     268             :       break;
     269             :     }
     270             :     default: {
     271           0 :       return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TestFunctions.getStringDataAsAString");
     272             :       break;
     273             :     }
     274             :   }
     275             :   MOZ_CRASH("We have an always-returning default case");
     276             :   return false;
     277             : }
     278             : 
     279             : static const JSJitInfo getStringDataAsAString_methodinfo = {
     280             :   { (JSJitGetterOp)getStringDataAsAString },
     281             :   { prototypes::id::TestFunctions },
     282             :   { PrototypeTraits<prototypes::id::TestFunctions>::Depth },
     283             :   JSJitInfo::Method,
     284             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     285             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     286             :   false,  /* isInfallible. False in setters. */
     287             :   false,  /* isMovable.  Not relevant for setters. */
     288             :   false, /* isEliminatable.  Not relevant for setters. */
     289             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     290             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     291             :   false,  /* isTypedMethod.  Only relevant for methods. */
     292             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     293             : };
     294             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     295             : static_assert(0 < 1, "There is no slot for us");
     296             : 
     297             : static bool
     298           0 : getStringDataAsDOMString(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TestFunctions* self, const JSJitMethodCallArgs& args)
     299             : {
     300           0 :   Optional<uint32_t> arg0;
     301           0 :   if (args.hasDefined(0)) {
     302           0 :     arg0.Construct();
     303           0 :     if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0.Value())) {
     304           0 :       return false;
     305             :     }
     306             :   }
     307           0 :   DOMString result;
     308           0 :   self->GetStringDataAsDOMString(Constify(arg0), result);
     309           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     310           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     311           0 :     return false;
     312             :   }
     313           0 :   return true;
     314             : }
     315             : 
     316             : static const JSJitInfo getStringDataAsDOMString_methodinfo = {
     317             :   { (JSJitGetterOp)getStringDataAsDOMString },
     318             :   { prototypes::id::TestFunctions },
     319             :   { PrototypeTraits<prototypes::id::TestFunctions>::Depth },
     320             :   JSJitInfo::Method,
     321             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     322             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     323             :   false,  /* isInfallible. False in setters. */
     324             :   false,  /* isMovable.  Not relevant for setters. */
     325             :   false, /* isEliminatable.  Not relevant for setters. */
     326             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     327             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     328             :   false,  /* isTypedMethod.  Only relevant for methods. */
     329             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     330             : };
     331             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     332             : static_assert(0 < 1, "There is no slot for us");
     333             : 
     334             : static void
     335           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     336             : {
     337           0 :   mozilla::dom::TestFunctions* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TestFunctions>(obj);
     338           0 :   if (self) {
     339           0 :     AddForDeferredFinalization<mozilla::dom::TestFunctions>(self);
     340             :   }
     341           0 : }
     342             : 
     343             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     344             : #if defined(__clang__)
     345             : #pragma clang diagnostic push
     346             : #pragma clang diagnostic ignored "-Wmissing-braces"
     347             : #endif
     348             : static const JSFunctionSpec sStaticMethods_specs[] = {
     349             :   JS_FNSPEC("throwUncatchableException", throwUncatchableException, nullptr, 0, JSPROP_ENUMERATE, nullptr),
     350             :   JS_FNSPEC("passThroughPromise", StaticMethodPromiseWrapper, &passThroughPromise_methodinfo, 1, JSPROP_ENUMERATE, nullptr),
     351             :   JS_FNSPEC("passThroughCallbackPromise", StaticMethodPromiseWrapper, &passThroughCallbackPromise_methodinfo, 1, JSPROP_ENUMERATE, nullptr),
     352             :   JS_FS_END
     353             : };
     354             : #if defined(__clang__)
     355             : #pragma clang diagnostic pop
     356             : #endif
     357             : 
     358             : 
     359             : // Can't be const because the pref-enabled boolean needs to be writable
     360             : static Prefable<const JSFunctionSpec> sStaticMethods[] = {
     361             :   { nullptr, &sStaticMethods_specs[0] },
     362             :   { nullptr, nullptr }
     363             : };
     364             : 
     365             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     366             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     367             : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     368             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     369             : 
     370             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     371             : #if defined(__clang__)
     372             : #pragma clang diagnostic push
     373             : #pragma clang diagnostic ignored "-Wmissing-braces"
     374             : #endif
     375             : static const JSFunctionSpec sMethods_specs[] = {
     376             :   JS_FNSPEC("setStringData", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setStringData_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     377             :   JS_FNSPEC("getStringDataAsAString", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getStringDataAsAString_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     378             :   JS_FNSPEC("getStringDataAsDOMString", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getStringDataAsDOMString_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
     379             :   JS_FS_END
     380             : };
     381             : #if defined(__clang__)
     382             : #pragma clang diagnostic pop
     383             : #endif
     384             : 
     385             : 
     386             : // Can't be const because the pref-enabled boolean needs to be writable
     387             : static Prefable<const JSFunctionSpec> sMethods[] = {
     388             :   { nullptr, &sMethods_specs[0] },
     389             :   { nullptr, nullptr }
     390             : };
     391             : 
     392             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     393             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     394             : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     395             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     396             : 
     397             : 
     398             : static uint16_t sNativeProperties_sortedPropertyIndices[6];
     399             : static PropertyInfo sNativeProperties_propertyInfos[6];
     400             : 
     401             : static const NativePropertiesN<2> sNativeProperties = {
     402             :   true,  0 /* sStaticMethods */,
     403             :   false, 0,
     404             :   true,  1 /* sMethods */,
     405             :   false, 0,
     406             :   false, 0,
     407             :   false, 0,
     408             :   false, 0,
     409             :   -1,
     410             :   6,
     411             :   sNativeProperties_sortedPropertyIndices,
     412             :   {
     413             :     { sStaticMethods, &sNativeProperties_propertyInfos[0] },
     414             :     { sMethods, &sNativeProperties_propertyInfos[3] }
     415             :   }
     416             : };
     417             : static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     418             :     "We have a property info count that is oversized");
     419             : 
     420             : static bool
     421           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     422             : {
     423           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     424           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     425           0 :   if (!args.isConstructing()) {
     426             :     // XXXbz wish I could get the name from the callee instead of
     427             :     // Adding more relocations
     428           0 :     return ThrowConstructorWithoutNew(cx, "TestFunctions");
     429             :   }
     430             : 
     431           0 :   GlobalObject global(cx, obj);
     432           0 :   if (global.Failed()) {
     433           0 :     return false;
     434             :   }
     435             : 
     436           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     437           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     438           0 :     return false;
     439             :   }
     440             : 
     441           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     442           0 :   Maybe<JSAutoCompartment> ac;
     443           0 :   if (objIsXray) {
     444           0 :     obj = js::CheckedUnwrap(obj);
     445           0 :     if (!obj) {
     446           0 :       return false;
     447             :     }
     448           0 :     ac.emplace(cx, obj);
     449           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     450           0 :       return false;
     451             :     }
     452             :   }
     453           0 :   binding_detail::FastErrorResult rv;
     454           0 :   auto result(StrongOrRawPtr<mozilla::dom::TestFunctions>(mozilla::dom::TestFunctions::Constructor(global, rv)));
     455           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     456           0 :     return false;
     457             :   }
     458           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     459             :   static_assert(!IsPointer<decltype(result)>::value,
     460             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     461           0 :   if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
     462           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     463           0 :     return false;
     464             :   }
     465           0 :   return true;
     466             : }
     467             : 
     468             : static const js::ClassOps sInterfaceObjectClassOps = {
     469             :     nullptr,               /* addProperty */
     470             :     nullptr,               /* delProperty */
     471             :     nullptr,               /* getProperty */
     472             :     nullptr,               /* setProperty */
     473             :     nullptr,               /* enumerate */
     474             :     nullptr,               /* newEnumerate */
     475             :     nullptr,               /* resolve */
     476             :     nullptr,               /* mayResolve */
     477             :     nullptr,               /* finalize */
     478             :     _constructor, /* call */
     479             :     nullptr,               /* hasInstance */
     480             :     _constructor, /* construct */
     481             :     nullptr,               /* trace */
     482             : };
     483             : 
     484             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     485             :   {
     486             :     "Function",
     487             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     488             :     &sInterfaceObjectClassOps,
     489             :     JS_NULL_CLASS_SPEC,
     490             :     JS_NULL_CLASS_EXT,
     491             :     &sInterfaceObjectClassObjectOps
     492             :   },
     493             :   eInterface,
     494             :   true,
     495             :   prototypes::id::TestFunctions,
     496             :   PrototypeTraits<prototypes::id::TestFunctions>::Depth,
     497             :   sNativePropertyHooks,
     498             :   "function TestFunctions() {\n    [native code]\n}",
     499             :   JS::GetRealmFunctionPrototype
     500             : };
     501             : 
     502             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     503             :   {
     504             :     "TestFunctionsPrototype",
     505             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     506             :     JS_NULL_CLASS_OPS,
     507             :     JS_NULL_CLASS_SPEC,
     508             :     JS_NULL_CLASS_EXT,
     509             :     JS_NULL_OBJECT_OPS
     510             :   },
     511             :   eInterfacePrototype,
     512             :   false,
     513             :   prototypes::id::TestFunctions,
     514             :   PrototypeTraits<prototypes::id::TestFunctions>::Depth,
     515             :   sNativePropertyHooks,
     516             :   "[object TestFunctionsPrototype]",
     517             :   JS::GetRealmObjectPrototype
     518             : };
     519             : 
     520             : bool
     521           0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
     522             : {
     523             :   static bool sPrefValue;
     524             :   static bool sPrefCacheSetUp = false;
     525           0 :   if (!sPrefCacheSetUp) {
     526           0 :     sPrefCacheSetUp = true;
     527           0 :     Preferences::AddBoolVarCache(&sPrefValue, "dom.expose_test_interfaces");
     528             :   }
     529             : 
     530           0 :   return sPrefValue;
     531             : }
     532             : 
     533             : JSObject*
     534           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     535             : {
     536           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     537             : }
     538             : 
     539             : static const js::ClassOps sClassOps = {
     540             :   nullptr, /* addProperty */
     541             :   nullptr,               /* delProperty */
     542             :   nullptr,               /* getProperty */
     543             :   nullptr,               /* setProperty */
     544             :   nullptr,               /* enumerate */
     545             :   nullptr, /* newEnumerate */
     546             :   nullptr, /* resolve */
     547             :   nullptr, /* mayResolve */
     548             :   _finalize, /* finalize */
     549             :   nullptr, /* call */
     550             :   nullptr,               /* hasInstance */
     551             :   nullptr,               /* construct */
     552             :   nullptr, /* trace */
     553             : };
     554             : 
     555             : static const js::ClassExtension sClassExtension = {
     556             :   nullptr, /* weakmapKeyDelegateOp */
     557             :   nullptr /* objectMovedOp */
     558             : };
     559             : 
     560             : static const DOMJSClass sClass = {
     561             :   { "TestFunctions",
     562             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     563             :     &sClassOps,
     564             :     JS_NULL_CLASS_SPEC,
     565             :     &sClassExtension,
     566             :     JS_NULL_OBJECT_OPS
     567             :   },
     568             :   { prototypes::id::TestFunctions, 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 },
     569             :   IsBaseOf<nsISupports, mozilla::dom::TestFunctions >::value,
     570             :   sNativePropertyHooks,
     571             :   FindAssociatedGlobalForNative<mozilla::dom::TestFunctions>::Get,
     572             :   GetProtoObjectHandle,
     573             :   GetCCParticipant<mozilla::dom::TestFunctions>::Get()
     574             : };
     575             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     576             :               "Must have the right minimal number of reserved slots.");
     577             : static_assert(1 >= 1,
     578             :               "Must have enough reserved slots.");
     579             : 
     580             : const JSClass*
     581           0 : GetJSClass()
     582             : {
     583           0 :   return sClass.ToJSClass();
     584             : }
     585             : 
     586             : bool
     587           0 : Wrap(JSContext* aCx, mozilla::dom::TestFunctions* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     588             : {
     589             :   MOZ_ASSERT(static_cast<mozilla::dom::TestFunctions*>(aObject) ==
     590             :              reinterpret_cast<mozilla::dom::TestFunctions*>(aObject),
     591             :              "Multiple inheritance for mozilla::dom::TestFunctions is broken.");
     592           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     593           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     594             : 
     595           0 :   JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
     596           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     597           0 :   if (!canonicalProto) {
     598           0 :     return false;
     599             :   }
     600           0 :   JS::Rooted<JSObject*> proto(aCx);
     601           0 :   if (aGivenProto) {
     602           0 :     proto = aGivenProto;
     603             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     604             :     // coming in, we changed compartments to that of "parent" so may need
     605             :     // to wrap the proto here.
     606           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     607           0 :       if (!JS_WrapObject(aCx, &proto)) {
     608           0 :         return false;
     609             :       }
     610             :     }
     611             :   } else {
     612           0 :     proto = canonicalProto;
     613             :   }
     614             : 
     615           0 :   BindingJSObjectCreator<mozilla::dom::TestFunctions> creator(aCx);
     616           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     617           0 :   if (!aReflector) {
     618           0 :     return false;
     619             :   }
     620             : 
     621             : 
     622             : 
     623           0 :   creator.InitializationSucceeded();
     624           0 :   return true;
     625             : }
     626             : 
     627             : const NativePropertyHooks sNativePropertyHooks[] = { {
     628             :   nullptr,
     629             :   nullptr,
     630             :   nullptr,
     631             :   { sNativeProperties.Upcast(), nullptr },
     632             :   prototypes::id::TestFunctions,
     633             :   constructors::id::TestFunctions,
     634             :   nullptr,
     635             :   &DefaultXrayExpandoObjectClass
     636             : } };
     637             : 
     638             : void
     639           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     640             : {
     641           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     642           0 :   if (!parentProto) {
     643           0 :     return;
     644             :   }
     645             : 
     646           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
     647           0 :   if (!constructorProto) {
     648           0 :     return;
     649             :   }
     650             : 
     651             :   static bool sIdsInited = false;
     652           0 :   if (!sIdsInited && NS_IsMainThread()) {
     653           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     654           0 :       return;
     655             :     }
     656           0 :     sIdsInited = true;
     657             :   }
     658             : 
     659           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TestFunctions);
     660           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TestFunctions);
     661           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     662             :                               &sPrototypeClass.mBase, protoCache,
     663             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
     664             :                               interfaceCache,
     665             :                               sNativeProperties.Upcast(),
     666             :                               nullptr,
     667             :                               "TestFunctions", aDefineOnGlobal,
     668             :                               nullptr,
     669           0 :                               false);
     670             : }
     671             : 
     672             : JS::Handle<JSObject*>
     673           0 : GetProtoObjectHandle(JSContext* aCx)
     674             : {
     675             :   /* Get the interface prototype object for this class.  This will create the
     676             :      object as needed. */
     677           0 :   bool aDefineOnGlobal = true;
     678             : 
     679             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     680           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     681           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     682           0 :     return nullptr;
     683             :   }
     684             : 
     685             :   /* Check to see whether the interface objects are already installed */
     686           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     687           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::TestFunctions)) {
     688           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     689           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     690             :   }
     691             : 
     692             :   /*
     693             :    * The object might _still_ be null, but that's OK.
     694             :    *
     695             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     696             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     697             :    * changed after they have been set.
     698             :    *
     699             :    * Calling address() avoids the read read barrier that does gray
     700             :    * unmarking, but it's not possible for the object to be gray here.
     701             :    */
     702             : 
     703           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::TestFunctions);
     704           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     705           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     706             : }
     707             : 
     708             : JS::Handle<JSObject*>
     709           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     710             : {
     711             :   /* Get the interface object for this class.  This will create the object as
     712             :      needed. */
     713             : 
     714             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     715           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     716           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     717           0 :     return nullptr;
     718             :   }
     719             : 
     720             :   /* Check to see whether the interface objects are already installed */
     721           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     722           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::TestFunctions)) {
     723           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     724           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     725             :   }
     726             : 
     727             :   /*
     728             :    * The object might _still_ be null, but that's OK.
     729             :    *
     730             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     731             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     732             :    * changed after they have been set.
     733             :    *
     734             :    * Calling address() avoids the read read barrier that does gray
     735             :    * unmarking, but it's not possible for the object to be gray here.
     736             :    */
     737             : 
     738           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::TestFunctions);
     739           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     740           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     741             : }
     742             : 
     743             : JSObject*
     744           0 : GetConstructorObject(JSContext* aCx)
     745             : {
     746           0 :   return GetConstructorObjectHandle(aCx);
     747             : }
     748             : 
     749             : } // namespace TestFunctionsBinding
     750             : 
     751             : 
     752             : 
     753             : } // namespace dom
     754             : } // namespace mozilla

Generated by: LCOV version 1.13