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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM XPathEvaluator.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "DocumentBinding.h"
       4             : #include "WrapperFactory.h"
       5             : #include "XPathEvaluatorBinding.h"
       6             : #include "XPathNSResolverBinding.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/Nullable.h"
      12             : #include "mozilla/dom/PrimitiveConversions.h"
      13             : #include "mozilla/dom/XPathEvaluator.h"
      14             : #include "mozilla/dom/XPathExpression.h"
      15             : #include "mozilla/dom/XPathResult.h"
      16             : #include "mozilla/dom/XrayExpandoClass.h"
      17             : #include "nsContentUtils.h"
      18             : #include "nsIDOMXPathEvaluator.h"
      19             : #include "nsINode.h"
      20             : #include "nsISupports.h"
      21             : #include "xpcjsid.h"
      22             : 
      23             : namespace mozilla {
      24             : namespace dom {
      25             : 
      26             : namespace XPathEvaluatorBinding {
      27             : 
      28             : static bool
      29           0 : createExpression(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XPathEvaluator* self, const JSJitMethodCallArgs& args)
      30             : {
      31           0 :   if (MOZ_UNLIKELY(args.length() < 2)) {
      32           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XPathEvaluator.createExpression");
      33             :   }
      34           0 :   binding_detail::FakeString arg0;
      35           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
      36           0 :     return false;
      37             :   }
      38           0 :   RootedCallback<RefPtr<binding_detail::FastXPathNSResolver>> arg1(cx);
      39           0 :   if (args[1].isObject()) {
      40             :     { // scope for tempRoot
      41           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
      42           0 :       arg1 = new binding_detail::FastXPathNSResolver(tempRoot);
      43             :     }
      44           0 :   } else if (args[1].isNullOrUndefined()) {
      45           0 :     arg1 = nullptr;
      46             :   } else {
      47           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of XPathEvaluator.createExpression");
      48           0 :     return false;
      49             :   }
      50           0 :   binding_detail::FastErrorResult rv;
      51           0 :   auto result(StrongOrRawPtr<mozilla::dom::XPathExpression>(self->CreateExpression(NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
      52           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
      53           0 :     return false;
      54             :   }
      55           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
      56             :   static_assert(!IsPointer<decltype(result)>::value,
      57             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
      58           0 :   if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval())) {
      59           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
      60           0 :     return false;
      61             :   }
      62           0 :   return true;
      63             : }
      64             : 
      65             : static const JSJitInfo createExpression_methodinfo = {
      66             :   { (JSJitGetterOp)createExpression },
      67             :   { prototypes::id::XPathEvaluator },
      68             :   { PrototypeTraits<prototypes::id::XPathEvaluator>::Depth },
      69             :   JSJitInfo::Method,
      70             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
      71             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
      72             :   false,  /* isInfallible. False in setters. */
      73             :   false,  /* isMovable.  Not relevant for setters. */
      74             :   false, /* isEliminatable.  Not relevant for setters. */
      75             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
      76             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
      77             :   false,  /* isTypedMethod.  Only relevant for methods. */
      78             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
      79             : };
      80             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
      81             : static_assert(0 < 1, "There is no slot for us");
      82             : 
      83             : static bool
      84           0 : createNSResolver(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XPathEvaluator* self, const JSJitMethodCallArgs& args)
      85             : {
      86           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
      87           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XPathEvaluator.createNSResolver");
      88             :   }
      89           0 :   NonNull<nsINode> arg0;
      90           0 :   if (args[0].isObject()) {
      91             :     {
      92           0 :       nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[0], arg0);
      93           0 :       if (NS_FAILED(rv)) {
      94           0 :         ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of XPathEvaluator.createNSResolver", "Node");
      95           0 :         return false;
      96             :       }
      97             :     }
      98             :   } else {
      99           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of XPathEvaluator.createNSResolver");
     100           0 :     return false;
     101             :   }
     102           0 :   auto result(StrongOrRawPtr<nsINode>(self->CreateNSResolver(NonNullHelper(arg0))));
     103           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     104           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
     105           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     106           0 :     return false;
     107             :   }
     108           0 :   return true;
     109             : }
     110             : 
     111             : static const JSJitInfo::ArgType createNSResolver_methodinfo_argTypes[] = { JSJitInfo::Object, JSJitInfo::ArgTypeListEnd };
     112             : static const JSTypedMethodJitInfo createNSResolver_methodinfo = {
     113             :   {
     114             :     { (JSJitGetterOp)createNSResolver },
     115             :     { prototypes::id::XPathEvaluator },
     116             :     { PrototypeTraits<prototypes::id::XPathEvaluator>::Depth },
     117             :     JSJitInfo::Method,
     118             :     JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
     119             :     JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     120             :     false,  /* isInfallible. False in setters. */
     121             :     true,  /* isMovable.  Not relevant for setters. */
     122             :     true, /* isEliminatable.  Not relevant for setters. */
     123             :     false, /* isAlwaysInSlot.  Only relevant for getters. */
     124             :     false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     125             :     true,  /* isTypedMethod.  Only relevant for methods. */
     126             :     0   /* Reserved slot index, if we're stored in a slot, else 0. */
     127             :   },
     128             :   createNSResolver_methodinfo_argTypes
     129             : };
     130             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     131             : static_assert(0 < 1, "There is no slot for us");
     132             : 
     133             : static bool
     134           0 : evaluate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::XPathEvaluator* self, const JSJitMethodCallArgs& args)
     135             : {
     136           0 :   if (MOZ_UNLIKELY(args.length() < 5)) {
     137           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "XPathEvaluator.evaluate");
     138             :   }
     139           0 :   binding_detail::FakeString arg0;
     140           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     141           0 :     return false;
     142             :   }
     143           0 :   NonNull<nsINode> arg1;
     144           0 :   if (args[1].isObject()) {
     145             :     {
     146           0 :       nsresult rv = UnwrapObject<prototypes::id::Node, nsINode>(args[1], arg1);
     147           0 :       if (NS_FAILED(rv)) {
     148           0 :         ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 2 of XPathEvaluator.evaluate", "Node");
     149           0 :         return false;
     150             :       }
     151             :     }
     152             :   } else {
     153           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of XPathEvaluator.evaluate");
     154           0 :     return false;
     155             :   }
     156           0 :   RootedCallback<RefPtr<binding_detail::FastXPathNSResolver>> arg2(cx);
     157           0 :   if (args[2].isObject()) {
     158             :     { // scope for tempRoot
     159           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[2].toObject());
     160           0 :       arg2 = new binding_detail::FastXPathNSResolver(tempRoot);
     161             :     }
     162           0 :   } else if (args[2].isNullOrUndefined()) {
     163           0 :     arg2 = nullptr;
     164             :   } else {
     165           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 3 of XPathEvaluator.evaluate");
     166           0 :     return false;
     167             :   }
     168             :   uint16_t arg3;
     169           0 :   if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[3], &arg3)) {
     170           0 :     return false;
     171             :   }
     172           0 :   JS::Rooted<JSObject*> arg4(cx);
     173           0 :   if (args[4].isObject()) {
     174           0 :     arg4 = &args[4].toObject();
     175           0 :   } else if (args[4].isNullOrUndefined()) {
     176           0 :     arg4 = nullptr;
     177             :   } else {
     178           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 5 of XPathEvaluator.evaluate");
     179           0 :     return false;
     180             :   }
     181           0 :   binding_detail::FastErrorResult rv;
     182           0 :   auto result(StrongOrRawPtr<mozilla::dom::XPathResult>(self->Evaluate(cx, NonNullHelper(Constify(arg0)), NonNullHelper(arg1), Constify(arg2), arg3, arg4, rv)));
     183           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     184           0 :     return false;
     185             :   }
     186           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     187           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
     188           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     189           0 :     return false;
     190             :   }
     191           0 :   return true;
     192             : }
     193             : 
     194             : static const JSJitInfo evaluate_methodinfo = {
     195             :   { (JSJitGetterOp)evaluate },
     196             :   { prototypes::id::XPathEvaluator },
     197             :   { PrototypeTraits<prototypes::id::XPathEvaluator>::Depth },
     198             :   JSJitInfo::Method,
     199             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     200             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     201             :   false,  /* isInfallible. False in setters. */
     202             :   false,  /* isMovable.  Not relevant for setters. */
     203             :   false, /* isEliminatable.  Not relevant for setters. */
     204             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     205             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     206             :   false,  /* isTypedMethod.  Only relevant for methods. */
     207             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     208             : };
     209             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     210             : static_assert(0 < 1, "There is no slot for us");
     211             : 
     212             : static void
     213           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     214             : {
     215           0 :   mozilla::dom::XPathEvaluator* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::XPathEvaluator>(obj);
     216           0 :   if (self) {
     217           0 :     AddForDeferredFinalization<mozilla::dom::XPathEvaluator>(self);
     218             :   }
     219           0 : }
     220             : 
     221             : static bool
     222           0 : _hasInstance(JSContext* cx, unsigned argc, JS::Value* vp)
     223             : {
     224           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     225           0 :   if (!args.get(0).isObject()) {
     226           0 :     args.rval().setBoolean(false);
     227           0 :     return true;
     228             :   }
     229             : 
     230           0 :   JS::Rooted<JSObject*> instance(cx, &args[0].toObject());
     231             : 
     232             :   static_assert(IsBaseOf<nsISupports, mozilla::dom::XPathEvaluator>::value,
     233             :                 "HasInstance only works for nsISupports-based classes.");
     234             : 
     235           0 :   bool ok = InterfaceHasInstance(cx, argc, vp);
     236           0 :   if (!ok || args.rval().toBoolean()) {
     237           0 :     return ok;
     238             :   }
     239             : 
     240             :   // FIXME Limit this to chrome by checking xpc::AccessCheck::isChrome(obj).
     241             :   nsCOMPtr<nsISupports> native =
     242           0 :     xpc::UnwrapReflectorToISupports(js::UncheckedUnwrap(instance, /* stopAtWindowProxy = */ false));
     243           0 :   nsCOMPtr<nsIDOMXPathEvaluator> qiResult = do_QueryInterface(native);
     244           0 :   args.rval().setBoolean(!!qiResult);
     245           0 :   return true;
     246             : }
     247             : 
     248             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     249             : #if defined(__clang__)
     250             : #pragma clang diagnostic push
     251             : #pragma clang diagnostic ignored "-Wmissing-braces"
     252             : #endif
     253             : static const JSFunctionSpec sStaticMethods_specs[] = {
     254             :   JS_SYM_FNSPEC(hasInstance, _hasInstance, nullptr, 1, JSPROP_READONLY | JSPROP_PERMANENT, nullptr),
     255             :   JS_FS_END
     256             : };
     257             : #if defined(__clang__)
     258             : #pragma clang diagnostic pop
     259             : #endif
     260             : 
     261             : 
     262             : // Can't be const because the pref-enabled boolean needs to be writable
     263             : static Prefable<const JSFunctionSpec> sStaticMethods[] = {
     264             :   { nullptr, &sStaticMethods_specs[0] },
     265             :   { nullptr, nullptr }
     266             : };
     267             : 
     268             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     269             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     270             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     271             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     272             : 
     273             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     274             : #if defined(__clang__)
     275             : #pragma clang diagnostic push
     276             : #pragma clang diagnostic ignored "-Wmissing-braces"
     277             : #endif
     278             : static const JSFunctionSpec sMethods_specs[] = {
     279             :   JS_FNSPEC("createExpression", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&createExpression_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
     280             :   JS_FNSPEC("createNSResolver", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&createNSResolver_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     281             :   JS_FNSPEC("evaluate", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&evaluate_methodinfo), 5, JSPROP_ENUMERATE, nullptr),
     282             :   JS_FS_END,
     283             :   JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
     284             :   JS_FS_END
     285             : };
     286             : #if defined(__clang__)
     287             : #pragma clang diagnostic pop
     288             : #endif
     289             : 
     290             : static PrefableDisablers sMethods_disablers4 = {
     291             :   true, false, 0, &WantsQueryInterface<mozilla::dom::XPathEvaluator>::Enabled
     292             : };
     293             : 
     294             : // Can't be const because the pref-enabled boolean needs to be writable
     295             : static Prefable<const JSFunctionSpec> sMethods[] = {
     296             :   { nullptr, &sMethods_specs[0] },
     297             :   { &sMethods_disablers4, &sMethods_specs[4] },
     298             :   { nullptr, nullptr }
     299             : };
     300             : 
     301             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     302             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     303             : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     304             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     305             : 
     306             : 
     307             : static uint16_t sNativeProperties_sortedPropertyIndices[5];
     308             : static PropertyInfo sNativeProperties_propertyInfos[5];
     309             : 
     310             : static const NativePropertiesN<2> sNativeProperties = {
     311             :   true,  0 /* sStaticMethods */,
     312             :   false, 0,
     313             :   true,  1 /* sMethods */,
     314             :   false, 0,
     315             :   false, 0,
     316             :   false, 0,
     317             :   false, 0,
     318             :   -1,
     319             :   5,
     320             :   sNativeProperties_sortedPropertyIndices,
     321             :   {
     322             :     { sStaticMethods, &sNativeProperties_propertyInfos[0] },
     323             :     { sMethods, &sNativeProperties_propertyInfos[1] }
     324             :   }
     325             : };
     326             : static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     327             :     "We have a property info count that is oversized");
     328             : 
     329             : static bool
     330           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     331             : {
     332           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     333           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     334           0 :   if (!args.isConstructing()) {
     335             :     // XXXbz wish I could get the name from the callee instead of
     336             :     // Adding more relocations
     337           0 :     return ThrowConstructorWithoutNew(cx, "XPathEvaluator");
     338             :   }
     339             : 
     340           0 :   GlobalObject global(cx, obj);
     341           0 :   if (global.Failed()) {
     342           0 :     return false;
     343             :   }
     344             : 
     345           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     346           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     347           0 :     return false;
     348             :   }
     349             : 
     350           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     351           0 :   Maybe<JSAutoCompartment> ac;
     352           0 :   if (objIsXray) {
     353           0 :     obj = js::CheckedUnwrap(obj);
     354           0 :     if (!obj) {
     355           0 :       return false;
     356             :     }
     357           0 :     ac.emplace(cx, obj);
     358           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     359           0 :       return false;
     360             :     }
     361             :   }
     362           0 :   binding_detail::FastErrorResult rv;
     363           0 :   auto result(StrongOrRawPtr<mozilla::dom::XPathEvaluator>(mozilla::dom::XPathEvaluator::Constructor(global, rv)));
     364           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     365           0 :     return false;
     366             :   }
     367           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     368             :   static_assert(!IsPointer<decltype(result)>::value,
     369             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     370           0 :   if (!WrapNewBindingNonWrapperCachedObject(cx, obj, result, args.rval(), desiredProto)) {
     371           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     372           0 :     return false;
     373             :   }
     374           0 :   return true;
     375             : }
     376             : 
     377             : static const js::ClassOps sInterfaceObjectClassOps = {
     378             :     nullptr,               /* addProperty */
     379             :     nullptr,               /* delProperty */
     380             :     nullptr,               /* getProperty */
     381             :     nullptr,               /* setProperty */
     382             :     nullptr,               /* enumerate */
     383             :     nullptr,               /* newEnumerate */
     384             :     nullptr,               /* resolve */
     385             :     nullptr,               /* mayResolve */
     386             :     nullptr,               /* finalize */
     387             :     _constructor, /* call */
     388             :     nullptr,               /* hasInstance */
     389             :     _constructor, /* construct */
     390             :     nullptr,               /* trace */
     391             : };
     392             : 
     393             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     394             :   {
     395             :     "Function",
     396             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     397             :     &sInterfaceObjectClassOps,
     398             :     JS_NULL_CLASS_SPEC,
     399             :     JS_NULL_CLASS_EXT,
     400             :     &sInterfaceObjectClassObjectOps
     401             :   },
     402             :   eInterface,
     403             :   false,
     404             :   prototypes::id::XPathEvaluator,
     405             :   PrototypeTraits<prototypes::id::XPathEvaluator>::Depth,
     406             :   sNativePropertyHooks,
     407             :   "function XPathEvaluator() {\n    [native code]\n}",
     408             :   JS::GetRealmFunctionPrototype
     409             : };
     410             : 
     411             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     412             :   {
     413             :     "XPathEvaluatorPrototype",
     414             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     415             :     JS_NULL_CLASS_OPS,
     416             :     JS_NULL_CLASS_SPEC,
     417             :     JS_NULL_CLASS_EXT,
     418             :     JS_NULL_OBJECT_OPS
     419             :   },
     420             :   eInterfacePrototype,
     421             :   false,
     422             :   prototypes::id::XPathEvaluator,
     423             :   PrototypeTraits<prototypes::id::XPathEvaluator>::Depth,
     424             :   sNativePropertyHooks,
     425             :   "[object XPathEvaluatorPrototype]",
     426             :   JS::GetRealmObjectPrototype
     427             : };
     428             : 
     429             : JSObject*
     430           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     431             : {
     432           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     433             : }
     434             : 
     435             : static const js::ClassOps sClassOps = {
     436             :   nullptr, /* addProperty */
     437             :   nullptr,               /* delProperty */
     438             :   nullptr,               /* getProperty */
     439             :   nullptr,               /* setProperty */
     440             :   nullptr,               /* enumerate */
     441             :   nullptr, /* newEnumerate */
     442             :   nullptr, /* resolve */
     443             :   nullptr, /* mayResolve */
     444             :   _finalize, /* finalize */
     445             :   nullptr, /* call */
     446             :   nullptr,               /* hasInstance */
     447             :   nullptr,               /* construct */
     448             :   nullptr, /* trace */
     449             : };
     450             : 
     451             : static const js::ClassExtension sClassExtension = {
     452             :   nullptr, /* weakmapKeyDelegateOp */
     453             :   nullptr /* objectMovedOp */
     454             : };
     455             : 
     456             : static const DOMJSClass sClass = {
     457             :   { "XPathEvaluator",
     458             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     459             :     &sClassOps,
     460             :     JS_NULL_CLASS_SPEC,
     461             :     &sClassExtension,
     462             :     JS_NULL_OBJECT_OPS
     463             :   },
     464             :   { prototypes::id::XPathEvaluator, 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 },
     465             :   IsBaseOf<nsISupports, mozilla::dom::XPathEvaluator >::value,
     466             :   sNativePropertyHooks,
     467             :   FindAssociatedGlobalForNative<mozilla::dom::XPathEvaluator>::Get,
     468             :   GetProtoObjectHandle,
     469             :   GetCCParticipant<mozilla::dom::XPathEvaluator>::Get()
     470             : };
     471             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     472             :               "Must have the right minimal number of reserved slots.");
     473             : static_assert(1 >= 1,
     474             :               "Must have enough reserved slots.");
     475             : 
     476             : const JSClass*
     477           0 : GetJSClass()
     478             : {
     479           0 :   return sClass.ToJSClass();
     480             : }
     481             : 
     482             : bool
     483           0 : Wrap(JSContext* aCx, mozilla::dom::XPathEvaluator* aObject, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     484             : {
     485             :   MOZ_ASSERT(static_cast<mozilla::dom::XPathEvaluator*>(aObject) ==
     486             :              reinterpret_cast<mozilla::dom::XPathEvaluator*>(aObject),
     487             :              "Multiple inheritance for mozilla::dom::XPathEvaluator is broken.");
     488           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     489           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     490             : 
     491           0 :   JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx));
     492           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     493           0 :   if (!canonicalProto) {
     494           0 :     return false;
     495             :   }
     496           0 :   JS::Rooted<JSObject*> proto(aCx);
     497           0 :   if (aGivenProto) {
     498           0 :     proto = aGivenProto;
     499             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     500             :     // coming in, we changed compartments to that of "parent" so may need
     501             :     // to wrap the proto here.
     502           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     503           0 :       if (!JS_WrapObject(aCx, &proto)) {
     504           0 :         return false;
     505             :       }
     506             :     }
     507             :   } else {
     508           0 :     proto = canonicalProto;
     509             :   }
     510             : 
     511           0 :   BindingJSObjectCreator<mozilla::dom::XPathEvaluator> creator(aCx);
     512           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     513           0 :   if (!aReflector) {
     514           0 :     return false;
     515             :   }
     516             : 
     517             : 
     518             : 
     519           0 :   creator.InitializationSucceeded();
     520           0 :   return true;
     521             : }
     522             : 
     523             : const NativePropertyHooks sNativePropertyHooks[] = { {
     524             :   nullptr,
     525             :   nullptr,
     526             :   nullptr,
     527             :   { sNativeProperties.Upcast(), nullptr },
     528             :   prototypes::id::XPathEvaluator,
     529             :   constructors::id::XPathEvaluator,
     530             :   nullptr,
     531             :   &DefaultXrayExpandoObjectClass
     532             : } };
     533             : 
     534             : void
     535           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     536             : {
     537           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     538           0 :   if (!parentProto) {
     539           0 :     return;
     540             :   }
     541             : 
     542           0 :   JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
     543           0 :   if (!constructorProto) {
     544           0 :     return;
     545             :   }
     546             : 
     547             :   static bool sIdsInited = false;
     548           0 :   if (!sIdsInited && NS_IsMainThread()) {
     549           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     550           0 :       return;
     551             :     }
     552           0 :     sIdsInited = true;
     553             :   }
     554             : 
     555           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::XPathEvaluator);
     556           0 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::XPathEvaluator);
     557           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     558             :                               &sPrototypeClass.mBase, protoCache,
     559             :                               constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
     560             :                               interfaceCache,
     561             :                               sNativeProperties.Upcast(),
     562             :                               nullptr,
     563             :                               "XPathEvaluator", aDefineOnGlobal,
     564             :                               nullptr,
     565           0 :                               false);
     566             : }
     567             : 
     568             : JS::Handle<JSObject*>
     569           0 : GetProtoObjectHandle(JSContext* aCx)
     570             : {
     571             :   /* Get the interface prototype object for this class.  This will create the
     572             :      object as needed. */
     573           0 :   bool aDefineOnGlobal = true;
     574             : 
     575             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     576           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     577           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     578           0 :     return nullptr;
     579             :   }
     580             : 
     581             :   /* Check to see whether the interface objects are already installed */
     582           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     583           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::XPathEvaluator)) {
     584           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     585           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     586             :   }
     587             : 
     588             :   /*
     589             :    * The object might _still_ be null, but that's OK.
     590             :    *
     591             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     592             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     593             :    * changed after they have been set.
     594             :    *
     595             :    * Calling address() avoids the read read barrier that does gray
     596             :    * unmarking, but it's not possible for the object to be gray here.
     597             :    */
     598             : 
     599           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::XPathEvaluator);
     600           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     601           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     602             : }
     603             : 
     604             : JS::Handle<JSObject*>
     605           0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
     606             : {
     607             :   /* Get the interface object for this class.  This will create the object as
     608             :      needed. */
     609             : 
     610             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     611           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     612           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     613           0 :     return nullptr;
     614             :   }
     615             : 
     616             :   /* Check to see whether the interface objects are already installed */
     617           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     618           0 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::XPathEvaluator)) {
     619           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     620           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     621             :   }
     622             : 
     623             :   /*
     624             :    * The object might _still_ be null, but that's OK.
     625             :    *
     626             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     627             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     628             :    * changed after they have been set.
     629             :    *
     630             :    * Calling address() avoids the read read barrier that does gray
     631             :    * unmarking, but it's not possible for the object to be gray here.
     632             :    */
     633             : 
     634           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::XPathEvaluator);
     635           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     636           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     637             : }
     638             : 
     639             : JSObject*
     640           0 : GetConstructorObject(JSContext* aCx)
     641             : {
     642           0 :   return GetConstructorObjectHandle(aCx);
     643             : }
     644             : 
     645             : } // namespace XPathEvaluatorBinding
     646             : 
     647             : 
     648             : 
     649             : } // namespace dom
     650             : } // namespace mozilla

Generated by: LCOV version 1.13