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

          Line data    Source code
       1             : /* THIS FILE IS AUTOGENERATED FROM Geolocation.webidl BY Codegen.py - DO NOT EDIT */
       2             : 
       3             : #include "AtomList.h"
       4             : #include "GeolocationBinding.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/NonRefcountedDOMObject.h"
      10             : #include "mozilla/dom/Nullable.h"
      11             : #include "mozilla/dom/PrimitiveConversions.h"
      12             : #include "mozilla/dom/ScriptSettings.h"
      13             : #include "mozilla/dom/SimpleGlobalObject.h"
      14             : #include "mozilla/dom/XrayExpandoClass.h"
      15             : #include "nsContentUtils.h"
      16             : #include "nsGeoPosition.h"
      17             : #include "nsGeolocation.h"
      18             : 
      19             : namespace mozilla {
      20             : namespace dom {
      21             : 
      22             : 
      23           0 : PositionOptions::PositionOptions()
      24             : {
      25             :   // Safe to pass a null context if we pass a null value
      26           0 :   Init(nullptr, JS::NullHandleValue);
      27           0 : }
      28             : 
      29             : 
      30             : 
      31             : bool
      32           0 : PositionOptions::InitIds(JSContext* cx, PositionOptionsAtoms* atomsCache)
      33             : {
      34           0 :   MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
      35             : 
      36             :   // Initialize these in reverse order so that any failure leaves the first one
      37             :   // uninitialized.
      38           0 :   if (!atomsCache->timeout_id.init(cx, "timeout") ||
      39           0 :       !atomsCache->maximumAge_id.init(cx, "maximumAge") ||
      40           0 :       !atomsCache->enableHighAccuracy_id.init(cx, "enableHighAccuracy")) {
      41           0 :     return false;
      42             :   }
      43           0 :   return true;
      44             : }
      45             : 
      46             : bool
      47           0 : PositionOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
      48             : {
      49             :   // Passing a null JSContext is OK only if we're initing from null,
      50             :   // Since in that case we will not have to do any property gets
      51             :   // Also evaluate isNullOrUndefined in order to avoid false-positive
      52             :   // checkers by static analysis tools
      53           0 :   MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
      54           0 :   PositionOptionsAtoms* atomsCache = nullptr;
      55           0 :   if (cx) {
      56           0 :     atomsCache = GetAtomCache<PositionOptionsAtoms>(cx);
      57           0 :     if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
      58           0 :       return false;
      59             :     }
      60             :   }
      61             : 
      62           0 :   if (!IsConvertibleToDictionary(val)) {
      63           0 :     return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
      64             :   }
      65             : 
      66           0 :   bool isNull = val.isNullOrUndefined();
      67             :   // We only need these if !isNull, in which case we have |cx|.
      68           0 :   Maybe<JS::Rooted<JSObject *> > object;
      69           0 :   Maybe<JS::Rooted<JS::Value> > temp;
      70           0 :   if (!isNull) {
      71           0 :     MOZ_ASSERT(cx);
      72           0 :     object.emplace(cx, &val.toObject());
      73           0 :     temp.emplace(cx);
      74             :   }
      75           0 :   if (!isNull) {
      76           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->enableHighAccuracy_id, temp.ptr())) {
      77           0 :       return false;
      78             :     }
      79             :   }
      80           0 :   if (!isNull && !temp->isUndefined()) {
      81           0 :     if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mEnableHighAccuracy)) {
      82           0 :       return false;
      83             :     }
      84             :   } else {
      85           0 :     mEnableHighAccuracy = false;
      86             :   }
      87           0 :   mIsAnyMemberPresent = true;
      88             : 
      89           0 :   if (!isNull) {
      90           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->maximumAge_id, temp.ptr())) {
      91           0 :       return false;
      92             :     }
      93             :   }
      94           0 :   if (!isNull && !temp->isUndefined()) {
      95           0 :     if (!ValueToPrimitive<uint32_t, eClamp>(cx, temp.ref(), &mMaximumAge)) {
      96           0 :       return false;
      97             :     }
      98             :   } else {
      99           0 :     mMaximumAge = 0U;
     100             :   }
     101           0 :   mIsAnyMemberPresent = true;
     102             : 
     103           0 :   if (!isNull) {
     104           0 :     if (!JS_GetPropertyById(cx, *object, atomsCache->timeout_id, temp.ptr())) {
     105           0 :       return false;
     106             :     }
     107             :   }
     108           0 :   if (!isNull && !temp->isUndefined()) {
     109           0 :     if (!ValueToPrimitive<uint32_t, eClamp>(cx, temp.ref(), &mTimeout)) {
     110           0 :       return false;
     111             :     }
     112             :   } else {
     113           0 :     mTimeout = 2147483647U;
     114             :   }
     115           0 :   mIsAnyMemberPresent = true;
     116           0 :   return true;
     117             : }
     118             : 
     119             : bool
     120           0 : PositionOptions::Init(const nsAString& aJSON)
     121             : {
     122           0 :   AutoJSAPI jsapi;
     123           0 :   JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
     124           0 :   if (!cleanGlobal) {
     125           0 :     return false;
     126             :   }
     127           0 :   if (!jsapi.Init(cleanGlobal)) {
     128           0 :     return false;
     129             :   }
     130           0 :   JSContext* cx = jsapi.cx();
     131           0 :   JS::Rooted<JS::Value> json(cx);
     132           0 :   bool ok = ParseJSON(cx, aJSON, &json);
     133           0 :   NS_ENSURE_TRUE(ok, false);
     134           0 :   return Init(cx, json);
     135             : }
     136             : 
     137             : bool
     138           0 : PositionOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
     139             : {
     140           0 :   PositionOptionsAtoms* atomsCache = GetAtomCache<PositionOptionsAtoms>(cx);
     141           0 :   if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
     142           0 :     return false;
     143             :   }
     144             : 
     145           0 :   JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
     146           0 :   if (!obj) {
     147           0 :     return false;
     148             :   }
     149           0 :   rval.set(JS::ObjectValue(*obj));
     150             : 
     151             :   do {
     152             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     153           0 :     JS::Rooted<JS::Value> temp(cx);
     154           0 :     bool const & currentValue = mEnableHighAccuracy;
     155           0 :     temp.setBoolean(currentValue);
     156           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->enableHighAccuracy_id, temp, JSPROP_ENUMERATE)) {
     157           0 :       return false;
     158             :     }
     159           0 :     break;
     160             :   } while(0);
     161             : 
     162             :   do {
     163             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     164           0 :     JS::Rooted<JS::Value> temp(cx);
     165           0 :     uint32_t const & currentValue = mMaximumAge;
     166           0 :     temp.setNumber(currentValue);
     167           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->maximumAge_id, temp, JSPROP_ENUMERATE)) {
     168           0 :       return false;
     169             :     }
     170           0 :     break;
     171             :   } while(0);
     172             : 
     173             :   do {
     174             :     // block for our 'break' successCode and scope for 'temp' and 'currentValue'
     175           0 :     JS::Rooted<JS::Value> temp(cx);
     176           0 :     uint32_t const & currentValue = mTimeout;
     177           0 :     temp.setNumber(currentValue);
     178           0 :     if (!JS_DefinePropertyById(cx, obj, atomsCache->timeout_id, temp, JSPROP_ENUMERATE)) {
     179           0 :       return false;
     180             :     }
     181           0 :     break;
     182             :   } while(0);
     183             : 
     184           0 :   return true;
     185             : }
     186             : 
     187             : bool
     188           0 : PositionOptions::ToJSON(nsAString& aJSON) const
     189             : {
     190           0 :   AutoJSAPI jsapi;
     191           0 :   jsapi.Init();
     192           0 :   JSContext *cx = jsapi.cx();
     193             :   // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
     194             :   // because we'll only be creating objects, in ways that have no
     195             :   // side-effects, followed by a call to JS::ToJSONMaybeSafely,
     196             :   // which likewise guarantees no side-effects for the sorts of
     197             :   // things we will pass it.
     198           0 :   JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
     199           0 :   JS::Rooted<JS::Value> val(cx);
     200           0 :   if (!ToObjectInternal(cx, &val)) {
     201           0 :     return false;
     202             :   }
     203           0 :   JS::Rooted<JSObject*> obj(cx, &val.toObject());
     204           0 :   return StringifyToJSON(cx, obj, aJSON);
     205             : }
     206             : 
     207             : void
     208           0 : PositionOptions::TraceDictionary(JSTracer* trc)
     209             : {
     210           0 : }
     211             : 
     212             : PositionOptions&
     213           0 : PositionOptions::operator=(const PositionOptions& aOther)
     214             : {
     215           0 :   mEnableHighAccuracy = aOther.mEnableHighAccuracy;
     216           0 :   mMaximumAge = aOther.mMaximumAge;
     217           0 :   mTimeout = aOther.mTimeout;
     218           0 :   return *this;
     219             : }
     220             : 
     221             : namespace binding_detail {
     222             : } // namespace binding_detail
     223             : 
     224             : 
     225             : void
     226           0 : PositionCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, Position& position, ErrorResult& aRv)
     227             : {
     228           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     229           0 :   JS::AutoValueVector argv(cx);
     230           0 :   if (!argv.resize(1)) {
     231           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     232           0 :     return;
     233             :   }
     234           0 :   unsigned argc = 1;
     235             : 
     236             :   do {
     237           0 :     if (!GetOrCreateDOMReflector(cx, position, argv[0])) {
     238           0 :       MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     239           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     240           0 :       return;
     241             :     }
     242           0 :     break;
     243             :   } while (0);
     244             : 
     245           0 :   JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
     246           0 :   if (!JS::Call(cx, aThisVal, callable,
     247           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
     248           0 :     aRv.NoteJSContextException(cx);
     249           0 :     return;
     250             :   }
     251             : }
     252             : 
     253             : 
     254             : 
     255             : void
     256           0 : PositionErrorCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, PositionError& positionError, ErrorResult& aRv)
     257             : {
     258           0 :   JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
     259           0 :   JS::AutoValueVector argv(cx);
     260           0 :   if (!argv.resize(1)) {
     261           0 :     aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
     262           0 :     return;
     263             :   }
     264           0 :   unsigned argc = 1;
     265             : 
     266             :   do {
     267           0 :     if (!GetOrCreateDOMReflector(cx, positionError, argv[0])) {
     268           0 :       MOZ_ASSERT(true || JS_IsExceptionPending(cx));
     269           0 :       aRv.Throw(NS_ERROR_UNEXPECTED);
     270           0 :       return;
     271             :     }
     272           0 :     break;
     273             :   } while (0);
     274             : 
     275           0 :   JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
     276           0 :   if (!JS::Call(cx, aThisVal, callable,
     277           0 :                 JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
     278           0 :     aRv.NoteJSContextException(cx);
     279           0 :     return;
     280             :   }
     281             : }
     282             : 
     283             : 
     284             : 
     285             : namespace binding_detail {
     286             : } // namespace binding_detail
     287             : 
     288             : 
     289             : namespace binding_detail {
     290             : } // namespace binding_detail
     291             : 
     292             : 
     293             : namespace GeolocationBinding {
     294             : 
     295             : static bool
     296           0 : getCurrentPosition(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Geolocation* self, const JSJitMethodCallArgs& args)
     297             : {
     298           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     299           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Geolocation.getCurrentPosition");
     300             :   }
     301           0 :   RootedCallback<OwningNonNull<binding_detail::FastPositionCallback>> arg0(cx);
     302           0 :   if (args[0].isObject()) {
     303           0 :     if (JS::IsCallable(&args[0].toObject())) {
     304             :     { // scope for tempRoot
     305           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     306           0 :       arg0 = new binding_detail::FastPositionCallback(tempRoot);
     307             :     }
     308             :     } else {
     309           0 :       ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of Geolocation.getCurrentPosition");
     310           0 :       return false;
     311             :     }
     312             :   } else {
     313           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of Geolocation.getCurrentPosition");
     314           0 :     return false;
     315             :   }
     316           0 :   RootedCallback<RefPtr<binding_detail::FastPositionErrorCallback>> arg1(cx);
     317           0 :   if (args.hasDefined(1)) {
     318           0 :     if (args[1].isObject()) {
     319           0 :       if (JS::IsCallable(&args[1].toObject())) {
     320             :       { // scope for tempRoot
     321           0 :         JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
     322           0 :         arg1 = new binding_detail::FastPositionErrorCallback(tempRoot);
     323             :       }
     324             :       } else {
     325           0 :         ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of Geolocation.getCurrentPosition");
     326           0 :         return false;
     327             :       }
     328           0 :     } else if (args[1].isNullOrUndefined()) {
     329           0 :       arg1 = nullptr;
     330             :     } else {
     331           0 :       ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of Geolocation.getCurrentPosition");
     332           0 :       return false;
     333             :     }
     334             :   } else {
     335           0 :     arg1 = nullptr;
     336             :   }
     337           0 :   binding_detail::FastPositionOptions arg2;
     338           0 :   if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue,  "Argument 3 of Geolocation.getCurrentPosition", false)) {
     339           0 :     return false;
     340             :   }
     341           0 :   binding_detail::FastErrorResult rv;
     342           0 :   self->GetCurrentPosition(NonNullHelper(arg0), Constify(arg1), Constify(arg2), nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv);
     343           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     344           0 :     return false;
     345             :   }
     346           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     347           0 :   args.rval().setUndefined();
     348           0 :   return true;
     349             : }
     350             : 
     351             : static const JSJitInfo getCurrentPosition_methodinfo = {
     352             :   { (JSJitGetterOp)getCurrentPosition },
     353             :   { prototypes::id::Geolocation },
     354             :   { PrototypeTraits<prototypes::id::Geolocation>::Depth },
     355             :   JSJitInfo::Method,
     356             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     357             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     358             :   false,  /* isInfallible. False in setters. */
     359             :   false,  /* isMovable.  Not relevant for setters. */
     360             :   false, /* isEliminatable.  Not relevant for setters. */
     361             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     362             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     363             :   false,  /* isTypedMethod.  Only relevant for methods. */
     364             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     365             : };
     366             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     367             : static_assert(0 < 1, "There is no slot for us");
     368             : 
     369             : static bool
     370           0 : watchPosition(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Geolocation* self, const JSJitMethodCallArgs& args)
     371             : {
     372           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     373           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Geolocation.watchPosition");
     374             :   }
     375           0 :   RootedCallback<OwningNonNull<binding_detail::FastPositionCallback>> arg0(cx);
     376           0 :   if (args[0].isObject()) {
     377           0 :     if (JS::IsCallable(&args[0].toObject())) {
     378             :     { // scope for tempRoot
     379           0 :       JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
     380           0 :       arg0 = new binding_detail::FastPositionCallback(tempRoot);
     381             :     }
     382             :     } else {
     383           0 :       ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of Geolocation.watchPosition");
     384           0 :       return false;
     385             :     }
     386             :   } else {
     387           0 :     ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of Geolocation.watchPosition");
     388           0 :     return false;
     389             :   }
     390           0 :   RootedCallback<RefPtr<binding_detail::FastPositionErrorCallback>> arg1(cx);
     391           0 :   if (args.hasDefined(1)) {
     392           0 :     if (args[1].isObject()) {
     393           0 :       if (JS::IsCallable(&args[1].toObject())) {
     394             :       { // scope for tempRoot
     395           0 :         JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
     396           0 :         arg1 = new binding_detail::FastPositionErrorCallback(tempRoot);
     397             :       }
     398             :       } else {
     399           0 :         ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 2 of Geolocation.watchPosition");
     400           0 :         return false;
     401             :       }
     402           0 :     } else if (args[1].isNullOrUndefined()) {
     403           0 :       arg1 = nullptr;
     404             :     } else {
     405           0 :       ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of Geolocation.watchPosition");
     406           0 :       return false;
     407             :     }
     408             :   } else {
     409           0 :     arg1 = nullptr;
     410             :   }
     411           0 :   binding_detail::FastPositionOptions arg2;
     412           0 :   if (!arg2.Init(cx, (args.hasDefined(2)) ? args[2] : JS::NullHandleValue,  "Argument 3 of Geolocation.watchPosition", false)) {
     413           0 :     return false;
     414             :   }
     415           0 :   binding_detail::FastErrorResult rv;
     416           0 :   int32_t result(self->WatchPosition(NonNullHelper(arg0), Constify(arg1), Constify(arg2), nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv));
     417           0 :   if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
     418           0 :     return false;
     419             :   }
     420           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     421           0 :   args.rval().setInt32(int32_t(result));
     422           0 :   return true;
     423             : }
     424             : 
     425             : static const JSJitInfo watchPosition_methodinfo = {
     426             :   { (JSJitGetterOp)watchPosition },
     427             :   { prototypes::id::Geolocation },
     428             :   { PrototypeTraits<prototypes::id::Geolocation>::Depth },
     429             :   JSJitInfo::Method,
     430             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     431             :   JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
     432             :   false,  /* isInfallible. False in setters. */
     433             :   false,  /* isMovable.  Not relevant for setters. */
     434             :   false, /* isEliminatable.  Not relevant for setters. */
     435             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     436             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     437             :   false,  /* isTypedMethod.  Only relevant for methods. */
     438             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     439             : };
     440             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     441             : static_assert(0 < 1, "There is no slot for us");
     442             : 
     443             : static bool
     444           0 : clearWatch(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Geolocation* self, const JSJitMethodCallArgs& args)
     445             : {
     446           0 :   if (MOZ_UNLIKELY(args.length() < 1)) {
     447           0 :     return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Geolocation.clearWatch");
     448             :   }
     449             :   int32_t arg0;
     450           0 :   if (!ValueToPrimitive<int32_t, eDefault>(cx, args[0], &arg0)) {
     451           0 :     return false;
     452             :   }
     453           0 :   self->ClearWatch(arg0);
     454           0 :   MOZ_ASSERT(!JS_IsExceptionPending(cx));
     455           0 :   args.rval().setUndefined();
     456           0 :   return true;
     457             : }
     458             : 
     459             : static const JSJitInfo clearWatch_methodinfo = {
     460             :   { (JSJitGetterOp)clearWatch },
     461             :   { prototypes::id::Geolocation },
     462             :   { PrototypeTraits<prototypes::id::Geolocation>::Depth },
     463             :   JSJitInfo::Method,
     464             :   JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
     465             :   JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
     466             :   false,  /* isInfallible. False in setters. */
     467             :   false,  /* isMovable.  Not relevant for setters. */
     468             :   false, /* isEliminatable.  Not relevant for setters. */
     469             :   false, /* isAlwaysInSlot.  Only relevant for getters. */
     470             :   false, /* isLazilyCachedInSlot.  Only relevant for getters. */
     471             :   false,  /* isTypedMethod.  Only relevant for methods. */
     472             :   0   /* Reserved slot index, if we're stored in a slot, else 0. */
     473             : };
     474             : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
     475             : static_assert(0 < 1, "There is no slot for us");
     476             : 
     477             : static bool
     478           0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
     479             : {
     480           0 :   mozilla::dom::Geolocation* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Geolocation>(obj);
     481             :   // We don't want to preserve if we don't have a wrapper, and we
     482             :   // obviously can't preserve if we're not initialized.
     483           0 :   if (self && self->GetWrapperPreserveColor()) {
     484           0 :     PreserveWrapper(self);
     485             :   }
     486           0 :   return true;
     487             : }
     488             : 
     489             : static void
     490           0 : _finalize(js::FreeOp* fop, JSObject* obj)
     491             : {
     492           0 :   mozilla::dom::Geolocation* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Geolocation>(obj);
     493           0 :   if (self) {
     494           0 :     ClearWrapper(self, self, obj);
     495           0 :     AddForDeferredFinalization<mozilla::dom::Geolocation>(self);
     496             :   }
     497           0 : }
     498             : 
     499             : static void
     500           0 : _objectMoved(JSObject* obj, const JSObject* old)
     501             : {
     502           0 :   mozilla::dom::Geolocation* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Geolocation>(obj);
     503           0 :   if (self) {
     504           0 :     UpdateWrapper(self, self, obj, old);
     505             :   }
     506           0 : }
     507             : 
     508             : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
     509             : #if defined(__clang__)
     510             : #pragma clang diagnostic push
     511             : #pragma clang diagnostic ignored "-Wmissing-braces"
     512             : #endif
     513             : static const JSFunctionSpec sMethods_specs[] = {
     514             :   JS_FNSPEC("getCurrentPosition", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getCurrentPosition_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     515             :   JS_FNSPEC("watchPosition", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&watchPosition_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     516             :   JS_FNSPEC("clearWatch", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&clearWatch_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
     517             :   JS_FS_END
     518             : };
     519             : #if defined(__clang__)
     520             : #pragma clang diagnostic pop
     521             : #endif
     522             : 
     523             : 
     524             : // Can't be const because the pref-enabled boolean needs to be writable
     525             : static Prefable<const JSFunctionSpec> sMethods[] = {
     526             :   { nullptr, &sMethods_specs[0] },
     527             :   { nullptr, nullptr }
     528             : };
     529             : 
     530             : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
     531             :     "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
     532             : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
     533             :     "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
     534             : 
     535             : 
     536             : static uint16_t sNativeProperties_sortedPropertyIndices[3];
     537             : static PropertyInfo sNativeProperties_propertyInfos[3];
     538             : 
     539             : static const NativePropertiesN<1> sNativeProperties = {
     540             :   false, 0,
     541             :   false, 0,
     542             :   true,  0 /* sMethods */,
     543             :   false, 0,
     544             :   false, 0,
     545             :   false, 0,
     546             :   false, 0,
     547             :   -1,
     548             :   3,
     549             :   sNativeProperties_sortedPropertyIndices,
     550             :   {
     551             :     { sMethods, &sNativeProperties_propertyInfos[0] }
     552             :   }
     553             : };
     554             : static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
     555             :     "We have a property info count that is oversized");
     556             : 
     557             : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
     558             :   {
     559             :     "GeolocationPrototype",
     560             :     JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
     561             :     JS_NULL_CLASS_OPS,
     562             :     JS_NULL_CLASS_SPEC,
     563             :     JS_NULL_CLASS_EXT,
     564             :     JS_NULL_OBJECT_OPS
     565             :   },
     566             :   eInterfacePrototype,
     567             :   false,
     568             :   prototypes::id::Geolocation,
     569             :   PrototypeTraits<prototypes::id::Geolocation>::Depth,
     570             :   sNativePropertyHooks,
     571             :   "[object GeolocationPrototype]",
     572             :   JS::GetRealmObjectPrototype
     573             : };
     574             : 
     575             : static const js::ClassOps sClassOps = {
     576             :   _addProperty, /* addProperty */
     577             :   nullptr,               /* delProperty */
     578             :   nullptr,               /* getProperty */
     579             :   nullptr,               /* setProperty */
     580             :   nullptr,               /* enumerate */
     581             :   nullptr, /* newEnumerate */
     582             :   nullptr, /* resolve */
     583             :   nullptr, /* mayResolve */
     584             :   _finalize, /* finalize */
     585             :   nullptr, /* call */
     586             :   nullptr,               /* hasInstance */
     587             :   nullptr,               /* construct */
     588             :   nullptr, /* trace */
     589             : };
     590             : 
     591             : static const js::ClassExtension sClassExtension = {
     592             :   nullptr, /* weakmapKeyDelegateOp */
     593             :   _objectMoved /* objectMovedOp */
     594             : };
     595             : 
     596             : static const DOMJSClass sClass = {
     597             :   { "Geolocation",
     598             :     JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
     599             :     &sClassOps,
     600             :     JS_NULL_CLASS_SPEC,
     601             :     &sClassExtension,
     602             :     JS_NULL_OBJECT_OPS
     603             :   },
     604             :   { prototypes::id::Geolocation, 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 },
     605             :   IsBaseOf<nsISupports, mozilla::dom::Geolocation >::value,
     606             :   sNativePropertyHooks,
     607             :   FindAssociatedGlobalForNative<mozilla::dom::Geolocation>::Get,
     608             :   GetProtoObjectHandle,
     609             :   GetCCParticipant<mozilla::dom::Geolocation>::Get()
     610             : };
     611             : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
     612             :               "Must have the right minimal number of reserved slots.");
     613             : static_assert(1 >= 1,
     614             :               "Must have enough reserved slots.");
     615             : 
     616             : const JSClass*
     617           0 : GetJSClass()
     618             : {
     619           0 :   return sClass.ToJSClass();
     620             : }
     621             : 
     622             : bool
     623           0 : Wrap(JSContext* aCx, mozilla::dom::Geolocation* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
     624             : {
     625             :   MOZ_ASSERT(static_cast<mozilla::dom::Geolocation*>(aObject) ==
     626             :              reinterpret_cast<mozilla::dom::Geolocation*>(aObject),
     627             :              "Multiple inheritance for mozilla::dom::Geolocation is broken.");
     628           0 :   MOZ_ASSERT(ToSupportsIsCorrect(aObject));
     629           0 :   MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
     630           0 :   MOZ_ASSERT(!aCache->GetWrapper(),
     631             :              "You should probably not be using Wrap() directly; use "
     632             :              "GetOrCreateDOMReflector instead");
     633             : 
     634           0 :   MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
     635             :              "nsISupports must be on our primary inheritance chain");
     636             : 
     637           0 :   JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
     638           0 :   if (!global) {
     639           0 :     return false;
     640             :   }
     641           0 :   MOZ_ASSERT(JS_IsGlobalObject(global));
     642           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(global));
     643             : 
     644             :   // That might have ended up wrapping us already, due to the wonders
     645             :   // of XBL.  Check for that, and bail out as needed.
     646           0 :   aReflector.set(aCache->GetWrapper());
     647           0 :   if (aReflector) {
     648             : #ifdef DEBUG
     649           0 :     binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
     650             : #endif // DEBUG
     651           0 :     return true;
     652             :   }
     653             : 
     654           0 :   JSAutoCompartment ac(aCx, global);
     655           0 :   JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
     656           0 :   if (!canonicalProto) {
     657           0 :     return false;
     658             :   }
     659           0 :   JS::Rooted<JSObject*> proto(aCx);
     660           0 :   if (aGivenProto) {
     661           0 :     proto = aGivenProto;
     662             :     // Unfortunately, while aGivenProto was in the compartment of aCx
     663             :     // coming in, we changed compartments to that of "parent" so may need
     664             :     // to wrap the proto here.
     665           0 :     if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
     666           0 :       if (!JS_WrapObject(aCx, &proto)) {
     667           0 :         return false;
     668             :       }
     669             :     }
     670             :   } else {
     671           0 :     proto = canonicalProto;
     672             :   }
     673             : 
     674           0 :   BindingJSObjectCreator<mozilla::dom::Geolocation> creator(aCx);
     675           0 :   creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
     676           0 :   if (!aReflector) {
     677           0 :     return false;
     678             :   }
     679             : 
     680           0 :   aCache->SetWrapper(aReflector);
     681           0 :   creator.InitializationSucceeded();
     682             : 
     683           0 :   MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
     684             :              aCache->GetWrapperPreserveColor() == aReflector);
     685             :   // If proto != canonicalProto, we have to preserve our wrapper;
     686             :   // otherwise we won't be able to properly recreate it later, since
     687             :   // we won't know what proto to use.  Note that we don't check
     688             :   // aGivenProto here, since it's entirely possible (and even
     689             :   // somewhat common) to have a non-null aGivenProto which is the
     690             :   // same as canonicalProto.
     691           0 :   if (proto != canonicalProto) {
     692           0 :     PreserveWrapper(aObject);
     693             :   }
     694             : 
     695           0 :   return true;
     696             : }
     697             : 
     698             : const NativePropertyHooks sNativePropertyHooks[] = { {
     699             :   nullptr,
     700             :   nullptr,
     701             :   nullptr,
     702             :   { sNativeProperties.Upcast(), nullptr },
     703             :   prototypes::id::Geolocation,
     704             :   constructors::id::_ID_Count,
     705             :   nullptr,
     706             :   &DefaultXrayExpandoObjectClass
     707             : } };
     708             : 
     709             : void
     710           0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
     711             : {
     712           0 :   JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
     713           0 :   if (!parentProto) {
     714           0 :     return;
     715             :   }
     716             : 
     717             :   static bool sIdsInited = false;
     718           0 :   if (!sIdsInited && NS_IsMainThread()) {
     719           0 :     if (!InitIds(aCx, sNativeProperties.Upcast())) {
     720           0 :       return;
     721             :     }
     722           0 :     sIdsInited = true;
     723             :   }
     724             : 
     725           0 :   JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Geolocation);
     726           0 :   JS::Heap<JSObject*>* interfaceCache = nullptr;
     727           0 :   dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
     728             :                               &sPrototypeClass.mBase, protoCache,
     729             :                               nullptr, nullptr, 0, nullptr,
     730             :                               interfaceCache,
     731             :                               sNativeProperties.Upcast(),
     732             :                               nullptr,
     733             :                               nullptr, aDefineOnGlobal,
     734             :                               nullptr,
     735           0 :                               false);
     736             : }
     737             : 
     738             : JS::Handle<JSObject*>
     739           0 : GetProtoObjectHandle(JSContext* aCx)
     740             : {
     741             :   /* Get the interface prototype object for this class.  This will create the
     742             :      object as needed. */
     743           0 :   bool aDefineOnGlobal = true;
     744             : 
     745             :   /* Make sure our global is sane.  Hopefully we can remove this sometime */
     746           0 :   JSObject* global = JS::CurrentGlobalOrNull(aCx);
     747           0 :   if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
     748           0 :     return nullptr;
     749             :   }
     750             : 
     751             :   /* Check to see whether the interface objects are already installed */
     752           0 :   ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
     753           0 :   if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::Geolocation)) {
     754           0 :     JS::Rooted<JSObject*> rootedGlobal(aCx, global);
     755           0 :     CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
     756             :   }
     757             : 
     758             :   /*
     759             :    * The object might _still_ be null, but that's OK.
     760             :    *
     761             :    * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
     762             :    * traced by TraceProtoAndIfaceCache() and its contents are never
     763             :    * changed after they have been set.
     764             :    *
     765             :    * Calling address() avoids the read read barrier that does gray
     766             :    * unmarking, but it's not possible for the object to be gray here.
     767             :    */
     768             : 
     769           0 :   const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::Geolocation);
     770           0 :   MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
     771           0 :   return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
     772             : }
     773             : 
     774             : } // namespace GeolocationBinding
     775             : 
     776             : 
     777             : 
     778             : } // namespace dom
     779             : } // namespace mozilla

Generated by: LCOV version 1.13