/work/obj-fuzz/dom/bindings/VisualViewportBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM VisualViewport.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventTargetBinding.h" |
4 | | #include "VisualViewportBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/FloatingPoint.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/PrimitiveConversions.h" |
12 | | #include "mozilla/dom/VisualViewport.h" |
13 | | #include "mozilla/dom/XrayExpandoClass.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace dom { |
17 | | |
18 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
19 | | using namespace mozilla::dom::binding_detail; |
20 | | |
21 | | |
22 | | namespace VisualViewport_Binding { |
23 | | |
24 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
25 | | "Can't inherit from an interface with a different ownership model."); |
26 | | |
27 | | MOZ_CAN_RUN_SCRIPT static bool |
28 | | get_offsetLeft(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VisualViewport* self, JSJitGetterCallArgs args) |
29 | 0 | { |
30 | 0 | AUTO_PROFILER_LABEL_FAST("get VisualViewport.offsetLeft", DOM, cx); |
31 | 0 |
|
32 | 0 | double result(self->OffsetLeft()); |
33 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
34 | 0 | args.rval().set(JS_NumberValue(double(result))); |
35 | 0 | return true; |
36 | 0 | } |
37 | | |
38 | | static const JSJitInfo offsetLeft_getterinfo = { |
39 | | { (JSJitGetterOp)get_offsetLeft }, |
40 | | { prototypes::id::VisualViewport }, |
41 | | { PrototypeTraits<prototypes::id::VisualViewport>::Depth }, |
42 | | JSJitInfo::Getter, |
43 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
44 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
45 | | true, /* isInfallible. False in setters. */ |
46 | | false, /* isMovable. Not relevant for setters. */ |
47 | | false, /* isEliminatable. Not relevant for setters. */ |
48 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
49 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
50 | | false, /* isTypedMethod. Only relevant for methods. */ |
51 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
52 | | }; |
53 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
54 | | static_assert(0 < 1, "There is no slot for us"); |
55 | | |
56 | | MOZ_CAN_RUN_SCRIPT static bool |
57 | | get_offsetTop(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VisualViewport* self, JSJitGetterCallArgs args) |
58 | 0 | { |
59 | 0 | AUTO_PROFILER_LABEL_FAST("get VisualViewport.offsetTop", DOM, cx); |
60 | 0 |
|
61 | 0 | double result(self->OffsetTop()); |
62 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
63 | 0 | args.rval().set(JS_NumberValue(double(result))); |
64 | 0 | return true; |
65 | 0 | } |
66 | | |
67 | | static const JSJitInfo offsetTop_getterinfo = { |
68 | | { (JSJitGetterOp)get_offsetTop }, |
69 | | { prototypes::id::VisualViewport }, |
70 | | { PrototypeTraits<prototypes::id::VisualViewport>::Depth }, |
71 | | JSJitInfo::Getter, |
72 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
73 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
74 | | true, /* isInfallible. False in setters. */ |
75 | | false, /* isMovable. Not relevant for setters. */ |
76 | | false, /* isEliminatable. Not relevant for setters. */ |
77 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
78 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
79 | | false, /* isTypedMethod. Only relevant for methods. */ |
80 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
81 | | }; |
82 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
83 | | static_assert(0 < 1, "There is no slot for us"); |
84 | | |
85 | | MOZ_CAN_RUN_SCRIPT static bool |
86 | | get_pageLeft(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VisualViewport* self, JSJitGetterCallArgs args) |
87 | 0 | { |
88 | 0 | AUTO_PROFILER_LABEL_FAST("get VisualViewport.pageLeft", DOM, cx); |
89 | 0 |
|
90 | 0 | double result(self->PageLeft()); |
91 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
92 | 0 | args.rval().set(JS_NumberValue(double(result))); |
93 | 0 | return true; |
94 | 0 | } |
95 | | |
96 | | static const JSJitInfo pageLeft_getterinfo = { |
97 | | { (JSJitGetterOp)get_pageLeft }, |
98 | | { prototypes::id::VisualViewport }, |
99 | | { PrototypeTraits<prototypes::id::VisualViewport>::Depth }, |
100 | | JSJitInfo::Getter, |
101 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
102 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
103 | | true, /* isInfallible. False in setters. */ |
104 | | false, /* isMovable. Not relevant for setters. */ |
105 | | false, /* isEliminatable. Not relevant for setters. */ |
106 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
107 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
108 | | false, /* isTypedMethod. Only relevant for methods. */ |
109 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
110 | | }; |
111 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
112 | | static_assert(0 < 1, "There is no slot for us"); |
113 | | |
114 | | MOZ_CAN_RUN_SCRIPT static bool |
115 | | get_pageTop(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VisualViewport* self, JSJitGetterCallArgs args) |
116 | 0 | { |
117 | 0 | AUTO_PROFILER_LABEL_FAST("get VisualViewport.pageTop", DOM, cx); |
118 | 0 |
|
119 | 0 | double result(self->PageTop()); |
120 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
121 | 0 | args.rval().set(JS_NumberValue(double(result))); |
122 | 0 | return true; |
123 | 0 | } |
124 | | |
125 | | static const JSJitInfo pageTop_getterinfo = { |
126 | | { (JSJitGetterOp)get_pageTop }, |
127 | | { prototypes::id::VisualViewport }, |
128 | | { PrototypeTraits<prototypes::id::VisualViewport>::Depth }, |
129 | | JSJitInfo::Getter, |
130 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
131 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
132 | | true, /* isInfallible. False in setters. */ |
133 | | false, /* isMovable. Not relevant for setters. */ |
134 | | false, /* isEliminatable. Not relevant for setters. */ |
135 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
136 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
137 | | false, /* isTypedMethod. Only relevant for methods. */ |
138 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
139 | | }; |
140 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
141 | | static_assert(0 < 1, "There is no slot for us"); |
142 | | |
143 | | MOZ_CAN_RUN_SCRIPT static bool |
144 | | get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VisualViewport* self, JSJitGetterCallArgs args) |
145 | 0 | { |
146 | 0 | AUTO_PROFILER_LABEL_FAST("get VisualViewport.width", DOM, cx); |
147 | 0 |
|
148 | 0 | double result(self->Width()); |
149 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
150 | 0 | args.rval().set(JS_NumberValue(double(result))); |
151 | 0 | return true; |
152 | 0 | } |
153 | | |
154 | | static const JSJitInfo width_getterinfo = { |
155 | | { (JSJitGetterOp)get_width }, |
156 | | { prototypes::id::VisualViewport }, |
157 | | { PrototypeTraits<prototypes::id::VisualViewport>::Depth }, |
158 | | JSJitInfo::Getter, |
159 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
160 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
161 | | true, /* isInfallible. False in setters. */ |
162 | | false, /* isMovable. Not relevant for setters. */ |
163 | | false, /* isEliminatable. Not relevant for setters. */ |
164 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
165 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
166 | | false, /* isTypedMethod. Only relevant for methods. */ |
167 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
168 | | }; |
169 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
170 | | static_assert(0 < 1, "There is no slot for us"); |
171 | | |
172 | | MOZ_CAN_RUN_SCRIPT static bool |
173 | | get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VisualViewport* self, JSJitGetterCallArgs args) |
174 | 0 | { |
175 | 0 | AUTO_PROFILER_LABEL_FAST("get VisualViewport.height", DOM, cx); |
176 | 0 |
|
177 | 0 | double result(self->Height()); |
178 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
179 | 0 | args.rval().set(JS_NumberValue(double(result))); |
180 | 0 | return true; |
181 | 0 | } |
182 | | |
183 | | static const JSJitInfo height_getterinfo = { |
184 | | { (JSJitGetterOp)get_height }, |
185 | | { prototypes::id::VisualViewport }, |
186 | | { PrototypeTraits<prototypes::id::VisualViewport>::Depth }, |
187 | | JSJitInfo::Getter, |
188 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
189 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
190 | | true, /* isInfallible. False in setters. */ |
191 | | false, /* isMovable. Not relevant for setters. */ |
192 | | false, /* isEliminatable. Not relevant for setters. */ |
193 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
194 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
195 | | false, /* isTypedMethod. Only relevant for methods. */ |
196 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
197 | | }; |
198 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
199 | | static_assert(0 < 1, "There is no slot for us"); |
200 | | |
201 | | MOZ_CAN_RUN_SCRIPT static bool |
202 | | get_scale(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::VisualViewport* self, JSJitGetterCallArgs args) |
203 | 0 | { |
204 | 0 | AUTO_PROFILER_LABEL_FAST("get VisualViewport.scale", DOM, cx); |
205 | 0 |
|
206 | 0 | double result(self->Scale()); |
207 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
208 | 0 | args.rval().set(JS_NumberValue(double(result))); |
209 | 0 | return true; |
210 | 0 | } |
211 | | |
212 | | static const JSJitInfo scale_getterinfo = { |
213 | | { (JSJitGetterOp)get_scale }, |
214 | | { prototypes::id::VisualViewport }, |
215 | | { PrototypeTraits<prototypes::id::VisualViewport>::Depth }, |
216 | | JSJitInfo::Getter, |
217 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
218 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
219 | | true, /* isInfallible. False in setters. */ |
220 | | false, /* isMovable. Not relevant for setters. */ |
221 | | false, /* isEliminatable. Not relevant for setters. */ |
222 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
223 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
224 | | false, /* isTypedMethod. Only relevant for methods. */ |
225 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
226 | | }; |
227 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
228 | | static_assert(0 < 1, "There is no slot for us"); |
229 | | |
230 | | static bool |
231 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
232 | 0 | { |
233 | 0 | mozilla::dom::VisualViewport* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VisualViewport>(obj); |
234 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
235 | 0 | // obviously can't preserve if we're not initialized. |
236 | 0 | if (self && self->GetWrapperPreserveColor()) { |
237 | 0 | PreserveWrapper(self); |
238 | 0 | } |
239 | 0 | return true; |
240 | 0 | } |
241 | | |
242 | | static void |
243 | | _finalize(js::FreeOp* fop, JSObject* obj) |
244 | 0 | { |
245 | 0 | mozilla::dom::VisualViewport* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VisualViewport>(obj); |
246 | 0 | if (self) { |
247 | 0 | ClearWrapper(self, self, obj); |
248 | 0 | AddForDeferredFinalization<mozilla::dom::VisualViewport>(self); |
249 | 0 | } |
250 | 0 | } |
251 | | |
252 | | static size_t |
253 | | _objectMoved(JSObject* obj, JSObject* old) |
254 | 0 | { |
255 | 0 | mozilla::dom::VisualViewport* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::VisualViewport>(obj); |
256 | 0 | if (self) { |
257 | 0 | UpdateWrapper(self, self, obj, old); |
258 | 0 | } |
259 | 0 |
|
260 | 0 | return 0; |
261 | 0 | } |
262 | | |
263 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
264 | | #if defined(__clang__) |
265 | | #pragma clang diagnostic push |
266 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
267 | | #endif |
268 | | static const JSPropertySpec sAttributes_specs[] = { |
269 | | { "offsetLeft", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &offsetLeft_getterinfo, nullptr, nullptr }, |
270 | | { "offsetTop", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &offsetTop_getterinfo, nullptr, nullptr }, |
271 | | { "pageLeft", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pageLeft_getterinfo, nullptr, nullptr }, |
272 | | { "pageTop", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &pageTop_getterinfo, nullptr, nullptr }, |
273 | | { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, nullptr, nullptr }, |
274 | | { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, nullptr, nullptr }, |
275 | | { "scale", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &scale_getterinfo, nullptr, nullptr }, |
276 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
277 | | }; |
278 | | #if defined(__clang__) |
279 | | #pragma clang diagnostic pop |
280 | | #endif |
281 | | |
282 | | |
283 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
284 | | { nullptr, &sAttributes_specs[0] }, |
285 | | { nullptr, nullptr } |
286 | | }; |
287 | | |
288 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
289 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
290 | | static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
291 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
292 | | |
293 | | |
294 | | static uint16_t sNativeProperties_sortedPropertyIndices[7]; |
295 | | static PropertyInfo sNativeProperties_propertyInfos[7]; |
296 | | |
297 | | static const NativePropertiesN<1> sNativeProperties = { |
298 | | false, 0, |
299 | | false, 0, |
300 | | false, 0, |
301 | | true, 0 /* sAttributes */, |
302 | | false, 0, |
303 | | false, 0, |
304 | | false, 0, |
305 | | -1, |
306 | | 7, |
307 | | sNativeProperties_sortedPropertyIndices, |
308 | | { |
309 | | { sAttributes, &sNativeProperties_propertyInfos[0] } |
310 | | } |
311 | | }; |
312 | | static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
313 | | "We have a property info count that is oversized"); |
314 | | |
315 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
316 | | { |
317 | | "Function", |
318 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
319 | | &sBoringInterfaceObjectClassClassOps, |
320 | | JS_NULL_CLASS_SPEC, |
321 | | JS_NULL_CLASS_EXT, |
322 | | &sInterfaceObjectClassObjectOps |
323 | | }, |
324 | | eInterface, |
325 | | true, |
326 | | prototypes::id::VisualViewport, |
327 | | PrototypeTraits<prototypes::id::VisualViewport>::Depth, |
328 | | sNativePropertyHooks, |
329 | | "function VisualViewport() {\n [native code]\n}", |
330 | | EventTarget_Binding::GetConstructorObject |
331 | | }; |
332 | | |
333 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
334 | | { |
335 | | "VisualViewportPrototype", |
336 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
337 | | JS_NULL_CLASS_OPS, |
338 | | JS_NULL_CLASS_SPEC, |
339 | | JS_NULL_CLASS_EXT, |
340 | | JS_NULL_OBJECT_OPS |
341 | | }, |
342 | | eInterfacePrototype, |
343 | | false, |
344 | | prototypes::id::VisualViewport, |
345 | | PrototypeTraits<prototypes::id::VisualViewport>::Depth, |
346 | | sNativePropertyHooks, |
347 | | "[object VisualViewportPrototype]", |
348 | | EventTarget_Binding::GetProtoObject |
349 | | }; |
350 | | |
351 | | static const js::ClassOps sClassOps = { |
352 | | _addProperty, /* addProperty */ |
353 | | nullptr, /* delProperty */ |
354 | | nullptr, /* enumerate */ |
355 | | nullptr, /* newEnumerate */ |
356 | | nullptr, /* resolve */ |
357 | | nullptr, /* mayResolve */ |
358 | | _finalize, /* finalize */ |
359 | | nullptr, /* call */ |
360 | | nullptr, /* hasInstance */ |
361 | | nullptr, /* construct */ |
362 | | nullptr, /* trace */ |
363 | | }; |
364 | | |
365 | | static const js::ClassExtension sClassExtension = { |
366 | | nullptr, /* weakmapKeyDelegateOp */ |
367 | | _objectMoved /* objectMovedOp */ |
368 | | }; |
369 | | |
370 | | static const DOMJSClass sClass = { |
371 | | { "VisualViewport", |
372 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
373 | | &sClassOps, |
374 | | JS_NULL_CLASS_SPEC, |
375 | | &sClassExtension, |
376 | | JS_NULL_OBJECT_OPS |
377 | | }, |
378 | | { prototypes::id::EventTarget, prototypes::id::VisualViewport, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
379 | | IsBaseOf<nsISupports, mozilla::dom::VisualViewport >::value, |
380 | | sNativePropertyHooks, |
381 | | FindAssociatedGlobalForNative<mozilla::dom::VisualViewport>::Get, |
382 | | GetProtoObjectHandle, |
383 | | GetCCParticipant<mozilla::dom::VisualViewport>::Get() |
384 | | }; |
385 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
386 | | "Must have the right minimal number of reserved slots."); |
387 | | static_assert(1 >= 1, |
388 | | "Must have enough reserved slots."); |
389 | | |
390 | | const JSClass* |
391 | | GetJSClass() |
392 | 0 | { |
393 | 0 | return sClass.ToJSClass(); |
394 | 0 | } |
395 | | |
396 | | bool |
397 | | Wrap(JSContext* aCx, mozilla::dom::VisualViewport* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
398 | 0 | { |
399 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::VisualViewport>::value, |
400 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
401 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::VisualViewport*>(aObject) == |
402 | 0 | reinterpret_cast<mozilla::dom::VisualViewport*>(aObject), |
403 | 0 | "Multiple inheritance for mozilla::dom::VisualViewport is broken."); |
404 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
405 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
406 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
407 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
408 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
409 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
410 | 0 | "You should probably not be using Wrap() directly; use " |
411 | 0 | "GetOrCreateDOMReflector instead"); |
412 | 0 |
|
413 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
414 | 0 | "nsISupports must be on our primary inheritance chain"); |
415 | 0 |
|
416 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
417 | 0 | if (!global) { |
418 | 0 | return false; |
419 | 0 | } |
420 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
421 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
422 | 0 |
|
423 | 0 | // That might have ended up wrapping us already, due to the wonders |
424 | 0 | // of XBL. Check for that, and bail out as needed. |
425 | 0 | aReflector.set(aCache->GetWrapper()); |
426 | 0 | if (aReflector) { |
427 | | #ifdef DEBUG |
428 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
429 | | #endif // DEBUG |
430 | | return true; |
431 | 0 | } |
432 | 0 |
|
433 | 0 | JSAutoRealm ar(aCx, global); |
434 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
435 | 0 | if (!canonicalProto) { |
436 | 0 | return false; |
437 | 0 | } |
438 | 0 | JS::Rooted<JSObject*> proto(aCx); |
439 | 0 | if (aGivenProto) { |
440 | 0 | proto = aGivenProto; |
441 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
442 | 0 | // coming in, we changed compartments to that of "parent" so may need |
443 | 0 | // to wrap the proto here. |
444 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
445 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
446 | 0 | return false; |
447 | 0 | } |
448 | 0 | } |
449 | 0 | } else { |
450 | 0 | proto = canonicalProto; |
451 | 0 | } |
452 | 0 |
|
453 | 0 | BindingJSObjectCreator<mozilla::dom::VisualViewport> creator(aCx); |
454 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
455 | 0 | if (!aReflector) { |
456 | 0 | return false; |
457 | 0 | } |
458 | 0 | |
459 | 0 | aCache->SetWrapper(aReflector); |
460 | 0 | creator.InitializationSucceeded(); |
461 | 0 |
|
462 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
463 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
464 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
465 | 0 | // otherwise we won't be able to properly recreate it later, since |
466 | 0 | // we won't know what proto to use. Note that we don't check |
467 | 0 | // aGivenProto here, since it's entirely possible (and even |
468 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
469 | 0 | // same as canonicalProto. |
470 | 0 | if (proto != canonicalProto) { |
471 | 0 | PreserveWrapper(aObject); |
472 | 0 | } |
473 | 0 |
|
474 | 0 | return true; |
475 | 0 | } |
476 | | |
477 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
478 | | nullptr, |
479 | | nullptr, |
480 | | nullptr, |
481 | | { sNativeProperties.Upcast(), nullptr }, |
482 | | prototypes::id::VisualViewport, |
483 | | constructors::id::VisualViewport, |
484 | | EventTarget_Binding::sNativePropertyHooks, |
485 | | &DefaultXrayExpandoObjectClass |
486 | | } }; |
487 | | |
488 | | void |
489 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
490 | 0 | { |
491 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
492 | 0 | if (!parentProto) { |
493 | 0 | return; |
494 | 0 | } |
495 | 0 | |
496 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
497 | 0 | if (!constructorProto) { |
498 | 0 | return; |
499 | 0 | } |
500 | 0 | |
501 | 0 | static bool sIdsInited = false; |
502 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
503 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
504 | 0 | return; |
505 | 0 | } |
506 | 0 | sIdsInited = true; |
507 | 0 | } |
508 | 0 |
|
509 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::VisualViewport); |
510 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::VisualViewport); |
511 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
512 | 0 | &sPrototypeClass.mBase, protoCache, |
513 | 0 | nullptr, |
514 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
515 | 0 | interfaceCache, |
516 | 0 | sNativeProperties.Upcast(), |
517 | 0 | nullptr, |
518 | 0 | "VisualViewport", aDefineOnGlobal, |
519 | 0 | nullptr, |
520 | 0 | false); |
521 | 0 | } |
522 | | |
523 | | JSObject* |
524 | | GetConstructorObject(JSContext* aCx) |
525 | 0 | { |
526 | 0 | return GetConstructorObjectHandle(aCx); |
527 | 0 | } |
528 | | |
529 | | } // namespace VisualViewport_Binding |
530 | | |
531 | | |
532 | | |
533 | | } // namespace dom |
534 | | } // namespace mozilla |