/work/obj-fuzz/dom/bindings/DOMRectBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM DOMRect.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "AtomList.h" |
4 | | #include "DOMRectBinding.h" |
5 | | #include "WrapperFactory.h" |
6 | | #include "mozilla/OwningNonNull.h" |
7 | | #include "mozilla/dom/BindingUtils.h" |
8 | | #include "mozilla/dom/DOMJSClass.h" |
9 | | #include "mozilla/dom/DOMRect.h" |
10 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
11 | | #include "mozilla/dom/PrimitiveConversions.h" |
12 | | #include "mozilla/dom/ScriptSettings.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 | | |
23 | | DOMRectInit::DOMRectInit() |
24 | 0 | { |
25 | 0 | // Safe to pass a null context if we pass a null value |
26 | 0 | Init(nullptr, JS::NullHandleValue); |
27 | 0 | } |
28 | | |
29 | | |
30 | | |
31 | | bool |
32 | | DOMRectInit::InitIds(JSContext* cx, DOMRectInitAtoms* atomsCache) |
33 | 0 | { |
34 | 0 | MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache)); |
35 | 0 |
|
36 | 0 | // Initialize these in reverse order so that any failure leaves the first one |
37 | 0 | // uninitialized. |
38 | 0 | if (!atomsCache->y_id.init(cx, "y") || |
39 | 0 | !atomsCache->x_id.init(cx, "x") || |
40 | 0 | !atomsCache->width_id.init(cx, "width") || |
41 | 0 | !atomsCache->height_id.init(cx, "height")) { |
42 | 0 | return false; |
43 | 0 | } |
44 | 0 | return true; |
45 | 0 | } |
46 | | |
47 | | bool |
48 | | DOMRectInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl) |
49 | 0 | { |
50 | 0 | // Passing a null JSContext is OK only if we're initing from null, |
51 | 0 | // Since in that case we will not have to do any property gets |
52 | 0 | // Also evaluate isNullOrUndefined in order to avoid false-positive |
53 | 0 | // checkers by static analysis tools |
54 | 0 | MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined()); |
55 | 0 | DOMRectInitAtoms* atomsCache = nullptr; |
56 | 0 | if (cx) { |
57 | 0 | atomsCache = GetAtomCache<DOMRectInitAtoms>(cx); |
58 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
59 | 0 | return false; |
60 | 0 | } |
61 | 0 | } |
62 | 0 | |
63 | 0 | if (!IsConvertibleToDictionary(val)) { |
64 | 0 | return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription); |
65 | 0 | } |
66 | 0 | |
67 | 0 | bool isNull = val.isNullOrUndefined(); |
68 | 0 | // We only need these if !isNull, in which case we have |cx|. |
69 | 0 | Maybe<JS::Rooted<JSObject *> > object; |
70 | 0 | Maybe<JS::Rooted<JS::Value> > temp; |
71 | 0 | if (!isNull) { |
72 | 0 | MOZ_ASSERT(cx); |
73 | 0 | object.emplace(cx, &val.toObject()); |
74 | 0 | temp.emplace(cx); |
75 | 0 | } |
76 | 0 | if (!isNull) { |
77 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) { |
78 | 0 | return false; |
79 | 0 | } |
80 | 0 | } |
81 | 0 | if (!isNull && !temp->isUndefined()) { |
82 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mHeight)) { |
83 | 0 | return false; |
84 | 0 | } |
85 | 0 | } else { |
86 | 0 | mHeight = 0.0; |
87 | 0 | } |
88 | 0 | mIsAnyMemberPresent = true; |
89 | 0 |
|
90 | 0 | if (!isNull) { |
91 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) { |
92 | 0 | return false; |
93 | 0 | } |
94 | 0 | } |
95 | 0 | if (!isNull && !temp->isUndefined()) { |
96 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mWidth)) { |
97 | 0 | return false; |
98 | 0 | } |
99 | 0 | } else { |
100 | 0 | mWidth = 0.0; |
101 | 0 | } |
102 | 0 | mIsAnyMemberPresent = true; |
103 | 0 |
|
104 | 0 | if (!isNull) { |
105 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->x_id, temp.ptr())) { |
106 | 0 | return false; |
107 | 0 | } |
108 | 0 | } |
109 | 0 | if (!isNull && !temp->isUndefined()) { |
110 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mX)) { |
111 | 0 | return false; |
112 | 0 | } |
113 | 0 | } else { |
114 | 0 | mX = 0.0; |
115 | 0 | } |
116 | 0 | mIsAnyMemberPresent = true; |
117 | 0 |
|
118 | 0 | if (!isNull) { |
119 | 0 | if (!JS_GetPropertyById(cx, *object, atomsCache->y_id, temp.ptr())) { |
120 | 0 | return false; |
121 | 0 | } |
122 | 0 | } |
123 | 0 | if (!isNull && !temp->isUndefined()) { |
124 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mY)) { |
125 | 0 | return false; |
126 | 0 | } |
127 | 0 | } else { |
128 | 0 | mY = 0.0; |
129 | 0 | } |
130 | 0 | mIsAnyMemberPresent = true; |
131 | 0 | return true; |
132 | 0 | } |
133 | | |
134 | | bool |
135 | | DOMRectInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const |
136 | 0 | { |
137 | 0 | DOMRectInitAtoms* atomsCache = GetAtomCache<DOMRectInitAtoms>(cx); |
138 | 0 | if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) { |
139 | 0 | return false; |
140 | 0 | } |
141 | 0 | |
142 | 0 | JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx)); |
143 | 0 | if (!obj) { |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | rval.set(JS::ObjectValue(*obj)); |
147 | 0 |
|
148 | 0 | do { |
149 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
150 | 0 | JS::Rooted<JS::Value> temp(cx); |
151 | 0 | double const & currentValue = mHeight; |
152 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
153 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | break; |
157 | 0 | } while(false); |
158 | 0 |
|
159 | 0 | do { |
160 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
161 | 0 | JS::Rooted<JS::Value> temp(cx); |
162 | 0 | double const & currentValue = mWidth; |
163 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
164 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) { |
165 | 0 | return false; |
166 | 0 | } |
167 | 0 | break; |
168 | 0 | } while(false); |
169 | 0 |
|
170 | 0 | do { |
171 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
172 | 0 | JS::Rooted<JS::Value> temp(cx); |
173 | 0 | double const & currentValue = mX; |
174 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
175 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->x_id, temp, JSPROP_ENUMERATE)) { |
176 | 0 | return false; |
177 | 0 | } |
178 | 0 | break; |
179 | 0 | } while(false); |
180 | 0 |
|
181 | 0 | do { |
182 | 0 | // block for our 'break' successCode and scope for 'temp' and 'currentValue' |
183 | 0 | JS::Rooted<JS::Value> temp(cx); |
184 | 0 | double const & currentValue = mY; |
185 | 0 | temp.set(JS_NumberValue(double(currentValue))); |
186 | 0 | if (!JS_DefinePropertyById(cx, obj, atomsCache->y_id, temp, JSPROP_ENUMERATE)) { |
187 | 0 | return false; |
188 | 0 | } |
189 | 0 | break; |
190 | 0 | } while(false); |
191 | 0 |
|
192 | 0 | return true; |
193 | 0 | } |
194 | | |
195 | | void |
196 | | DOMRectInit::TraceDictionary(JSTracer* trc) |
197 | 0 | { |
198 | 0 | } |
199 | | |
200 | | DOMRectInit& |
201 | | DOMRectInit::operator=(const DOMRectInit& aOther) |
202 | 0 | { |
203 | 0 | DictionaryBase::operator=(aOther); |
204 | 0 | mHeight = aOther.mHeight; |
205 | 0 | mWidth = aOther.mWidth; |
206 | 0 | mX = aOther.mX; |
207 | 0 | mY = aOther.mY; |
208 | 0 | return *this; |
209 | 0 | } |
210 | | |
211 | | namespace binding_detail { |
212 | | } // namespace binding_detail |
213 | | |
214 | | |
215 | | namespace DOMRect_Binding { |
216 | | |
217 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<DOMRectReadOnly_Binding::NativeType>::value, |
218 | | "Can't inherit from an interface with a different ownership model."); |
219 | | |
220 | | MOZ_CAN_RUN_SCRIPT static bool |
221 | | get_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitGetterCallArgs args) |
222 | 0 | { |
223 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRect.x", DOM, cx); |
224 | 0 |
|
225 | 0 | double result(self->X()); |
226 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
227 | 0 | args.rval().set(JS_NumberValue(double(result))); |
228 | 0 | return true; |
229 | 0 | } |
230 | | |
231 | | MOZ_CAN_RUN_SCRIPT static bool |
232 | | set_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitSetterCallArgs args) |
233 | 0 | { |
234 | 0 | AUTO_PROFILER_LABEL_FAST("set DOMRect.x", DOM, cx); |
235 | 0 |
|
236 | 0 | double arg0; |
237 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) { |
238 | 0 | return false; |
239 | 0 | } |
240 | 0 | self->SetX(arg0); |
241 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
242 | 0 |
|
243 | 0 | return true; |
244 | 0 | } |
245 | | |
246 | | static const JSJitInfo x_getterinfo = { |
247 | | { (JSJitGetterOp)get_x }, |
248 | | { prototypes::id::DOMRect }, |
249 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
250 | | JSJitInfo::Getter, |
251 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
252 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
253 | | true, /* isInfallible. False in setters. */ |
254 | | false, /* isMovable. Not relevant for setters. */ |
255 | | false, /* isEliminatable. Not relevant for setters. */ |
256 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
257 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
258 | | false, /* isTypedMethod. Only relevant for methods. */ |
259 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
260 | | }; |
261 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
262 | | static_assert(0 < 1, "There is no slot for us"); |
263 | | static const JSJitInfo x_setterinfo = { |
264 | | { (JSJitGetterOp)set_x }, |
265 | | { prototypes::id::DOMRect }, |
266 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
267 | | JSJitInfo::Setter, |
268 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
269 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
270 | | false, /* isInfallible. False in setters. */ |
271 | | false, /* isMovable. Not relevant for setters. */ |
272 | | false, /* isEliminatable. Not relevant for setters. */ |
273 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
274 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
275 | | false, /* isTypedMethod. Only relevant for methods. */ |
276 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
277 | | }; |
278 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
279 | | static_assert(0 < 1, "There is no slot for us"); |
280 | | |
281 | | MOZ_CAN_RUN_SCRIPT static bool |
282 | | get_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitGetterCallArgs args) |
283 | 0 | { |
284 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRect.y", DOM, cx); |
285 | 0 |
|
286 | 0 | double result(self->Y()); |
287 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
288 | 0 | args.rval().set(JS_NumberValue(double(result))); |
289 | 0 | return true; |
290 | 0 | } |
291 | | |
292 | | MOZ_CAN_RUN_SCRIPT static bool |
293 | | set_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitSetterCallArgs args) |
294 | 0 | { |
295 | 0 | AUTO_PROFILER_LABEL_FAST("set DOMRect.y", DOM, cx); |
296 | 0 |
|
297 | 0 | double arg0; |
298 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) { |
299 | 0 | return false; |
300 | 0 | } |
301 | 0 | self->SetY(arg0); |
302 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
303 | 0 |
|
304 | 0 | return true; |
305 | 0 | } |
306 | | |
307 | | static const JSJitInfo y_getterinfo = { |
308 | | { (JSJitGetterOp)get_y }, |
309 | | { prototypes::id::DOMRect }, |
310 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
311 | | JSJitInfo::Getter, |
312 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
313 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
314 | | true, /* isInfallible. False in setters. */ |
315 | | false, /* isMovable. Not relevant for setters. */ |
316 | | false, /* isEliminatable. Not relevant for setters. */ |
317 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
318 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
319 | | false, /* isTypedMethod. Only relevant for methods. */ |
320 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
321 | | }; |
322 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
323 | | static_assert(0 < 1, "There is no slot for us"); |
324 | | static const JSJitInfo y_setterinfo = { |
325 | | { (JSJitGetterOp)set_y }, |
326 | | { prototypes::id::DOMRect }, |
327 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
328 | | JSJitInfo::Setter, |
329 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
330 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
331 | | false, /* isInfallible. False in setters. */ |
332 | | false, /* isMovable. Not relevant for setters. */ |
333 | | false, /* isEliminatable. Not relevant for setters. */ |
334 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
335 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
336 | | false, /* isTypedMethod. Only relevant for methods. */ |
337 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
338 | | }; |
339 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
340 | | static_assert(0 < 1, "There is no slot for us"); |
341 | | |
342 | | MOZ_CAN_RUN_SCRIPT static bool |
343 | | get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitGetterCallArgs args) |
344 | 0 | { |
345 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRect.width", DOM, cx); |
346 | 0 |
|
347 | 0 | double result(self->Width()); |
348 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
349 | 0 | args.rval().set(JS_NumberValue(double(result))); |
350 | 0 | return true; |
351 | 0 | } |
352 | | |
353 | | MOZ_CAN_RUN_SCRIPT static bool |
354 | | set_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitSetterCallArgs args) |
355 | 0 | { |
356 | 0 | AUTO_PROFILER_LABEL_FAST("set DOMRect.width", DOM, cx); |
357 | 0 |
|
358 | 0 | double arg0; |
359 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) { |
360 | 0 | return false; |
361 | 0 | } |
362 | 0 | self->SetWidth(arg0); |
363 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
364 | 0 |
|
365 | 0 | return true; |
366 | 0 | } |
367 | | |
368 | | static const JSJitInfo width_getterinfo = { |
369 | | { (JSJitGetterOp)get_width }, |
370 | | { prototypes::id::DOMRect }, |
371 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
372 | | JSJitInfo::Getter, |
373 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
374 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
375 | | true, /* isInfallible. False in setters. */ |
376 | | false, /* isMovable. Not relevant for setters. */ |
377 | | false, /* isEliminatable. Not relevant for setters. */ |
378 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
379 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
380 | | false, /* isTypedMethod. Only relevant for methods. */ |
381 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
382 | | }; |
383 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
384 | | static_assert(0 < 1, "There is no slot for us"); |
385 | | static const JSJitInfo width_setterinfo = { |
386 | | { (JSJitGetterOp)set_width }, |
387 | | { prototypes::id::DOMRect }, |
388 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
389 | | JSJitInfo::Setter, |
390 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
391 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
392 | | false, /* isInfallible. False in setters. */ |
393 | | false, /* isMovable. Not relevant for setters. */ |
394 | | false, /* isEliminatable. Not relevant for setters. */ |
395 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
396 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
397 | | false, /* isTypedMethod. Only relevant for methods. */ |
398 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
399 | | }; |
400 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
401 | | static_assert(0 < 1, "There is no slot for us"); |
402 | | |
403 | | MOZ_CAN_RUN_SCRIPT static bool |
404 | | get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitGetterCallArgs args) |
405 | 0 | { |
406 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRect.height", DOM, cx); |
407 | 0 |
|
408 | 0 | double result(self->Height()); |
409 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
410 | 0 | args.rval().set(JS_NumberValue(double(result))); |
411 | 0 | return true; |
412 | 0 | } |
413 | | |
414 | | MOZ_CAN_RUN_SCRIPT static bool |
415 | | set_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRect* self, JSJitSetterCallArgs args) |
416 | 0 | { |
417 | 0 | AUTO_PROFILER_LABEL_FAST("set DOMRect.height", DOM, cx); |
418 | 0 |
|
419 | 0 | double arg0; |
420 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) { |
421 | 0 | return false; |
422 | 0 | } |
423 | 0 | self->SetHeight(arg0); |
424 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
425 | 0 |
|
426 | 0 | return true; |
427 | 0 | } |
428 | | |
429 | | static const JSJitInfo height_getterinfo = { |
430 | | { (JSJitGetterOp)get_height }, |
431 | | { prototypes::id::DOMRect }, |
432 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
433 | | JSJitInfo::Getter, |
434 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
435 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
436 | | true, /* isInfallible. False in setters. */ |
437 | | false, /* isMovable. Not relevant for setters. */ |
438 | | false, /* isEliminatable. Not relevant for setters. */ |
439 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
440 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
441 | | false, /* isTypedMethod. Only relevant for methods. */ |
442 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
443 | | }; |
444 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
445 | | static_assert(0 < 1, "There is no slot for us"); |
446 | | static const JSJitInfo height_setterinfo = { |
447 | | { (JSJitGetterOp)set_height }, |
448 | | { prototypes::id::DOMRect }, |
449 | | { PrototypeTraits<prototypes::id::DOMRect>::Depth }, |
450 | | JSJitInfo::Setter, |
451 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
452 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
453 | | false, /* isInfallible. False in setters. */ |
454 | | false, /* isMovable. Not relevant for setters. */ |
455 | | false, /* isEliminatable. Not relevant for setters. */ |
456 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
457 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
458 | | false, /* isTypedMethod. Only relevant for methods. */ |
459 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
460 | | }; |
461 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
462 | | static_assert(0 < 1, "There is no slot for us"); |
463 | | |
464 | | static bool |
465 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
466 | 0 | { |
467 | 0 | mozilla::dom::DOMRect* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMRect>(obj); |
468 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
469 | 0 | // obviously can't preserve if we're not initialized. |
470 | 0 | if (self && self->GetWrapperPreserveColor()) { |
471 | 0 | PreserveWrapper(self); |
472 | 0 | } |
473 | 0 | return true; |
474 | 0 | } |
475 | | |
476 | | static void |
477 | | _finalize(js::FreeOp* fop, JSObject* obj) |
478 | 0 | { |
479 | 0 | mozilla::dom::DOMRect* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMRect>(obj); |
480 | 0 | if (self) { |
481 | 0 | ClearWrapper(self, self, obj); |
482 | 0 | AddForDeferredFinalization<mozilla::dom::DOMRect>(self); |
483 | 0 | } |
484 | 0 | } |
485 | | |
486 | | static size_t |
487 | | _objectMoved(JSObject* obj, JSObject* old) |
488 | 0 | { |
489 | 0 | mozilla::dom::DOMRect* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMRect>(obj); |
490 | 0 | if (self) { |
491 | 0 | UpdateWrapper(self, self, obj, old); |
492 | 0 | } |
493 | 0 |
|
494 | 0 | return 0; |
495 | 0 | } |
496 | | |
497 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
498 | | #if defined(__clang__) |
499 | | #pragma clang diagnostic push |
500 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
501 | | #endif |
502 | | static const JSPropertySpec sAttributes_specs[] = { |
503 | | { "x", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &x_getterinfo, GenericSetter<NormalThisPolicy>, &x_setterinfo }, |
504 | | { "y", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &y_getterinfo, GenericSetter<NormalThisPolicy>, &y_setterinfo }, |
505 | | { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, GenericSetter<NormalThisPolicy>, &width_setterinfo }, |
506 | | { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, GenericSetter<NormalThisPolicy>, &height_setterinfo }, |
507 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
508 | | }; |
509 | | #if defined(__clang__) |
510 | | #pragma clang diagnostic pop |
511 | | #endif |
512 | | |
513 | | |
514 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
515 | | { nullptr, &sAttributes_specs[0] }, |
516 | | { nullptr, nullptr } |
517 | | }; |
518 | | |
519 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
520 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
521 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
522 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
523 | | |
524 | | |
525 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
526 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
527 | | |
528 | | static const NativePropertiesN<1> sNativeProperties = { |
529 | | false, 0, |
530 | | false, 0, |
531 | | false, 0, |
532 | | true, 0 /* sAttributes */, |
533 | | false, 0, |
534 | | false, 0, |
535 | | false, 0, |
536 | | -1, |
537 | | 4, |
538 | | sNativeProperties_sortedPropertyIndices, |
539 | | { |
540 | | { sAttributes, &sNativeProperties_propertyInfos[0] } |
541 | | } |
542 | | }; |
543 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
544 | | "We have a property info count that is oversized"); |
545 | | |
546 | | static bool |
547 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
548 | 0 | { |
549 | 0 | AUTO_PROFILER_LABEL_FAST("DOMRect constructor", DOM, cx); |
550 | 0 |
|
551 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
552 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
553 | 0 | if (!args.isConstructing()) { |
554 | 0 | // XXXbz wish I could get the name from the callee instead of |
555 | 0 | // Adding more relocations |
556 | 0 | return ThrowConstructorWithoutNew(cx, "DOMRect"); |
557 | 0 | } |
558 | 0 | |
559 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
560 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
561 | 0 | return false; |
562 | 0 | } |
563 | 0 | |
564 | 0 | GlobalObject global(cx, obj); |
565 | 0 | if (global.Failed()) { |
566 | 0 | return false; |
567 | 0 | } |
568 | 0 | |
569 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
570 | 0 | double arg0; |
571 | 0 | if (args.hasDefined(0)) { |
572 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) { |
573 | 0 | return false; |
574 | 0 | } |
575 | 0 | } else { |
576 | 0 | arg0 = 0.0; |
577 | 0 | } |
578 | 0 | double arg1; |
579 | 0 | if (args.hasDefined(1)) { |
580 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[1], &arg1)) { |
581 | 0 | return false; |
582 | 0 | } |
583 | 0 | } else { |
584 | 0 | arg1 = 0.0; |
585 | 0 | } |
586 | 0 | double arg2; |
587 | 0 | if (args.hasDefined(2)) { |
588 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[2], &arg2)) { |
589 | 0 | return false; |
590 | 0 | } |
591 | 0 | } else { |
592 | 0 | arg2 = 0.0; |
593 | 0 | } |
594 | 0 | double arg3; |
595 | 0 | if (args.hasDefined(3)) { |
596 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[3], &arg3)) { |
597 | 0 | return false; |
598 | 0 | } |
599 | 0 | } else { |
600 | 0 | arg3 = 0.0; |
601 | 0 | } |
602 | 0 | Maybe<JSAutoRealm> ar; |
603 | 0 | if (objIsXray) { |
604 | 0 | obj = js::CheckedUnwrap(obj); |
605 | 0 | if (!obj) { |
606 | 0 | return false; |
607 | 0 | } |
608 | 0 | ar.emplace(cx, obj); |
609 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
610 | 0 | return false; |
611 | 0 | } |
612 | 0 | } |
613 | 0 | FastErrorResult rv; |
614 | 0 | auto result(StrongOrRawPtr<mozilla::dom::DOMRect>(mozilla::dom::DOMRect::Constructor(global, arg0, arg1, arg2, arg3, rv))); |
615 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
616 | 0 | return false; |
617 | 0 | } |
618 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
619 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
620 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
621 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
622 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
623 | 0 | return false; |
624 | 0 | } |
625 | 0 | return true; |
626 | 0 | } |
627 | | |
628 | | static const js::ClassOps sInterfaceObjectClassOps = { |
629 | | nullptr, /* addProperty */ |
630 | | nullptr, /* delProperty */ |
631 | | nullptr, /* enumerate */ |
632 | | nullptr, /* newEnumerate */ |
633 | | nullptr, /* resolve */ |
634 | | nullptr, /* mayResolve */ |
635 | | nullptr, /* finalize */ |
636 | | _constructor, /* call */ |
637 | | nullptr, /* hasInstance */ |
638 | | _constructor, /* construct */ |
639 | | nullptr, /* trace */ |
640 | | }; |
641 | | |
642 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
643 | | { |
644 | | "Function", |
645 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
646 | | &sInterfaceObjectClassOps, |
647 | | JS_NULL_CLASS_SPEC, |
648 | | JS_NULL_CLASS_EXT, |
649 | | &sInterfaceObjectClassObjectOps |
650 | | }, |
651 | | eInterface, |
652 | | true, |
653 | | prototypes::id::DOMRect, |
654 | | PrototypeTraits<prototypes::id::DOMRect>::Depth, |
655 | | sNativePropertyHooks, |
656 | | "function DOMRect() {\n [native code]\n}", |
657 | | DOMRectReadOnly_Binding::GetConstructorObject |
658 | | }; |
659 | | |
660 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
661 | | { |
662 | | "DOMRectPrototype", |
663 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
664 | | JS_NULL_CLASS_OPS, |
665 | | JS_NULL_CLASS_SPEC, |
666 | | JS_NULL_CLASS_EXT, |
667 | | JS_NULL_OBJECT_OPS |
668 | | }, |
669 | | eInterfacePrototype, |
670 | | false, |
671 | | prototypes::id::DOMRect, |
672 | | PrototypeTraits<prototypes::id::DOMRect>::Depth, |
673 | | sNativePropertyHooks, |
674 | | "[object DOMRectPrototype]", |
675 | | DOMRectReadOnly_Binding::GetProtoObject |
676 | | }; |
677 | | |
678 | | static const js::ClassOps sClassOps = { |
679 | | _addProperty, /* addProperty */ |
680 | | nullptr, /* delProperty */ |
681 | | nullptr, /* enumerate */ |
682 | | nullptr, /* newEnumerate */ |
683 | | nullptr, /* resolve */ |
684 | | nullptr, /* mayResolve */ |
685 | | _finalize, /* finalize */ |
686 | | nullptr, /* call */ |
687 | | nullptr, /* hasInstance */ |
688 | | nullptr, /* construct */ |
689 | | nullptr, /* trace */ |
690 | | }; |
691 | | |
692 | | static const js::ClassExtension sClassExtension = { |
693 | | nullptr, /* weakmapKeyDelegateOp */ |
694 | | _objectMoved /* objectMovedOp */ |
695 | | }; |
696 | | |
697 | | static const DOMJSClass sClass = { |
698 | | { "DOMRect", |
699 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE, |
700 | | &sClassOps, |
701 | | JS_NULL_CLASS_SPEC, |
702 | | &sClassExtension, |
703 | | JS_NULL_OBJECT_OPS |
704 | | }, |
705 | | { prototypes::id::DOMRectReadOnly, prototypes::id::DOMRect, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
706 | | IsBaseOf<nsISupports, mozilla::dom::DOMRect >::value, |
707 | | sNativePropertyHooks, |
708 | | FindAssociatedGlobalForNative<mozilla::dom::DOMRect>::Get, |
709 | | GetProtoObjectHandle, |
710 | | GetCCParticipant<mozilla::dom::DOMRect>::Get() |
711 | | }; |
712 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
713 | | "Must have the right minimal number of reserved slots."); |
714 | | static_assert(1 >= 1, |
715 | | "Must have enough reserved slots."); |
716 | | |
717 | | const JSClass* |
718 | | GetJSClass() |
719 | 0 | { |
720 | 0 | return sClass.ToJSClass(); |
721 | 0 | } |
722 | | |
723 | | bool |
724 | | Wrap(JSContext* aCx, mozilla::dom::DOMRect* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
725 | 0 | { |
726 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DOMRect>::value, |
727 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
728 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::DOMRect*>(aObject) == |
729 | 0 | reinterpret_cast<mozilla::dom::DOMRect*>(aObject), |
730 | 0 | "Multiple inheritance for mozilla::dom::DOMRect is broken."); |
731 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::DOMRectReadOnly*>(aObject) == |
732 | 0 | reinterpret_cast<mozilla::dom::DOMRectReadOnly*>(aObject), |
733 | 0 | "Multiple inheritance for mozilla::dom::DOMRectReadOnly is broken."); |
734 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
735 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
736 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
737 | 0 | "You should probably not be using Wrap() directly; use " |
738 | 0 | "GetOrCreateDOMReflector instead"); |
739 | 0 |
|
740 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
741 | 0 | "nsISupports must be on our primary inheritance chain"); |
742 | 0 |
|
743 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
744 | 0 | if (!global) { |
745 | 0 | return false; |
746 | 0 | } |
747 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
748 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
749 | 0 |
|
750 | 0 | // That might have ended up wrapping us already, due to the wonders |
751 | 0 | // of XBL. Check for that, and bail out as needed. |
752 | 0 | aReflector.set(aCache->GetWrapper()); |
753 | 0 | if (aReflector) { |
754 | | #ifdef DEBUG |
755 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
756 | | #endif // DEBUG |
757 | | return true; |
758 | 0 | } |
759 | 0 |
|
760 | 0 | JSAutoRealm ar(aCx, global); |
761 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
762 | 0 | if (!canonicalProto) { |
763 | 0 | return false; |
764 | 0 | } |
765 | 0 | JS::Rooted<JSObject*> proto(aCx); |
766 | 0 | if (aGivenProto) { |
767 | 0 | proto = aGivenProto; |
768 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
769 | 0 | // coming in, we changed compartments to that of "parent" so may need |
770 | 0 | // to wrap the proto here. |
771 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
772 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
773 | 0 | return false; |
774 | 0 | } |
775 | 0 | } |
776 | 0 | } else { |
777 | 0 | proto = canonicalProto; |
778 | 0 | } |
779 | 0 |
|
780 | 0 | BindingJSObjectCreator<mozilla::dom::DOMRect> creator(aCx); |
781 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
782 | 0 | if (!aReflector) { |
783 | 0 | return false; |
784 | 0 | } |
785 | 0 | |
786 | 0 | aCache->SetWrapper(aReflector); |
787 | 0 | creator.InitializationSucceeded(); |
788 | 0 |
|
789 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
790 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
791 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
792 | 0 | // otherwise we won't be able to properly recreate it later, since |
793 | 0 | // we won't know what proto to use. Note that we don't check |
794 | 0 | // aGivenProto here, since it's entirely possible (and even |
795 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
796 | 0 | // same as canonicalProto. |
797 | 0 | if (proto != canonicalProto) { |
798 | 0 | PreserveWrapper(aObject); |
799 | 0 | } |
800 | 0 |
|
801 | 0 | return true; |
802 | 0 | } |
803 | | |
804 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
805 | | nullptr, |
806 | | nullptr, |
807 | | nullptr, |
808 | | { sNativeProperties.Upcast(), nullptr }, |
809 | | prototypes::id::DOMRect, |
810 | | constructors::id::DOMRect, |
811 | | DOMRectReadOnly_Binding::sNativePropertyHooks, |
812 | | &DefaultXrayExpandoObjectClass |
813 | | } }; |
814 | | |
815 | | void |
816 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
817 | 0 | { |
818 | 0 | JS::Handle<JSObject*> parentProto(DOMRectReadOnly_Binding::GetProtoObjectHandle(aCx)); |
819 | 0 | if (!parentProto) { |
820 | 0 | return; |
821 | 0 | } |
822 | 0 | |
823 | 0 | JS::Handle<JSObject*> constructorProto(DOMRectReadOnly_Binding::GetConstructorObjectHandle(aCx)); |
824 | 0 | if (!constructorProto) { |
825 | 0 | return; |
826 | 0 | } |
827 | 0 | |
828 | 0 | static bool sIdsInited = false; |
829 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
830 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
831 | 0 | return; |
832 | 0 | } |
833 | 0 | sIdsInited = true; |
834 | 0 | } |
835 | 0 |
|
836 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DOMRect); |
837 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DOMRect); |
838 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
839 | 0 | &sPrototypeClass.mBase, protoCache, |
840 | 0 | nullptr, |
841 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
842 | 0 | interfaceCache, |
843 | 0 | sNativeProperties.Upcast(), |
844 | 0 | nullptr, |
845 | 0 | "DOMRect", aDefineOnGlobal, |
846 | 0 | nullptr, |
847 | 0 | false); |
848 | 0 | } |
849 | | |
850 | | JSObject* |
851 | | GetConstructorObject(JSContext* aCx) |
852 | 0 | { |
853 | 0 | return GetConstructorObjectHandle(aCx); |
854 | 0 | } |
855 | | |
856 | | } // namespace DOMRect_Binding |
857 | | |
858 | | |
859 | | |
860 | | namespace DOMRectReadOnly_Binding { |
861 | | |
862 | | MOZ_CAN_RUN_SCRIPT static bool |
863 | | get_x(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
864 | 0 | { |
865 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.x", DOM, cx); |
866 | 0 |
|
867 | 0 | double result(self->X()); |
868 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
869 | 0 | args.rval().set(JS_NumberValue(double(result))); |
870 | 0 | return true; |
871 | 0 | } |
872 | | |
873 | | static const JSJitInfo x_getterinfo = { |
874 | | { (JSJitGetterOp)get_x }, |
875 | | { prototypes::id::DOMRectReadOnly }, |
876 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
877 | | JSJitInfo::Getter, |
878 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
879 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
880 | | true, /* isInfallible. False in setters. */ |
881 | | false, /* isMovable. Not relevant for setters. */ |
882 | | false, /* isEliminatable. Not relevant for setters. */ |
883 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
884 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
885 | | false, /* isTypedMethod. Only relevant for methods. */ |
886 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
887 | | }; |
888 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
889 | | static_assert(0 < 1, "There is no slot for us"); |
890 | | |
891 | | MOZ_CAN_RUN_SCRIPT static bool |
892 | | get_y(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
893 | 0 | { |
894 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.y", DOM, cx); |
895 | 0 |
|
896 | 0 | double result(self->Y()); |
897 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
898 | 0 | args.rval().set(JS_NumberValue(double(result))); |
899 | 0 | return true; |
900 | 0 | } |
901 | | |
902 | | static const JSJitInfo y_getterinfo = { |
903 | | { (JSJitGetterOp)get_y }, |
904 | | { prototypes::id::DOMRectReadOnly }, |
905 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
906 | | JSJitInfo::Getter, |
907 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
908 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
909 | | true, /* isInfallible. False in setters. */ |
910 | | false, /* isMovable. Not relevant for setters. */ |
911 | | false, /* isEliminatable. Not relevant for setters. */ |
912 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
913 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
914 | | false, /* isTypedMethod. Only relevant for methods. */ |
915 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
916 | | }; |
917 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
918 | | static_assert(0 < 1, "There is no slot for us"); |
919 | | |
920 | | MOZ_CAN_RUN_SCRIPT static bool |
921 | | get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
922 | 0 | { |
923 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.width", DOM, cx); |
924 | 0 |
|
925 | 0 | double result(self->Width()); |
926 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
927 | 0 | args.rval().set(JS_NumberValue(double(result))); |
928 | 0 | return true; |
929 | 0 | } |
930 | | |
931 | | static const JSJitInfo width_getterinfo = { |
932 | | { (JSJitGetterOp)get_width }, |
933 | | { prototypes::id::DOMRectReadOnly }, |
934 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
935 | | JSJitInfo::Getter, |
936 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
937 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
938 | | true, /* isInfallible. False in setters. */ |
939 | | false, /* isMovable. Not relevant for setters. */ |
940 | | false, /* isEliminatable. Not relevant for setters. */ |
941 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
942 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
943 | | false, /* isTypedMethod. Only relevant for methods. */ |
944 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
945 | | }; |
946 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
947 | | static_assert(0 < 1, "There is no slot for us"); |
948 | | |
949 | | MOZ_CAN_RUN_SCRIPT static bool |
950 | | get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
951 | 0 | { |
952 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.height", DOM, cx); |
953 | 0 |
|
954 | 0 | double result(self->Height()); |
955 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
956 | 0 | args.rval().set(JS_NumberValue(double(result))); |
957 | 0 | return true; |
958 | 0 | } |
959 | | |
960 | | static const JSJitInfo height_getterinfo = { |
961 | | { (JSJitGetterOp)get_height }, |
962 | | { prototypes::id::DOMRectReadOnly }, |
963 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
964 | | JSJitInfo::Getter, |
965 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
966 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
967 | | true, /* isInfallible. False in setters. */ |
968 | | false, /* isMovable. Not relevant for setters. */ |
969 | | false, /* isEliminatable. Not relevant for setters. */ |
970 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
971 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
972 | | false, /* isTypedMethod. Only relevant for methods. */ |
973 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
974 | | }; |
975 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
976 | | static_assert(0 < 1, "There is no slot for us"); |
977 | | |
978 | | MOZ_CAN_RUN_SCRIPT static bool |
979 | | get_top(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
980 | 0 | { |
981 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.top", DOM, cx); |
982 | 0 |
|
983 | 0 | double result(self->Top()); |
984 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
985 | 0 | args.rval().set(JS_NumberValue(double(result))); |
986 | 0 | return true; |
987 | 0 | } |
988 | | |
989 | | static const JSJitInfo top_getterinfo = { |
990 | | { (JSJitGetterOp)get_top }, |
991 | | { prototypes::id::DOMRectReadOnly }, |
992 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
993 | | JSJitInfo::Getter, |
994 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
995 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
996 | | true, /* isInfallible. False in setters. */ |
997 | | false, /* isMovable. Not relevant for setters. */ |
998 | | false, /* isEliminatable. Not relevant for setters. */ |
999 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1000 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1001 | | false, /* isTypedMethod. Only relevant for methods. */ |
1002 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1003 | | }; |
1004 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1005 | | static_assert(0 < 1, "There is no slot for us"); |
1006 | | |
1007 | | MOZ_CAN_RUN_SCRIPT static bool |
1008 | | get_right(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
1009 | 0 | { |
1010 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.right", DOM, cx); |
1011 | 0 |
|
1012 | 0 | double result(self->Right()); |
1013 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1014 | 0 | args.rval().set(JS_NumberValue(double(result))); |
1015 | 0 | return true; |
1016 | 0 | } |
1017 | | |
1018 | | static const JSJitInfo right_getterinfo = { |
1019 | | { (JSJitGetterOp)get_right }, |
1020 | | { prototypes::id::DOMRectReadOnly }, |
1021 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
1022 | | JSJitInfo::Getter, |
1023 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1024 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1025 | | true, /* isInfallible. False in setters. */ |
1026 | | false, /* isMovable. Not relevant for setters. */ |
1027 | | false, /* isEliminatable. Not relevant for setters. */ |
1028 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1029 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1030 | | false, /* isTypedMethod. Only relevant for methods. */ |
1031 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1032 | | }; |
1033 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1034 | | static_assert(0 < 1, "There is no slot for us"); |
1035 | | |
1036 | | MOZ_CAN_RUN_SCRIPT static bool |
1037 | | get_bottom(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
1038 | 0 | { |
1039 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.bottom", DOM, cx); |
1040 | 0 |
|
1041 | 0 | double result(self->Bottom()); |
1042 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1043 | 0 | args.rval().set(JS_NumberValue(double(result))); |
1044 | 0 | return true; |
1045 | 0 | } |
1046 | | |
1047 | | static const JSJitInfo bottom_getterinfo = { |
1048 | | { (JSJitGetterOp)get_bottom }, |
1049 | | { prototypes::id::DOMRectReadOnly }, |
1050 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
1051 | | JSJitInfo::Getter, |
1052 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1053 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1054 | | true, /* isInfallible. False in setters. */ |
1055 | | false, /* isMovable. Not relevant for setters. */ |
1056 | | false, /* isEliminatable. Not relevant for setters. */ |
1057 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1058 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1059 | | false, /* isTypedMethod. Only relevant for methods. */ |
1060 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1061 | | }; |
1062 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1063 | | static_assert(0 < 1, "There is no slot for us"); |
1064 | | |
1065 | | MOZ_CAN_RUN_SCRIPT static bool |
1066 | | get_left(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JSJitGetterCallArgs args) |
1067 | 0 | { |
1068 | 0 | AUTO_PROFILER_LABEL_FAST("get DOMRectReadOnly.left", DOM, cx); |
1069 | 0 |
|
1070 | 0 | double result(self->Left()); |
1071 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1072 | 0 | args.rval().set(JS_NumberValue(double(result))); |
1073 | 0 | return true; |
1074 | 0 | } |
1075 | | |
1076 | | static const JSJitInfo left_getterinfo = { |
1077 | | { (JSJitGetterOp)get_left }, |
1078 | | { prototypes::id::DOMRectReadOnly }, |
1079 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
1080 | | JSJitInfo::Getter, |
1081 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1082 | | JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */ |
1083 | | true, /* isInfallible. False in setters. */ |
1084 | | false, /* isMovable. Not relevant for setters. */ |
1085 | | false, /* isEliminatable. Not relevant for setters. */ |
1086 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1087 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1088 | | false, /* isTypedMethod. Only relevant for methods. */ |
1089 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1090 | | }; |
1091 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1092 | | static_assert(0 < 1, "There is no slot for us"); |
1093 | | |
1094 | | MOZ_CAN_RUN_SCRIPT static bool |
1095 | | toJSON(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, const JSJitMethodCallArgs& args) |
1096 | 0 | { |
1097 | 0 | AUTO_PROFILER_LABEL_FAST("DOMRectReadOnly.toJSON", DOM, cx); |
1098 | 0 |
|
1099 | 0 | JS::Rooted<JSObject*> result(cx, JS_NewPlainObject(cx)); |
1100 | 0 | if (!result) { |
1101 | 0 | return false; |
1102 | 0 | } |
1103 | 0 | if (!DOMRectReadOnly_Binding::CollectJSONAttributes(cx, obj, self, result)) { |
1104 | 0 | return false; |
1105 | 0 | } |
1106 | 0 | args.rval().setObject(*result); |
1107 | 0 | return true; |
1108 | 0 | } |
1109 | | |
1110 | | static const JSJitInfo toJSON_methodinfo = { |
1111 | | { (JSJitGetterOp)toJSON }, |
1112 | | { prototypes::id::DOMRectReadOnly }, |
1113 | | { PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth }, |
1114 | | JSJitInfo::Method, |
1115 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
1116 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
1117 | | false, /* isInfallible. False in setters. */ |
1118 | | false, /* isMovable. Not relevant for setters. */ |
1119 | | false, /* isEliminatable. Not relevant for setters. */ |
1120 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
1121 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
1122 | | false, /* isTypedMethod. Only relevant for methods. */ |
1123 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
1124 | | }; |
1125 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
1126 | | static_assert(0 < 1, "There is no slot for us"); |
1127 | | |
1128 | | static bool |
1129 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
1130 | 0 | { |
1131 | 0 | mozilla::dom::DOMRectReadOnly* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMRectReadOnly>(obj); |
1132 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
1133 | 0 | // obviously can't preserve if we're not initialized. |
1134 | 0 | if (self && self->GetWrapperPreserveColor()) { |
1135 | 0 | PreserveWrapper(self); |
1136 | 0 | } |
1137 | 0 | return true; |
1138 | 0 | } |
1139 | | |
1140 | | static void |
1141 | | _finalize(js::FreeOp* fop, JSObject* obj) |
1142 | 0 | { |
1143 | 0 | mozilla::dom::DOMRectReadOnly* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMRectReadOnly>(obj); |
1144 | 0 | if (self) { |
1145 | 0 | ClearWrapper(self, self, obj); |
1146 | 0 | AddForDeferredFinalization<mozilla::dom::DOMRectReadOnly>(self); |
1147 | 0 | } |
1148 | 0 | } |
1149 | | |
1150 | | static size_t |
1151 | | _objectMoved(JSObject* obj, JSObject* old) |
1152 | 0 | { |
1153 | 0 | mozilla::dom::DOMRectReadOnly* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMRectReadOnly>(obj); |
1154 | 0 | if (self) { |
1155 | 0 | UpdateWrapper(self, self, obj, old); |
1156 | 0 | } |
1157 | 0 |
|
1158 | 0 | return 0; |
1159 | 0 | } |
1160 | | |
1161 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1162 | | #if defined(__clang__) |
1163 | | #pragma clang diagnostic push |
1164 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1165 | | #endif |
1166 | | static const JSFunctionSpec sMethods_specs[] = { |
1167 | | JS_FNSPEC("toJSON", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&toJSON_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
1168 | | JS_FS_END |
1169 | | }; |
1170 | | #if defined(__clang__) |
1171 | | #pragma clang diagnostic pop |
1172 | | #endif |
1173 | | |
1174 | | |
1175 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
1176 | | { nullptr, &sMethods_specs[0] }, |
1177 | | { nullptr, nullptr } |
1178 | | }; |
1179 | | |
1180 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1181 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1182 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1183 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1184 | | |
1185 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
1186 | | #if defined(__clang__) |
1187 | | #pragma clang diagnostic push |
1188 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
1189 | | #endif |
1190 | | static const JSPropertySpec sAttributes_specs[] = { |
1191 | | { "x", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &x_getterinfo, nullptr, nullptr }, |
1192 | | { "y", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &y_getterinfo, nullptr, nullptr }, |
1193 | | { "width", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &width_getterinfo, nullptr, nullptr }, |
1194 | | { "height", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &height_getterinfo, nullptr, nullptr }, |
1195 | | { "top", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &top_getterinfo, nullptr, nullptr }, |
1196 | | { "right", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &right_getterinfo, nullptr, nullptr }, |
1197 | | { "bottom", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &bottom_getterinfo, nullptr, nullptr }, |
1198 | | { "left", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &left_getterinfo, nullptr, nullptr }, |
1199 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
1200 | | }; |
1201 | | #if defined(__clang__) |
1202 | | #pragma clang diagnostic pop |
1203 | | #endif |
1204 | | |
1205 | | |
1206 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
1207 | | { nullptr, &sAttributes_specs[0] }, |
1208 | | { nullptr, nullptr } |
1209 | | }; |
1210 | | |
1211 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
1212 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
1213 | | static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
1214 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
1215 | | |
1216 | | |
1217 | | static uint16_t sNativeProperties_sortedPropertyIndices[9]; |
1218 | | static PropertyInfo sNativeProperties_propertyInfos[9]; |
1219 | | |
1220 | | static const NativePropertiesN<2> sNativeProperties = { |
1221 | | false, 0, |
1222 | | false, 0, |
1223 | | true, 0 /* sMethods */, |
1224 | | true, 1 /* sAttributes */, |
1225 | | false, 0, |
1226 | | false, 0, |
1227 | | false, 0, |
1228 | | -1, |
1229 | | 9, |
1230 | | sNativeProperties_sortedPropertyIndices, |
1231 | | { |
1232 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
1233 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
1234 | | } |
1235 | | }; |
1236 | | static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
1237 | | "We have a property info count that is oversized"); |
1238 | | |
1239 | | MOZ_CAN_RUN_SCRIPT bool |
1240 | | CollectJSONAttributes(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMRectReadOnly* self, JS::Rooted<JSObject*>& result) |
1241 | 0 | { |
1242 | 0 | { // scope for "temp" |
1243 | 0 | JS::Rooted<JS::Value> temp(cx); |
1244 | 0 | if (!get_x(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1245 | 0 | return false; |
1246 | 0 | } |
1247 | 0 | if (!JS_DefineProperty(cx, result, "x", temp, JSPROP_ENUMERATE)) { |
1248 | 0 | return false; |
1249 | 0 | } |
1250 | 0 | } |
1251 | 0 | { // scope for "temp" |
1252 | 0 | JS::Rooted<JS::Value> temp(cx); |
1253 | 0 | if (!get_y(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1254 | 0 | return false; |
1255 | 0 | } |
1256 | 0 | if (!JS_DefineProperty(cx, result, "y", temp, JSPROP_ENUMERATE)) { |
1257 | 0 | return false; |
1258 | 0 | } |
1259 | 0 | } |
1260 | 0 | { // scope for "temp" |
1261 | 0 | JS::Rooted<JS::Value> temp(cx); |
1262 | 0 | if (!get_width(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1263 | 0 | return false; |
1264 | 0 | } |
1265 | 0 | if (!JS_DefineProperty(cx, result, "width", temp, JSPROP_ENUMERATE)) { |
1266 | 0 | return false; |
1267 | 0 | } |
1268 | 0 | } |
1269 | 0 | { // scope for "temp" |
1270 | 0 | JS::Rooted<JS::Value> temp(cx); |
1271 | 0 | if (!get_height(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1272 | 0 | return false; |
1273 | 0 | } |
1274 | 0 | if (!JS_DefineProperty(cx, result, "height", temp, JSPROP_ENUMERATE)) { |
1275 | 0 | return false; |
1276 | 0 | } |
1277 | 0 | } |
1278 | 0 | { // scope for "temp" |
1279 | 0 | JS::Rooted<JS::Value> temp(cx); |
1280 | 0 | if (!get_top(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1281 | 0 | return false; |
1282 | 0 | } |
1283 | 0 | if (!JS_DefineProperty(cx, result, "top", temp, JSPROP_ENUMERATE)) { |
1284 | 0 | return false; |
1285 | 0 | } |
1286 | 0 | } |
1287 | 0 | { // scope for "temp" |
1288 | 0 | JS::Rooted<JS::Value> temp(cx); |
1289 | 0 | if (!get_right(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1290 | 0 | return false; |
1291 | 0 | } |
1292 | 0 | if (!JS_DefineProperty(cx, result, "right", temp, JSPROP_ENUMERATE)) { |
1293 | 0 | return false; |
1294 | 0 | } |
1295 | 0 | } |
1296 | 0 | { // scope for "temp" |
1297 | 0 | JS::Rooted<JS::Value> temp(cx); |
1298 | 0 | if (!get_bottom(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1299 | 0 | return false; |
1300 | 0 | } |
1301 | 0 | if (!JS_DefineProperty(cx, result, "bottom", temp, JSPROP_ENUMERATE)) { |
1302 | 0 | return false; |
1303 | 0 | } |
1304 | 0 | } |
1305 | 0 | { // scope for "temp" |
1306 | 0 | JS::Rooted<JS::Value> temp(cx); |
1307 | 0 | if (!get_left(cx, obj, self, JSJitGetterCallArgs(&temp))) { |
1308 | 0 | return false; |
1309 | 0 | } |
1310 | 0 | if (!JS_DefineProperty(cx, result, "left", temp, JSPROP_ENUMERATE)) { |
1311 | 0 | return false; |
1312 | 0 | } |
1313 | 0 | } |
1314 | 0 | return true; |
1315 | 0 | } |
1316 | | |
1317 | | static bool |
1318 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
1319 | 0 | { |
1320 | 0 | AUTO_PROFILER_LABEL_FAST("DOMRectReadOnly constructor", DOM, cx); |
1321 | 0 |
|
1322 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
1323 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
1324 | 0 | if (!args.isConstructing()) { |
1325 | 0 | // XXXbz wish I could get the name from the callee instead of |
1326 | 0 | // Adding more relocations |
1327 | 0 | return ThrowConstructorWithoutNew(cx, "DOMRectReadOnly"); |
1328 | 0 | } |
1329 | 0 | |
1330 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
1331 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
1332 | 0 | return false; |
1333 | 0 | } |
1334 | 0 | |
1335 | 0 | GlobalObject global(cx, obj); |
1336 | 0 | if (global.Failed()) { |
1337 | 0 | return false; |
1338 | 0 | } |
1339 | 0 | |
1340 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
1341 | 0 | double arg0; |
1342 | 0 | if (args.hasDefined(0)) { |
1343 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) { |
1344 | 0 | return false; |
1345 | 0 | } |
1346 | 0 | } else { |
1347 | 0 | arg0 = 0.0; |
1348 | 0 | } |
1349 | 0 | double arg1; |
1350 | 0 | if (args.hasDefined(1)) { |
1351 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[1], &arg1)) { |
1352 | 0 | return false; |
1353 | 0 | } |
1354 | 0 | } else { |
1355 | 0 | arg1 = 0.0; |
1356 | 0 | } |
1357 | 0 | double arg2; |
1358 | 0 | if (args.hasDefined(2)) { |
1359 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[2], &arg2)) { |
1360 | 0 | return false; |
1361 | 0 | } |
1362 | 0 | } else { |
1363 | 0 | arg2 = 0.0; |
1364 | 0 | } |
1365 | 0 | double arg3; |
1366 | 0 | if (args.hasDefined(3)) { |
1367 | 0 | if (!ValueToPrimitive<double, eDefault>(cx, args[3], &arg3)) { |
1368 | 0 | return false; |
1369 | 0 | } |
1370 | 0 | } else { |
1371 | 0 | arg3 = 0.0; |
1372 | 0 | } |
1373 | 0 | Maybe<JSAutoRealm> ar; |
1374 | 0 | if (objIsXray) { |
1375 | 0 | obj = js::CheckedUnwrap(obj); |
1376 | 0 | if (!obj) { |
1377 | 0 | return false; |
1378 | 0 | } |
1379 | 0 | ar.emplace(cx, obj); |
1380 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
1381 | 0 | return false; |
1382 | 0 | } |
1383 | 0 | } |
1384 | 0 | FastErrorResult rv; |
1385 | 0 | auto result(StrongOrRawPtr<mozilla::dom::DOMRectReadOnly>(mozilla::dom::DOMRectReadOnly::Constructor(global, arg0, arg1, arg2, arg3, rv))); |
1386 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
1387 | 0 | return false; |
1388 | 0 | } |
1389 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
1390 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
1391 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
1392 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
1393 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
1394 | 0 | return false; |
1395 | 0 | } |
1396 | 0 | return true; |
1397 | 0 | } |
1398 | | |
1399 | | static const js::ClassOps sInterfaceObjectClassOps = { |
1400 | | nullptr, /* addProperty */ |
1401 | | nullptr, /* delProperty */ |
1402 | | nullptr, /* enumerate */ |
1403 | | nullptr, /* newEnumerate */ |
1404 | | nullptr, /* resolve */ |
1405 | | nullptr, /* mayResolve */ |
1406 | | nullptr, /* finalize */ |
1407 | | _constructor, /* call */ |
1408 | | nullptr, /* hasInstance */ |
1409 | | _constructor, /* construct */ |
1410 | | nullptr, /* trace */ |
1411 | | }; |
1412 | | |
1413 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
1414 | | { |
1415 | | "Function", |
1416 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
1417 | | &sInterfaceObjectClassOps, |
1418 | | JS_NULL_CLASS_SPEC, |
1419 | | JS_NULL_CLASS_EXT, |
1420 | | &sInterfaceObjectClassObjectOps |
1421 | | }, |
1422 | | eInterface, |
1423 | | true, |
1424 | | prototypes::id::DOMRectReadOnly, |
1425 | | PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth, |
1426 | | sNativePropertyHooks, |
1427 | | "function DOMRectReadOnly() {\n [native code]\n}", |
1428 | | JS::GetRealmFunctionPrototype |
1429 | | }; |
1430 | | |
1431 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
1432 | | { |
1433 | | "DOMRectReadOnlyPrototype", |
1434 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
1435 | | JS_NULL_CLASS_OPS, |
1436 | | JS_NULL_CLASS_SPEC, |
1437 | | JS_NULL_CLASS_EXT, |
1438 | | JS_NULL_OBJECT_OPS |
1439 | | }, |
1440 | | eInterfacePrototype, |
1441 | | false, |
1442 | | prototypes::id::DOMRectReadOnly, |
1443 | | PrototypeTraits<prototypes::id::DOMRectReadOnly>::Depth, |
1444 | | sNativePropertyHooks, |
1445 | | "[object DOMRectReadOnlyPrototype]", |
1446 | | JS::GetRealmObjectPrototype |
1447 | | }; |
1448 | | |
1449 | | static const js::ClassOps sClassOps = { |
1450 | | _addProperty, /* addProperty */ |
1451 | | nullptr, /* delProperty */ |
1452 | | nullptr, /* enumerate */ |
1453 | | nullptr, /* newEnumerate */ |
1454 | | nullptr, /* resolve */ |
1455 | | nullptr, /* mayResolve */ |
1456 | | _finalize, /* finalize */ |
1457 | | nullptr, /* call */ |
1458 | | nullptr, /* hasInstance */ |
1459 | | nullptr, /* construct */ |
1460 | | nullptr, /* trace */ |
1461 | | }; |
1462 | | |
1463 | | static const js::ClassExtension sClassExtension = { |
1464 | | nullptr, /* weakmapKeyDelegateOp */ |
1465 | | _objectMoved /* objectMovedOp */ |
1466 | | }; |
1467 | | |
1468 | | static const DOMJSClass sClass = { |
1469 | | { "DOMRectReadOnly", |
1470 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE, |
1471 | | &sClassOps, |
1472 | | JS_NULL_CLASS_SPEC, |
1473 | | &sClassExtension, |
1474 | | JS_NULL_OBJECT_OPS |
1475 | | }, |
1476 | | { prototypes::id::DOMRectReadOnly, 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 }, |
1477 | | IsBaseOf<nsISupports, mozilla::dom::DOMRectReadOnly >::value, |
1478 | | sNativePropertyHooks, |
1479 | | FindAssociatedGlobalForNative<mozilla::dom::DOMRectReadOnly>::Get, |
1480 | | GetProtoObjectHandle, |
1481 | | GetCCParticipant<mozilla::dom::DOMRectReadOnly>::Get() |
1482 | | }; |
1483 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
1484 | | "Must have the right minimal number of reserved slots."); |
1485 | | static_assert(1 >= 1, |
1486 | | "Must have enough reserved slots."); |
1487 | | |
1488 | | const JSClass* |
1489 | | GetJSClass() |
1490 | 0 | { |
1491 | 0 | return sClass.ToJSClass(); |
1492 | 0 | } |
1493 | | |
1494 | | bool |
1495 | | Wrap(JSContext* aCx, mozilla::dom::DOMRectReadOnly* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
1496 | 0 | { |
1497 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DOMRectReadOnly>::value, |
1498 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
1499 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::DOMRectReadOnly*>(aObject) == |
1500 | 0 | reinterpret_cast<mozilla::dom::DOMRectReadOnly*>(aObject), |
1501 | 0 | "Multiple inheritance for mozilla::dom::DOMRectReadOnly is broken."); |
1502 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
1503 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
1504 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
1505 | 0 | "You should probably not be using Wrap() directly; use " |
1506 | 0 | "GetOrCreateDOMReflector instead"); |
1507 | 0 |
|
1508 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
1509 | 0 | "nsISupports must be on our primary inheritance chain"); |
1510 | 0 |
|
1511 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
1512 | 0 | if (!global) { |
1513 | 0 | return false; |
1514 | 0 | } |
1515 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
1516 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
1517 | 0 |
|
1518 | 0 | // That might have ended up wrapping us already, due to the wonders |
1519 | 0 | // of XBL. Check for that, and bail out as needed. |
1520 | 0 | aReflector.set(aCache->GetWrapper()); |
1521 | 0 | if (aReflector) { |
1522 | | #ifdef DEBUG |
1523 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
1524 | | #endif // DEBUG |
1525 | | return true; |
1526 | 0 | } |
1527 | 0 |
|
1528 | 0 | JSAutoRealm ar(aCx, global); |
1529 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
1530 | 0 | if (!canonicalProto) { |
1531 | 0 | return false; |
1532 | 0 | } |
1533 | 0 | JS::Rooted<JSObject*> proto(aCx); |
1534 | 0 | if (aGivenProto) { |
1535 | 0 | proto = aGivenProto; |
1536 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
1537 | 0 | // coming in, we changed compartments to that of "parent" so may need |
1538 | 0 | // to wrap the proto here. |
1539 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
1540 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
1541 | 0 | return false; |
1542 | 0 | } |
1543 | 0 | } |
1544 | 0 | } else { |
1545 | 0 | proto = canonicalProto; |
1546 | 0 | } |
1547 | 0 |
|
1548 | 0 | BindingJSObjectCreator<mozilla::dom::DOMRectReadOnly> creator(aCx); |
1549 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
1550 | 0 | if (!aReflector) { |
1551 | 0 | return false; |
1552 | 0 | } |
1553 | 0 | |
1554 | 0 | aCache->SetWrapper(aReflector); |
1555 | 0 | creator.InitializationSucceeded(); |
1556 | 0 |
|
1557 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
1558 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
1559 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
1560 | 0 | // otherwise we won't be able to properly recreate it later, since |
1561 | 0 | // we won't know what proto to use. Note that we don't check |
1562 | 0 | // aGivenProto here, since it's entirely possible (and even |
1563 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
1564 | 0 | // same as canonicalProto. |
1565 | 0 | if (proto != canonicalProto) { |
1566 | 0 | PreserveWrapper(aObject); |
1567 | 0 | } |
1568 | 0 |
|
1569 | 0 | return true; |
1570 | 0 | } |
1571 | | |
1572 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
1573 | | nullptr, |
1574 | | nullptr, |
1575 | | nullptr, |
1576 | | { sNativeProperties.Upcast(), nullptr }, |
1577 | | prototypes::id::DOMRectReadOnly, |
1578 | | constructors::id::DOMRectReadOnly, |
1579 | | nullptr, |
1580 | | &DefaultXrayExpandoObjectClass |
1581 | | } }; |
1582 | | |
1583 | | void |
1584 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
1585 | 0 | { |
1586 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
1587 | 0 | if (!parentProto) { |
1588 | 0 | return; |
1589 | 0 | } |
1590 | 0 | |
1591 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
1592 | 0 | if (!constructorProto) { |
1593 | 0 | return; |
1594 | 0 | } |
1595 | 0 | |
1596 | 0 | static bool sIdsInited = false; |
1597 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
1598 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
1599 | 0 | return; |
1600 | 0 | } |
1601 | 0 | sIdsInited = true; |
1602 | 0 | } |
1603 | 0 |
|
1604 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DOMRectReadOnly); |
1605 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DOMRectReadOnly); |
1606 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
1607 | 0 | &sPrototypeClass.mBase, protoCache, |
1608 | 0 | nullptr, |
1609 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
1610 | 0 | interfaceCache, |
1611 | 0 | sNativeProperties.Upcast(), |
1612 | 0 | nullptr, |
1613 | 0 | "DOMRectReadOnly", aDefineOnGlobal, |
1614 | 0 | nullptr, |
1615 | 0 | false); |
1616 | 0 | } |
1617 | | |
1618 | | JSObject* |
1619 | | GetProtoObject(JSContext* aCx) |
1620 | 0 | { |
1621 | 0 | return GetProtoObjectHandle(aCx); |
1622 | 0 | } |
1623 | | |
1624 | | JSObject* |
1625 | | GetConstructorObject(JSContext* aCx) |
1626 | 0 | { |
1627 | 0 | return GetConstructorObjectHandle(aCx); |
1628 | 0 | } |
1629 | | |
1630 | | } // namespace DOMRectReadOnly_Binding |
1631 | | |
1632 | | |
1633 | | |
1634 | | } // namespace dom |
1635 | | } // namespace mozilla |