LCOV - code coverage report
Current view: top level - obj-x86_64-pc-linux-gnu/dom/bindings - FileBinding.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 26 462 5.6 %
Date: 2017-07-14 16:53:18 Functions: 3 34 8.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM File.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "BlobBinding.h"
       5             : #include "FileBinding.h"
       6             : #include "WrapperFactory.h"
       7             : #include "mozilla/OwningNonNull.h"
       8             : #include "mozilla/dom/BindingUtils.h"
       9             : #include "mozilla/dom/DOMJSClass.h"
      10             : #include "mozilla/dom/Date.h"
      11             : #include "mozilla/dom/Directory.h"
      12             : #include "mozilla/dom/File.h"
      13             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      14             : #include "mozilla/dom/PrimitiveConversions.h"
      15             : #include "mozilla/dom/Promise.h"
      16             : #include "mozilla/dom/ScriptSettings.h"
      17             : #include "mozilla/dom/SimpleGlobalObject.h"
      18             : #include "mozilla/dom/ToJSValue.h"
      19             : #include "mozilla/dom/UnionConversions.h"
      20             : #include "mozilla/dom/XrayExpandoClass.h"
      21             : #include "nsContentUtils.h"
      22             : #include "nsIDocument.h"
      23             : #include "nsIFile.h"
      24             : 
      25             : namespace mozilla {
      26             : namespace dom {
      27             : 
      28             : 
      29           0 : FilePropertyBag::FilePropertyBag()
      30             : {
      31             :   // Safe to pass a null context if we pass a null value
      32           0 :   Init(nullptr, JS::NullHandleValue);
      33           0 : }
      34             : 
      35             : 
      36             : 
      37             : bool
      38           0 : FilePropertyBag::InitIds(JSContext* cx, FilePropertyBagAtoms* atomsCache)
      39             : {
      40           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      41             : 
      42             :   // Initialize these in reverse order so that any failure leaves the first one
      43             :   // uninitialized.
      44           0 :   if (!atomsCache->type_id.init(cx, "type") ||
      45           0 :       !atomsCache->lastModified_id.init(cx, "lastModified")) {
      46           0 :     return false;
      47             :   }
      48           0 :   return true;
      49             : }
      50             : 
      51             : bool
      52           0 : FilePropertyBag::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      53             : {
      54             :   // Passing a null JSContext is OK only if we're initing from null,
      55             :   // Since in that case we will not have to do any property gets
      56             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      57             :   // checkers by static analysis tools
      58           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      59           0 :   FilePropertyBagAtoms* atomsCache = nullptr;
      60           0 :   if (cx) {
      61           0 :     atomsCache = GetAtomCache<FilePropertyBagAtoms>(cx);
      62           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      63           0 :       return false;
      64             :     }
      65             :   }
      66             : 
      67           0 :   if (!IsConvertibleToDictionary(val)) {
      68           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      69             :   }
      70             : 
      71           0 :   bool isNull = val.isNullOrUndefined();
      72             :   // We only need these if !isNull, in which case we have |cx|.
      73           0 :   Maybe<JS::Rooted<JSObject *> > object;
      74           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      75           0 :   if (!isNull) {
      76           0 :     MOZ_ASSERT(cx);
      77           0 :     object.emplace(cx, &val.toObject());
      78           0 :     temp.emplace(cx);
      79             :   }
      80           0 :   if (!isNull) {
      81           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->lastModified_id, temp.ptr())) {
      82           0 :       return false;
      83             :     }
      84             :   }
      85           0 :   if (!isNull && !temp->isUndefined()) {
      86           0 :     mLastModified.Construct();
      87           0 :     if (!ValueToPrimitive<int64_t, eDefault>(cx, temp.ref(), &(mLastModified.Value()))) {
      88           0 :       return false;
      89             :     }
      90           0 :     mIsAnyMemberPresent = true;
      91             :   }
      92             : 
      93           0 :   if (!isNull) {
      94           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->type_id, temp.ptr())) {
      95           0 :       return false;
      96             :     }
      97             :   }
      98           0 :   if (!isNull && !temp->isUndefined()) {
      99           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mType)) {
     100           0 :       return false;
     101             :     }
     102             :   } else {
     103             :     static const char16_t data[] = { 0 };
     104           0 :     mType.Rebind(data, ArrayLength(data) - 1);
     105             :   }
     106           0 :   mIsAnyMemberPresent = true;
     107           0 :   return true;
     108             : }
     109             : 
     110             : bool
     111           0 : FilePropertyBag::Init(const nsAString& aJSON)
     112             : {
     113           0 :   AutoJSAPI jsapi;
     114           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     115           0 :   if (!cleanGlobal) {
     116           0 :     return false;
     117             :   }
     118           0 :   if (!jsapi.Init(cleanGlobal)) {
     119           0 :     return false;
     120             :   }
     121           0 :   JSContext* cx = jsapi.cx();
     122           0 :   JS::Rooted<JS::Value> json(cx);
     123           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     124           0 :   NS_ENSURE_TRUE(ok, false);
     125           0 :   return Init(cx, json);
     126             : }
     127             : 
     128             : bool
     129           0 : FilePropertyBag::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     130             : {
     131           0 :   FilePropertyBagAtoms* atomsCache = GetAtomCache<FilePropertyBagAtoms>(cx);
     132           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     133           0 :     return false;
     134             :   }
     135             : 
     136           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     137           0 :   if (!obj) {
     138           0 :     return false;
     139             :   }
     140           0 :   rval.set(JS::ObjectValue(*obj));
     141             : 
     142           0 :   if (mLastModified.WasPassed()) {
     143             :     do {
     144             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     145           0 :       JS::Rooted<JS::Value> temp(cx);
     146           0 :       int64_t const & currentValue = mLastModified.InternalValue();
     147           0 :       temp.set(JS_NumberValue(double(currentValue)));
     148           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->lastModified_id, temp, JSPROP_ENUMERATE)) {
     149           0 :         return false;
     150             :       }
     151           0 :       break;
     152             :     } while(0);
     153             :   }
     154             : 
     155             :   do {
     156             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     157           0 :     JS::Rooted<JS::Value> temp(cx);
     158           0 :     nsString const & currentValue = mType;
     159           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     160           0 :       return false;
     161             :     }
     162           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->type_id, temp, JSPROP_ENUMERATE)) {
     163           0 :       return false;
     164             :     }
     165           0 :     break;
     166             :   } while(0);
     167             : 
     168           0 :   return true;
     169             : }
     170             : 
     171             : bool
     172           0 : FilePropertyBag::ToJSON(nsAString& aJSON) const
     173             : {
     174           0 :   AutoJSAPI jsapi;
     175           0 :   jsapi.Init();
     176           0 :   JSContext *cx = jsapi.cx();
     177             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     178             :   // because we'll only be creating objects, in ways that have no
     179             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     180             :   // which likewise guarantees no side-effects for the sorts of
     181             :   // things we will pass it.
     182           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     183           0 :   JS::Rooted<JS::Value> val(cx);
     184           0 :   if (!ToObjectInternal(cx, &val)) {
     185           0 :     return false;
     186             :   }
     187           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     188           0 :   return StringifyToJSON(cx, obj, aJSON);
     189             : }
     190             : 
     191             : void
     192           0 : FilePropertyBag::TraceDictionary(JSTracer* trc)
     193             : {
     194           0 : }
     195             : 
     196             : FilePropertyBag&
     197           0 : FilePropertyBag::operator=(const FilePropertyBag& aOther)
     198             : {
     199           0 :   mLastModified.Reset();
     200           0 :   if (aOther.mLastModified.WasPassed()) {
     201           0 :     mLastModified.Construct(aOther.mLastModified.Value());
     202             :   }
     203           0 :   mType = aOther.mType;
     204           0 :   return *this;
     205             : }
     206             : 
     207             : namespace binding_detail {
     208             : } // namespace binding_detail
     209             : 
     210             : 
     211             : 
     212           0 : ChromeFilePropertyBag::ChromeFilePropertyBag()
     213           0 :   : FilePropertyBag(FastDictionaryInitializer())
     214             : {
     215             :   // Safe to pass a null context if we pass a null value
     216           0 :   Init(nullptr, JS::NullHandleValue);
     217           0 : }
     218             : 
     219             : 
     220             : 
     221             : bool
     222           0 : ChromeFilePropertyBag::InitIds(JSContext* cx, ChromeFilePropertyBagAtoms* atomsCache)
     223             : {
     224           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     225             : 
     226             :   // Initialize these in reverse order so that any failure leaves the first one
     227             :   // uninitialized.
     228           0 :   if (!atomsCache->name_id.init(cx, "name") ||
     229           0 :       !atomsCache->existenceCheck_id.init(cx, "existenceCheck")) {
     230           0 :     return false;
     231             :   }
     232           0 :   return true;
     233             : }
     234             : 
     235             : bool
     236           0 : ChromeFilePropertyBag::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     237             : {
     238             :   // Passing a null JSContext is OK only if we're initing from null,
     239             :   // Since in that case we will not have to do any property gets
     240             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     241             :   // checkers by static analysis tools
     242           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     243           0 :   ChromeFilePropertyBagAtoms* atomsCache = nullptr;
     244           0 :   if (cx) {
     245           0 :     atomsCache = GetAtomCache<ChromeFilePropertyBagAtoms>(cx);
     246           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     247           0 :       return false;
     248             :     }
     249             :   }
     250             : 
     251             :   // Per spec, we init the parent's members first
     252           0 :   if (!FilePropertyBag::Init(cx, val)) {
     253           0 :     return false;
     254             :   }
     255             : 
     256           0 :   bool isNull = val.isNullOrUndefined();
     257             :   // We only need these if !isNull, in which case we have |cx|.
     258           0 :   Maybe<JS::Rooted<JSObject *> > object;
     259           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     260           0 :   if (!isNull) {
     261           0 :     MOZ_ASSERT(cx);
     262           0 :     object.emplace(cx, &val.toObject());
     263           0 :     temp.emplace(cx);
     264             :   }
     265           0 :   if (!isNull) {
     266           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->existenceCheck_id, temp.ptr())) {
     267           0 :       return false;
     268             :     }
     269             :   }
     270           0 :   if (!isNull && !temp->isUndefined()) {
     271           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mExistenceCheck)) {
     272           0 :       return false;
     273             :     }
     274             :   } else {
     275           0 :     mExistenceCheck = true;
     276             :   }
     277           0 :   mIsAnyMemberPresent = true;
     278             : 
     279           0 :   if (!isNull) {
     280           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->name_id, temp.ptr())) {
     281           0 :       return false;
     282             :     }
     283             :   }
     284           0 :   if (!isNull && !temp->isUndefined()) {
     285           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mName)) {
     286           0 :       return false;
     287             :     }
     288             :   } else {
     289             :     static const char16_t data[] = { 0 };
     290           0 :     mName.Rebind(data, ArrayLength(data) - 1);
     291             :   }
     292           0 :   mIsAnyMemberPresent = true;
     293           0 :   return true;
     294             : }
     295             : 
     296             : bool
     297           0 : ChromeFilePropertyBag::Init(const nsAString& aJSON)
     298             : {
     299           0 :   AutoJSAPI jsapi;
     300           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     301           0 :   if (!cleanGlobal) {
     302           0 :     return false;
     303             :   }
     304           0 :   if (!jsapi.Init(cleanGlobal)) {
     305           0 :     return false;
     306             :   }
     307           0 :   JSContext* cx = jsapi.cx();
     308           0 :   JS::Rooted<JS::Value> json(cx);
     309           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     310           0 :   NS_ENSURE_TRUE(ok, false);
     311           0 :   return Init(cx, json);
     312             : }
     313             : 
     314             : bool
     315           0 : ChromeFilePropertyBag::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     316             : {
     317           0 :   ChromeFilePropertyBagAtoms* atomsCache = GetAtomCache<ChromeFilePropertyBagAtoms>(cx);
     318           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     319           0 :     return false;
     320             :   }
     321             : 
     322             :   // Per spec, we define the parent's members first
     323           0 :   if (!FilePropertyBag::ToObjectInternal(cx, rval)) {
     324           0 :     return false;
     325             :   }
     326           0 :   JS::Rooted<JSObject*> obj(cx, &rval.toObject());
     327             : 
     328             :   do {
     329             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     330           0 :     JS::Rooted<JS::Value> temp(cx);
     331           0 :     bool const & currentValue = mExistenceCheck;
     332           0 :     temp.setBoolean(currentValue);
     333           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->existenceCheck_id, temp, JSPROP_ENUMERATE)) {
     334           0 :       return false;
     335             :     }
     336           0 :     break;
     337             :   } while(0);
     338             : 
     339             :   do {
     340             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     341           0 :     JS::Rooted<JS::Value> temp(cx);
     342           0 :     nsString const & currentValue = mName;
     343           0 :     if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     344           0 :       return false;
     345             :     }
     346           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->name_id, temp, JSPROP_ENUMERATE)) {
     347           0 :       return false;
     348             :     }
     349           0 :     break;
     350             :   } while(0);
     351             : 
     352           0 :   return true;
     353             : }
     354             : 
     355             : bool
     356           0 : ChromeFilePropertyBag::ToJSON(nsAString& aJSON) const
     357             : {
     358           0 :   AutoJSAPI jsapi;
     359           0 :   jsapi.Init();
     360           0 :   JSContext *cx = jsapi.cx();
     361             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     362             :   // because we'll only be creating objects, in ways that have no
     363             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     364             :   // which likewise guarantees no side-effects for the sorts of
     365             :   // things we will pass it.
     366           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     367           0 :   JS::Rooted<JS::Value> val(cx);
     368           0 :   if (!ToObjectInternal(cx, &val)) {
     369           0 :     return false;
     370             :   }
     371           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     372           0 :   return StringifyToJSON(cx, obj, aJSON);
     373             : }
     374             : 
     375             : void
     376           0 : ChromeFilePropertyBag::TraceDictionary(JSTracer* trc)
     377             : {
     378           0 :   FilePropertyBag::TraceDictionary(trc);
     379           0 : }
     380             : 
     381             : ChromeFilePropertyBag&
     382           0 : ChromeFilePropertyBag::operator=(const ChromeFilePropertyBag& aOther)
     383             : {
     384           0 :   FilePropertyBag::operator=(aOther);
     385           0 :   mExistenceCheck = aOther.mExistenceCheck;
     386           0 :   mName = aOther.mName;
     387           0 :   return *this;
     388             : }
     389             : 
     390             : namespace binding_detail {
     391             : } // namespace binding_detail
     392             : 
     393             : 
     394             : namespace FileBinding {
     395             : 
     396             : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<BlobBinding::NativeType>::value,
     397             :               "Can't inherit from an interface with a different ownership model.");
     398             : 
     399             : static bool
     400           0 : get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::File* self, JSJitGetterCallArgs args)
     401             : {
     402           0 :   DOMString result;
     403           0 :   self->GetName(result);
     404           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     405           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     406           0 :     return false;
     407             :   }
     408           0 :   return true;
     409             : }
     410             : 
     411             : static const JSJitInfo name_getterinfo = {
     412             :   { (JSJitGetterOp)get_name },
     413             :   { prototypes::id::File },
     414             :   { PrototypeTraits<prototypes::id::File>::Depth },
     415             :   JSJitInfo::Getter,
     416             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     417             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     418             :   false,  /* isInfallible. False in setters. */
     419             :   false,  /* isMovable.  Not relevant for setters. */
     420             :   false, /* isEliminatable.  Not relevant for setters. */
     421             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     422             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     423             :   false,  /* isTypedMethod.  Only relevant for methods. */
     424             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     425             : };
     426             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     427             : static_assert(0 < 1, "There is no slot for us");
     428             : 
     429             : static bool
     430           0 : get_lastModified(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::File* self, JSJitGetterCallArgs args)
     431             : {
     432           0 :   binding_detail::FastErrorResult rv;
     433           0 :   int64_t result(self->GetLastModified(rv));
     434           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     435           0 :     return false;
     436             :   }
     437           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     438           0 :   args.rval().set(JS_NumberValue(double(result)));
     439           0 :   return true;
     440             : }
     441             : 
     442             : static const JSJitInfo lastModified_getterinfo = {
     443             :   { (JSJitGetterOp)get_lastModified },
     444             :   { prototypes::id::File },
     445             :   { PrototypeTraits<prototypes::id::File>::Depth },
     446             :   JSJitInfo::Getter,
     447             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     448             :   JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
     449             :   false,  /* isInfallible. False in setters. */
     450             :   false,  /* isMovable.  Not relevant for setters. */
     451             :   false, /* isEliminatable.  Not relevant for setters. */
     452             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     453             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     454             :   false,  /* isTypedMethod.  Only relevant for methods. */
     455             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     456             : };
     457             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     458             : static_assert(0 < 1, "There is no slot for us");
     459             : 
     460             : static bool
     461           0 : get_lastModifiedDate(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::File* self, JSJitGetterCallArgs args)
     462             : {
     463           0 :   DeprecationWarning(cx, obj, nsIDocument::eFileLastModifiedDate);
     464           0 :   binding_detail::FastErrorResult rv;
     465           0 :   Date result(self->GetLastModifiedDate(rv));
     466           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     467           0 :     return false;
     468             :   }
     469           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     470           0 :   if (!result.ToDateObject(cx, args.rval())) {
     471           0 :     return false;
     472             :   }
     473           0 :   return true;
     474             : }
     475             : 
     476             : static const JSJitInfo lastModifiedDate_getterinfo = {
     477             :   { (JSJitGetterOp)get_lastModifiedDate },
     478             :   { prototypes::id::File },
     479             :   { PrototypeTraits<prototypes::id::File>::Depth },
     480             :   JSJitInfo::Getter,
     481             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     482             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     483             :   false,  /* isInfallible. False in setters. */
     484             :   false,  /* isMovable.  Not relevant for setters. */
     485             :   false, /* isEliminatable.  Not relevant for setters. */
     486             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     487             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     488             :   false,  /* isTypedMethod.  Only relevant for methods. */
     489             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     490             : };
     491             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     492             : static_assert(0 < 1, "There is no slot for us");
     493             : 
     494             : static bool
     495           0 : get_webkitRelativePath(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::File* self, JSJitGetterCallArgs args)
     496             : {
     497           0 :   DOMString result;
     498           0 :   self->GetRelativePath(result);
     499           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     500           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     501           0 :     return false;
     502             :   }
     503           0 :   return true;
     504             : }
     505             : 
     506             : static const JSJitInfo webkitRelativePath_getterinfo = {
     507             :   { (JSJitGetterOp)get_webkitRelativePath },
     508             :   { prototypes::id::File },
     509             :   { PrototypeTraits<prototypes::id::File>::Depth },
     510             :   JSJitInfo::Getter,
     511             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     512             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     513             :   false,  /* isInfallible. False in setters. */
     514             :   false,  /* isMovable.  Not relevant for setters. */
     515             :   false, /* isEliminatable.  Not relevant for setters. */
     516             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     517             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     518             :   false,  /* isTypedMethod.  Only relevant for methods. */
     519             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     520             : };
     521             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     522             : static_assert(0 < 1, "There is no slot for us");
     523             : 
     524             : static bool
     525           0 : get_mozFullPath(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::File* self, JSJitGetterCallArgs args)
     526             : {
     527           0 :   binding_detail::FastErrorResult rv;
     528           0 :   DOMString result;
     529           0 :   self->GetMozFullPath(result, SystemCallerGuarantee(), rv);
     530           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     531           0 :     return false;
     532             :   }
     533           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     534           0 :   if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
     535           0 :     return false;
     536             :   }
     537           0 :   return true;
     538             : }
     539             : 
     540             : static const JSJitInfo mozFullPath_getterinfo = {
     541             :   { (JSJitGetterOp)get_mozFullPath },
     542             :   { prototypes::id::File },
     543             :   { PrototypeTraits<prototypes::id::File>::Depth },
     544             :   JSJitInfo::Getter,
     545             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     546             :   JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
     547             :   false,  /* isInfallible. False in setters. */
     548             :   false,  /* isMovable.  Not relevant for setters. */
     549             :   false, /* isEliminatable.  Not relevant for setters. */
     550             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     551             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     552             :   false,  /* isTypedMethod.  Only relevant for methods. */
     553             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     554             : };
     555             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     556             : static_assert(0 < 1, "There is no slot for us");
     557             : 
     558             : static bool
     559           0 : createFromNsIFile(JSContext* cx, unsigned argc, JS::Value* vp)
     560             : {
     561           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     562           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     563             : 
     564           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     565           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "File.createFromNsIFile");
     566             :   }
     567           0 :   GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
     568           0 :   if (global.Failed()) {
     569           0 :     return false;
     570             :   }
     571             : 
     572             :   nsIFile* arg0;
     573           0 :   RefPtr<nsIFile> arg0_holder;
     574           0 :   if (args[0].isObject()) {
     575           0 :     JS::Rooted<JSObject*> source(cx, &args[0].toObject());
     576           0 :     if (NS_FAILED(UnwrapArg<nsIFile>(cx, source, getter_AddRefs(arg0_holder)))) {
     577           0 :       ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of File.createFromNsIFile", "nsIFile");
     578           0 :       return false;
     579             :     }
     580           0 :     MOZ_ASSERT(arg0_holder);
     581           0 :     arg0 = arg0_holder;
     582             :   } else {
     583           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of File.createFromNsIFile");
     584           0 :     return false;
     585             :   }
     586           0 :   binding_detail::FastChromeFilePropertyBag arg1;
     587           0 :   if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of File.createFromNsIFile", false)) {
     588           0 :     return false;
     589             :   }
     590           0 :   binding_detail::FastErrorResult rv;
     591           0 :   auto result(StrongOrRawPtr<Promise>(mozilla::dom::File::CreateFromNsIFile(global, NonNullHelper(arg0), Constify(arg1), SystemCallerGuarantee(), rv)));
     592           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     593           0 :     return false;
     594             :   }
     595           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     596           0 :   if (!ToJSValue(cx, result, args.rval())) {
     597           0 :     return false;
     598             :   }
     599           0 :   return true;
     600             : }
     601             : 
     602             : 
     603             : static const JSJitInfo createFromNsIFile_methodinfo = {
     604             :   { (JSJitGetterOp)createFromNsIFile },
     605             :   { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
     606             :   JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
     607             :   false, false, 0
     608             : };
     609             : 
     610             : static bool
     611           0 : createFromFileName(JSContext* cx, unsigned argc, JS::Value* vp)
     612             : {
     613           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     614           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     615             : 
     616           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     617           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "File.createFromFileName");
     618             :   }
     619           0 :   GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
     620           0 :   if (global.Failed()) {
     621           0 :     return false;
     622             :   }
     623             : 
     624           0 :   binding_detail::FakeString arg0;
     625           0 :   if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
     626           0 :     return false;
     627             :   }
     628           0 :   NormalizeUSVString(arg0);
     629           0 :   binding_detail::FastChromeFilePropertyBag arg1;
     630           0 :   if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of File.createFromFileName", false)) {
     631           0 :     return false;
     632             :   }
     633           0 :   binding_detail::FastErrorResult rv;
     634           0 :   auto result(StrongOrRawPtr<Promise>(mozilla::dom::File::CreateFromFileName(global, Constify(arg0), Constify(arg1), SystemCallerGuarantee(), rv)));
     635           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     636           0 :     return false;
     637             :   }
     638           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     639           0 :   if (!ToJSValue(cx, result, args.rval())) {
     640           0 :     return false;
     641             :   }
     642           0 :   return true;
     643             : }
     644             : 
     645             : 
     646             : static const JSJitInfo createFromFileName_methodinfo = {
     647             :   { (JSJitGetterOp)createFromFileName },
     648             :   { prototypes::id::_ID_Count }, { 0 }, JSJitInfo::StaticMethod,
     649             :   JSJitInfo::AliasEverything, JSVAL_TYPE_MISSING, false, false,
     650             :   false, false, 0
     651             : };
     652             : 
     653             : static bool
     654           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     655             : {
     656           0 :   mozilla::dom::File* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::File>(obj);
     657             :   // We don't want to preserve if we don't have a wrapper, and we
     658             :   // obviously can't preserve if we're not initialized.
     659           0 :   if (self && self->GetWrapperPreserveColor()) {
     660           0 :     PreserveWrapper(self);
     661             :   }
     662           0 :   return true;
     663             : }
     664             : 
     665             : static void
     666           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     667             : {
     668           0 :   mozilla::dom::File* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::File>(obj);
     669           0 :   if (self) {
     670           0 :     ClearWrapper(self, self, obj);
     671           0 :     AddForDeferredFinalization<mozilla::dom::File>(self);
     672             :   }
     673           0 : }
     674             : 
     675             : static void
     676           0 : _objectMoved(JSObject* obj, const JSObject* old)
     677             : {
     678           0 :   mozilla::dom::File* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::File>(obj);
     679           0 :   if (self) {
     680           0 :     UpdateWrapper(self, self, obj, old);
     681             :   }
     682           0 : }
     683             : 
     684             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     685             : #if defined(__clang__)
     686             : #pragma clang diagnostic push
     687             : #pragma clang diagnostic ignored "-Wmissing-braces"
     688             : #endif
     689             : static const JSFunctionSpec sChromeStaticMethods_specs[] = {
     690             :   JS_FNSPEC("createFromNsIFile", StaticMethodPromiseWrapper, &createFromNsIFile_methodinfo, 1, JSPROP_ENUMERATE, nullptr),
     691             :   JS_FNSPEC("createFromFileName", StaticMethodPromiseWrapper, &createFromFileName_methodinfo, 1, JSPROP_ENUMERATE, nullptr),
     692             :   JS_FS_END
     693             : };
     694             : #if defined(__clang__)
     695             : #pragma clang diagnostic pop
     696             : #endif
     697             : 
     698             : static PrefableDisablers sChromeStaticMethods_disablers0 = {
     699             :   true, false, GlobalNames::DedicatedWorkerGlobalScope | GlobalNames::ServiceWorkerGlobalScope | GlobalNames::SharedWorkerGlobalScope, nullptr
     700             : };
     701             : 
     702             : // Can't be const because the pref-enabled boolean needs to be writable
     703             : static Prefable<const JSFunctionSpec> sChromeStaticMethods[] = {
     704             :   { &sChromeStaticMethods_disablers0, &sChromeStaticMethods_specs[0] },
     705             :   { nullptr, nullptr }
     706             : };
     707             : 
     708             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     709             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     710             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     711             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     712             : 
     713             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     714             : #if defined(__clang__)
     715             : #pragma clang diagnostic push
     716             : #pragma clang diagnostic ignored "-Wmissing-braces"
     717             : #endif
     718             : static const JSPropertySpec sAttributes_specs[] = {
     719             :   { "name", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &name_getterinfo, nullptr, nullptr },
     720             :   { "lastModified", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &lastModified_getterinfo, nullptr, nullptr },
     721             :   { "lastModifiedDate", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &lastModifiedDate_getterinfo, nullptr, nullptr },
     722             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr },
     723             :   { "webkitRelativePath", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &webkitRelativePath_getterinfo, nullptr, nullptr },
     724             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     725             : };
     726             : #if defined(__clang__)
     727             : #pragma clang diagnostic pop
     728             : #endif
     729             : 
     730             : static PrefableDisablers sAttributes_disablers4 = {
     731             :   true, false, 0, &mozilla::dom::Directory::WebkitBlinkDirectoryPickerEnabled
     732             : };
     733             : 
     734             : // Can't be const because the pref-enabled boolean needs to be writable
     735             : static Prefable<const JSPropertySpec> sAttributes[] = {
     736             :   { nullptr, &sAttributes_specs[0] },
     737             :   { &sAttributes_disablers4, &sAttributes_specs[4] },
     738             :   { nullptr, nullptr }
     739             : };
     740             : 
     741             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     742             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     743             : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     744             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     745             : 
     746             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     747             : #if defined(__clang__)
     748             : #pragma clang diagnostic push
     749             : #pragma clang diagnostic ignored "-Wmissing-braces"
     750             : #endif
     751             : static const JSPropertySpec sChromeAttributes_specs[] = {
     752             :   { "mozFullPath", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &mozFullPath_getterinfo, nullptr, nullptr },
     753             :   { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
     754             : };
     755             : #if defined(__clang__)
     756             : #pragma clang diagnostic pop
     757             : #endif
     758             : 
     759             : 
     760             : // Can't be const because the pref-enabled boolean needs to be writable
     761             : static Prefable<const JSPropertySpec> sChromeAttributes[] = {
     762             :   { nullptr, &sChromeAttributes_specs[0] },
     763             :   { nullptr, nullptr }
     764             : };
     765             : 
     766             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     767             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     768             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     769             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     770             : 
     771             : 
     772             : static uint16_t sNativeProperties_sortedPropertyIndices[4];
     773             : static PropertyInfo sNativeProperties_propertyInfos[4];
     774             : 
     775             : static const NativePropertiesN<1> sNativeProperties = {
     776             :   false, 0,
     777             :   false, 0,
     778             :   false, 0,
     779             :   true,  0 /* sAttributes */,
     780             :   false, 0,
     781             :   false, 0,
     782             :   false, 0,
     783             :   -1,
     784             :   4,
     785             :   sNativeProperties_sortedPropertyIndices,
     786             :   {
     787             :     { sAttributes, &sNativeProperties_propertyInfos[0] }
     788             :   }
     789             : };
     790             : static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     791             :     "We have a property info count that is oversized");
     792             : 
     793             : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[3];
     794             : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[3];
     795             : 
     796             : static const NativePropertiesN<2> sChromeOnlyNativeProperties = {
     797             :   true,  0 /* sChromeStaticMethods */,
     798             :   false, 0,
     799             :   false, 0,
     800             :   true,  1 /* sChromeAttributes */,
     801             :   false, 0,
     802             :   false, 0,
     803             :   false, 0,
     804             :   -1,
     805             :   3,
     806             :   sChromeOnlyNativeProperties_sortedPropertyIndices,
     807             :   {
     808             :     { sChromeStaticMethods, &sChromeOnlyNativeProperties_propertyInfos[0] },
     809             :     { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[2] }
     810             :   }
     811             : };
     812             : static_assert(3 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
     813             :     "We have a property info count that is oversized");
     814             : 
     815             : static bool
     816           0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
     817             : {
     818           0 :   JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
     819           0 :   JS::Rooted<JSObject*> obj(cx, &args.callee());
     820           0 :   if (!args.isConstructing()) {
     821             :     // XXXbz wish I could get the name from the callee instead of
     822             :     // Adding more relocations
     823           0 :     return ThrowConstructorWithoutNew(cx, "File");
     824             :   }
     825             : 
     826           0 :   GlobalObject global(cx, obj);
     827           0 :   if (global.Failed()) {
     828           0 :     return false;
     829             :   }
     830             : 
     831           0 :   JS::Rooted<JSObject*> desiredProto(cx);
     832           0 :   if (!GetDesiredProto(cx, args, &desiredProto)) {
     833           0 :     return false;
     834             :   }
     835             : 
     836           0 :   if (MOZ_UNLIKELY(args.length() < 2)) {
     837           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "File");
     838             :   }
     839           0 :   bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
     840           0 :   binding_detail::AutoSequence<OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString> arg0;
     841           0 :   SequenceRooter<OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString> arg0_holder(cx, &arg0);
     842           0 :   if (args[0].isObject()) {
     843           0 :     JS::ForOfIterator iter(cx);
     844           0 :     if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
     845           0 :       return false;
     846             :     }
     847           0 :     if (!iter.valueIsIterable()) {
     848           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of File.constructor");
     849           0 :       return false;
     850             :     }
     851           0 :     binding_detail::AutoSequence<OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString> &arr = arg0;
     852           0 :     JS::Rooted<JS::Value> temp(cx);
     853             :     while (true) {
     854             :       bool done;
     855           0 :       if (!iter.next(&temp, &done)) {
     856           0 :         return false;
     857             :       }
     858           0 :       if (done) {
     859           0 :         break;
     860             :       }
     861           0 :       OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString* slotPtr = arr.AppendElement(mozilla::fallible);
     862           0 :       if (!slotPtr) {
     863           0 :         JS_ReportOutOfMemory(cx);
     864           0 :         return false;
     865             :       }
     866           0 :       OwningArrayBufferViewOrArrayBufferOrBlobOrUSVString& slot = *slotPtr;
     867             :       {
     868           0 :         bool done = false, failed = false, tryNext;
     869           0 :         if (temp.isObject()) {
     870           0 :           done = (failed = !slot.TrySetToArrayBufferView(cx, temp, tryNext, false)) || !tryNext ||
     871           0 :                  (failed = !slot.TrySetToArrayBuffer(cx, temp, tryNext, false)) || !tryNext ||
     872           0 :                  (failed = !slot.TrySetToBlob(cx, temp, tryNext, false)) || !tryNext;
     873             : 
     874             :         }
     875           0 :         if (!done) {
     876             :           do {
     877           0 :             done = (failed = !slot.TrySetToUSVString(cx, temp, tryNext)) || !tryNext;
     878           0 :             break;
     879             :           } while (0);
     880             :         }
     881           0 :         if (failed) {
     882           0 :           return false;
     883             :         }
     884           0 :         if (!done) {
     885           0 :           ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Element of argument 1 of File.constructor", "ArrayBufferView, ArrayBuffer, Blob");
     886           0 :           return false;
     887             :         }
     888             :       }
     889           0 :     }
     890             :   } else {
     891           0 :     ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of File.constructor");
     892           0 :     return false;
     893             :   }
     894           0 :   binding_detail::FakeString arg1;
     895           0 :   if (!ConvertJSValueToString(cx, args[1], eStringify, eStringify, arg1)) {
     896           0 :     return false;
     897             :   }
     898           0 :   NormalizeUSVString(arg1);
     899           0 :   binding_detail::FastFilePropertyBag arg2;
     900           0 :   if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue,  "Argument 3 of File.constructor", false)) {
     901           0 :     return false;
     902             :   }
     903           0 :   Maybe<JSAutoCompartment> ac;
     904           0 :   if (objIsXray) {
     905           0 :     obj = js::CheckedUnwrap(obj);
     906           0 :     if (!obj) {
     907           0 :       return false;
     908             :     }
     909           0 :     ac.emplace(cx, obj);
     910           0 :     if (!JS_WrapObject(cx, &desiredProto)) {
     911           0 :       return false;
     912             :     }
     913           0 :     for (uint32_t indexName0 = 0; indexName0 < arg0.Length(); ++indexName0) {
     914           0 :       if (arg0[indexName0].IsArrayBufferView()) {
     915           0 :         if (!arg0[indexName0].GetAsArrayBufferView().WrapIntoNewCompartment(cx)) {
     916           0 :           return false;
     917             :         }
     918             :       }
     919           0 :       else if (arg0[indexName0].IsArrayBuffer()) {
     920           0 :         if (!arg0[indexName0].GetAsArrayBuffer().WrapIntoNewCompartment(cx)) {
     921           0 :           return false;
     922             :         }
     923             :       }
     924             :     }
     925             :   }
     926           0 :   binding_detail::FastErrorResult rv;
     927           0 :   auto result(StrongOrRawPtr<mozilla::dom::File>(mozilla::dom::File::Constructor(global, Constify(arg0), Constify(arg1), Constify(arg2), rv)));
     928           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     929           0 :     return false;
     930             :   }
     931           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     932             :   static_assert(!IsPointer<decltype(result)>::value,
     933             :                 "NewObject implies that we need to keep the object alive with a strong reference.");
     934           0 :   if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
     935           0 :     MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     936           0 :     return false;
     937             :   }
     938           0 :   return true;
     939             : }
     940             : 
     941             : static const js::ClassOps sInterfaceObjectClassOps = {
     942             :     nullptr,               /* addProperty */
     943             :     nullptr,               /* delProperty */
     944             :     nullptr,               /* getProperty */
     945             :     nullptr,               /* setProperty */
     946             :     nullptr,               /* enumerate */
     947             :     nullptr,               /* newEnumerate */
     948             :     nullptr,               /* resolve */
     949             :     nullptr,               /* mayResolve */
     950             :     nullptr,               /* finalize */
     951             :     _constructor, /* call */
     952             :     nullptr,               /* hasInstance */
     953             :     _constructor, /* construct */
     954             :     nullptr,               /* trace */
     955             : };
     956             : 
     957             : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
     958             :   {
     959             :     "Function",
     960             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
     961             :     &sInterfaceObjectClassOps,
     962             :     JS_NULL_CLASS_SPEC,
     963             :     JS_NULL_CLASS_EXT,
     964             :     &sInterfaceObjectClassObjectOps
     965             :   },
     966             :   eInterface,
     967             :   true,
     968             :   prototypes::id::File,
     969             :   PrototypeTraits<prototypes::id::File>::Depth,
     970             :   sNativePropertyHooks,
     971             :   "function File() {\n    [native code]\n}",
     972             :   BlobBinding::GetConstructorObject
     973             : };
     974             : 
     975             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     976             :   {
     977             :     "FilePrototype",
     978             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     979             :     JS_NULL_CLASS_OPS,
     980             :     JS_NULL_CLASS_SPEC,
     981             :     JS_NULL_CLASS_EXT,
     982             :     JS_NULL_OBJECT_OPS
     983             :   },
     984             :   eInterfacePrototype,
     985             :   false,
     986             :   prototypes::id::File,
     987             :   PrototypeTraits<prototypes::id::File>::Depth,
     988             :   sNativePropertyHooks,
     989             :   "[object FilePrototype]",
     990             :   BlobBinding::GetProtoObject
     991             : };
     992             : 
     993             : JSObject*
     994           0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
     995             : {
     996           0 :   return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
     997             : }
     998             : 
     999             : static const js::ClassOps sClassOps = {
    1000             :   _addProperty, /* addProperty */
    1001             :   nullptr,               /* delProperty */
    1002             :   nullptr,               /* getProperty */
    1003             :   nullptr,               /* setProperty */
    1004             :   nullptr,               /* enumerate */
    1005             :   nullptr, /* newEnumerate */
    1006             :   nullptr, /* resolve */
    1007             :   nullptr, /* mayResolve */
    1008             :   _finalize, /* finalize */
    1009             :   nullptr, /* call */
    1010             :   nullptr,               /* hasInstance */
    1011             :   nullptr,               /* construct */
    1012             :   nullptr, /* trace */
    1013             : };
    1014             : 
    1015             : static const js::ClassExtension sClassExtension = {
    1016             :   nullptr, /* weakmapKeyDelegateOp */
    1017             :   _objectMoved /* objectMovedOp */
    1018             : };
    1019             : 
    1020             : static const DOMJSClass sClass = {
    1021             :   { "File",
    1022             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
    1023             :     &sClassOps,
    1024             :     JS_NULL_CLASS_SPEC,
    1025             :     &sClassExtension,
    1026             :     JS_NULL_OBJECT_OPS
    1027             :   },
    1028             :   { prototypes::id::Blob, prototypes::id::File, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
    1029             :   IsBaseOf<nsISupports, mozilla::dom::File >::value,
    1030             :   sNativePropertyHooks,
    1031             :   FindAssociatedGlobalForNative<mozilla::dom::File>::Get,
    1032             :   GetProtoObjectHandle,
    1033             :   GetCCParticipant<mozilla::dom::File>::Get()
    1034             : };
    1035             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
    1036             :               "Must have the right minimal number of reserved slots.");
    1037             : static_assert(1 >= 1,
    1038             :               "Must have enough reserved slots.");
    1039             : 
    1040             : const JSClass*
    1041           0 : GetJSClass()
    1042             : {
    1043           0 :   return sClass.ToJSClass();
    1044             : }
    1045             : 
    1046             : bool
    1047           0 : Wrap(JSContext* aCx, mozilla::dom::File* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
    1048             : {
    1049             :   MOZ_ASSERT(static_cast<mozilla::dom::File*>(aObject) ==
    1050             :              reinterpret_cast<mozilla::dom::File*>(aObject),
    1051             :              "Multiple inheritance for mozilla::dom::File is broken.");
    1052             :   MOZ_ASSERT(static_cast<mozilla::dom::Blob*>(aObject) ==
    1053             :              reinterpret_cast<mozilla::dom::Blob*>(aObject),
    1054             :              "Multiple inheritance for mozilla::dom::Blob is broken.");
    1055           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
    1056           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
    1057           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
    1058             :              "You should probably not be using Wrap() directly; use "
    1059             :              "GetOrCreateDOMReflector instead");
    1060             : 
    1061           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
    1062             :              "nsISupports must be on our primary inheritance chain");
    1063             : 
    1064           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
    1065           0 :   if (!global) {
    1066           0 :     return false;
    1067             :   }
    1068           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
    1069           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
    1070             : 
    1071             :   // That might have ended up wrapping us already, due to the wonders
    1072             :   // of XBL.  Check for that, and bail out as needed.
    1073           0 :   aReflector.set(aCache->GetWrapper());
    1074           0 :   if (aReflector) {
    1075             : #ifdef DEBUG
    1076           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
    1077             : #endif // DEBUG
    1078           0 :     return true;
    1079             :   }
    1080             : 
    1081           0 :   JSAutoCompartment ac(aCx, global);
    1082           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
    1083           0 :   if (!canonicalProto) {
    1084           0 :     return false;
    1085             :   }
    1086           0 :   JS::Rooted<JSObject*> proto(aCx);
    1087           0 :   if (aGivenProto) {
    1088           0 :     proto = aGivenProto;
    1089             :     // Unfortunately, while aGivenProto was in the compartment of aCx
    1090             :     // coming in, we changed compartments to that of "parent" so may need
    1091             :     // to wrap the proto here.
    1092           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
    1093           0 :       if (!JS_WrapObject(aCx, &proto)) {
    1094           0 :         return false;
    1095             :       }
    1096             :     }
    1097             :   } else {
    1098           0 :     proto = canonicalProto;
    1099             :   }
    1100             : 
    1101           0 :   BindingJSObjectCreator<mozilla::dom::File> creator(aCx);
    1102           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1103           0 :   if (!aReflector) {
    1104           0 :     return false;
    1105             :   }
    1106             : 
    1107           0 :   aCache->SetWrapper(aReflector);
    1108           0 :   creator.InitializationSucceeded();
    1109             : 
    1110           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1111             :              aCache->GetWrapperPreserveColor() == aReflector);
    1112             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1113             :   // otherwise we won't be able to properly recreate it later, since
    1114             :   // we won't know what proto to use.  Note that we don't check
    1115             :   // aGivenProto here, since it's entirely possible (and even
    1116             :   // somewhat common) to have a non-null aGivenProto which is the
    1117             :   // same as canonicalProto.
    1118           0 :   if (proto != canonicalProto) {
    1119           0 :     PreserveWrapper(aObject);
    1120             :   }
    1121             : 
    1122           0 :   return true;
    1123             : }
    1124             : 
    1125             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1126             :   nullptr,
    1127             :   nullptr,
    1128             :   nullptr,
    1129             :   { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
    1130             :   prototypes::id::File,
    1131             :   constructors::id::File,
    1132             :   BlobBinding::sNativePropertyHooks,
    1133             :   &DefaultXrayExpandoObjectClass
    1134             : } };
    1135             : 
    1136             : void
    1137           2 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1138             : {
    1139           2 :   JS::Handle<JSObject*> parentProto(BlobBinding::GetProtoObjectHandle(aCx));
    1140           2 :   if (!parentProto) {
    1141           0 :     return;
    1142             :   }
    1143             : 
    1144           2 :   JS::Handle<JSObject*> constructorProto(BlobBinding::GetConstructorObjectHandle(aCx));
    1145           2 :   if (!constructorProto) {
    1146           0 :     return;
    1147             :   }
    1148             : 
    1149             :   static bool sIdsInited = false;
    1150           2 :   if (!sIdsInited && NS_IsMainThread()) {
    1151           1 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1152           0 :       return;
    1153             :     }
    1154           1 :     if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
    1155           0 :       return;
    1156             :     }
    1157           1 :     sIdsInited = true;
    1158             :   }
    1159             : 
    1160           2 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::File);
    1161           2 :   JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::File);
    1162           4 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1163             :                               &sPrototypeClass.mBase, protoCache,
    1164             :                               constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
    1165             :                               interfaceCache,
    1166             :                               sNativeProperties.Upcast(),
    1167           2 :                               nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
    1168             :                               "File", aDefineOnGlobal,
    1169             :                               nullptr,
    1170           2 :                               false);
    1171             : }
    1172             : 
    1173             : JS::Handle<JSObject*>
    1174           0 : GetProtoObjectHandle(JSContext* aCx)
    1175             : {
    1176             :   /* Get the interface prototype object for this class.  This will create the
    1177             :      object as needed. */
    1178           0 :   bool aDefineOnGlobal = true;
    1179             : 
    1180             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1181           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1182           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1183           0 :     return nullptr;
    1184             :   }
    1185             : 
    1186             :   /* Check to see whether the interface objects are already installed */
    1187           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1188           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::File)) {
    1189           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1190           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1191             :   }
    1192             : 
    1193             :   /*
    1194             :    * The object might _still_ be null, but that's OK.
    1195             :    *
    1196             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1197             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1198             :    * changed after they have been set.
    1199             :    *
    1200             :    * Calling address() avoids the read read barrier that does gray
    1201             :    * unmarking, but it's not possible for the object to be gray here.
    1202             :    */
    1203             : 
    1204           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::File);
    1205           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1206           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1207             : }
    1208             : 
    1209             : JS::Handle<JSObject*>
    1210           2 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
    1211             : {
    1212             :   /* Get the interface object for this class.  This will create the object as
    1213             :      needed. */
    1214             : 
    1215             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1216           2 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1217           2 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1218           0 :     return nullptr;
    1219             :   }
    1220             : 
    1221             :   /* Check to see whether the interface objects are already installed */
    1222           2 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1223           2 :   if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::File)) {
    1224           4 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1225           2 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1226             :   }
    1227             : 
    1228             :   /*
    1229             :    * The object might _still_ be null, but that's OK.
    1230             :    *
    1231             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1232             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1233             :    * changed after they have been set.
    1234             :    *
    1235             :    * Calling address() avoids the read read barrier that does gray
    1236             :    * unmarking, but it's not possible for the object to be gray here.
    1237             :    */
    1238             : 
    1239           2 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::File);
    1240           2 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1241           2 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1242             : }
    1243             : 
    1244             : JSObject*
    1245           2 : GetConstructorObject(JSContext* aCx)
    1246             : {
    1247           2 :   return GetConstructorObjectHandle(aCx);
    1248             : }
    1249             : 
    1250             : } // namespace FileBinding
    1251             : 
    1252             : 
    1253             : 
    1254             : } // namespace dom
    1255             : } // namespace mozilla

Generated by: LCOV version 1.13