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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM IntlUtils.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "IntlUtilsBinding.h"
       5             : #include "WrapperFactory.h"
       6             : #include "mozilla/OwningNonNull.h"
       7             : #include "mozilla/dom/BindingUtils.h"
       8             : #include "mozilla/dom/DOMJSClass.h"
       9             : #include "mozilla/dom/IntlUtils.h"
      10             : #include "mozilla/dom/NonRefcountedDOMObject.h"
      11             : #include "mozilla/dom/ScriptSettings.h"
      12             : #include "mozilla/dom/SimpleGlobalObject.h"
      13             : #include "mozilla/dom/XrayExpandoClass.h"
      14             : 
      15             : namespace mozilla {
      16             : namespace dom {
      17             : 
      18             : 
      19           0 : DisplayNameOptions::DisplayNameOptions()
      20             : {
      21             :   // Safe to pass a null context if we pass a null value
      22           0 :   Init(nullptr, JS::NullHandleValue);
      23           0 : }
      24             : 
      25             : 
      26             : 
      27             : bool
      28           0 : DisplayNameOptions::InitIds(JSContext* cx, DisplayNameOptionsAtoms* atomsCache)
      29             : {
      30           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      31             : 
      32             :   // Initialize these in reverse order so that any failure leaves the first one
      33             :   // uninitialized.
      34           0 :   if (!atomsCache->style_id.init(cx, "style") ||
      35           0 :       !atomsCache->keys_id.init(cx, "keys")) {
      36           0 :     return false;
      37             :   }
      38           0 :   return true;
      39             : }
      40             : 
      41             : bool
      42           0 : DisplayNameOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      43             : {
      44             :   // Passing a null JSContext is OK only if we're initing from null,
      45             :   // Since in that case we will not have to do any property gets
      46             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      47             :   // checkers by static analysis tools
      48           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      49           0 :   DisplayNameOptionsAtoms* atomsCache = nullptr;
      50           0 :   if (cx) {
      51           0 :     atomsCache = GetAtomCache<DisplayNameOptionsAtoms>(cx);
      52           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      53           0 :       return false;
      54             :     }
      55             :   }
      56             : 
      57           0 :   if (!IsConvertibleToDictionary(val)) {
      58           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      59             :   }
      60             : 
      61           0 :   bool isNull = val.isNullOrUndefined();
      62             :   // We only need these if !isNull, in which case we have |cx|.
      63           0 :   Maybe<JS::Rooted<JSObject *> > object;
      64           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      65           0 :   if (!isNull) {
      66           0 :     MOZ_ASSERT(cx);
      67           0 :     object.emplace(cx, &val.toObject());
      68           0 :     temp.emplace(cx);
      69             :   }
      70           0 :   if (!isNull) {
      71           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->keys_id, temp.ptr())) {
      72           0 :       return false;
      73             :     }
      74             :   }
      75           0 :   if (!isNull && !temp->isUndefined()) {
      76           0 :     mKeys.Construct();
      77           0 :     if (temp.ref().isObject()) {
      78           0 :       JS::ForOfIterator iter(cx);
      79           0 :       if (!iter.init(temp.ref(), JS::ForOfIterator::AllowNonIterable)) {
      80           0 :         return false;
      81             :       }
      82           0 :       if (!iter.valueIsIterable()) {
      83           0 :         ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'keys' member of DisplayNameOptions");
      84           0 :         return false;
      85             :       }
      86           0 :       Sequence<nsString> &arr = (mKeys.Value());
      87           0 :       JS::Rooted<JS::Value> temp(cx);
      88             :       while (true) {
      89             :         bool done;
      90           0 :         if (!iter.next(&temp, &done)) {
      91           0 :           return false;
      92             :         }
      93           0 :         if (done) {
      94           0 :           break;
      95             :         }
      96           0 :         nsString* slotPtr = arr.AppendElement(mozilla::fallible);
      97           0 :         if (!slotPtr) {
      98           0 :           JS_ReportOutOfMemory(cx);
      99           0 :           return false;
     100             :         }
     101           0 :         nsString& slot = *slotPtr;
     102           0 :         if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
     103           0 :           return false;
     104             :         }
     105           0 :       }
     106             :     } else {
     107           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "'keys' member of DisplayNameOptions");
     108           0 :       return false;
     109             :     }
     110           0 :     mIsAnyMemberPresent = true;
     111             :   }
     112             : 
     113           0 :   if (!isNull) {
     114           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->style_id, temp.ptr())) {
     115           0 :       return false;
     116             :     }
     117             :   }
     118           0 :   if (!isNull && !temp->isUndefined()) {
     119           0 :     mStyle.Construct();
     120           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mStyle.Value()))) {
     121           0 :       return false;
     122             :     }
     123           0 :     mIsAnyMemberPresent = true;
     124             :   }
     125           0 :   return true;
     126             : }
     127             : 
     128             : bool
     129           0 : DisplayNameOptions::Init(const nsAString& aJSON)
     130             : {
     131           0 :   AutoJSAPI jsapi;
     132           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     133           0 :   if (!cleanGlobal) {
     134           0 :     return false;
     135             :   }
     136           0 :   if (!jsapi.Init(cleanGlobal)) {
     137           0 :     return false;
     138             :   }
     139           0 :   JSContext* cx = jsapi.cx();
     140           0 :   JS::Rooted<JS::Value> json(cx);
     141           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     142           0 :   NS_ENSURE_TRUE(ok, false);
     143           0 :   return Init(cx, json);
     144             : }
     145             : 
     146             : bool
     147           0 : DisplayNameOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     148             : {
     149           0 :   DisplayNameOptionsAtoms* atomsCache = GetAtomCache<DisplayNameOptionsAtoms>(cx);
     150           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     151           0 :     return false;
     152             :   }
     153             : 
     154           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     155           0 :   if (!obj) {
     156           0 :     return false;
     157             :   }
     158           0 :   rval.set(JS::ObjectValue(*obj));
     159             : 
     160           0 :   if (mKeys.WasPassed()) {
     161             :     do {
     162             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     163           0 :       JS::Rooted<JS::Value> temp(cx);
     164           0 :       Sequence<nsString> const & currentValue = mKeys.InternalValue();
     165             : 
     166           0 :       uint32_t length = currentValue.Length();
     167           0 :       JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
     168           0 :       if (!returnArray) {
     169           0 :         return false;
     170             :       }
     171             :       // Scope for 'tmp'
     172             :       {
     173           0 :         JS::Rooted<JS::Value> tmp(cx);
     174           0 :         for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
     175             :           // Control block to let us common up the JS_DefineElement calls when there
     176             :           // are different ways to succeed at wrapping the object.
     177             :           do {
     178           0 :             if (!xpc::NonVoidStringToJsval(cx, currentValue[sequenceIdx0], &tmp)) {
     179           0 :               return false;
     180             :             }
     181           0 :             break;
     182             :           } while (0);
     183           0 :           if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
     184             :                                 JSPROP_ENUMERATE)) {
     185           0 :             return false;
     186             :           }
     187             :         }
     188             :       }
     189           0 :       temp.setObject(*returnArray);
     190           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->keys_id, temp, JSPROP_ENUMERATE)) {
     191           0 :         return false;
     192             :       }
     193           0 :       break;
     194             :     } while(0);
     195             :   }
     196             : 
     197           0 :   if (mStyle.WasPassed()) {
     198             :     do {
     199             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     200           0 :       JS::Rooted<JS::Value> temp(cx);
     201           0 :       nsString const & currentValue = mStyle.InternalValue();
     202           0 :       if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     203           0 :         return false;
     204             :       }
     205           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->style_id, temp, JSPROP_ENUMERATE)) {
     206           0 :         return false;
     207             :       }
     208           0 :       break;
     209             :     } while(0);
     210             :   }
     211             : 
     212           0 :   return true;
     213             : }
     214             : 
     215             : bool
     216           0 : DisplayNameOptions::ToJSON(nsAString& aJSON) const
     217             : {
     218           0 :   AutoJSAPI jsapi;
     219           0 :   jsapi.Init();
     220           0 :   JSContext *cx = jsapi.cx();
     221             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     222             :   // because we'll only be creating objects, in ways that have no
     223             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     224             :   // which likewise guarantees no side-effects for the sorts of
     225             :   // things we will pass it.
     226           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     227           0 :   JS::Rooted<JS::Value> val(cx);
     228           0 :   if (!ToObjectInternal(cx, &val)) {
     229           0 :     return false;
     230             :   }
     231           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     232           0 :   return StringifyToJSON(cx, obj, aJSON);
     233             : }
     234             : 
     235             : void
     236           0 : DisplayNameOptions::TraceDictionary(JSTracer* trc)
     237             : {
     238           0 : }
     239             : 
     240             : DisplayNameOptions&
     241           0 : DisplayNameOptions::operator=(const DisplayNameOptions& aOther)
     242             : {
     243           0 :   mKeys.Reset();
     244           0 :   if (aOther.mKeys.WasPassed()) {
     245           0 :     mKeys.Construct(aOther.mKeys.Value());
     246             :   }
     247           0 :   mStyle.Reset();
     248           0 :   if (aOther.mStyle.WasPassed()) {
     249           0 :     mStyle.Construct(aOther.mStyle.Value());
     250             :   }
     251           0 :   return *this;
     252             : }
     253             : 
     254             : namespace binding_detail {
     255             : } // namespace binding_detail
     256             : 
     257             : 
     258             : 
     259           0 : DisplayNameResult::DisplayNameResult()
     260             : {
     261             :   // Safe to pass a null context if we pass a null value
     262           0 :   Init(nullptr, JS::NullHandleValue);
     263           0 : }
     264             : 
     265             : 
     266             : bool
     267           0 : DisplayNameResult::InitIds(JSContext* cx, DisplayNameResultAtoms* atomsCache)
     268             : {
     269           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     270             : 
     271             :   // Initialize these in reverse order so that any failure leaves the first one
     272             :   // uninitialized.
     273           0 :   if (!atomsCache->values_id.init(cx, "values") ||
     274           0 :       !atomsCache->style_id.init(cx, "style") ||
     275           0 :       !atomsCache->locale_id.init(cx, "locale")) {
     276           0 :     return false;
     277             :   }
     278           0 :   return true;
     279             : }
     280             : 
     281             : bool
     282           0 : DisplayNameResult::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     283             : {
     284             :   // Passing a null JSContext is OK only if we're initing from null,
     285             :   // Since in that case we will not have to do any property gets
     286             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     287             :   // checkers by static analysis tools
     288           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     289           0 :   DisplayNameResultAtoms* atomsCache = nullptr;
     290           0 :   if (cx) {
     291           0 :     atomsCache = GetAtomCache<DisplayNameResultAtoms>(cx);
     292           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     293           0 :       return false;
     294             :     }
     295             :   }
     296             : 
     297           0 :   if (!IsConvertibleToDictionary(val)) {
     298           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
     299             :   }
     300             : 
     301           0 :   bool isNull = val.isNullOrUndefined();
     302             :   // We only need these if !isNull, in which case we have |cx|.
     303           0 :   Maybe<JS::Rooted<JSObject *> > object;
     304           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     305           0 :   if (!isNull) {
     306           0 :     MOZ_ASSERT(cx);
     307           0 :     object.emplace(cx, &val.toObject());
     308           0 :     temp.emplace(cx);
     309             :   }
     310           0 :   if (!isNull) {
     311           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->locale_id, temp.ptr())) {
     312           0 :       return false;
     313             :     }
     314             :   }
     315           0 :   if (!isNull && !temp->isUndefined()) {
     316           0 :     mLocale.Construct();
     317           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mLocale.Value()))) {
     318           0 :       return false;
     319             :     }
     320           0 :     mIsAnyMemberPresent = true;
     321             :   }
     322             : 
     323           0 :   if (!isNull) {
     324           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->style_id, temp.ptr())) {
     325           0 :       return false;
     326             :     }
     327             :   }
     328           0 :   if (!isNull && !temp->isUndefined()) {
     329           0 :     mStyle.Construct();
     330           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mStyle.Value()))) {
     331           0 :       return false;
     332             :     }
     333           0 :     mIsAnyMemberPresent = true;
     334             :   }
     335             : 
     336           0 :   if (!isNull) {
     337           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->values_id, temp.ptr())) {
     338           0 :       return false;
     339             :     }
     340             :   }
     341           0 :   if (!isNull && !temp->isUndefined()) {
     342           0 :     mValues.Construct();
     343           0 :     if (temp.ref().isObject()) {
     344           0 :       auto& recordEntries = (mValues.Value()).Entries();
     345             : 
     346           0 :       JS::Rooted<JSObject*> recordObj(cx, &temp.ref().toObject());
     347           0 :       JS::AutoIdVector ids(cx);
     348           0 :       if (!js::GetPropertyKeys(cx, recordObj,
     349             :                                JSITER_OWNONLY | JSITER_HIDDEN | JSITER_SYMBOLS, &ids)) {
     350           0 :         return false;
     351             :       }
     352           0 :       if (!recordEntries.SetCapacity(ids.length(), mozilla::fallible)) {
     353           0 :         JS_ReportOutOfMemory(cx);
     354           0 :         return false;
     355             :       }
     356           0 :       JS::Rooted<JS::Value> propNameValue(cx);
     357           0 :       JS::Rooted<JS::Value> temp(cx);
     358           0 :       JS::Rooted<jsid> curId(cx);
     359           0 :       JS::Rooted<JS::Value> idVal(cx);
     360             :       // Use a hashset to keep track of ids seen, to avoid
     361             :       // introducing nasty O(N^2) behavior scanning for them all the
     362             :       // time.  Ideally we'd use a data structure with O(1) lookup
     363             :       // _and_ ordering for the MozMap, but we don't have one lying
     364             :       // around.
     365           0 :       nsTHashtable<nsStringHashKey> idsSeen;
     366           0 :       for (size_t i = 0; i < ids.length(); ++i) {
     367           0 :         curId = ids[i];
     368             : 
     369           0 :         JS::Rooted<JS::PropertyDescriptor> desc(cx);
     370           0 :         if (!JS_GetOwnPropertyDescriptorById(cx, recordObj, curId,
     371             :                                              &desc)) {
     372           0 :           return false;
     373             :         }
     374             : 
     375           0 :         if (!desc.object() /* == undefined in spec terms */ ||
     376           0 :             !desc.enumerable()) {
     377           0 :           continue;
     378             :         }
     379             : 
     380           0 :         idVal = js::IdToValue(curId);
     381           0 :         nsString propName;
     382             :         // This will just throw if idVal is a Symbol, like the spec says
     383             :         // to do.
     384           0 :         if (!ConvertJSValueToString(cx, idVal, propName)) {
     385           0 :           return false;
     386             :         }
     387             : 
     388           0 :         if (!JS_GetPropertyById(cx, recordObj, curId, &temp)) {
     389           0 :           return false;
     390             :         }
     391             : 
     392             :         Record<nsString, nsString>::EntryType* entry;
     393           0 :         if (!idsSeen.EnsureInserted(propName)) {
     394             :           // Find the existing entry.
     395           0 :           auto idx = recordEntries.IndexOf(propName);
     396           0 :           MOZ_ASSERT(idx != recordEntries.NoIndex,
     397             :                      "Why is it not found?");
     398             :           // Now blow it away to make it look like it was just added
     399             :           // to the array, because it's not obvious that it's
     400             :           // safe to write to its already-initialized mValue via our
     401             :           // normal codegen conversions.  For example, the value
     402             :           // could be a union and this would change its type, but
     403             :           // codegen assumes we won't do that.
     404           0 :           entry = recordEntries.ReconstructElementAt(idx);
     405             :         } else {
     406             :           // Safe to do an infallible append here, because we did a
     407             :           // SetCapacity above to the right capacity.
     408           0 :           entry = recordEntries.AppendElement();
     409             :         }
     410           0 :         entry->mKey = propName;
     411           0 :         nsString& slot = entry->mValue;
     412           0 :         if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
     413           0 :           return false;
     414             :         }
     415             :       }
     416             :     } else {
     417           0 :       ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'values' member of DisplayNameResult");
     418           0 :       return false;
     419             :     }
     420           0 :     mIsAnyMemberPresent = true;
     421             :   }
     422           0 :   return true;
     423             : }
     424             : 
     425             : bool
     426           0 : DisplayNameResult::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     427             : {
     428           0 :   DisplayNameResultAtoms* atomsCache = GetAtomCache<DisplayNameResultAtoms>(cx);
     429           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     430           0 :     return false;
     431             :   }
     432             : 
     433           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     434           0 :   if (!obj) {
     435           0 :     return false;
     436             :   }
     437           0 :   rval.set(JS::ObjectValue(*obj));
     438             : 
     439           0 :   if (mLocale.WasPassed()) {
     440             :     do {
     441             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     442           0 :       JS::Rooted<JS::Value> temp(cx);
     443           0 :       nsString const & currentValue = mLocale.InternalValue();
     444           0 :       if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     445           0 :         return false;
     446             :       }
     447           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->locale_id, temp, JSPROP_ENUMERATE)) {
     448           0 :         return false;
     449             :       }
     450           0 :       break;
     451             :     } while(0);
     452             :   }
     453             : 
     454           0 :   if (mStyle.WasPassed()) {
     455             :     do {
     456             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     457           0 :       JS::Rooted<JS::Value> temp(cx);
     458           0 :       nsString const & currentValue = mStyle.InternalValue();
     459           0 :       if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     460           0 :         return false;
     461             :       }
     462           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->style_id, temp, JSPROP_ENUMERATE)) {
     463           0 :         return false;
     464             :       }
     465           0 :       break;
     466             :     } while(0);
     467             :   }
     468             : 
     469           0 :   if (mValues.WasPassed()) {
     470             :     do {
     471             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     472           0 :       JS::Rooted<JS::Value> temp(cx);
     473           0 :       Record<nsString, nsString> const & currentValue = mValues.InternalValue();
     474             : 
     475           0 :       JS::Rooted<JSObject*> returnObj(cx, JS_NewPlainObject(cx));
     476           0 :       if (!returnObj) {
     477           0 :         return false;
     478             :       }
     479             :       // Scope for 'tmp'
     480             :       {
     481           0 :         JS::Rooted<JS::Value> tmp(cx);
     482           0 :         for (auto& entry : currentValue.Entries()) {
     483           0 :           auto& recordValue0 = entry.mValue;
     484             :           // Control block to let us common up the JS_DefineUCProperty calls when there
     485             :           // are different ways to succeed at wrapping the value.
     486             :           do {
     487           0 :             if (!xpc::NonVoidStringToJsval(cx, recordValue0, &tmp)) {
     488           0 :               return false;
     489             :             }
     490           0 :             break;
     491             :           } while (0);
     492           0 :           if (!JS_DefineUCProperty(cx, returnObj,
     493             :                                    entry.mKey.BeginReading(),
     494           0 :                                    entry.mKey.Length(), tmp,
     495             :                                    JSPROP_ENUMERATE)) {
     496           0 :             return false;
     497             :           }
     498             :         }
     499             :       }
     500           0 :       temp.setObject(*returnObj);
     501           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->values_id, temp, JSPROP_ENUMERATE)) {
     502           0 :         return false;
     503             :       }
     504           0 :       break;
     505             :     } while(0);
     506             :   }
     507             : 
     508           0 :   return true;
     509             : }
     510             : 
     511             : void
     512           0 : DisplayNameResult::TraceDictionary(JSTracer* trc)
     513             : {
     514           0 : }
     515             : 
     516             : namespace binding_detail {
     517             : } // namespace binding_detail
     518             : 
     519             : 
     520             : 
     521           0 : LocaleInfo::LocaleInfo()
     522             : {
     523             :   // Safe to pass a null context if we pass a null value
     524           0 :   Init(nullptr, JS::NullHandleValue);
     525           0 : }
     526             : 
     527             : 
     528             : 
     529             : bool
     530           0 : LocaleInfo::InitIds(JSContext* cx, LocaleInfoAtoms* atomsCache)
     531             : {
     532           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
     533             : 
     534             :   // Initialize these in reverse order so that any failure leaves the first one
     535             :   // uninitialized.
     536           0 :   if (!atomsCache->locale_id.init(cx, "locale") ||
     537           0 :       !atomsCache->direction_id.init(cx, "direction")) {
     538           0 :     return false;
     539             :   }
     540           0 :   return true;
     541             : }
     542             : 
     543             : bool
     544           0 : LocaleInfo::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
     545             : {
     546             :   // Passing a null JSContext is OK only if we're initing from null,
     547             :   // Since in that case we will not have to do any property gets
     548             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
     549             :   // checkers by static analysis tools
     550           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
     551           0 :   LocaleInfoAtoms* atomsCache = nullptr;
     552           0 :   if (cx) {
     553           0 :     atomsCache = GetAtomCache<LocaleInfoAtoms>(cx);
     554           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     555           0 :       return false;
     556             :     }
     557             :   }
     558             : 
     559           0 :   if (!IsConvertibleToDictionary(val)) {
     560           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
     561             :   }
     562             : 
     563           0 :   bool isNull = val.isNullOrUndefined();
     564             :   // We only need these if !isNull, in which case we have |cx|.
     565           0 :   Maybe<JS::Rooted<JSObject *> > object;
     566           0 :   Maybe<JS::Rooted<JS::Value> > temp;
     567           0 :   if (!isNull) {
     568           0 :     MOZ_ASSERT(cx);
     569           0 :     object.emplace(cx, &val.toObject());
     570           0 :     temp.emplace(cx);
     571             :   }
     572           0 :   if (!isNull) {
     573           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->direction_id, temp.ptr())) {
     574           0 :       return false;
     575             :     }
     576             :   }
     577           0 :   if (!isNull && !temp->isUndefined()) {
     578           0 :     mDirection.Construct();
     579           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mDirection.Value()))) {
     580           0 :       return false;
     581             :     }
     582           0 :     mIsAnyMemberPresent = true;
     583             :   }
     584             : 
     585           0 :   if (!isNull) {
     586           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->locale_id, temp.ptr())) {
     587           0 :       return false;
     588             :     }
     589             :   }
     590           0 :   if (!isNull && !temp->isUndefined()) {
     591           0 :     mLocale.Construct();
     592           0 :     if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, (mLocale.Value()))) {
     593           0 :       return false;
     594             :     }
     595           0 :     mIsAnyMemberPresent = true;
     596             :   }
     597           0 :   return true;
     598             : }
     599             : 
     600             : bool
     601           0 : LocaleInfo::Init(const nsAString& aJSON)
     602             : {
     603           0 :   AutoJSAPI jsapi;
     604           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     605           0 :   if (!cleanGlobal) {
     606           0 :     return false;
     607             :   }
     608           0 :   if (!jsapi.Init(cleanGlobal)) {
     609           0 :     return false;
     610             :   }
     611           0 :   JSContext* cx = jsapi.cx();
     612           0 :   JS::Rooted<JS::Value> json(cx);
     613           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     614           0 :   NS_ENSURE_TRUE(ok, false);
     615           0 :   return Init(cx, json);
     616             : }
     617             : 
     618             : bool
     619           0 : LocaleInfo::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     620             : {
     621           0 :   LocaleInfoAtoms* atomsCache = GetAtomCache<LocaleInfoAtoms>(cx);
     622           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     623           0 :     return false;
     624             :   }
     625             : 
     626           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     627           0 :   if (!obj) {
     628           0 :     return false;
     629             :   }
     630           0 :   rval.set(JS::ObjectValue(*obj));
     631             : 
     632           0 :   if (mDirection.WasPassed()) {
     633             :     do {
     634             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     635           0 :       JS::Rooted<JS::Value> temp(cx);
     636           0 :       nsString const & currentValue = mDirection.InternalValue();
     637           0 :       if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     638           0 :         return false;
     639             :       }
     640           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->direction_id, temp, JSPROP_ENUMERATE)) {
     641           0 :         return false;
     642             :       }
     643           0 :       break;
     644             :     } while(0);
     645             :   }
     646             : 
     647           0 :   if (mLocale.WasPassed()) {
     648             :     do {
     649             :       // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     650           0 :       JS::Rooted<JS::Value> temp(cx);
     651           0 :       nsString const & currentValue = mLocale.InternalValue();
     652           0 :       if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
     653           0 :         return false;
     654             :       }
     655           0 :       if (!JS_DefinePropertyById(cx, obj, atomsCache->locale_id, temp, JSPROP_ENUMERATE)) {
     656           0 :         return false;
     657             :       }
     658           0 :       break;
     659             :     } while(0);
     660             :   }
     661             : 
     662           0 :   return true;
     663             : }
     664             : 
     665             : bool
     666           0 : LocaleInfo::ToJSON(nsAString& aJSON) const
     667             : {
     668           0 :   AutoJSAPI jsapi;
     669           0 :   jsapi.Init();
     670           0 :   JSContext *cx = jsapi.cx();
     671             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     672             :   // because we'll only be creating objects, in ways that have no
     673             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     674             :   // which likewise guarantees no side-effects for the sorts of
     675             :   // things we will pass it.
     676           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     677           0 :   JS::Rooted<JS::Value> val(cx);
     678           0 :   if (!ToObjectInternal(cx, &val)) {
     679           0 :     return false;
     680             :   }
     681           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     682           0 :   return StringifyToJSON(cx, obj, aJSON);
     683             : }
     684             : 
     685             : void
     686           0 : LocaleInfo::TraceDictionary(JSTracer* trc)
     687             : {
     688           0 : }
     689             : 
     690             : LocaleInfo&
     691           0 : LocaleInfo::operator=(const LocaleInfo& aOther)
     692             : {
     693           0 :   mDirection.Reset();
     694           0 :   if (aOther.mDirection.WasPassed()) {
     695           0 :     mDirection.Construct(aOther.mDirection.Value());
     696             :   }
     697           0 :   mLocale.Reset();
     698           0 :   if (aOther.mLocale.WasPassed()) {
     699           0 :     mLocale.Construct(aOther.mLocale.Value());
     700             :   }
     701           0 :   return *this;
     702             : }
     703             : 
     704             : namespace binding_detail {
     705             : } // namespace binding_detail
     706             : 
     707             : 
     708             : namespace IntlUtilsBinding {
     709             : 
     710             : static bool
     711           0 : getDisplayNames(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IntlUtils* self, const JSJitMethodCallArgs& args)
     712             : {
     713           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     714           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IntlUtils.getDisplayNames");
     715             :   }
     716           0 :   binding_detail::AutoSequence<nsString> arg0;
     717           0 :   if (args[0].isObject()) {
     718           0 :     JS::ForOfIterator iter(cx);
     719           0 :     if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
     720           0 :       return false;
     721             :     }
     722           0 :     if (!iter.valueIsIterable()) {
     723           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of IntlUtils.getDisplayNames");
     724           0 :       return false;
     725             :     }
     726           0 :     binding_detail::AutoSequence<nsString> &arr = arg0;
     727           0 :     JS::Rooted<JS::Value> temp(cx);
     728             :     while (true) {
     729             :       bool done;
     730           0 :       if (!iter.next(&temp, &done)) {
     731           0 :         return false;
     732             :       }
     733           0 :       if (done) {
     734           0 :         break;
     735             :       }
     736           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
     737           0 :       if (!slotPtr) {
     738           0 :         JS_ReportOutOfMemory(cx);
     739           0 :         return false;
     740             :       }
     741           0 :       nsString& slot = *slotPtr;
     742           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
     743           0 :         return false;
     744             :       }
     745           0 :     }
     746             :   } else {
     747           0 :     ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of IntlUtils.getDisplayNames");
     748           0 :     return false;
     749             :   }
     750           0 :   binding_detail::FastDisplayNameOptions arg1;
     751           0 :   if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of IntlUtils.getDisplayNames", false)) {
     752           0 :     return false;
     753             :   }
     754           0 :   binding_detail::FastErrorResult rv;
     755           0 :   DisplayNameResult result;
     756           0 :   self->GetDisplayNames(Constify(arg0), Constify(arg1), result, rv);
     757           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     758           0 :     return false;
     759             :   }
     760           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     761           0 :   if (!result.ToObjectInternal(cx, args.rval())) {
     762           0 :     return false;
     763             :   }
     764           0 :   return true;
     765             : }
     766             : 
     767             : static const JSJitInfo getDisplayNames_methodinfo = {
     768             :   { (JSJitGetterOp)getDisplayNames },
     769             :   { prototypes::id::IntlUtils },
     770             :   { PrototypeTraits<prototypes::id::IntlUtils>::Depth },
     771             :   JSJitInfo::Method,
     772             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     773             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     774             :   false,  /* isInfallible. False in setters. */
     775             :   false,  /* isMovable.  Not relevant for setters. */
     776             :   false, /* isEliminatable.  Not relevant for setters. */
     777             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     778             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     779             :   false,  /* isTypedMethod.  Only relevant for methods. */
     780             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     781             : };
     782             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     783             : static_assert(0 < 1, "There is no slot for us");
     784             : 
     785             : static bool
     786           0 : getLocaleInfo(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IntlUtils* self, const JSJitMethodCallArgs& args)
     787             : {
     788           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     789           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IntlUtils.getLocaleInfo");
     790             :   }
     791           0 :   binding_detail::AutoSequence<nsString> arg0;
     792           0 :   if (args[0].isObject()) {
     793           0 :     JS::ForOfIterator iter(cx);
     794           0 :     if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
     795           0 :       return false;
     796             :     }
     797           0 :     if (!iter.valueIsIterable()) {
     798           0 :       ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of IntlUtils.getLocaleInfo");
     799           0 :       return false;
     800             :     }
     801           0 :     binding_detail::AutoSequence<nsString> &arr = arg0;
     802           0 :     JS::Rooted<JS::Value> temp(cx);
     803             :     while (true) {
     804             :       bool done;
     805           0 :       if (!iter.next(&temp, &done)) {
     806           0 :         return false;
     807             :       }
     808           0 :       if (done) {
     809           0 :         break;
     810             :       }
     811           0 :       nsString* slotPtr = arr.AppendElement(mozilla::fallible);
     812           0 :       if (!slotPtr) {
     813           0 :         JS_ReportOutOfMemory(cx);
     814           0 :         return false;
     815             :       }
     816           0 :       nsString& slot = *slotPtr;
     817           0 :       if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
     818           0 :         return false;
     819             :       }
     820           0 :     }
     821             :   } else {
     822           0 :     ThrowErrorMessage(cx, MSG_NOT_SEQUENCE, "Argument 1 of IntlUtils.getLocaleInfo");
     823           0 :     return false;
     824             :   }
     825           0 :   binding_detail::FastErrorResult rv;
     826           0 :   LocaleInfo result;
     827           0 :   self->GetLocaleInfo(Constify(arg0), result, rv);
     828           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     829           0 :     return false;
     830             :   }
     831           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     832           0 :   if (!result.ToObjectInternal(cx, args.rval())) {
     833           0 :     return false;
     834             :   }
     835           0 :   return true;
     836             : }
     837             : 
     838             : static const JSJitInfo getLocaleInfo_methodinfo = {
     839             :   { (JSJitGetterOp)getLocaleInfo },
     840             :   { prototypes::id::IntlUtils },
     841             :   { PrototypeTraits<prototypes::id::IntlUtils>::Depth },
     842             :   JSJitInfo::Method,
     843             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     844             :   JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
     845             :   false,  /* isInfallible. False in setters. */
     846             :   false,  /* isMovable.  Not relevant for setters. */
     847             :   false, /* isEliminatable.  Not relevant for setters. */
     848             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     849             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     850             :   false,  /* isTypedMethod.  Only relevant for methods. */
     851             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     852             : };
     853             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     854             : static_assert(0 < 1, "There is no slot for us");
     855             : 
     856             : static bool
     857           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     858             : {
     859           0 :   mozilla::dom::IntlUtils* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IntlUtils>(obj);
     860             :   // We don't want to preserve if we don't have a wrapper, and we
     861             :   // obviously can't preserve if we're not initialized.
     862           0 :   if (self && self->GetWrapperPreserveColor()) {
     863           0 :     PreserveWrapper(self);
     864             :   }
     865           0 :   return true;
     866             : }
     867             : 
     868             : static void
     869           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     870             : {
     871           0 :   mozilla::dom::IntlUtils* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IntlUtils>(obj);
     872           0 :   if (self) {
     873           0 :     ClearWrapper(self, self, obj);
     874           0 :     AddForDeferredFinalization<mozilla::dom::IntlUtils>(self);
     875             :   }
     876           0 : }
     877             : 
     878             : static void
     879           0 : _objectMoved(JSObject* obj, const JSObject* old)
     880             : {
     881           0 :   mozilla::dom::IntlUtils* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IntlUtils>(obj);
     882           0 :   if (self) {
     883           0 :     UpdateWrapper(self, self, obj, old);
     884             :   }
     885           0 : }
     886             : 
     887             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     888             : #if defined(__clang__)
     889             : #pragma clang diagnostic push
     890             : #pragma clang diagnostic ignored "-Wmissing-braces"
     891             : #endif
     892             : static const JSFunctionSpec sMethods_specs[] = {
     893             :   JS_FNSPEC("getDisplayNames", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getDisplayNames_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     894             :   JS_FNSPEC("getLocaleInfo", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getLocaleInfo_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     895             :   JS_FS_END
     896             : };
     897             : #if defined(__clang__)
     898             : #pragma clang diagnostic pop
     899             : #endif
     900             : 
     901             : 
     902             : // Can't be const because the pref-enabled boolean needs to be writable
     903             : static Prefable<const JSFunctionSpec> sMethods[] = {
     904             :   { nullptr, &sMethods_specs[0] },
     905             :   { nullptr, nullptr }
     906             : };
     907             : 
     908             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     909             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     910             : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     911             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     912             : 
     913             : 
     914             : static uint16_t sNativeProperties_sortedPropertyIndices[2];
     915             : static PropertyInfo sNativeProperties_propertyInfos[2];
     916             : 
     917             : static const NativePropertiesN<1> sNativeProperties = {
     918             :   false, 0,
     919             :   false, 0,
     920             :   true,  0 /* sMethods */,
     921             :   false, 0,
     922             :   false, 0,
     923             :   false, 0,
     924             :   false, 0,
     925             :   -1,
     926             :   2,
     927             :   sNativeProperties_sortedPropertyIndices,
     928             :   {
     929             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     930             :   }
     931             : };
     932             : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     933             :     "We have a property info count that is oversized");
     934             : 
     935             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     936             :   {
     937             :     "IntlUtilsPrototype",
     938             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     939             :     JS_NULL_CLASS_OPS,
     940             :     JS_NULL_CLASS_SPEC,
     941             :     JS_NULL_CLASS_EXT,
     942             :     JS_NULL_OBJECT_OPS
     943             :   },
     944             :   eInterfacePrototype,
     945             :   false,
     946             :   prototypes::id::IntlUtils,
     947             :   PrototypeTraits<prototypes::id::IntlUtils>::Depth,
     948             :   sNativePropertyHooks,
     949             :   "[object IntlUtilsPrototype]",
     950             :   JS::GetRealmObjectPrototype
     951             : };
     952             : 
     953             : static const js::ClassOps sClassOps = {
     954             :   _addProperty, /* addProperty */
     955             :   nullptr,               /* delProperty */
     956             :   nullptr,               /* getProperty */
     957             :   nullptr,               /* setProperty */
     958             :   nullptr,               /* enumerate */
     959             :   nullptr, /* newEnumerate */
     960             :   nullptr, /* resolve */
     961             :   nullptr, /* mayResolve */
     962             :   _finalize, /* finalize */
     963             :   nullptr, /* call */
     964             :   nullptr,               /* hasInstance */
     965             :   nullptr,               /* construct */
     966             :   nullptr, /* trace */
     967             : };
     968             : 
     969             : static const js::ClassExtension sClassExtension = {
     970             :   nullptr, /* weakmapKeyDelegateOp */
     971             :   _objectMoved /* objectMovedOp */
     972             : };
     973             : 
     974             : static const DOMJSClass sClass = {
     975             :   { "IntlUtils",
     976             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     977             :     &sClassOps,
     978             :     JS_NULL_CLASS_SPEC,
     979             :     &sClassExtension,
     980             :     JS_NULL_OBJECT_OPS
     981             :   },
     982             :   { prototypes::id::IntlUtils, 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 },
     983             :   IsBaseOf<nsISupports, mozilla::dom::IntlUtils >::value,
     984             :   sNativePropertyHooks,
     985             :   FindAssociatedGlobalForNative<mozilla::dom::IntlUtils>::Get,
     986             :   GetProtoObjectHandle,
     987             :   GetCCParticipant<mozilla::dom::IntlUtils>::Get()
     988             : };
     989             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     990             :               "Must have the right minimal number of reserved slots.");
     991             : static_assert(1 >= 1,
     992             :               "Must have enough reserved slots.");
     993             : 
     994             : const JSClass*
     995           0 : GetJSClass()
     996             : {
     997           0 :   return sClass.ToJSClass();
     998             : }
     999             : 
    1000             : bool
    1001           0 : Wrap(JSContext* aCx, mozilla::dom::IntlUtils* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
    1002             : {
    1003             :   MOZ_ASSERT(static_cast<mozilla::dom::IntlUtils*>(aObject) ==
    1004             :              reinterpret_cast<mozilla::dom::IntlUtils*>(aObject),
    1005             :              "Multiple inheritance for mozilla::dom::IntlUtils is broken.");
    1006           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
    1007           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
    1008           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
    1009             :              "You should probably not be using Wrap() directly; use "
    1010             :              "GetOrCreateDOMReflector instead");
    1011             : 
    1012           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
    1013             :              "nsISupports must be on our primary inheritance chain");
    1014             : 
    1015           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
    1016           0 :   if (!global) {
    1017           0 :     return false;
    1018             :   }
    1019           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
    1020           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
    1021             : 
    1022             :   // That might have ended up wrapping us already, due to the wonders
    1023             :   // of XBL.  Check for that, and bail out as needed.
    1024           0 :   aReflector.set(aCache->GetWrapper());
    1025           0 :   if (aReflector) {
    1026             : #ifdef DEBUG
    1027           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
    1028             : #endif // DEBUG
    1029           0 :     return true;
    1030             :   }
    1031             : 
    1032           0 :   JSAutoCompartment ac(aCx, global);
    1033           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
    1034           0 :   if (!canonicalProto) {
    1035           0 :     return false;
    1036             :   }
    1037           0 :   JS::Rooted<JSObject*> proto(aCx);
    1038           0 :   if (aGivenProto) {
    1039           0 :     proto = aGivenProto;
    1040             :     // Unfortunately, while aGivenProto was in the compartment of aCx
    1041             :     // coming in, we changed compartments to that of "parent" so may need
    1042             :     // to wrap the proto here.
    1043           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
    1044           0 :       if (!JS_WrapObject(aCx, &proto)) {
    1045           0 :         return false;
    1046             :       }
    1047             :     }
    1048             :   } else {
    1049           0 :     proto = canonicalProto;
    1050             :   }
    1051             : 
    1052           0 :   BindingJSObjectCreator<mozilla::dom::IntlUtils> creator(aCx);
    1053           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
    1054           0 :   if (!aReflector) {
    1055           0 :     return false;
    1056             :   }
    1057             : 
    1058           0 :   aCache->SetWrapper(aReflector);
    1059           0 :   creator.InitializationSucceeded();
    1060             : 
    1061           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
    1062             :              aCache->GetWrapperPreserveColor() == aReflector);
    1063             :   // If proto != canonicalProto, we have to preserve our wrapper;
    1064             :   // otherwise we won't be able to properly recreate it later, since
    1065             :   // we won't know what proto to use.  Note that we don't check
    1066             :   // aGivenProto here, since it's entirely possible (and even
    1067             :   // somewhat common) to have a non-null aGivenProto which is the
    1068             :   // same as canonicalProto.
    1069           0 :   if (proto != canonicalProto) {
    1070           0 :     PreserveWrapper(aObject);
    1071             :   }
    1072             : 
    1073           0 :   return true;
    1074             : }
    1075             : 
    1076             : const NativePropertyHooks sNativePropertyHooks[] = { {
    1077             :   nullptr,
    1078             :   nullptr,
    1079             :   nullptr,
    1080             :   { sNativeProperties.Upcast(), nullptr },
    1081             :   prototypes::id::IntlUtils,
    1082             :   constructors::id::_ID_Count,
    1083             :   nullptr,
    1084             :   &DefaultXrayExpandoObjectClass
    1085             : } };
    1086             : 
    1087             : void
    1088           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
    1089             : {
    1090           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
    1091           0 :   if (!parentProto) {
    1092           0 :     return;
    1093             :   }
    1094             : 
    1095             :   static bool sIdsInited = false;
    1096           0 :   if (!sIdsInited && NS_IsMainThread()) {
    1097           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
    1098           0 :       return;
    1099             :     }
    1100           0 :     sIdsInited = true;
    1101             :   }
    1102             : 
    1103           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::IntlUtils);
    1104           0 :   JS::Heap<JSObject*>* interfaceCache = nullptr;
    1105           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
    1106             :                               &sPrototypeClass.mBase, protoCache,
    1107             :                               nullptr, nullptr, 0, nullptr,
    1108             :                               interfaceCache,
    1109             :                               sNativeProperties.Upcast(),
    1110             :                               nullptr,
    1111             :                               nullptr, aDefineOnGlobal,
    1112             :                               nullptr,
    1113           0 :                               false);
    1114             : }
    1115             : 
    1116             : JS::Handle<JSObject*>
    1117           0 : GetProtoObjectHandle(JSContext* aCx)
    1118             : {
    1119             :   /* Get the interface prototype object for this class.  This will create the
    1120             :      object as needed. */
    1121           0 :   bool aDefineOnGlobal = true;
    1122             : 
    1123             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
    1124           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
    1125           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
    1126           0 :     return nullptr;
    1127             :   }
    1128             : 
    1129             :   /* Check to see whether the interface objects are already installed */
    1130           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
    1131           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::IntlUtils)) {
    1132           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
    1133           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
    1134             :   }
    1135             : 
    1136             :   /*
    1137             :    * The object might _still_ be null, but that's OK.
    1138             :    *
    1139             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
    1140             :    * traced by TraceProtoAndIfaceCache() and its contents are never
    1141             :    * changed after they have been set.
    1142             :    *
    1143             :    * Calling address() avoids the read read barrier that does gray
    1144             :    * unmarking, but it's not possible for the object to be gray here.
    1145             :    */
    1146             : 
    1147           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::IntlUtils);
    1148           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
    1149           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
    1150             : }
    1151             : 
    1152             : } // namespace IntlUtilsBinding
    1153             : 
    1154             : 
    1155             : 
    1156             : } // namespace dom
    1157             : } // namespace mozilla

Generated by: LCOV version 1.13