Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM Screen.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "EventHandlerBinding.h"
4 : #include "EventTargetBinding.h"
5 : #include "ScreenBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/Nullable.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/ScreenOrientation.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 : #include "nsContentUtils.h"
16 : #include "nsISupports.h"
17 : #include "nsScreen.h"
18 : #include "xpcjsid.h"
19 :
20 : namespace mozilla {
21 : namespace dom {
22 :
23 : namespace ScreenBinding {
24 :
25 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
26 : "Can't inherit from an interface with a different ownership model.");
27 :
28 : static bool
29 1 : get_availWidth(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
30 : {
31 2 : binding_detail::FastErrorResult rv;
32 1 : int32_t result(self->GetAvailWidth(rv));
33 1 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
34 0 : return false;
35 : }
36 1 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
37 1 : args.rval().setInt32(int32_t(result));
38 1 : return true;
39 : }
40 :
41 : static const JSJitInfo availWidth_getterinfo = {
42 : { (JSJitGetterOp)get_availWidth },
43 : { prototypes::id::Screen },
44 : { PrototypeTraits<prototypes::id::Screen>::Depth },
45 : JSJitInfo::Getter,
46 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
47 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
48 : false, /* isInfallible. False in setters. */
49 : false, /* isMovable. Not relevant for setters. */
50 : false, /* isEliminatable. Not relevant for setters. */
51 : false, /* isAlwaysInSlot. Only relevant for getters. */
52 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
53 : false, /* isTypedMethod. Only relevant for methods. */
54 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
55 : };
56 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
57 : static_assert(0 < 1, "There is no slot for us");
58 :
59 : static bool
60 1 : get_availHeight(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
61 : {
62 2 : binding_detail::FastErrorResult rv;
63 1 : int32_t result(self->GetAvailHeight(rv));
64 1 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
65 0 : return false;
66 : }
67 1 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
68 1 : args.rval().setInt32(int32_t(result));
69 1 : return true;
70 : }
71 :
72 : static const JSJitInfo availHeight_getterinfo = {
73 : { (JSJitGetterOp)get_availHeight },
74 : { prototypes::id::Screen },
75 : { PrototypeTraits<prototypes::id::Screen>::Depth },
76 : JSJitInfo::Getter,
77 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
78 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
79 : false, /* isInfallible. False in setters. */
80 : false, /* isMovable. Not relevant for setters. */
81 : false, /* isEliminatable. Not relevant for setters. */
82 : false, /* isAlwaysInSlot. Only relevant for getters. */
83 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
84 : false, /* isTypedMethod. Only relevant for methods. */
85 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
86 : };
87 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
88 : static_assert(0 < 1, "There is no slot for us");
89 :
90 : static bool
91 3 : get_width(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
92 : {
93 6 : binding_detail::FastErrorResult rv;
94 3 : int32_t result(self->GetWidth(rv));
95 3 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
96 0 : return false;
97 : }
98 3 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
99 3 : args.rval().setInt32(int32_t(result));
100 3 : return true;
101 : }
102 :
103 : static const JSJitInfo width_getterinfo = {
104 : { (JSJitGetterOp)get_width },
105 : { prototypes::id::Screen },
106 : { PrototypeTraits<prototypes::id::Screen>::Depth },
107 : JSJitInfo::Getter,
108 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
109 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
110 : false, /* isInfallible. False in setters. */
111 : false, /* isMovable. Not relevant for setters. */
112 : false, /* isEliminatable. Not relevant for setters. */
113 : false, /* isAlwaysInSlot. Only relevant for getters. */
114 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
115 : false, /* isTypedMethod. Only relevant for methods. */
116 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
117 : };
118 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
119 : static_assert(0 < 1, "There is no slot for us");
120 :
121 : static bool
122 3 : get_height(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
123 : {
124 6 : binding_detail::FastErrorResult rv;
125 3 : int32_t result(self->GetHeight(rv));
126 3 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
127 0 : return false;
128 : }
129 3 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
130 3 : args.rval().setInt32(int32_t(result));
131 3 : return true;
132 : }
133 :
134 : static const JSJitInfo height_getterinfo = {
135 : { (JSJitGetterOp)get_height },
136 : { prototypes::id::Screen },
137 : { PrototypeTraits<prototypes::id::Screen>::Depth },
138 : JSJitInfo::Getter,
139 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
140 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
141 : false, /* isInfallible. False in setters. */
142 : false, /* isMovable. Not relevant for setters. */
143 : false, /* isEliminatable. Not relevant for setters. */
144 : false, /* isAlwaysInSlot. Only relevant for getters. */
145 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
146 : false, /* isTypedMethod. Only relevant for methods. */
147 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
148 : };
149 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
150 : static_assert(0 < 1, "There is no slot for us");
151 :
152 : static bool
153 0 : get_colorDepth(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
154 : {
155 0 : binding_detail::FastErrorResult rv;
156 0 : int32_t result(self->GetColorDepth(rv));
157 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
158 0 : return false;
159 : }
160 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
161 0 : args.rval().setInt32(int32_t(result));
162 0 : return true;
163 : }
164 :
165 : static const JSJitInfo colorDepth_getterinfo = {
166 : { (JSJitGetterOp)get_colorDepth },
167 : { prototypes::id::Screen },
168 : { PrototypeTraits<prototypes::id::Screen>::Depth },
169 : JSJitInfo::Getter,
170 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
171 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
172 : false, /* isInfallible. False in setters. */
173 : false, /* isMovable. Not relevant for setters. */
174 : false, /* isEliminatable. Not relevant for setters. */
175 : false, /* isAlwaysInSlot. Only relevant for getters. */
176 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
177 : false, /* isTypedMethod. Only relevant for methods. */
178 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
179 : };
180 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
181 : static_assert(0 < 1, "There is no slot for us");
182 :
183 : static bool
184 0 : get_pixelDepth(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
185 : {
186 0 : binding_detail::FastErrorResult rv;
187 0 : int32_t result(self->GetPixelDepth(rv));
188 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
189 0 : return false;
190 : }
191 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
192 0 : args.rval().setInt32(int32_t(result));
193 0 : return true;
194 : }
195 :
196 : static const JSJitInfo pixelDepth_getterinfo = {
197 : { (JSJitGetterOp)get_pixelDepth },
198 : { prototypes::id::Screen },
199 : { PrototypeTraits<prototypes::id::Screen>::Depth },
200 : JSJitInfo::Getter,
201 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
202 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
203 : false, /* isInfallible. False in setters. */
204 : false, /* isMovable. Not relevant for setters. */
205 : false, /* isEliminatable. Not relevant for setters. */
206 : false, /* isAlwaysInSlot. Only relevant for getters. */
207 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
208 : false, /* isTypedMethod. Only relevant for methods. */
209 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
210 : };
211 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
212 : static_assert(0 < 1, "There is no slot for us");
213 :
214 : static bool
215 0 : get_top(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
216 : {
217 0 : binding_detail::FastErrorResult rv;
218 0 : int32_t result(self->GetTop(rv));
219 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
220 0 : return false;
221 : }
222 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
223 0 : args.rval().setInt32(int32_t(result));
224 0 : return true;
225 : }
226 :
227 : static const JSJitInfo top_getterinfo = {
228 : { (JSJitGetterOp)get_top },
229 : { prototypes::id::Screen },
230 : { PrototypeTraits<prototypes::id::Screen>::Depth },
231 : JSJitInfo::Getter,
232 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
233 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
234 : false, /* isInfallible. False in setters. */
235 : false, /* isMovable. Not relevant for setters. */
236 : false, /* isEliminatable. Not relevant for setters. */
237 : false, /* isAlwaysInSlot. Only relevant for getters. */
238 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
239 : false, /* isTypedMethod. Only relevant for methods. */
240 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
241 : };
242 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
243 : static_assert(0 < 1, "There is no slot for us");
244 :
245 : static bool
246 0 : get_left(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
247 : {
248 0 : binding_detail::FastErrorResult rv;
249 0 : int32_t result(self->GetLeft(rv));
250 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
251 0 : return false;
252 : }
253 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
254 0 : args.rval().setInt32(int32_t(result));
255 0 : return true;
256 : }
257 :
258 : static const JSJitInfo left_getterinfo = {
259 : { (JSJitGetterOp)get_left },
260 : { prototypes::id::Screen },
261 : { PrototypeTraits<prototypes::id::Screen>::Depth },
262 : JSJitInfo::Getter,
263 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
264 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
265 : false, /* isInfallible. False in setters. */
266 : false, /* isMovable. Not relevant for setters. */
267 : false, /* isEliminatable. Not relevant for setters. */
268 : false, /* isAlwaysInSlot. Only relevant for getters. */
269 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
270 : false, /* isTypedMethod. Only relevant for methods. */
271 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
272 : };
273 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
274 : static_assert(0 < 1, "There is no slot for us");
275 :
276 : static bool
277 0 : get_availTop(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
278 : {
279 0 : binding_detail::FastErrorResult rv;
280 0 : int32_t result(self->GetAvailTop(rv));
281 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
282 0 : return false;
283 : }
284 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
285 0 : args.rval().setInt32(int32_t(result));
286 0 : return true;
287 : }
288 :
289 : static const JSJitInfo availTop_getterinfo = {
290 : { (JSJitGetterOp)get_availTop },
291 : { prototypes::id::Screen },
292 : { PrototypeTraits<prototypes::id::Screen>::Depth },
293 : JSJitInfo::Getter,
294 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
295 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
296 : false, /* isInfallible. False in setters. */
297 : false, /* isMovable. Not relevant for setters. */
298 : false, /* isEliminatable. Not relevant for setters. */
299 : false, /* isAlwaysInSlot. Only relevant for getters. */
300 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
301 : false, /* isTypedMethod. Only relevant for methods. */
302 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
303 : };
304 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
305 : static_assert(0 < 1, "There is no slot for us");
306 :
307 : static bool
308 0 : get_availLeft(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
309 : {
310 0 : binding_detail::FastErrorResult rv;
311 0 : int32_t result(self->GetAvailLeft(rv));
312 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
313 0 : return false;
314 : }
315 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
316 0 : args.rval().setInt32(int32_t(result));
317 0 : return true;
318 : }
319 :
320 : static const JSJitInfo availLeft_getterinfo = {
321 : { (JSJitGetterOp)get_availLeft },
322 : { prototypes::id::Screen },
323 : { PrototypeTraits<prototypes::id::Screen>::Depth },
324 : JSJitInfo::Getter,
325 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
326 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
327 : false, /* isInfallible. False in setters. */
328 : false, /* isMovable. Not relevant for setters. */
329 : false, /* isEliminatable. Not relevant for setters. */
330 : false, /* isAlwaysInSlot. Only relevant for getters. */
331 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
332 : false, /* isTypedMethod. Only relevant for methods. */
333 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
334 : };
335 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
336 : static_assert(0 < 1, "There is no slot for us");
337 :
338 : static bool
339 0 : get_mozOrientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
340 : {
341 0 : DOMString result;
342 0 : self->GetMozOrientation(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem);
343 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
344 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
345 0 : return false;
346 : }
347 0 : return true;
348 : }
349 :
350 : static const JSJitInfo mozOrientation_getterinfo = {
351 : { (JSJitGetterOp)get_mozOrientation },
352 : { prototypes::id::Screen },
353 : { PrototypeTraits<prototypes::id::Screen>::Depth },
354 : JSJitInfo::Getter,
355 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
356 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
357 : false, /* isInfallible. False in setters. */
358 : false, /* isMovable. Not relevant for setters. */
359 : false, /* isEliminatable. Not relevant for setters. */
360 : false, /* isAlwaysInSlot. Only relevant for getters. */
361 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
362 : false, /* isTypedMethod. Only relevant for methods. */
363 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
364 : };
365 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
366 : static_assert(0 < 1, "There is no slot for us");
367 :
368 : static bool
369 0 : get_onmozorientationchange(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
370 : {
371 0 : RefPtr<EventHandlerNonNull> result(self->GetOnmozorientationchange());
372 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
373 0 : if (result) {
374 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
375 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
376 0 : return false;
377 : }
378 0 : return true;
379 : } else {
380 0 : args.rval().setNull();
381 0 : return true;
382 : }
383 : }
384 :
385 : static bool
386 0 : set_onmozorientationchange(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitSetterCallArgs args)
387 : {
388 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
389 0 : if (args[0].isObject()) {
390 : { // scope for tempRoot
391 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
392 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
393 : }
394 : } else {
395 0 : arg0 = nullptr;
396 : }
397 0 : self->SetOnmozorientationchange(Constify(arg0));
398 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
399 :
400 0 : return true;
401 : }
402 :
403 : static const JSJitInfo onmozorientationchange_getterinfo = {
404 : { (JSJitGetterOp)get_onmozorientationchange },
405 : { prototypes::id::Screen },
406 : { PrototypeTraits<prototypes::id::Screen>::Depth },
407 : JSJitInfo::Getter,
408 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
409 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
410 : false, /* isInfallible. False in setters. */
411 : false, /* isMovable. Not relevant for setters. */
412 : false, /* isEliminatable. Not relevant for setters. */
413 : false, /* isAlwaysInSlot. Only relevant for getters. */
414 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
415 : false, /* isTypedMethod. Only relevant for methods. */
416 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
417 : };
418 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
419 : static_assert(0 < 1, "There is no slot for us");
420 : static const JSJitInfo onmozorientationchange_setterinfo = {
421 : { (JSJitGetterOp)set_onmozorientationchange },
422 : { prototypes::id::Screen },
423 : { PrototypeTraits<prototypes::id::Screen>::Depth },
424 : JSJitInfo::Setter,
425 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
426 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
427 : false, /* isInfallible. False in setters. */
428 : false, /* isMovable. Not relevant for setters. */
429 : false, /* isEliminatable. Not relevant for setters. */
430 : false, /* isAlwaysInSlot. Only relevant for getters. */
431 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
432 : false, /* isTypedMethod. Only relevant for methods. */
433 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
434 : };
435 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
436 : static_assert(0 < 1, "There is no slot for us");
437 :
438 : static bool
439 0 : mozLockOrientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, const JSJitMethodCallArgs& args)
440 : {
441 0 : unsigned argcount = std::min(args.length(), 1u);
442 0 : switch (argcount) {
443 : case 1: {
444 0 : if (args[0].isObject()) {
445 : do {
446 0 : binding_detail::AutoSequence<nsString> arg0;
447 0 : JS::ForOfIterator iter(cx);
448 0 : if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) {
449 0 : return false;
450 : }
451 0 : if (!iter.valueIsIterable()) {
452 0 : break;
453 : }
454 0 : binding_detail::AutoSequence<nsString> &arr = arg0;
455 0 : JS::Rooted<JS::Value> temp(cx);
456 : while (true) {
457 : bool done;
458 0 : if (!iter.next(&temp, &done)) {
459 0 : return false;
460 : }
461 0 : if (done) {
462 0 : break;
463 : }
464 0 : nsString* slotPtr = arr.AppendElement(mozilla::fallible);
465 0 : if (!slotPtr) {
466 0 : JS_ReportOutOfMemory(cx);
467 0 : return false;
468 : }
469 0 : nsString& slot = *slotPtr;
470 0 : if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) {
471 0 : return false;
472 : }
473 0 : }
474 0 : if (!mozilla::dom::EnforceNotInPrerendering(cx, obj)) {
475 : // Return false from the JSNative in order to trigger
476 : // an uncatchable exception.
477 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
478 0 : return false;
479 : }
480 0 : binding_detail::FastErrorResult rv;
481 0 : bool result(self->MozLockOrientation(Constify(arg0), rv));
482 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
483 0 : return false;
484 : }
485 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
486 0 : args.rval().setBoolean(result);
487 0 : return true;
488 : } while (0);
489 : }
490 0 : if (!mozilla::dom::EnforceNotInPrerendering(cx, obj)) {
491 : // Return false from the JSNative in order to trigger
492 : // an uncatchable exception.
493 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
494 0 : return false;
495 : }
496 0 : binding_detail::FakeString arg0;
497 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
498 0 : return false;
499 : }
500 0 : binding_detail::FastErrorResult rv;
501 0 : bool result(self->MozLockOrientation(NonNullHelper(Constify(arg0)), rv));
502 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
503 0 : return false;
504 : }
505 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
506 0 : args.rval().setBoolean(result);
507 0 : return true;
508 : break;
509 : }
510 : default: {
511 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Screen.mozLockOrientation");
512 : break;
513 : }
514 : }
515 : MOZ_CRASH("We have an always-returning default case");
516 : return false;
517 : }
518 :
519 : static const JSJitInfo mozLockOrientation_methodinfo = {
520 : { (JSJitGetterOp)mozLockOrientation },
521 : { prototypes::id::Screen },
522 : { PrototypeTraits<prototypes::id::Screen>::Depth },
523 : JSJitInfo::Method,
524 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
525 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
526 : false, /* isInfallible. False in setters. */
527 : false, /* isMovable. Not relevant for setters. */
528 : false, /* isEliminatable. Not relevant for setters. */
529 : false, /* isAlwaysInSlot. Only relevant for getters. */
530 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
531 : false, /* isTypedMethod. Only relevant for methods. */
532 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
533 : };
534 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
535 : static_assert(0 < 1, "There is no slot for us");
536 :
537 : static bool
538 0 : mozUnlockOrientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, const JSJitMethodCallArgs& args)
539 : {
540 0 : if (!mozilla::dom::EnforceNotInPrerendering(cx, obj)) {
541 : // Return false from the JSNative in order to trigger
542 : // an uncatchable exception.
543 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
544 0 : return false;
545 : }
546 0 : self->MozUnlockOrientation();
547 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
548 0 : args.rval().setUndefined();
549 0 : return true;
550 : }
551 :
552 : static const JSJitInfo mozUnlockOrientation_methodinfo = {
553 : { (JSJitGetterOp)mozUnlockOrientation },
554 : { prototypes::id::Screen },
555 : { PrototypeTraits<prototypes::id::Screen>::Depth },
556 : JSJitInfo::Method,
557 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
558 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
559 : true, /* isInfallible. False in setters. */
560 : false, /* isMovable. Not relevant for setters. */
561 : false, /* isEliminatable. Not relevant for setters. */
562 : false, /* isAlwaysInSlot. Only relevant for getters. */
563 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
564 : false, /* isTypedMethod. Only relevant for methods. */
565 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
566 : };
567 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
568 : static_assert(0 < 1, "There is no slot for us");
569 :
570 : static bool
571 0 : get_orientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args)
572 : {
573 0 : auto result(StrongOrRawPtr<mozilla::dom::ScreenOrientation>(self->Orientation()));
574 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
575 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
576 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
577 0 : return false;
578 : }
579 0 : return true;
580 : }
581 :
582 : static const JSJitInfo orientation_getterinfo = {
583 : { (JSJitGetterOp)get_orientation },
584 : { prototypes::id::Screen },
585 : { PrototypeTraits<prototypes::id::Screen>::Depth },
586 : JSJitInfo::Getter,
587 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
588 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
589 : false, /* isInfallible. False in setters. */
590 : false, /* isMovable. Not relevant for setters. */
591 : false, /* isEliminatable. Not relevant for setters. */
592 : false, /* isAlwaysInSlot. Only relevant for getters. */
593 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
594 : false, /* isTypedMethod. Only relevant for methods. */
595 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
596 : };
597 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
598 : static_assert(0 < 1, "There is no slot for us");
599 :
600 : static bool
601 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
602 : {
603 0 : nsScreen* self = UnwrapPossiblyNotInitializedDOMObject<nsScreen>(obj);
604 : // We don't want to preserve if we don't have a wrapper, and we
605 : // obviously can't preserve if we're not initialized.
606 0 : if (self && self->GetWrapperPreserveColor()) {
607 0 : PreserveWrapper(self);
608 : }
609 0 : return true;
610 : }
611 :
612 : static void
613 0 : _finalize(js::FreeOp* fop, JSObject* obj)
614 : {
615 0 : nsScreen* self = UnwrapPossiblyNotInitializedDOMObject<nsScreen>(obj);
616 0 : if (self) {
617 0 : ClearWrapper(self, self, obj);
618 0 : AddForDeferredFinalization<nsScreen>(self);
619 : }
620 0 : }
621 :
622 : static void
623 0 : _objectMoved(JSObject* obj, const JSObject* old)
624 : {
625 0 : nsScreen* self = UnwrapPossiblyNotInitializedDOMObject<nsScreen>(obj);
626 0 : if (self) {
627 0 : UpdateWrapper(self, self, obj, old);
628 : }
629 0 : }
630 :
631 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
632 : #if defined(__clang__)
633 : #pragma clang diagnostic push
634 : #pragma clang diagnostic ignored "-Wmissing-braces"
635 : #endif
636 : static const JSFunctionSpec sMethods_specs[] = {
637 : JS_FNSPEC("mozLockOrientation", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&mozLockOrientation_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
638 : JS_FNSPEC("mozUnlockOrientation", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&mozUnlockOrientation_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
639 : JS_FS_END,
640 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
641 : JS_FS_END
642 : };
643 : #if defined(__clang__)
644 : #pragma clang diagnostic pop
645 : #endif
646 :
647 : static PrefableDisablers sMethods_disablers3 = {
648 : true, false, 0, &WantsQueryInterface<nsScreen>::Enabled
649 : };
650 :
651 : // Can't be const because the pref-enabled boolean needs to be writable
652 : static Prefable<const JSFunctionSpec> sMethods[] = {
653 : { nullptr, &sMethods_specs[0] },
654 : { &sMethods_disablers3, &sMethods_specs[3] },
655 : { nullptr, nullptr }
656 : };
657 :
658 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
659 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
660 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
661 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
662 :
663 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
664 : #if defined(__clang__)
665 : #pragma clang diagnostic push
666 : #pragma clang diagnostic ignored "-Wmissing-braces"
667 : #endif
668 : static const JSPropertySpec sAttributes_specs[] = {
669 : { "availWidth", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &availWidth_getterinfo, nullptr, nullptr },
670 : { "availHeight", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &availHeight_getterinfo, nullptr, nullptr },
671 : { "width", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &width_getterinfo, nullptr, nullptr },
672 : { "height", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &height_getterinfo, nullptr, nullptr },
673 : { "colorDepth", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &colorDepth_getterinfo, nullptr, nullptr },
674 : { "pixelDepth", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &pixelDepth_getterinfo, nullptr, nullptr },
675 : { "top", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &top_getterinfo, nullptr, nullptr },
676 : { "left", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &left_getterinfo, nullptr, nullptr },
677 : { "availTop", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &availTop_getterinfo, nullptr, nullptr },
678 : { "availLeft", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &availLeft_getterinfo, nullptr, nullptr },
679 : { "mozOrientation", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &mozOrientation_getterinfo, nullptr, nullptr },
680 : { "onmozorientationchange", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onmozorientationchange_getterinfo, GenericBindingSetter, &onmozorientationchange_setterinfo },
681 : { "orientation", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &orientation_getterinfo, nullptr, nullptr },
682 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
683 : };
684 : #if defined(__clang__)
685 : #pragma clang diagnostic pop
686 : #endif
687 :
688 :
689 : // Can't be const because the pref-enabled boolean needs to be writable
690 : static Prefable<const JSPropertySpec> sAttributes[] = {
691 : { nullptr, &sAttributes_specs[0] },
692 : { nullptr, nullptr }
693 : };
694 :
695 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
696 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
697 : static_assert(13 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
698 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
699 :
700 :
701 : static uint16_t sNativeProperties_sortedPropertyIndices[16];
702 : static PropertyInfo sNativeProperties_propertyInfos[16];
703 :
704 : static const NativePropertiesN<2> sNativeProperties = {
705 : false, 0,
706 : false, 0,
707 : true, 0 /* sMethods */,
708 : true, 1 /* sAttributes */,
709 : false, 0,
710 : false, 0,
711 : false, 0,
712 : -1,
713 : 16,
714 : sNativeProperties_sortedPropertyIndices,
715 : {
716 : { sMethods, &sNativeProperties_propertyInfos[0] },
717 : { sAttributes, &sNativeProperties_propertyInfos[3] }
718 : }
719 : };
720 : static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
721 : "We have a property info count that is oversized");
722 :
723 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
724 : {
725 : "Function",
726 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
727 : &sBoringInterfaceObjectClassClassOps,
728 : JS_NULL_CLASS_SPEC,
729 : JS_NULL_CLASS_EXT,
730 : &sInterfaceObjectClassObjectOps
731 : },
732 : eInterface,
733 : true,
734 : prototypes::id::Screen,
735 : PrototypeTraits<prototypes::id::Screen>::Depth,
736 : sNativePropertyHooks,
737 : "function Screen() {\n [native code]\n}",
738 : EventTargetBinding::GetConstructorObject
739 : };
740 :
741 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
742 : {
743 : "ScreenPrototype",
744 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
745 : JS_NULL_CLASS_OPS,
746 : JS_NULL_CLASS_SPEC,
747 : JS_NULL_CLASS_EXT,
748 : JS_NULL_OBJECT_OPS
749 : },
750 : eInterfacePrototype,
751 : false,
752 : prototypes::id::Screen,
753 : PrototypeTraits<prototypes::id::Screen>::Depth,
754 : sNativePropertyHooks,
755 : "[object ScreenPrototype]",
756 : EventTargetBinding::GetProtoObject
757 : };
758 :
759 : JSObject*
760 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
761 : {
762 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
763 : }
764 :
765 : static const js::ClassOps sClassOps = {
766 : _addProperty, /* addProperty */
767 : nullptr, /* delProperty */
768 : nullptr, /* getProperty */
769 : nullptr, /* setProperty */
770 : nullptr, /* enumerate */
771 : nullptr, /* newEnumerate */
772 : nullptr, /* resolve */
773 : nullptr, /* mayResolve */
774 : _finalize, /* finalize */
775 : nullptr, /* call */
776 : nullptr, /* hasInstance */
777 : nullptr, /* construct */
778 : nullptr, /* trace */
779 : };
780 :
781 : static const js::ClassExtension sClassExtension = {
782 : nullptr, /* weakmapKeyDelegateOp */
783 : _objectMoved /* objectMovedOp */
784 : };
785 :
786 : static const DOMJSClass sClass = {
787 : { "Screen",
788 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
789 : &sClassOps,
790 : JS_NULL_CLASS_SPEC,
791 : &sClassExtension,
792 : JS_NULL_OBJECT_OPS
793 : },
794 : { prototypes::id::EventTarget, prototypes::id::Screen, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
795 : IsBaseOf<nsISupports, nsScreen >::value,
796 : sNativePropertyHooks,
797 : FindAssociatedGlobalForNative<nsScreen>::Get,
798 : GetProtoObjectHandle,
799 : GetCCParticipant<nsScreen>::Get()
800 : };
801 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
802 : "Must have the right minimal number of reserved slots.");
803 : static_assert(1 >= 1,
804 : "Must have enough reserved slots.");
805 :
806 : const JSClass*
807 0 : GetJSClass()
808 : {
809 0 : return sClass.ToJSClass();
810 : }
811 :
812 : bool
813 1 : Wrap(JSContext* aCx, nsScreen* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
814 : {
815 : MOZ_ASSERT(static_cast<nsScreen*>(aObject) ==
816 : reinterpret_cast<nsScreen*>(aObject),
817 : "Multiple inheritance for nsScreen is broken.");
818 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
819 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
820 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
821 1 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
822 1 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
823 1 : MOZ_ASSERT(!aCache->GetWrapper(),
824 : "You should probably not be using Wrap() directly; use "
825 : "GetOrCreateDOMReflector instead");
826 :
827 1 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
828 : "nsISupports must be on our primary inheritance chain");
829 :
830 2 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
831 1 : if (!global) {
832 0 : return false;
833 : }
834 1 : MOZ_ASSERT(JS_IsGlobalObject(global));
835 1 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
836 :
837 : // That might have ended up wrapping us already, due to the wonders
838 : // of XBL. Check for that, and bail out as needed.
839 1 : aReflector.set(aCache->GetWrapper());
840 1 : if (aReflector) {
841 : #ifdef DEBUG
842 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
843 : #endif // DEBUG
844 0 : return true;
845 : }
846 :
847 2 : JSAutoCompartment ac(aCx, global);
848 1 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
849 1 : if (!canonicalProto) {
850 0 : return false;
851 : }
852 2 : JS::Rooted<JSObject*> proto(aCx);
853 1 : if (aGivenProto) {
854 0 : proto = aGivenProto;
855 : // Unfortunately, while aGivenProto was in the compartment of aCx
856 : // coming in, we changed compartments to that of "parent" so may need
857 : // to wrap the proto here.
858 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
859 0 : if (!JS_WrapObject(aCx, &proto)) {
860 0 : return false;
861 : }
862 : }
863 : } else {
864 1 : proto = canonicalProto;
865 : }
866 :
867 2 : BindingJSObjectCreator<nsScreen> creator(aCx);
868 1 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
869 1 : if (!aReflector) {
870 0 : return false;
871 : }
872 :
873 1 : aCache->SetWrapper(aReflector);
874 1 : creator.InitializationSucceeded();
875 :
876 1 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
877 : aCache->GetWrapperPreserveColor() == aReflector);
878 : // If proto != canonicalProto, we have to preserve our wrapper;
879 : // otherwise we won't be able to properly recreate it later, since
880 : // we won't know what proto to use. Note that we don't check
881 : // aGivenProto here, since it's entirely possible (and even
882 : // somewhat common) to have a non-null aGivenProto which is the
883 : // same as canonicalProto.
884 1 : if (proto != canonicalProto) {
885 0 : PreserveWrapper(aObject);
886 : }
887 :
888 1 : return true;
889 : }
890 :
891 : const NativePropertyHooks sNativePropertyHooks[] = { {
892 : nullptr,
893 : nullptr,
894 : nullptr,
895 : { sNativeProperties.Upcast(), nullptr },
896 : prototypes::id::Screen,
897 : constructors::id::Screen,
898 : EventTargetBinding::sNativePropertyHooks,
899 : &DefaultXrayExpandoObjectClass
900 : } };
901 :
902 : void
903 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
904 : {
905 1 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
906 1 : if (!parentProto) {
907 0 : return;
908 : }
909 :
910 1 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
911 1 : if (!constructorProto) {
912 0 : return;
913 : }
914 :
915 : static bool sIdsInited = false;
916 1 : if (!sIdsInited && NS_IsMainThread()) {
917 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
918 0 : return;
919 : }
920 1 : sIdsInited = true;
921 : }
922 :
923 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Screen);
924 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Screen);
925 1 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
926 : &sPrototypeClass.mBase, protoCache,
927 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
928 : interfaceCache,
929 : sNativeProperties.Upcast(),
930 : nullptr,
931 : "Screen", aDefineOnGlobal,
932 : nullptr,
933 1 : false);
934 : }
935 :
936 : JS::Handle<JSObject*>
937 1 : GetProtoObjectHandle(JSContext* aCx)
938 : {
939 : /* Get the interface prototype object for this class. This will create the
940 : object as needed. */
941 1 : bool aDefineOnGlobal = true;
942 :
943 : /* Make sure our global is sane. Hopefully we can remove this sometime */
944 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
945 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
946 0 : return nullptr;
947 : }
948 :
949 : /* Check to see whether the interface objects are already installed */
950 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
951 1 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::Screen)) {
952 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
953 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
954 : }
955 :
956 : /*
957 : * The object might _still_ be null, but that's OK.
958 : *
959 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
960 : * traced by TraceProtoAndIfaceCache() and its contents are never
961 : * changed after they have been set.
962 : *
963 : * Calling address() avoids the read read barrier that does gray
964 : * unmarking, but it's not possible for the object to be gray here.
965 : */
966 :
967 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::Screen);
968 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
969 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
970 : }
971 :
972 : JS::Handle<JSObject*>
973 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
974 : {
975 : /* Get the interface object for this class. This will create the object as
976 : needed. */
977 :
978 : /* Make sure our global is sane. Hopefully we can remove this sometime */
979 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
980 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
981 0 : return nullptr;
982 : }
983 :
984 : /* Check to see whether the interface objects are already installed */
985 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
986 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::Screen)) {
987 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
988 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
989 : }
990 :
991 : /*
992 : * The object might _still_ be null, but that's OK.
993 : *
994 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
995 : * traced by TraceProtoAndIfaceCache() and its contents are never
996 : * changed after they have been set.
997 : *
998 : * Calling address() avoids the read read barrier that does gray
999 : * unmarking, but it's not possible for the object to be gray here.
1000 : */
1001 :
1002 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::Screen);
1003 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1004 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1005 : }
1006 :
1007 : JSObject*
1008 0 : GetConstructorObject(JSContext* aCx)
1009 : {
1010 0 : return GetConstructorObjectHandle(aCx);
1011 : }
1012 :
1013 : } // namespace ScreenBinding
1014 :
1015 :
1016 :
1017 : } // namespace dom
1018 : } // namespace mozilla
|