/work/obj-fuzz/dom/bindings/ScreenBinding.cpp
Line | Count | Source (jump to first uncovered line) |
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 "jsapi.h" |
8 | | #include "mozilla/FloatingPoint.h" |
9 | | #include "mozilla/OwningNonNull.h" |
10 | | #include "mozilla/dom/BindingUtils.h" |
11 | | #include "mozilla/dom/DOMJSClass.h" |
12 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
13 | | #include "mozilla/dom/Nullable.h" |
14 | | #include "mozilla/dom/PrimitiveConversions.h" |
15 | | #include "mozilla/dom/ScreenLuminance.h" |
16 | | #include "mozilla/dom/ScreenOrientation.h" |
17 | | #include "mozilla/dom/XrayExpandoClass.h" |
18 | | #include "nsContentUtils.h" |
19 | | #include "nsScreen.h" |
20 | | |
21 | | namespace mozilla { |
22 | | namespace dom { |
23 | | |
24 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
25 | | using namespace mozilla::dom::binding_detail; |
26 | | |
27 | | |
28 | | namespace ScreenColorGamutValues { |
29 | | extern const EnumEntry strings[4] = { |
30 | | {"srgb", 4}, |
31 | | {"p3", 2}, |
32 | | {"rec2020", 7}, |
33 | | { nullptr, 0 } |
34 | | }; |
35 | | } // namespace ScreenColorGamutValues |
36 | | |
37 | | bool |
38 | | ToJSValue(JSContext* aCx, ScreenColorGamut aArgument, JS::MutableHandle<JS::Value> aValue) |
39 | 0 | { |
40 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ScreenColorGamutValues::strings)); |
41 | 0 | JSString* resultStr = |
42 | 0 | JS_NewStringCopyN(aCx, ScreenColorGamutValues::strings[uint32_t(aArgument)].value, |
43 | 0 | ScreenColorGamutValues::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 Screen_Binding { |
53 | | |
54 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
55 | | "Can't inherit from an interface with a different ownership model."); |
56 | | |
57 | | MOZ_CAN_RUN_SCRIPT static bool |
58 | | get_availWidth(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
59 | 0 | { |
60 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.availWidth", DOM, cx); |
61 | 0 |
|
62 | 0 | FastErrorResult rv; |
63 | 0 | int32_t result(self->GetAvailWidth(rv)); |
64 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
65 | 0 | return false; |
66 | 0 | } |
67 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
68 | 0 | args.rval().setInt32(int32_t(result)); |
69 | 0 | return true; |
70 | 0 | } |
71 | | |
72 | | static const JSJitInfo availWidth_getterinfo = { |
73 | | { (JSJitGetterOp)get_availWidth }, |
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 | | MOZ_CAN_RUN_SCRIPT static bool |
91 | | get_availHeight(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
92 | 0 | { |
93 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.availHeight", DOM, cx); |
94 | 0 |
|
95 | 0 | FastErrorResult rv; |
96 | 0 | int32_t result(self->GetAvailHeight(rv)); |
97 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
98 | 0 | return false; |
99 | 0 | } |
100 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
101 | 0 | args.rval().setInt32(int32_t(result)); |
102 | 0 | return true; |
103 | 0 | } |
104 | | |
105 | | static const JSJitInfo availHeight_getterinfo = { |
106 | | { (JSJitGetterOp)get_availHeight }, |
107 | | { prototypes::id::Screen }, |
108 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
109 | | JSJitInfo::Getter, |
110 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
111 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
112 | | false, /* isInfallible. False in setters. */ |
113 | | false, /* isMovable. Not relevant for setters. */ |
114 | | false, /* isEliminatable. Not relevant for setters. */ |
115 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
116 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
117 | | false, /* isTypedMethod. Only relevant for methods. */ |
118 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
119 | | }; |
120 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
121 | | static_assert(0 < 1, "There is no slot for us"); |
122 | | |
123 | | MOZ_CAN_RUN_SCRIPT static bool |
124 | | get_width(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
125 | 0 | { |
126 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.width", DOM, cx); |
127 | 0 |
|
128 | 0 | FastErrorResult rv; |
129 | 0 | int32_t result(self->GetWidth(rv)); |
130 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
131 | 0 | return false; |
132 | 0 | } |
133 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
134 | 0 | args.rval().setInt32(int32_t(result)); |
135 | 0 | return true; |
136 | 0 | } |
137 | | |
138 | | static const JSJitInfo width_getterinfo = { |
139 | | { (JSJitGetterOp)get_width }, |
140 | | { prototypes::id::Screen }, |
141 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
142 | | JSJitInfo::Getter, |
143 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
144 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
145 | | false, /* isInfallible. False in setters. */ |
146 | | false, /* isMovable. Not relevant for setters. */ |
147 | | false, /* isEliminatable. Not relevant for setters. */ |
148 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
149 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
150 | | false, /* isTypedMethod. Only relevant for methods. */ |
151 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
152 | | }; |
153 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
154 | | static_assert(0 < 1, "There is no slot for us"); |
155 | | |
156 | | MOZ_CAN_RUN_SCRIPT static bool |
157 | | get_height(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
158 | 0 | { |
159 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.height", DOM, cx); |
160 | 0 |
|
161 | 0 | FastErrorResult rv; |
162 | 0 | int32_t result(self->GetHeight(rv)); |
163 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
164 | 0 | return false; |
165 | 0 | } |
166 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
167 | 0 | args.rval().setInt32(int32_t(result)); |
168 | 0 | return true; |
169 | 0 | } |
170 | | |
171 | | static const JSJitInfo height_getterinfo = { |
172 | | { (JSJitGetterOp)get_height }, |
173 | | { prototypes::id::Screen }, |
174 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
175 | | JSJitInfo::Getter, |
176 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
177 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
178 | | false, /* isInfallible. False in setters. */ |
179 | | false, /* isMovable. Not relevant for setters. */ |
180 | | false, /* isEliminatable. Not relevant for setters. */ |
181 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
182 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
183 | | false, /* isTypedMethod. Only relevant for methods. */ |
184 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
185 | | }; |
186 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
187 | | static_assert(0 < 1, "There is no slot for us"); |
188 | | |
189 | | MOZ_CAN_RUN_SCRIPT static bool |
190 | | get_colorDepth(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
191 | 0 | { |
192 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.colorDepth", DOM, cx); |
193 | 0 |
|
194 | 0 | FastErrorResult rv; |
195 | 0 | int32_t result(self->GetColorDepth(rv)); |
196 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
197 | 0 | return false; |
198 | 0 | } |
199 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
200 | 0 | args.rval().setInt32(int32_t(result)); |
201 | 0 | return true; |
202 | 0 | } |
203 | | |
204 | | static const JSJitInfo colorDepth_getterinfo = { |
205 | | { (JSJitGetterOp)get_colorDepth }, |
206 | | { prototypes::id::Screen }, |
207 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
208 | | JSJitInfo::Getter, |
209 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
210 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
211 | | false, /* isInfallible. False in setters. */ |
212 | | false, /* isMovable. Not relevant for setters. */ |
213 | | false, /* isEliminatable. Not relevant for setters. */ |
214 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
215 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
216 | | false, /* isTypedMethod. Only relevant for methods. */ |
217 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
218 | | }; |
219 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
220 | | static_assert(0 < 1, "There is no slot for us"); |
221 | | |
222 | | MOZ_CAN_RUN_SCRIPT static bool |
223 | | get_pixelDepth(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
224 | 0 | { |
225 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.pixelDepth", DOM, cx); |
226 | 0 |
|
227 | 0 | FastErrorResult rv; |
228 | 0 | int32_t result(self->GetPixelDepth(rv)); |
229 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
230 | 0 | return false; |
231 | 0 | } |
232 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
233 | 0 | args.rval().setInt32(int32_t(result)); |
234 | 0 | return true; |
235 | 0 | } |
236 | | |
237 | | static const JSJitInfo pixelDepth_getterinfo = { |
238 | | { (JSJitGetterOp)get_pixelDepth }, |
239 | | { prototypes::id::Screen }, |
240 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
241 | | JSJitInfo::Getter, |
242 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
243 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
244 | | false, /* isInfallible. False in setters. */ |
245 | | false, /* isMovable. Not relevant for setters. */ |
246 | | false, /* isEliminatable. Not relevant for setters. */ |
247 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
248 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
249 | | false, /* isTypedMethod. Only relevant for methods. */ |
250 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
251 | | }; |
252 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
253 | | static_assert(0 < 1, "There is no slot for us"); |
254 | | |
255 | | MOZ_CAN_RUN_SCRIPT static bool |
256 | | get_top(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
257 | 0 | { |
258 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.top", DOM, cx); |
259 | 0 |
|
260 | 0 | FastErrorResult rv; |
261 | 0 | int32_t result(self->GetTop(rv)); |
262 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
263 | 0 | return false; |
264 | 0 | } |
265 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
266 | 0 | args.rval().setInt32(int32_t(result)); |
267 | 0 | return true; |
268 | 0 | } |
269 | | |
270 | | static const JSJitInfo top_getterinfo = { |
271 | | { (JSJitGetterOp)get_top }, |
272 | | { prototypes::id::Screen }, |
273 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
274 | | JSJitInfo::Getter, |
275 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
276 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
277 | | false, /* isInfallible. False in setters. */ |
278 | | false, /* isMovable. Not relevant for setters. */ |
279 | | false, /* isEliminatable. Not relevant for setters. */ |
280 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
281 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
282 | | false, /* isTypedMethod. Only relevant for methods. */ |
283 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
284 | | }; |
285 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
286 | | static_assert(0 < 1, "There is no slot for us"); |
287 | | |
288 | | MOZ_CAN_RUN_SCRIPT static bool |
289 | | get_left(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
290 | 0 | { |
291 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.left", DOM, cx); |
292 | 0 |
|
293 | 0 | FastErrorResult rv; |
294 | 0 | int32_t result(self->GetLeft(rv)); |
295 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
296 | 0 | return false; |
297 | 0 | } |
298 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
299 | 0 | args.rval().setInt32(int32_t(result)); |
300 | 0 | return true; |
301 | 0 | } |
302 | | |
303 | | static const JSJitInfo left_getterinfo = { |
304 | | { (JSJitGetterOp)get_left }, |
305 | | { prototypes::id::Screen }, |
306 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
307 | | JSJitInfo::Getter, |
308 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
309 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
310 | | false, /* isInfallible. False in setters. */ |
311 | | false, /* isMovable. Not relevant for setters. */ |
312 | | false, /* isEliminatable. Not relevant for setters. */ |
313 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
314 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
315 | | false, /* isTypedMethod. Only relevant for methods. */ |
316 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
317 | | }; |
318 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
319 | | static_assert(0 < 1, "There is no slot for us"); |
320 | | |
321 | | MOZ_CAN_RUN_SCRIPT static bool |
322 | | get_availTop(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
323 | 0 | { |
324 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.availTop", DOM, cx); |
325 | 0 |
|
326 | 0 | FastErrorResult rv; |
327 | 0 | int32_t result(self->GetAvailTop(rv)); |
328 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
329 | 0 | return false; |
330 | 0 | } |
331 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
332 | 0 | args.rval().setInt32(int32_t(result)); |
333 | 0 | return true; |
334 | 0 | } |
335 | | |
336 | | static const JSJitInfo availTop_getterinfo = { |
337 | | { (JSJitGetterOp)get_availTop }, |
338 | | { prototypes::id::Screen }, |
339 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
340 | | JSJitInfo::Getter, |
341 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
342 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
343 | | false, /* isInfallible. False in setters. */ |
344 | | false, /* isMovable. Not relevant for setters. */ |
345 | | false, /* isEliminatable. Not relevant for setters. */ |
346 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
347 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
348 | | false, /* isTypedMethod. Only relevant for methods. */ |
349 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
350 | | }; |
351 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
352 | | static_assert(0 < 1, "There is no slot for us"); |
353 | | |
354 | | MOZ_CAN_RUN_SCRIPT static bool |
355 | | get_availLeft(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
356 | 0 | { |
357 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.availLeft", DOM, cx); |
358 | 0 |
|
359 | 0 | FastErrorResult rv; |
360 | 0 | int32_t result(self->GetAvailLeft(rv)); |
361 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
362 | 0 | return false; |
363 | 0 | } |
364 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
365 | 0 | args.rval().setInt32(int32_t(result)); |
366 | 0 | return true; |
367 | 0 | } |
368 | | |
369 | | static const JSJitInfo availLeft_getterinfo = { |
370 | | { (JSJitGetterOp)get_availLeft }, |
371 | | { prototypes::id::Screen }, |
372 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
373 | | JSJitInfo::Getter, |
374 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
375 | | JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */ |
376 | | false, /* isInfallible. False in setters. */ |
377 | | false, /* isMovable. Not relevant for setters. */ |
378 | | false, /* isEliminatable. Not relevant for setters. */ |
379 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
380 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
381 | | false, /* isTypedMethod. Only relevant for methods. */ |
382 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
383 | | }; |
384 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
385 | | static_assert(0 < 1, "There is no slot for us"); |
386 | | |
387 | | MOZ_CAN_RUN_SCRIPT static bool |
388 | | get_mozOrientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
389 | 0 | { |
390 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.mozOrientation", DOM, cx); |
391 | 0 |
|
392 | 0 | DOMString result; |
393 | 0 | self->GetMozOrientation(result, nsContentUtils::IsSystemCaller(cx) ? CallerType::System : CallerType::NonSystem); |
394 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
395 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
396 | 0 | return false; |
397 | 0 | } |
398 | 0 | return true; |
399 | 0 | } |
400 | | |
401 | | static const JSJitInfo mozOrientation_getterinfo = { |
402 | | { (JSJitGetterOp)get_mozOrientation }, |
403 | | { prototypes::id::Screen }, |
404 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
405 | | JSJitInfo::Getter, |
406 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
407 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
408 | | false, /* isInfallible. False in setters. */ |
409 | | false, /* isMovable. Not relevant for setters. */ |
410 | | false, /* isEliminatable. Not relevant for setters. */ |
411 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
412 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
413 | | false, /* isTypedMethod. Only relevant for methods. */ |
414 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
415 | | }; |
416 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
417 | | static_assert(0 < 1, "There is no slot for us"); |
418 | | |
419 | | MOZ_CAN_RUN_SCRIPT static bool |
420 | | get_onmozorientationchange(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
421 | 0 | { |
422 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.onmozorientationchange", DOM, cx); |
423 | 0 |
|
424 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnmozorientationchange()); |
425 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
426 | 0 | if (result) { |
427 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
428 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
429 | 0 | return false; |
430 | 0 | } |
431 | 0 | return true; |
432 | 0 | } else { |
433 | 0 | args.rval().setNull(); |
434 | 0 | return true; |
435 | 0 | } |
436 | 0 | } |
437 | | |
438 | | MOZ_CAN_RUN_SCRIPT static bool |
439 | | set_onmozorientationchange(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitSetterCallArgs args) |
440 | 0 | { |
441 | 0 | AUTO_PROFILER_LABEL_FAST("set Screen.onmozorientationchange", DOM, cx); |
442 | 0 |
|
443 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
444 | 0 | if (args[0].isObject()) { |
445 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
446 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
447 | 0 | } |
448 | 0 | } else { |
449 | 0 | arg0 = nullptr; |
450 | 0 | } |
451 | 0 | self->SetOnmozorientationchange(Constify(arg0)); |
452 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
453 | 0 |
|
454 | 0 | return true; |
455 | 0 | } |
456 | | |
457 | | static const JSJitInfo onmozorientationchange_getterinfo = { |
458 | | { (JSJitGetterOp)get_onmozorientationchange }, |
459 | | { prototypes::id::Screen }, |
460 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
461 | | JSJitInfo::Getter, |
462 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
463 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
464 | | false, /* isInfallible. False in setters. */ |
465 | | false, /* isMovable. Not relevant for setters. */ |
466 | | false, /* isEliminatable. Not relevant for setters. */ |
467 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
468 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
469 | | false, /* isTypedMethod. Only relevant for methods. */ |
470 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
471 | | }; |
472 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
473 | | static_assert(0 < 1, "There is no slot for us"); |
474 | | static const JSJitInfo onmozorientationchange_setterinfo = { |
475 | | { (JSJitGetterOp)set_onmozorientationchange }, |
476 | | { prototypes::id::Screen }, |
477 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
478 | | JSJitInfo::Setter, |
479 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
480 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
481 | | false, /* isInfallible. False in setters. */ |
482 | | false, /* isMovable. Not relevant for setters. */ |
483 | | false, /* isEliminatable. Not relevant for setters. */ |
484 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
485 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
486 | | false, /* isTypedMethod. Only relevant for methods. */ |
487 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
488 | | }; |
489 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
490 | | static_assert(0 < 1, "There is no slot for us"); |
491 | | |
492 | | MOZ_CAN_RUN_SCRIPT static bool |
493 | | mozLockOrientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, const JSJitMethodCallArgs& args) |
494 | 0 | { |
495 | 0 | AUTO_PROFILER_LABEL_FAST("Screen.mozLockOrientation", DOM, cx); |
496 | 0 |
|
497 | 0 | unsigned argcount = std::min(args.length(), 1u); |
498 | 0 | switch (argcount) { |
499 | 0 | case 1: { |
500 | 0 | if (args[0].isObject()) { |
501 | 0 | do { |
502 | 0 | binding_detail::AutoSequence<nsString> arg0; |
503 | 0 | JS::ForOfIterator iter(cx); |
504 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
505 | 0 | return false; |
506 | 0 | } |
507 | 0 | if (!iter.valueIsIterable()) { |
508 | 0 | break; |
509 | 0 | } |
510 | 0 | binding_detail::AutoSequence<nsString> &arr = arg0; |
511 | 0 | JS::Rooted<JS::Value> temp(cx); |
512 | 0 | while (true) { |
513 | 0 | bool done; |
514 | 0 | if (!iter.next(&temp, &done)) { |
515 | 0 | return false; |
516 | 0 | } |
517 | 0 | if (done) { |
518 | 0 | break; |
519 | 0 | } |
520 | 0 | nsString* slotPtr = arr.AppendElement(mozilla::fallible); |
521 | 0 | if (!slotPtr) { |
522 | 0 | JS_ReportOutOfMemory(cx); |
523 | 0 | return false; |
524 | 0 | } |
525 | 0 | nsString& slot = *slotPtr; |
526 | 0 | if (!ConvertJSValueToString(cx, temp, eStringify, eStringify, slot)) { |
527 | 0 | return false; |
528 | 0 | } |
529 | 0 | } |
530 | 0 | FastErrorResult rv; |
531 | 0 | bool result(self->MozLockOrientation(Constify(arg0), rv)); |
532 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
533 | 0 | return false; |
534 | 0 | } |
535 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
536 | 0 | args.rval().setBoolean(result); |
537 | 0 | return true; |
538 | 0 | } while (false); |
539 | 0 | } |
540 | 0 | binding_detail::FakeString arg0; |
541 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
542 | 0 | return false; |
543 | 0 | } |
544 | 0 | FastErrorResult rv; |
545 | 0 | bool result(self->MozLockOrientation(NonNullHelper(Constify(arg0)), rv)); |
546 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
547 | 0 | return false; |
548 | 0 | } |
549 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
550 | 0 | args.rval().setBoolean(result); |
551 | 0 | return true; |
552 | 0 | break; |
553 | 0 | } |
554 | 0 | default: { |
555 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Screen.mozLockOrientation"); |
556 | 0 | break; |
557 | 0 | } |
558 | 0 | } |
559 | 0 | MOZ_CRASH("We have an always-returning default case"); |
560 | 0 | return false; |
561 | 0 | } |
562 | | |
563 | | static const JSJitInfo mozLockOrientation_methodinfo = { |
564 | | { (JSJitGetterOp)mozLockOrientation }, |
565 | | { prototypes::id::Screen }, |
566 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
567 | | JSJitInfo::Method, |
568 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
569 | | JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */ |
570 | | false, /* isInfallible. False in setters. */ |
571 | | false, /* isMovable. Not relevant for setters. */ |
572 | | false, /* isEliminatable. Not relevant for setters. */ |
573 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
574 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
575 | | false, /* isTypedMethod. Only relevant for methods. */ |
576 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
577 | | }; |
578 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
579 | | static_assert(0 < 1, "There is no slot for us"); |
580 | | |
581 | | MOZ_CAN_RUN_SCRIPT static bool |
582 | | mozUnlockOrientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, const JSJitMethodCallArgs& args) |
583 | 0 | { |
584 | 0 | AUTO_PROFILER_LABEL_FAST("Screen.mozUnlockOrientation", DOM, cx); |
585 | 0 |
|
586 | 0 | self->MozUnlockOrientation(); |
587 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
588 | 0 | args.rval().setUndefined(); |
589 | 0 | return true; |
590 | 0 | } |
591 | | |
592 | | static const JSJitInfo mozUnlockOrientation_methodinfo = { |
593 | | { (JSJitGetterOp)mozUnlockOrientation }, |
594 | | { prototypes::id::Screen }, |
595 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
596 | | JSJitInfo::Method, |
597 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
598 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
599 | | true, /* isInfallible. False in setters. */ |
600 | | false, /* isMovable. Not relevant for setters. */ |
601 | | false, /* isEliminatable. Not relevant for setters. */ |
602 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
603 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
604 | | false, /* isTypedMethod. Only relevant for methods. */ |
605 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
606 | | }; |
607 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
608 | | static_assert(0 < 1, "There is no slot for us"); |
609 | | |
610 | | MOZ_CAN_RUN_SCRIPT static bool |
611 | | get_orientation(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
612 | 0 | { |
613 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.orientation", DOM, cx); |
614 | 0 |
|
615 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ScreenOrientation>(self->Orientation())); |
616 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
617 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
618 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
619 | 0 | return false; |
620 | 0 | } |
621 | 0 | return true; |
622 | 0 | } |
623 | | |
624 | | static const JSJitInfo orientation_getterinfo = { |
625 | | { (JSJitGetterOp)get_orientation }, |
626 | | { prototypes::id::Screen }, |
627 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
628 | | JSJitInfo::Getter, |
629 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
630 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
631 | | false, /* isInfallible. False in setters. */ |
632 | | false, /* isMovable. Not relevant for setters. */ |
633 | | false, /* isEliminatable. Not relevant for setters. */ |
634 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
635 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
636 | | false, /* isTypedMethod. Only relevant for methods. */ |
637 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
638 | | }; |
639 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
640 | | static_assert(0 < 1, "There is no slot for us"); |
641 | | |
642 | | MOZ_CAN_RUN_SCRIPT static bool |
643 | | get_colorGamut(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
644 | 0 | { |
645 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.colorGamut", DOM, cx); |
646 | 0 |
|
647 | 0 | ScreenColorGamut result(self->ColorGamut()); |
648 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
649 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
650 | 0 | return false; |
651 | 0 | } |
652 | 0 | return true; |
653 | 0 | } |
654 | | |
655 | | static const JSJitInfo colorGamut_getterinfo = { |
656 | | { (JSJitGetterOp)get_colorGamut }, |
657 | | { prototypes::id::Screen }, |
658 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
659 | | JSJitInfo::Getter, |
660 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
661 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
662 | | false, /* isInfallible. False in setters. */ |
663 | | false, /* isMovable. Not relevant for setters. */ |
664 | | false, /* isEliminatable. Not relevant for setters. */ |
665 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
666 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
667 | | false, /* isTypedMethod. Only relevant for methods. */ |
668 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
669 | | }; |
670 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
671 | | static_assert(0 < 1, "There is no slot for us"); |
672 | | |
673 | | MOZ_CAN_RUN_SCRIPT static bool |
674 | | get_luminance(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
675 | 0 | { |
676 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.luminance", DOM, cx); |
677 | 0 |
|
678 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ScreenLuminance>(self->GetLuminance())); |
679 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
680 | 0 | if (!result) { |
681 | 0 | args.rval().setNull(); |
682 | 0 | return true; |
683 | 0 | } |
684 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
685 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
686 | 0 | return false; |
687 | 0 | } |
688 | 0 | return true; |
689 | 0 | } |
690 | | |
691 | | static const JSJitInfo luminance_getterinfo = { |
692 | | { (JSJitGetterOp)get_luminance }, |
693 | | { prototypes::id::Screen }, |
694 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
695 | | JSJitInfo::Getter, |
696 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
697 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
698 | | false, /* isInfallible. False in setters. */ |
699 | | false, /* isMovable. Not relevant for setters. */ |
700 | | false, /* isEliminatable. Not relevant for setters. */ |
701 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
702 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
703 | | false, /* isTypedMethod. Only relevant for methods. */ |
704 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
705 | | }; |
706 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
707 | | static_assert(0 < 1, "There is no slot for us"); |
708 | | |
709 | | MOZ_CAN_RUN_SCRIPT static bool |
710 | | get_onchange(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitGetterCallArgs args) |
711 | 0 | { |
712 | 0 | AUTO_PROFILER_LABEL_FAST("get Screen.onchange", DOM, cx); |
713 | 0 |
|
714 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnchange()); |
715 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
716 | 0 | if (result) { |
717 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
718 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
719 | 0 | return false; |
720 | 0 | } |
721 | 0 | return true; |
722 | 0 | } else { |
723 | 0 | args.rval().setNull(); |
724 | 0 | return true; |
725 | 0 | } |
726 | 0 | } |
727 | | |
728 | | MOZ_CAN_RUN_SCRIPT static bool |
729 | | set_onchange(JSContext* cx, JS::Handle<JSObject*> obj, nsScreen* self, JSJitSetterCallArgs args) |
730 | 0 | { |
731 | 0 | AUTO_PROFILER_LABEL_FAST("set Screen.onchange", DOM, cx); |
732 | 0 |
|
733 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
734 | 0 | if (args[0].isObject()) { |
735 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
736 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
737 | 0 | } |
738 | 0 | } else { |
739 | 0 | arg0 = nullptr; |
740 | 0 | } |
741 | 0 | self->SetOnchange(Constify(arg0)); |
742 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
743 | 0 |
|
744 | 0 | return true; |
745 | 0 | } |
746 | | |
747 | | static const JSJitInfo onchange_getterinfo = { |
748 | | { (JSJitGetterOp)get_onchange }, |
749 | | { prototypes::id::Screen }, |
750 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
751 | | JSJitInfo::Getter, |
752 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
753 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
754 | | false, /* isInfallible. False in setters. */ |
755 | | false, /* isMovable. Not relevant for setters. */ |
756 | | false, /* isEliminatable. Not relevant for setters. */ |
757 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
758 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
759 | | false, /* isTypedMethod. Only relevant for methods. */ |
760 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
761 | | }; |
762 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
763 | | static_assert(0 < 1, "There is no slot for us"); |
764 | | static const JSJitInfo onchange_setterinfo = { |
765 | | { (JSJitGetterOp)set_onchange }, |
766 | | { prototypes::id::Screen }, |
767 | | { PrototypeTraits<prototypes::id::Screen>::Depth }, |
768 | | JSJitInfo::Setter, |
769 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
770 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
771 | | false, /* isInfallible. False in setters. */ |
772 | | false, /* isMovable. Not relevant for setters. */ |
773 | | false, /* isEliminatable. Not relevant for setters. */ |
774 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
775 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
776 | | false, /* isTypedMethod. Only relevant for methods. */ |
777 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
778 | | }; |
779 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
780 | | static_assert(0 < 1, "There is no slot for us"); |
781 | | |
782 | | static bool |
783 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
784 | 0 | { |
785 | 0 | nsScreen* self = UnwrapPossiblyNotInitializedDOMObject<nsScreen>(obj); |
786 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
787 | 0 | // obviously can't preserve if we're not initialized. |
788 | 0 | if (self && self->GetWrapperPreserveColor()) { |
789 | 0 | PreserveWrapper(self); |
790 | 0 | } |
791 | 0 | return true; |
792 | 0 | } |
793 | | |
794 | | static void |
795 | | _finalize(js::FreeOp* fop, JSObject* obj) |
796 | 0 | { |
797 | 0 | nsScreen* self = UnwrapPossiblyNotInitializedDOMObject<nsScreen>(obj); |
798 | 0 | if (self) { |
799 | 0 | ClearWrapper(self, self, obj); |
800 | 0 | AddForDeferredFinalization<nsScreen>(self); |
801 | 0 | } |
802 | 0 | } |
803 | | |
804 | | static size_t |
805 | | _objectMoved(JSObject* obj, JSObject* old) |
806 | 0 | { |
807 | 0 | nsScreen* self = UnwrapPossiblyNotInitializedDOMObject<nsScreen>(obj); |
808 | 0 | if (self) { |
809 | 0 | UpdateWrapper(self, self, obj, old); |
810 | 0 | } |
811 | 0 |
|
812 | 0 | return 0; |
813 | 0 | } |
814 | | |
815 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
816 | | #if defined(__clang__) |
817 | | #pragma clang diagnostic push |
818 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
819 | | #endif |
820 | | static const JSFunctionSpec sMethods_specs[] = { |
821 | | JS_FNSPEC("mozLockOrientation", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozLockOrientation_methodinfo), 1, JSPROP_ENUMERATE, nullptr), |
822 | | JS_FNSPEC("mozUnlockOrientation", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&mozUnlockOrientation_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
823 | | JS_FS_END |
824 | | }; |
825 | | #if defined(__clang__) |
826 | | #pragma clang diagnostic pop |
827 | | #endif |
828 | | |
829 | | |
830 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
831 | | { nullptr, &sMethods_specs[0] }, |
832 | | { nullptr, nullptr } |
833 | | }; |
834 | | |
835 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
836 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
837 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
838 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
839 | | |
840 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
841 | | #if defined(__clang__) |
842 | | #pragma clang diagnostic push |
843 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
844 | | #endif |
845 | | static const JSPropertySpec sAttributes_specs[] = { |
846 | | { "availWidth", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &availWidth_getterinfo, nullptr, nullptr }, |
847 | | { "availHeight", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &availHeight_getterinfo, nullptr, nullptr }, |
848 | | { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, nullptr, nullptr }, |
849 | | { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, nullptr, nullptr }, |
850 | | { "colorDepth", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &colorDepth_getterinfo, nullptr, nullptr }, |
851 | | { "pixelDepth", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pixelDepth_getterinfo, nullptr, nullptr }, |
852 | | { "top", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &top_getterinfo, nullptr, nullptr }, |
853 | | { "left", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &left_getterinfo, nullptr, nullptr }, |
854 | | { "availTop", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &availTop_getterinfo, nullptr, nullptr }, |
855 | | { "availLeft", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &availLeft_getterinfo, nullptr, nullptr }, |
856 | | { "mozOrientation", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &mozOrientation_getterinfo, nullptr, nullptr }, |
857 | | { "onmozorientationchange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onmozorientationchange_getterinfo, GenericSetter<NormalThisPolicy>, &onmozorientationchange_setterinfo }, |
858 | | { "orientation", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &orientation_getterinfo, nullptr, nullptr }, |
859 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr }, |
860 | | { "colorGamut", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &colorGamut_getterinfo, nullptr, nullptr }, |
861 | | { "luminance", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &luminance_getterinfo, nullptr, nullptr }, |
862 | | { "onchange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onchange_getterinfo, GenericSetter<NormalThisPolicy>, &onchange_setterinfo }, |
863 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
864 | | }; |
865 | | #if defined(__clang__) |
866 | | #pragma clang diagnostic pop |
867 | | #endif |
868 | | |
869 | | // Can't be const because the pref-enabled boolean needs to be writable |
870 | | static PrefableDisablers sAttributes_disablers14 = { |
871 | | true, false, 0, &nsScreen::MediaCapabilitiesEnabled |
872 | | }; |
873 | | |
874 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
875 | | { nullptr, &sAttributes_specs[0] }, |
876 | | { &sAttributes_disablers14, &sAttributes_specs[14] }, |
877 | | { nullptr, nullptr } |
878 | | }; |
879 | | |
880 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
881 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
882 | | static_assert(13 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
883 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
884 | | |
885 | | |
886 | | static uint16_t sNativeProperties_sortedPropertyIndices[18]; |
887 | | static PropertyInfo sNativeProperties_propertyInfos[18]; |
888 | | |
889 | | static const NativePropertiesN<2> sNativeProperties = { |
890 | | false, 0, |
891 | | false, 0, |
892 | | true, 0 /* sMethods */, |
893 | | true, 1 /* sAttributes */, |
894 | | false, 0, |
895 | | false, 0, |
896 | | false, 0, |
897 | | -1, |
898 | | 18, |
899 | | sNativeProperties_sortedPropertyIndices, |
900 | | { |
901 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
902 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
903 | | } |
904 | | }; |
905 | | static_assert(18 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
906 | | "We have a property info count that is oversized"); |
907 | | |
908 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
909 | | { |
910 | | "Function", |
911 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
912 | | &sBoringInterfaceObjectClassClassOps, |
913 | | JS_NULL_CLASS_SPEC, |
914 | | JS_NULL_CLASS_EXT, |
915 | | &sInterfaceObjectClassObjectOps |
916 | | }, |
917 | | eInterface, |
918 | | true, |
919 | | prototypes::id::Screen, |
920 | | PrototypeTraits<prototypes::id::Screen>::Depth, |
921 | | sNativePropertyHooks, |
922 | | "function Screen() {\n [native code]\n}", |
923 | | EventTarget_Binding::GetConstructorObject |
924 | | }; |
925 | | |
926 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
927 | | { |
928 | | "ScreenPrototype", |
929 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
930 | | JS_NULL_CLASS_OPS, |
931 | | JS_NULL_CLASS_SPEC, |
932 | | JS_NULL_CLASS_EXT, |
933 | | JS_NULL_OBJECT_OPS |
934 | | }, |
935 | | eInterfacePrototype, |
936 | | false, |
937 | | prototypes::id::Screen, |
938 | | PrototypeTraits<prototypes::id::Screen>::Depth, |
939 | | sNativePropertyHooks, |
940 | | "[object ScreenPrototype]", |
941 | | EventTarget_Binding::GetProtoObject |
942 | | }; |
943 | | |
944 | | static const js::ClassOps sClassOps = { |
945 | | _addProperty, /* addProperty */ |
946 | | nullptr, /* delProperty */ |
947 | | nullptr, /* enumerate */ |
948 | | nullptr, /* newEnumerate */ |
949 | | nullptr, /* resolve */ |
950 | | nullptr, /* mayResolve */ |
951 | | _finalize, /* finalize */ |
952 | | nullptr, /* call */ |
953 | | nullptr, /* hasInstance */ |
954 | | nullptr, /* construct */ |
955 | | nullptr, /* trace */ |
956 | | }; |
957 | | |
958 | | static const js::ClassExtension sClassExtension = { |
959 | | nullptr, /* weakmapKeyDelegateOp */ |
960 | | _objectMoved /* objectMovedOp */ |
961 | | }; |
962 | | |
963 | | static const DOMJSClass sClass = { |
964 | | { "Screen", |
965 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
966 | | &sClassOps, |
967 | | JS_NULL_CLASS_SPEC, |
968 | | &sClassExtension, |
969 | | JS_NULL_OBJECT_OPS |
970 | | }, |
971 | | { 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 }, |
972 | | IsBaseOf<nsISupports, nsScreen >::value, |
973 | | sNativePropertyHooks, |
974 | | FindAssociatedGlobalForNative<nsScreen>::Get, |
975 | | GetProtoObjectHandle, |
976 | | GetCCParticipant<nsScreen>::Get() |
977 | | }; |
978 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
979 | | "Must have the right minimal number of reserved slots."); |
980 | | static_assert(1 >= 1, |
981 | | "Must have enough reserved slots."); |
982 | | |
983 | | const JSClass* |
984 | | GetJSClass() |
985 | 0 | { |
986 | 0 | return sClass.ToJSClass(); |
987 | 0 | } |
988 | | |
989 | | bool |
990 | | Wrap(JSContext* aCx, nsScreen* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
991 | 0 | { |
992 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, nsScreen>::value, |
993 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
994 | 0 | MOZ_ASSERT(static_cast<nsScreen*>(aObject) == |
995 | 0 | reinterpret_cast<nsScreen*>(aObject), |
996 | 0 | "Multiple inheritance for nsScreen is broken."); |
997 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
998 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
999 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
1000 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1001 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1002 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1003 | 0 | "You should probably not be using Wrap() directly; use " |
1004 | 0 | "GetOrCreateDOMReflector instead"); |
1005 | 0 |
|
1006 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1007 | 0 | "nsISupports must be on our primary inheritance chain"); |
1008 | 0 |
|
1009 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1010 | 0 | if (!global) { |
1011 | 0 | return false; |
1012 | 0 | } |
1013 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1014 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1015 | 0 |
|
1016 | 0 | // That might have ended up wrapping us already, due to the wonders |
1017 | 0 | // of XBL. Check for that, and bail out as needed. |
1018 | 0 | aReflector.set(aCache->GetWrapper()); |
1019 | 0 | if (aReflector) { |
1020 | | #ifdef DEBUG |
1021 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1022 | | #endif // DEBUG |
1023 | | return true; |
1024 | 0 | } |
1025 | 0 |
|
1026 | 0 | JSAutoRealm ar(aCx, global); |
1027 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1028 | 0 | if (!canonicalProto) { |
1029 | 0 | return false; |
1030 | 0 | } |
1031 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1032 | 0 | if (aGivenProto) { |
1033 | 0 | proto = aGivenProto; |
1034 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1035 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1036 | 0 | // to wrap the proto here. |
1037 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1038 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1039 | 0 | return false; |
1040 | 0 | } |
1041 | 0 | } |
1042 | 0 | } else { |
1043 | 0 | proto = canonicalProto; |
1044 | 0 | } |
1045 | 0 |
|
1046 | 0 | BindingJSObjectCreator<nsScreen> creator(aCx); |
1047 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1048 | 0 | if (!aReflector) { |
1049 | 0 | return false; |
1050 | 0 | } |
1051 | 0 | |
1052 | 0 | aCache->SetWrapper(aReflector); |
1053 | 0 | creator.InitializationSucceeded(); |
1054 | 0 |
|
1055 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1056 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1057 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1058 | 0 | // otherwise we won't be able to properly recreate it later, since |
1059 | 0 | // we won't know what proto to use. Note that we don't check |
1060 | 0 | // aGivenProto here, since it's entirely possible (and even |
1061 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1062 | 0 | // same as canonicalProto. |
1063 | 0 | if (proto != canonicalProto) { |
1064 | 0 | PreserveWrapper(aObject); |
1065 | 0 | } |
1066 | 0 |
|
1067 | 0 | return true; |
1068 | 0 | } |
1069 | | |
1070 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1071 | | nullptr, |
1072 | | nullptr, |
1073 | | nullptr, |
1074 | | { sNativeProperties.Upcast(), nullptr }, |
1075 | | prototypes::id::Screen, |
1076 | | constructors::id::Screen, |
1077 | | EventTarget_Binding::sNativePropertyHooks, |
1078 | | &DefaultXrayExpandoObjectClass |
1079 | | } }; |
1080 | | |
1081 | | void |
1082 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1083 | 0 | { |
1084 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
1085 | 0 | if (!parentProto) { |
1086 | 0 | return; |
1087 | 0 | } |
1088 | 0 | |
1089 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
1090 | 0 | if (!constructorProto) { |
1091 | 0 | return; |
1092 | 0 | } |
1093 | 0 | |
1094 | 0 | static bool sIdsInited = false; |
1095 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1096 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1097 | 0 | return; |
1098 | 0 | } |
1099 | 0 | sIdsInited = true; |
1100 | 0 | } |
1101 | 0 |
|
1102 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Screen); |
1103 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Screen); |
1104 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1105 | 0 | &sPrototypeClass.mBase, protoCache, |
1106 | 0 | nullptr, |
1107 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1108 | 0 | interfaceCache, |
1109 | 0 | sNativeProperties.Upcast(), |
1110 | 0 | nullptr, |
1111 | 0 | "Screen", aDefineOnGlobal, |
1112 | 0 | nullptr, |
1113 | 0 | false); |
1114 | 0 | } |
1115 | | |
1116 | | JSObject* |
1117 | | GetConstructorObject(JSContext* aCx) |
1118 | 0 | { |
1119 | 0 | return GetConstructorObjectHandle(aCx); |
1120 | 0 | } |
1121 | | |
1122 | | } // namespace Screen_Binding |
1123 | | |
1124 | | |
1125 | | |
1126 | | namespace ScreenLuminance_Binding { |
1127 | | |
1128 | | MOZ_CAN_RUN_SCRIPT static bool |
1129 | | get_min(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenLuminance* self, JSJitGetterCallArgs args) |
1130 | 0 | { |
1131 | 0 | AUTO_PROFILER_LABEL_FAST("get ScreenLuminance.min", DOM, cx); |
1132 | 0 |
|
1133 | 0 | double result(self->Min()); |
1134 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1135 | 0 | args.rval().set(JS_NumberValue(double(result))); |
1136 | 0 | return true; |
1137 | 0 | } |
1138 | | |
1139 | | static const JSJitInfo min_getterinfo = { |
1140 | | { (JSJitGetterOp)get_min }, |
1141 | | { prototypes::id::ScreenLuminance }, |
1142 | | { PrototypeTraits<prototypes::id::ScreenLuminance>::Depth }, |
1143 | | JSJitInfo::Getter, |
1144 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1145 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1146 | | true, /* isInfallible. False in setters. */ |
1147 | | false, /* isMovable. Not relevant for setters. */ |
1148 | | false, /* isEliminatable. Not relevant for setters. */ |
1149 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1150 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1151 | | false, /* isTypedMethod. Only relevant for methods. */ |
1152 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1153 | | }; |
1154 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1155 | | static_assert(0 < 1, "There is no slot for us"); |
1156 | | |
1157 | | MOZ_CAN_RUN_SCRIPT static bool |
1158 | | get_max(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenLuminance* self, JSJitGetterCallArgs args) |
1159 | 0 | { |
1160 | 0 | AUTO_PROFILER_LABEL_FAST("get ScreenLuminance.max", DOM, cx); |
1161 | 0 |
|
1162 | 0 | double result(self->Max()); |
1163 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1164 | 0 | args.rval().set(JS_NumberValue(double(result))); |
1165 | 0 | return true; |
1166 | 0 | } |
1167 | | |
1168 | | static const JSJitInfo max_getterinfo = { |
1169 | | { (JSJitGetterOp)get_max }, |
1170 | | { prototypes::id::ScreenLuminance }, |
1171 | | { PrototypeTraits<prototypes::id::ScreenLuminance>::Depth }, |
1172 | | JSJitInfo::Getter, |
1173 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1174 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1175 | | true, /* isInfallible. False in setters. */ |
1176 | | false, /* isMovable. Not relevant for setters. */ |
1177 | | false, /* isEliminatable. Not relevant for setters. */ |
1178 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1179 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1180 | | false, /* isTypedMethod. Only relevant for methods. */ |
1181 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1182 | | }; |
1183 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1184 | | static_assert(0 < 1, "There is no slot for us"); |
1185 | | |
1186 | | MOZ_CAN_RUN_SCRIPT static bool |
1187 | | get_maxAverage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ScreenLuminance* self, JSJitGetterCallArgs args) |
1188 | 0 | { |
1189 | 0 | AUTO_PROFILER_LABEL_FAST("get ScreenLuminance.maxAverage", DOM, cx); |
1190 | 0 |
|
1191 | 0 | double result(self->MaxAverage()); |
1192 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1193 | 0 | args.rval().set(JS_NumberValue(double(result))); |
1194 | 0 | return true; |
1195 | 0 | } |
1196 | | |
1197 | | static const JSJitInfo maxAverage_getterinfo = { |
1198 | | { (JSJitGetterOp)get_maxAverage }, |
1199 | | { prototypes::id::ScreenLuminance }, |
1200 | | { PrototypeTraits<prototypes::id::ScreenLuminance>::Depth }, |
1201 | | JSJitInfo::Getter, |
1202 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1203 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1204 | | true, /* isInfallible. False in setters. */ |
1205 | | false, /* isMovable. Not relevant for setters. */ |
1206 | | false, /* isEliminatable. Not relevant for setters. */ |
1207 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1208 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1209 | | false, /* isTypedMethod. Only relevant for methods. */ |
1210 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1211 | | }; |
1212 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1213 | | static_assert(0 < 1, "There is no slot for us"); |
1214 | | |
1215 | | static bool |
1216 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
1217 | 0 | { |
1218 | 0 | mozilla::dom::ScreenLuminance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ScreenLuminance>(obj); |
1219 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
1220 | 0 | // obviously can't preserve if we're not initialized. |
1221 | 0 | if (self && self->GetWrapperPreserveColor()) { |
1222 | 0 | PreserveWrapper(self); |
1223 | 0 | } |
1224 | 0 | return true; |
1225 | 0 | } |
1226 | | |
1227 | | static void |
1228 | | _finalize(js::FreeOp* fop, JSObject* obj) |
1229 | 0 | { |
1230 | 0 | mozilla::dom::ScreenLuminance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ScreenLuminance>(obj); |
1231 | 0 | if (self) { |
1232 | 0 | ClearWrapper(self, self, obj); |
1233 | 0 | AddForDeferredFinalization<mozilla::dom::ScreenLuminance>(self); |
1234 | 0 | } |
1235 | 0 | } |
1236 | | |
1237 | | static size_t |
1238 | | _objectMoved(JSObject* obj, JSObject* old) |
1239 | 0 | { |
1240 | 0 | mozilla::dom::ScreenLuminance* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ScreenLuminance>(obj); |
1241 | 0 | if (self) { |
1242 | 0 | UpdateWrapper(self, self, obj, old); |
1243 | 0 | } |
1244 | 0 |
|
1245 | 0 | return 0; |
1246 | 0 | } |
1247 | | |
1248 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1249 | | #if defined(__clang__) |
1250 | | #pragma clang diagnostic push |
1251 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1252 | | #endif |
1253 | | static const JSPropertySpec sAttributes_specs[] = { |
1254 | | { "min", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &min_getterinfo, nullptr, nullptr }, |
1255 | | { "max", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &max_getterinfo, nullptr, nullptr }, |
1256 | | { "maxAverage", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &maxAverage_getterinfo, nullptr, nullptr }, |
1257 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
1258 | | }; |
1259 | | #if defined(__clang__) |
1260 | | #pragma clang diagnostic pop |
1261 | | #endif |
1262 | | |
1263 | | |
1264 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
1265 | | { nullptr, &sAttributes_specs[0] }, |
1266 | | { nullptr, nullptr } |
1267 | | }; |
1268 | | |
1269 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1270 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1271 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1272 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1273 | | |
1274 | | |
1275 | | static uint16_t sNativeProperties_sortedPropertyIndices[3]; |
1276 | | static PropertyInfo sNativeProperties_propertyInfos[3]; |
1277 | | |
1278 | | static const NativePropertiesN<1> sNativeProperties = { |
1279 | | false, 0, |
1280 | | false, 0, |
1281 | | false, 0, |
1282 | | true, 0 /* sAttributes */, |
1283 | | false, 0, |
1284 | | false, 0, |
1285 | | false, 0, |
1286 | | -1, |
1287 | | 3, |
1288 | | sNativeProperties_sortedPropertyIndices, |
1289 | | { |
1290 | | { sAttributes, &sNativeProperties_propertyInfos[0] } |
1291 | | } |
1292 | | }; |
1293 | | static_assert(3 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1294 | | "We have a property info count that is oversized"); |
1295 | | |
1296 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1297 | | { |
1298 | | "Function", |
1299 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1300 | | &sBoringInterfaceObjectClassClassOps, |
1301 | | JS_NULL_CLASS_SPEC, |
1302 | | JS_NULL_CLASS_EXT, |
1303 | | &sInterfaceObjectClassObjectOps |
1304 | | }, |
1305 | | eInterface, |
1306 | | true, |
1307 | | prototypes::id::ScreenLuminance, |
1308 | | PrototypeTraits<prototypes::id::ScreenLuminance>::Depth, |
1309 | | sNativePropertyHooks, |
1310 | | "function ScreenLuminance() {\n [native code]\n}", |
1311 | | JS::GetRealmFunctionPrototype |
1312 | | }; |
1313 | | |
1314 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1315 | | { |
1316 | | "ScreenLuminancePrototype", |
1317 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1318 | | JS_NULL_CLASS_OPS, |
1319 | | JS_NULL_CLASS_SPEC, |
1320 | | JS_NULL_CLASS_EXT, |
1321 | | JS_NULL_OBJECT_OPS |
1322 | | }, |
1323 | | eInterfacePrototype, |
1324 | | false, |
1325 | | prototypes::id::ScreenLuminance, |
1326 | | PrototypeTraits<prototypes::id::ScreenLuminance>::Depth, |
1327 | | sNativePropertyHooks, |
1328 | | "[object ScreenLuminancePrototype]", |
1329 | | JS::GetRealmObjectPrototype |
1330 | | }; |
1331 | | |
1332 | | bool |
1333 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
1334 | 0 | { |
1335 | 0 | return nsScreen::MediaCapabilitiesEnabled(aCx, aObj); |
1336 | 0 | } |
1337 | | |
1338 | | static const js::ClassOps sClassOps = { |
1339 | | _addProperty, /* addProperty */ |
1340 | | nullptr, /* delProperty */ |
1341 | | nullptr, /* enumerate */ |
1342 | | nullptr, /* newEnumerate */ |
1343 | | nullptr, /* resolve */ |
1344 | | nullptr, /* mayResolve */ |
1345 | | _finalize, /* finalize */ |
1346 | | nullptr, /* call */ |
1347 | | nullptr, /* hasInstance */ |
1348 | | nullptr, /* construct */ |
1349 | | nullptr, /* trace */ |
1350 | | }; |
1351 | | |
1352 | | static const js::ClassExtension sClassExtension = { |
1353 | | nullptr, /* weakmapKeyDelegateOp */ |
1354 | | _objectMoved /* objectMovedOp */ |
1355 | | }; |
1356 | | |
1357 | | static const DOMJSClass sClass = { |
1358 | | { "ScreenLuminance", |
1359 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
1360 | | &sClassOps, |
1361 | | JS_NULL_CLASS_SPEC, |
1362 | | &sClassExtension, |
1363 | | JS_NULL_OBJECT_OPS |
1364 | | }, |
1365 | | { prototypes::id::ScreenLuminance, 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 }, |
1366 | | IsBaseOf<nsISupports, mozilla::dom::ScreenLuminance >::value, |
1367 | | sNativePropertyHooks, |
1368 | | FindAssociatedGlobalForNative<mozilla::dom::ScreenLuminance>::Get, |
1369 | | GetProtoObjectHandle, |
1370 | | GetCCParticipant<mozilla::dom::ScreenLuminance>::Get() |
1371 | | }; |
1372 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1373 | | "Must have the right minimal number of reserved slots."); |
1374 | | static_assert(1 >= 1, |
1375 | | "Must have enough reserved slots."); |
1376 | | |
1377 | | const JSClass* |
1378 | | GetJSClass() |
1379 | 0 | { |
1380 | 0 | return sClass.ToJSClass(); |
1381 | 0 | } |
1382 | | |
1383 | | bool |
1384 | | Wrap(JSContext* aCx, mozilla::dom::ScreenLuminance* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1385 | 0 | { |
1386 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ScreenLuminance>::value, |
1387 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1388 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ScreenLuminance*>(aObject) == |
1389 | 0 | reinterpret_cast<mozilla::dom::ScreenLuminance*>(aObject), |
1390 | 0 | "Multiple inheritance for mozilla::dom::ScreenLuminance is broken."); |
1391 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1392 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1393 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1394 | 0 | "You should probably not be using Wrap() directly; use " |
1395 | 0 | "GetOrCreateDOMReflector instead"); |
1396 | 0 |
|
1397 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1398 | 0 | "nsISupports must be on our primary inheritance chain"); |
1399 | 0 |
|
1400 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1401 | 0 | if (!global) { |
1402 | 0 | return false; |
1403 | 0 | } |
1404 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1405 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1406 | 0 |
|
1407 | 0 | // That might have ended up wrapping us already, due to the wonders |
1408 | 0 | // of XBL. Check for that, and bail out as needed. |
1409 | 0 | aReflector.set(aCache->GetWrapper()); |
1410 | 0 | if (aReflector) { |
1411 | | #ifdef DEBUG |
1412 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1413 | | #endif // DEBUG |
1414 | | return true; |
1415 | 0 | } |
1416 | 0 |
|
1417 | 0 | JSAutoRealm ar(aCx, global); |
1418 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1419 | 0 | if (!canonicalProto) { |
1420 | 0 | return false; |
1421 | 0 | } |
1422 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1423 | 0 | if (aGivenProto) { |
1424 | 0 | proto = aGivenProto; |
1425 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1426 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1427 | 0 | // to wrap the proto here. |
1428 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1429 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1430 | 0 | return false; |
1431 | 0 | } |
1432 | 0 | } |
1433 | 0 | } else { |
1434 | 0 | proto = canonicalProto; |
1435 | 0 | } |
1436 | 0 |
|
1437 | 0 | BindingJSObjectCreator<mozilla::dom::ScreenLuminance> creator(aCx); |
1438 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1439 | 0 | if (!aReflector) { |
1440 | 0 | return false; |
1441 | 0 | } |
1442 | 0 | |
1443 | 0 | aCache->SetWrapper(aReflector); |
1444 | 0 | creator.InitializationSucceeded(); |
1445 | 0 |
|
1446 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1447 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1448 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1449 | 0 | // otherwise we won't be able to properly recreate it later, since |
1450 | 0 | // we won't know what proto to use. Note that we don't check |
1451 | 0 | // aGivenProto here, since it's entirely possible (and even |
1452 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1453 | 0 | // same as canonicalProto. |
1454 | 0 | if (proto != canonicalProto) { |
1455 | 0 | PreserveWrapper(aObject); |
1456 | 0 | } |
1457 | 0 |
|
1458 | 0 | return true; |
1459 | 0 | } |
1460 | | |
1461 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1462 | | nullptr, |
1463 | | nullptr, |
1464 | | nullptr, |
1465 | | { sNativeProperties.Upcast(), nullptr }, |
1466 | | prototypes::id::ScreenLuminance, |
1467 | | constructors::id::ScreenLuminance, |
1468 | | nullptr, |
1469 | | &DefaultXrayExpandoObjectClass |
1470 | | } }; |
1471 | | |
1472 | | void |
1473 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1474 | 0 | { |
1475 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1476 | 0 | if (!parentProto) { |
1477 | 0 | return; |
1478 | 0 | } |
1479 | 0 | |
1480 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
1481 | 0 | if (!constructorProto) { |
1482 | 0 | return; |
1483 | 0 | } |
1484 | 0 | |
1485 | 0 | static bool sIdsInited = false; |
1486 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1487 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1488 | 0 | return; |
1489 | 0 | } |
1490 | 0 | sIdsInited = true; |
1491 | 0 | } |
1492 | 0 |
|
1493 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ScreenLuminance); |
1494 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ScreenLuminance); |
1495 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1496 | 0 | &sPrototypeClass.mBase, protoCache, |
1497 | 0 | nullptr, |
1498 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1499 | 0 | interfaceCache, |
1500 | 0 | sNativeProperties.Upcast(), |
1501 | 0 | nullptr, |
1502 | 0 | "ScreenLuminance", aDefineOnGlobal, |
1503 | 0 | nullptr, |
1504 | 0 | false); |
1505 | 0 | } |
1506 | | |
1507 | | JSObject* |
1508 | | GetConstructorObject(JSContext* aCx) |
1509 | 0 | { |
1510 | 0 | return GetConstructorObjectHandle(aCx); |
1511 | 0 | } |
1512 | | |
1513 | | } // namespace ScreenLuminance_Binding |
1514 | | |
1515 | | |
1516 | | |
1517 | | } // namespace dom |
1518 | | } // namespace mozilla |