Coverage Report

Created: 2018-09-25 14:53

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