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

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

Generated by: LCOV version 1.13