Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ScreenOrientationBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM ScreenOrientation.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "EventHandlerBinding.h"
4
#include "EventTargetBinding.h"
5
#include "ScreenOrientationBinding.h"
6
#include "WrapperFactory.h"
7
#include "jsapi.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/NonRefcountedDOMObject.h"
12
#include "mozilla/dom/Nullable.h"
13
#include "mozilla/dom/PrimitiveConversions.h"
14
#include "mozilla/dom/Promise.h"
15
#include "mozilla/dom/ScreenOrientation.h"
16
#include "mozilla/dom/ToJSValue.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
#include "nsContentUtils.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
namespace OrientationTypeValues {
28
extern const EnumEntry strings[5] = {
29
  {"portrait-primary", 16},
30
  {"portrait-secondary", 18},
31
  {"landscape-primary", 17},
32
  {"landscape-secondary", 19},
33
  { nullptr, 0 }
34
};
35
} // namespace OrientationTypeValues
36
37
bool
38
ToJSValue(JSContext* aCx, OrientationType aArgument, JS::MutableHandle<JS::Value> aValue)
39
0
{
40
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(OrientationTypeValues::strings));
41
0
  JSString* resultStr =
42
0
    JS_NewStringCopyN(aCx, OrientationTypeValues::strings[uint32_t(aArgument)].value,
43
0
                      OrientationTypeValues::strings[uint32_t(aArgument)].length);
44
0
  if (!resultStr) {
45
0
    return false;
46
0
  }
47
0
  aValue.setString(resultStr);
48
0
  return true;
49
0
}
50
51
52
namespace OrientationLockTypeValues {
53
extern const EnumEntry strings[9] = {
54
  {"any", 3},
55
  {"natural", 7},
56
  {"landscape", 9},
57
  {"portrait", 8},
58
  {"portrait-primary", 16},
59
  {"portrait-secondary", 18},
60
  {"landscape-primary", 17},
61
  {"landscape-secondary", 19},
62
  { nullptr, 0 }
63
};
64
} // namespace OrientationLockTypeValues
65
66
bool
67
ToJSValue(JSContext* aCx, OrientationLockType aArgument, JS::MutableHandle<JS::Value> aValue)
68
0
{
69
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(OrientationLockTypeValues::strings));
70
0
  JSString* resultStr =
71
0
    JS_NewStringCopyN(aCx, OrientationLockTypeValues::strings[uint32_t(aArgument)].value,
72
0
                      OrientationLockTypeValues::strings[uint32_t(aArgument)].length);
73
0
  if (!resultStr) {
74
0
    return false;
75
0
  }
76
0
  aValue.setString(resultStr);
77
0
  return true;
78
0
}
79
80
81
namespace ScreenOrientation_Binding {
82
83
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
84
              "Can't inherit from an interface with a different ownership model.");
85
86
MOZ_CAN_RUN_SCRIPT static bool
87
lock(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenOrientation* self, const JSJitMethodCallArgs& args)
88
0
{
89
0
  AUTO_PROFILER_LABEL_FAST("ScreenOrientation.lock", DOM, cx);
90
0
91
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
92
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ScreenOrientation.lock");
93
0
  }
94
0
  OrientationLockType arg0;
95
0
  {
96
0
    int index;
97
0
    if (!FindEnumStringIndex<true>(cx, args[0], OrientationLockTypeValues::strings, "OrientationLockType", "Argument 1 of ScreenOrientation.lock", &index)) {
98
0
      return false;
99
0
    }
100
0
    MOZ_ASSERT(index >= 0);
101
0
    arg0 = static_cast<OrientationLockType>(index);
102
0
  }
103
0
  FastErrorResult rv;
104
0
  auto result(StrongOrRawPtr<Promise>(self->Lock(arg0, rv)));
105
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
106
0
    return false;
107
0
  }
108
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
109
0
  if (!ToJSValue(cx, result, args.rval())) {
110
0
    return false;
111
0
  }
112
0
  return true;
113
0
}
114
115
MOZ_CAN_RUN_SCRIPT static bool
116
lock_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenOrientation* self, const JSJitMethodCallArgs& args)
117
0
{
118
0
  bool ok = lock(cx, obj, self, args);
119
0
  if (ok) {
120
0
    return true;
121
0
  }
122
0
  return ConvertExceptionToPromise(cx, args.rval());
123
0
}
124
125
static const JSJitInfo lock_methodinfo = {
126
  { (JSJitGetterOp)lock_promiseWrapper },
127
  { prototypes::id::ScreenOrientation },
128
  { PrototypeTraits<prototypes::id::ScreenOrientation>::Depth },
129
  JSJitInfo::Method,
130
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
131
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
132
  false,  /* isInfallible. False in setters. */
133
  false,  /* isMovable.  Not relevant for setters. */
134
  false, /* isEliminatable.  Not relevant for setters. */
135
  false, /* isAlwaysInSlot.  Only relevant for getters. */
136
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
137
  false,  /* isTypedMethod.  Only relevant for methods. */
138
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
139
};
140
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
141
static_assert(0 < 1, "There is no slot for us");
142
143
MOZ_CAN_RUN_SCRIPT static bool
144
unlock(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenOrientation* self, const JSJitMethodCallArgs& args)
145
0
{
146
0
  AUTO_PROFILER_LABEL_FAST("ScreenOrientation.unlock", DOM, cx);
147
0
148
0
  FastErrorResult rv;
149
0
  self->Unlock(rv);
150
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
151
0
    return false;
152
0
  }
153
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
154
0
  args.rval().setUndefined();
155
0
  return true;
156
0
}
157
158
static const JSJitInfo unlock_methodinfo = {
159
  { (JSJitGetterOp)unlock },
160
  { prototypes::id::ScreenOrientation },
161
  { PrototypeTraits<prototypes::id::ScreenOrientation>::Depth },
162
  JSJitInfo::Method,
163
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
164
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
165
  false,  /* isInfallible. False in setters. */
166
  false,  /* isMovable.  Not relevant for setters. */
167
  false, /* isEliminatable.  Not relevant for setters. */
168
  false, /* isAlwaysInSlot.  Only relevant for getters. */
169
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
170
  false,  /* isTypedMethod.  Only relevant for methods. */
171
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
172
};
173
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
174
static_assert(0 < 1, "There is no slot for us");
175
176
MOZ_CAN_RUN_SCRIPT static bool
177
get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenOrientation* self, JSJitGetterCallArgs args)
178
0
{
179
0
  AUTO_PROFILER_LABEL_FAST("get ScreenOrientation.type", DOM, cx);
180
0
181
0
  FastErrorResult rv;
182
0
  OrientationType result(self->GetType(nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv));
183
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
184
0
    return false;
185
0
  }
186
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
187
0
  if (!ToJSValue(cx, result, args.rval())) {
188
0
    return false;
189
0
  }
190
0
  return true;
191
0
}
192
193
static const JSJitInfo type_getterinfo = {
194
  { (JSJitGetterOp)get_type },
195
  { prototypes::id::ScreenOrientation },
196
  { PrototypeTraits<prototypes::id::ScreenOrientation>::Depth },
197
  JSJitInfo::Getter,
198
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
199
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
200
  false,  /* isInfallible. False in setters. */
201
  false,  /* isMovable.  Not relevant for setters. */
202
  false, /* isEliminatable.  Not relevant for setters. */
203
  false, /* isAlwaysInSlot.  Only relevant for getters. */
204
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
205
  false,  /* isTypedMethod.  Only relevant for methods. */
206
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
207
};
208
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
209
static_assert(0 < 1, "There is no slot for us");
210
211
MOZ_CAN_RUN_SCRIPT static bool
212
get_angle(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenOrientation* self, JSJitGetterCallArgs args)
213
0
{
214
0
  AUTO_PROFILER_LABEL_FAST("get ScreenOrientation.angle", DOM, cx);
215
0
216
0
  FastErrorResult rv;
217
0
  uint16_t result(self->GetAngle(nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem, rv));
218
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
219
0
    return false;
220
0
  }
221
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
222
0
  args.rval().setInt32(int32_t(result));
223
0
  return true;
224
0
}
225
226
static const JSJitInfo angle_getterinfo = {
227
  { (JSJitGetterOp)get_angle },
228
  { prototypes::id::ScreenOrientation },
229
  { PrototypeTraits<prototypes::id::ScreenOrientation>::Depth },
230
  JSJitInfo::Getter,
231
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
232
  JSVAL_TYPE_INT32,  /* returnType.  Not relevant for setters. */
233
  false,  /* isInfallible. False in setters. */
234
  false,  /* isMovable.  Not relevant for setters. */
235
  false, /* isEliminatable.  Not relevant for setters. */
236
  false, /* isAlwaysInSlot.  Only relevant for getters. */
237
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
238
  false,  /* isTypedMethod.  Only relevant for methods. */
239
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
240
};
241
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
242
static_assert(0 < 1, "There is no slot for us");
243
244
MOZ_CAN_RUN_SCRIPT static bool
245
get_onchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenOrientation* self, JSJitGetterCallArgs args)
246
0
{
247
0
  AUTO_PROFILER_LABEL_FAST("get ScreenOrientation.onchange", DOM, cx);
248
0
249
0
  RefPtr<EventHandlerNonNull> result(self->GetOnchange());
250
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
251
0
  if (result) {
252
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
253
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
254
0
      return false;
255
0
    }
256
0
    return true;
257
0
  } else {
258
0
    args.rval().setNull();
259
0
    return true;
260
0
  }
261
0
}
262
263
MOZ_CAN_RUN_SCRIPT static bool
264
set_onchange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenOrientation* self, JSJitSetterCallArgs args)
265
0
{
266
0
  AUTO_PROFILER_LABEL_FAST("set ScreenOrientation.onchange", DOM, cx);
267
0
268
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
269
0
  if (args[0].isObject()) {
270
0
    { // scope for tempRoot and tempGlobalRoot if needed
271
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
272
0
    }
273
0
  } else {
274
0
    arg0 = nullptr;
275
0
  }
276
0
  self->SetOnchange(Constify(arg0));
277
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
278
0
279
0
  return true;
280
0
}
281
282
static const JSJitInfo onchange_getterinfo = {
283
  { (JSJitGetterOp)get_onchange },
284
  { prototypes::id::ScreenOrientation },
285
  { PrototypeTraits<prototypes::id::ScreenOrientation>::Depth },
286
  JSJitInfo::Getter,
287
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
288
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
289
  false,  /* isInfallible. False in setters. */
290
  false,  /* isMovable.  Not relevant for setters. */
291
  false, /* isEliminatable.  Not relevant for setters. */
292
  false, /* isAlwaysInSlot.  Only relevant for getters. */
293
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
294
  false,  /* isTypedMethod.  Only relevant for methods. */
295
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
296
};
297
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
298
static_assert(0 < 1, "There is no slot for us");
299
static const JSJitInfo onchange_setterinfo = {
300
  { (JSJitGetterOp)set_onchange },
301
  { prototypes::id::ScreenOrientation },
302
  { PrototypeTraits<prototypes::id::ScreenOrientation>::Depth },
303
  JSJitInfo::Setter,
304
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
305
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
306
  false,  /* isInfallible. False in setters. */
307
  false,  /* isMovable.  Not relevant for setters. */
308
  false, /* isEliminatable.  Not relevant for setters. */
309
  false, /* isAlwaysInSlot.  Only relevant for getters. */
310
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
311
  false,  /* isTypedMethod.  Only relevant for methods. */
312
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
313
};
314
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
315
static_assert(0 < 1, "There is no slot for us");
316
317
static bool
318
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
319
0
{
320
0
  mozilla::dom::ScreenOrientation* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ScreenOrientation>(obj);
321
0
  // We don't want to preserve if we don't have a wrapper, and we
322
0
  // obviously can't preserve if we're not initialized.
323
0
  if (self && self->GetWrapperPreserveColor()) {
324
0
    PreserveWrapper(self);
325
0
  }
326
0
  return true;
327
0
}
328
329
static void
330
_finalize(js::FreeOp* fop, JSObject* obj)
331
0
{
332
0
  mozilla::dom::ScreenOrientation* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ScreenOrientation>(obj);
333
0
  if (self) {
334
0
    ClearWrapper(self, self, obj);
335
0
    AddForDeferredFinalization<mozilla::dom::ScreenOrientation>(self);
336
0
  }
337
0
}
338
339
static size_t
340
_objectMoved(JSObject* obj, JSObject* old)
341
0
{
342
0
  mozilla::dom::ScreenOrientation* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ScreenOrientation>(obj);
343
0
  if (self) {
344
0
    UpdateWrapper(self, self, obj, old);
345
0
  }
346
0
347
0
  return 0;
348
0
}
349
350
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
351
#if defined(__clang__)
352
#pragma clang diagnostic push
353
#pragma clang diagnostic ignored "-Wmissing-braces"
354
#endif
355
static const JSFunctionSpec sMethods_specs[] = {
356
  JS_FNSPEC("lock", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&lock_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
357
  JS_FNSPEC("unlock", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&unlock_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
358
  JS_FS_END
359
};
360
#if defined(__clang__)
361
#pragma clang diagnostic pop
362
#endif
363
364
365
static const Prefable<const JSFunctionSpec> sMethods[] = {
366
  { nullptr, &sMethods_specs[0] },
367
  { nullptr, nullptr }
368
};
369
370
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
371
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
372
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
373
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
374
375
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
376
#if defined(__clang__)
377
#pragma clang diagnostic push
378
#pragma clang diagnostic ignored "-Wmissing-braces"
379
#endif
380
static const JSPropertySpec sAttributes_specs[] = {
381
  { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr },
382
  { "angle", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &angle_getterinfo, nullptr, nullptr },
383
  { "onchange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onchange_getterinfo, GenericSetter<NormalThisPolicy>, &onchange_setterinfo },
384
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
385
};
386
#if defined(__clang__)
387
#pragma clang diagnostic pop
388
#endif
389
390
391
static const Prefable<const JSPropertySpec> sAttributes[] = {
392
  { nullptr, &sAttributes_specs[0] },
393
  { nullptr, nullptr }
394
};
395
396
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
397
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
398
static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
399
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
400
401
402
static uint16_t sNativeProperties_sortedPropertyIndices[5];
403
static PropertyInfo sNativeProperties_propertyInfos[5];
404
405
static const NativePropertiesN<2> sNativeProperties = {
406
  false, 0,
407
  false, 0,
408
  true,  0 /* sMethods */,
409
  true,  1 /* sAttributes */,
410
  false, 0,
411
  false, 0,
412
  false, 0,
413
  -1,
414
  5,
415
  sNativeProperties_sortedPropertyIndices,
416
  {
417
    { sMethods, &sNativeProperties_propertyInfos[0] },
418
    { sAttributes, &sNativeProperties_propertyInfos[2] }
419
  }
420
};
421
static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
422
    "We have a property info count that is oversized");
423
424
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
425
  {
426
    "Function",
427
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
428
    &sBoringInterfaceObjectClassClassOps,
429
    JS_NULL_CLASS_SPEC,
430
    JS_NULL_CLASS_EXT,
431
    &sInterfaceObjectClassObjectOps
432
  },
433
  eInterface,
434
  true,
435
  prototypes::id::ScreenOrientation,
436
  PrototypeTraits<prototypes::id::ScreenOrientation>::Depth,
437
  sNativePropertyHooks,
438
  "function ScreenOrientation() {\n    [native code]\n}",
439
  EventTarget_Binding::GetConstructorObject
440
};
441
442
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
443
  {
444
    "ScreenOrientationPrototype",
445
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
446
    JS_NULL_CLASS_OPS,
447
    JS_NULL_CLASS_SPEC,
448
    JS_NULL_CLASS_EXT,
449
    JS_NULL_OBJECT_OPS
450
  },
451
  eInterfacePrototype,
452
  false,
453
  prototypes::id::ScreenOrientation,
454
  PrototypeTraits<prototypes::id::ScreenOrientation>::Depth,
455
  sNativePropertyHooks,
456
  "[object ScreenOrientationPrototype]",
457
  EventTarget_Binding::GetProtoObject
458
};
459
460
static const js::ClassOps sClassOps = {
461
  _addProperty, /* addProperty */
462
  nullptr,               /* delProperty */
463
  nullptr,               /* enumerate */
464
  nullptr, /* newEnumerate */
465
  nullptr, /* resolve */
466
  nullptr, /* mayResolve */
467
  _finalize, /* finalize */
468
  nullptr, /* call */
469
  nullptr,               /* hasInstance */
470
  nullptr,               /* construct */
471
  nullptr, /* trace */
472
};
473
474
static const js::ClassExtension sClassExtension = {
475
  nullptr, /* weakmapKeyDelegateOp */
476
  _objectMoved /* objectMovedOp */
477
};
478
479
static const DOMJSClass sClass = {
480
  { "ScreenOrientation",
481
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
482
    &sClassOps,
483
    JS_NULL_CLASS_SPEC,
484
    &sClassExtension,
485
    JS_NULL_OBJECT_OPS
486
  },
487
  { prototypes::id::EventTarget, prototypes::id::ScreenOrientation, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
488
  IsBaseOf<nsISupports, mozilla::dom::ScreenOrientation >::value,
489
  sNativePropertyHooks,
490
  FindAssociatedGlobalForNative<mozilla::dom::ScreenOrientation>::Get,
491
  GetProtoObjectHandle,
492
  GetCCParticipant<mozilla::dom::ScreenOrientation>::Get()
493
};
494
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
495
              "Must have the right minimal number of reserved slots.");
496
static_assert(1 >= 1,
497
              "Must have enough reserved slots.");
498
499
const JSClass*
500
GetJSClass()
501
0
{
502
0
  return sClass.ToJSClass();
503
0
}
504
505
bool
506
Wrap(JSContext* aCx, mozilla::dom::ScreenOrientation* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
507
0
{
508
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ScreenOrientation>::value,
509
0
                "Shouldn't have wrappercached things that are not refcounted.");
510
0
  MOZ_ASSERT(static_cast<mozilla::dom::ScreenOrientation*>(aObject) ==
511
0
             reinterpret_cast<mozilla::dom::ScreenOrientation*>(aObject),
512
0
             "Multiple inheritance for mozilla::dom::ScreenOrientation is broken.");
513
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
514
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
515
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
516
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
517
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
518
0
  MOZ_ASSERT(!aCache->GetWrapper(),
519
0
             "You should probably not be using Wrap() directly; use "
520
0
             "GetOrCreateDOMReflector instead");
521
0
522
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
523
0
             "nsISupports must be on our primary inheritance chain");
524
0
525
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
526
0
  if (!global) {
527
0
    return false;
528
0
  }
529
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
530
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
531
0
532
0
  // That might have ended up wrapping us already, due to the wonders
533
0
  // of XBL.  Check for that, and bail out as needed.
534
0
  aReflector.set(aCache->GetWrapper());
535
0
  if (aReflector) {
536
#ifdef DEBUG
537
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
538
#endif // DEBUG
539
    return true;
540
0
  }
541
0
542
0
  JSAutoRealm ar(aCx, global);
543
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
544
0
  if (!canonicalProto) {
545
0
    return false;
546
0
  }
547
0
  JS::Rooted<JSObject*> proto(aCx);
548
0
  if (aGivenProto) {
549
0
    proto = aGivenProto;
550
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
551
0
    // coming in, we changed compartments to that of "parent" so may need
552
0
    // to wrap the proto here.
553
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
554
0
      if (!JS_WrapObject(aCx, &proto)) {
555
0
        return false;
556
0
      }
557
0
    }
558
0
  } else {
559
0
    proto = canonicalProto;
560
0
  }
561
0
562
0
  BindingJSObjectCreator<mozilla::dom::ScreenOrientation> creator(aCx);
563
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
564
0
  if (!aReflector) {
565
0
    return false;
566
0
  }
567
0
568
0
  aCache->SetWrapper(aReflector);
569
0
  creator.InitializationSucceeded();
570
0
571
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
572
0
             aCache->GetWrapperPreserveColor() == aReflector);
573
0
  // If proto != canonicalProto, we have to preserve our wrapper;
574
0
  // otherwise we won't be able to properly recreate it later, since
575
0
  // we won't know what proto to use.  Note that we don't check
576
0
  // aGivenProto here, since it's entirely possible (and even
577
0
  // somewhat common) to have a non-null aGivenProto which is the
578
0
  // same as canonicalProto.
579
0
  if (proto != canonicalProto) {
580
0
    PreserveWrapper(aObject);
581
0
  }
582
0
583
0
  return true;
584
0
}
585
586
const NativePropertyHooks sNativePropertyHooks[] = { {
587
  nullptr,
588
  nullptr,
589
  nullptr,
590
  { sNativeProperties.Upcast(), nullptr },
591
  prototypes::id::ScreenOrientation,
592
  constructors::id::ScreenOrientation,
593
  EventTarget_Binding::sNativePropertyHooks,
594
  &DefaultXrayExpandoObjectClass
595
} };
596
597
void
598
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
599
0
{
600
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
601
0
  if (!parentProto) {
602
0
    return;
603
0
  }
604
0
605
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
606
0
  if (!constructorProto) {
607
0
    return;
608
0
  }
609
0
610
0
  static bool sIdsInited = false;
611
0
  if (!sIdsInited && NS_IsMainThread()) {
612
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
613
0
      return;
614
0
    }
615
0
    sIdsInited = true;
616
0
  }
617
0
618
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ScreenOrientation);
619
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ScreenOrientation);
620
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
621
0
                              &sPrototypeClass.mBase, protoCache,
622
0
                              nullptr,
623
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
624
0
                              interfaceCache,
625
0
                              sNativeProperties.Upcast(),
626
0
                              nullptr,
627
0
                              "ScreenOrientation", aDefineOnGlobal,
628
0
                              nullptr,
629
0
                              false);
630
0
}
631
632
JSObject*
633
GetConstructorObject(JSContext* aCx)
634
0
{
635
0
  return GetConstructorObjectHandle(aCx);
636
0
}
637
638
} // namespace ScreenOrientation_Binding
639
640
641
642
} // namespace dom
643
} // namespace mozilla