Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM WheelEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "MouseEventBinding.h"
5 : #include "WheelEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/FloatingPoint.h"
8 : #include "mozilla/OwningNonNull.h"
9 : #include "mozilla/dom/BindingUtils.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/ScriptSettings.h"
14 : #include "mozilla/dom/SimpleGlobalObject.h"
15 : #include "mozilla/dom/WheelEvent.h"
16 : #include "mozilla/dom/XrayExpandoClass.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 :
22 0 : WheelEventInit::WheelEventInit()
23 0 : : MouseEventInit(FastDictionaryInitializer())
24 : {
25 : // 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 0 : WheelEventInit::InitIds(JSContext* cx, WheelEventInitAtoms* atomsCache)
33 : {
34 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
35 :
36 : // Initialize these in reverse order so that any failure leaves the first one
37 : // uninitialized.
38 0 : if (!atomsCache->deltaZ_id.init(cx, "deltaZ") ||
39 0 : !atomsCache->deltaY_id.init(cx, "deltaY") ||
40 0 : !atomsCache->deltaX_id.init(cx, "deltaX") ||
41 0 : !atomsCache->deltaMode_id.init(cx, "deltaMode")) {
42 0 : return false;
43 : }
44 0 : return true;
45 : }
46 :
47 : bool
48 0 : WheelEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
49 : {
50 : // Passing a null JSContext is OK only if we're initing from null,
51 : // Since in that case we will not have to do any property gets
52 : // Also evaluate isNullOrUndefined in order to avoid false-positive
53 : // checkers by static analysis tools
54 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
55 0 : WheelEventInitAtoms* atomsCache = nullptr;
56 0 : if (cx) {
57 0 : atomsCache = GetAtomCache<WheelEventInitAtoms>(cx);
58 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
59 0 : return false;
60 : }
61 : }
62 :
63 : // Per spec, we init the parent's members first
64 0 : if (!MouseEventInit::Init(cx, val)) {
65 0 : return false;
66 : }
67 :
68 0 : bool isNull = val.isNullOrUndefined();
69 : // We only need these if !isNull, in which case we have |cx|.
70 0 : Maybe<JS::Rooted<JSObject *> > object;
71 0 : Maybe<JS::Rooted<JS::Value> > temp;
72 0 : if (!isNull) {
73 0 : MOZ_ASSERT(cx);
74 0 : object.emplace(cx, &val.toObject());
75 0 : temp.emplace(cx);
76 : }
77 0 : if (!isNull) {
78 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->deltaMode_id, temp.ptr())) {
79 0 : return false;
80 : }
81 : }
82 0 : if (!isNull && !temp->isUndefined()) {
83 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, temp.ref(), &mDeltaMode)) {
84 0 : return false;
85 : }
86 : } else {
87 0 : mDeltaMode = 0U;
88 : }
89 0 : mIsAnyMemberPresent = true;
90 :
91 0 : if (!isNull) {
92 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->deltaX_id, temp.ptr())) {
93 0 : return false;
94 : }
95 : }
96 0 : if (!isNull && !temp->isUndefined()) {
97 0 : if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mDeltaX)) {
98 0 : return false;
99 0 : } else if (!mozilla::IsFinite(mDeltaX)) {
100 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'deltaX' member of WheelEventInit");
101 0 : return false;
102 : }
103 : } else {
104 0 : mDeltaX = 0.0;
105 : }
106 0 : mIsAnyMemberPresent = true;
107 :
108 0 : if (!isNull) {
109 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->deltaY_id, temp.ptr())) {
110 0 : return false;
111 : }
112 : }
113 0 : if (!isNull && !temp->isUndefined()) {
114 0 : if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mDeltaY)) {
115 0 : return false;
116 0 : } else if (!mozilla::IsFinite(mDeltaY)) {
117 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'deltaY' member of WheelEventInit");
118 0 : return false;
119 : }
120 : } else {
121 0 : mDeltaY = 0.0;
122 : }
123 0 : mIsAnyMemberPresent = true;
124 :
125 0 : if (!isNull) {
126 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->deltaZ_id, temp.ptr())) {
127 0 : return false;
128 : }
129 : }
130 0 : if (!isNull && !temp->isUndefined()) {
131 0 : if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mDeltaZ)) {
132 0 : return false;
133 0 : } else if (!mozilla::IsFinite(mDeltaZ)) {
134 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'deltaZ' member of WheelEventInit");
135 0 : return false;
136 : }
137 : } else {
138 0 : mDeltaZ = 0.0;
139 : }
140 0 : mIsAnyMemberPresent = true;
141 0 : return true;
142 : }
143 :
144 : bool
145 0 : WheelEventInit::Init(const nsAString& aJSON)
146 : {
147 0 : AutoJSAPI jsapi;
148 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
149 0 : if (!cleanGlobal) {
150 0 : return false;
151 : }
152 0 : if (!jsapi.Init(cleanGlobal)) {
153 0 : return false;
154 : }
155 0 : JSContext* cx = jsapi.cx();
156 0 : JS::Rooted<JS::Value> json(cx);
157 0 : bool ok = ParseJSON(cx, aJSON, &json);
158 0 : NS_ENSURE_TRUE(ok, false);
159 0 : return Init(cx, json);
160 : }
161 :
162 : bool
163 0 : WheelEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
164 : {
165 0 : WheelEventInitAtoms* atomsCache = GetAtomCache<WheelEventInitAtoms>(cx);
166 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
167 0 : return false;
168 : }
169 :
170 : // Per spec, we define the parent's members first
171 0 : if (!MouseEventInit::ToObjectInternal(cx, rval)) {
172 0 : return false;
173 : }
174 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
175 :
176 : do {
177 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
178 0 : JS::Rooted<JS::Value> temp(cx);
179 0 : uint32_t const & currentValue = mDeltaMode;
180 0 : temp.setNumber(currentValue);
181 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->deltaMode_id, temp, JSPROP_ENUMERATE)) {
182 0 : return false;
183 : }
184 0 : break;
185 : } while(0);
186 :
187 : do {
188 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
189 0 : JS::Rooted<JS::Value> temp(cx);
190 0 : double const & currentValue = mDeltaX;
191 0 : temp.set(JS_NumberValue(double(currentValue)));
192 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->deltaX_id, temp, JSPROP_ENUMERATE)) {
193 0 : return false;
194 : }
195 0 : break;
196 : } while(0);
197 :
198 : do {
199 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
200 0 : JS::Rooted<JS::Value> temp(cx);
201 0 : double const & currentValue = mDeltaY;
202 0 : temp.set(JS_NumberValue(double(currentValue)));
203 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->deltaY_id, temp, JSPROP_ENUMERATE)) {
204 0 : return false;
205 : }
206 0 : break;
207 : } while(0);
208 :
209 : do {
210 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
211 0 : JS::Rooted<JS::Value> temp(cx);
212 0 : double const & currentValue = mDeltaZ;
213 0 : temp.set(JS_NumberValue(double(currentValue)));
214 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->deltaZ_id, temp, JSPROP_ENUMERATE)) {
215 0 : return false;
216 : }
217 0 : break;
218 : } while(0);
219 :
220 0 : return true;
221 : }
222 :
223 : bool
224 0 : WheelEventInit::ToJSON(nsAString& aJSON) const
225 : {
226 0 : AutoJSAPI jsapi;
227 0 : jsapi.Init();
228 0 : JSContext *cx = jsapi.cx();
229 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
230 : // because we'll only be creating objects, in ways that have no
231 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
232 : // which likewise guarantees no side-effects for the sorts of
233 : // things we will pass it.
234 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
235 0 : JS::Rooted<JS::Value> val(cx);
236 0 : if (!ToObjectInternal(cx, &val)) {
237 0 : return false;
238 : }
239 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
240 0 : return StringifyToJSON(cx, obj, aJSON);
241 : }
242 :
243 : void
244 0 : WheelEventInit::TraceDictionary(JSTracer* trc)
245 : {
246 0 : MouseEventInit::TraceDictionary(trc);
247 0 : }
248 :
249 : WheelEventInit&
250 0 : WheelEventInit::operator=(const WheelEventInit& aOther)
251 : {
252 0 : MouseEventInit::operator=(aOther);
253 0 : mDeltaMode = aOther.mDeltaMode;
254 0 : mDeltaX = aOther.mDeltaX;
255 0 : mDeltaY = aOther.mDeltaY;
256 0 : mDeltaZ = aOther.mDeltaZ;
257 0 : return *this;
258 : }
259 :
260 : namespace binding_detail {
261 : } // namespace binding_detail
262 :
263 :
264 : namespace WheelEventBinding {
265 :
266 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MouseEventBinding::NativeType>::value,
267 : "Can't inherit from an interface with a different ownership model.");
268 :
269 : static bool
270 0 : get_deltaX(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WheelEvent* self, JSJitGetterCallArgs args)
271 : {
272 0 : double result(self->DeltaX());
273 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
274 0 : args.rval().set(JS_NumberValue(double(result)));
275 0 : return true;
276 : }
277 :
278 : static const JSJitInfo deltaX_getterinfo = {
279 : { (JSJitGetterOp)get_deltaX },
280 : { prototypes::id::WheelEvent },
281 : { PrototypeTraits<prototypes::id::WheelEvent>::Depth },
282 : JSJitInfo::Getter,
283 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
284 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
285 : true, /* isInfallible. False in setters. */
286 : false, /* isMovable. Not relevant for setters. */
287 : false, /* isEliminatable. Not relevant for setters. */
288 : false, /* isAlwaysInSlot. Only relevant for getters. */
289 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
290 : false, /* isTypedMethod. Only relevant for methods. */
291 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
292 : };
293 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
294 : static_assert(0 < 1, "There is no slot for us");
295 :
296 : static bool
297 0 : get_deltaY(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WheelEvent* self, JSJitGetterCallArgs args)
298 : {
299 0 : double result(self->DeltaY());
300 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
301 0 : args.rval().set(JS_NumberValue(double(result)));
302 0 : return true;
303 : }
304 :
305 : static const JSJitInfo deltaY_getterinfo = {
306 : { (JSJitGetterOp)get_deltaY },
307 : { prototypes::id::WheelEvent },
308 : { PrototypeTraits<prototypes::id::WheelEvent>::Depth },
309 : JSJitInfo::Getter,
310 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
311 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
312 : true, /* isInfallible. False in setters. */
313 : false, /* isMovable. Not relevant for setters. */
314 : false, /* isEliminatable. Not relevant for setters. */
315 : false, /* isAlwaysInSlot. Only relevant for getters. */
316 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
317 : false, /* isTypedMethod. Only relevant for methods. */
318 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
319 : };
320 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
321 : static_assert(0 < 1, "There is no slot for us");
322 :
323 : static bool
324 0 : get_deltaZ(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WheelEvent* self, JSJitGetterCallArgs args)
325 : {
326 0 : double result(self->DeltaZ());
327 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
328 0 : args.rval().set(JS_NumberValue(double(result)));
329 0 : return true;
330 : }
331 :
332 : static const JSJitInfo deltaZ_getterinfo = {
333 : { (JSJitGetterOp)get_deltaZ },
334 : { prototypes::id::WheelEvent },
335 : { PrototypeTraits<prototypes::id::WheelEvent>::Depth },
336 : JSJitInfo::Getter,
337 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
338 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
339 : true, /* isInfallible. False in setters. */
340 : false, /* isMovable. Not relevant for setters. */
341 : false, /* isEliminatable. Not relevant for setters. */
342 : false, /* isAlwaysInSlot. Only relevant for getters. */
343 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
344 : false, /* isTypedMethod. Only relevant for methods. */
345 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
346 : };
347 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
348 : static_assert(0 < 1, "There is no slot for us");
349 :
350 : static bool
351 0 : get_deltaMode(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WheelEvent* self, JSJitGetterCallArgs args)
352 : {
353 0 : uint32_t result(self->DeltaMode());
354 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
355 0 : args.rval().setNumber(result);
356 0 : return true;
357 : }
358 :
359 : static const JSJitInfo deltaMode_getterinfo = {
360 : { (JSJitGetterOp)get_deltaMode },
361 : { prototypes::id::WheelEvent },
362 : { PrototypeTraits<prototypes::id::WheelEvent>::Depth },
363 : JSJitInfo::Getter,
364 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
365 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
366 : true, /* isInfallible. False in setters. */
367 : false, /* isMovable. Not relevant for setters. */
368 : false, /* isEliminatable. Not relevant for setters. */
369 : false, /* isAlwaysInSlot. Only relevant for getters. */
370 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
371 : false, /* isTypedMethod. Only relevant for methods. */
372 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
373 : };
374 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
375 : static_assert(0 < 1, "There is no slot for us");
376 :
377 : static bool
378 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::WheelEvent* self, JSJitGetterCallArgs args)
379 : {
380 0 : bool result(self->IsTrusted());
381 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
382 0 : args.rval().setBoolean(result);
383 0 : return true;
384 : }
385 :
386 : static const JSJitInfo isTrusted_getterinfo = {
387 : { (JSJitGetterOp)get_isTrusted },
388 : { prototypes::id::WheelEvent },
389 : { PrototypeTraits<prototypes::id::WheelEvent>::Depth },
390 : JSJitInfo::Getter,
391 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
392 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
393 : true, /* isInfallible. False in setters. */
394 : true, /* isMovable. Not relevant for setters. */
395 : true, /* isEliminatable. Not relevant for setters. */
396 : false, /* isAlwaysInSlot. Only relevant for getters. */
397 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
398 : false, /* isTypedMethod. Only relevant for methods. */
399 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
400 : };
401 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
402 : static_assert(0 < 1, "There is no slot for us");
403 :
404 : static bool
405 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
406 : {
407 0 : mozilla::dom::WheelEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WheelEvent>(obj);
408 : // We don't want to preserve if we don't have a wrapper, and we
409 : // obviously can't preserve if we're not initialized.
410 0 : if (self && self->GetWrapperPreserveColor()) {
411 0 : PreserveWrapper(self);
412 : }
413 0 : return true;
414 : }
415 :
416 : static void
417 0 : _finalize(js::FreeOp* fop, JSObject* obj)
418 : {
419 0 : mozilla::dom::WheelEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WheelEvent>(obj);
420 0 : if (self) {
421 0 : ClearWrapper(self, self, obj);
422 0 : AddForDeferredFinalization<mozilla::dom::WheelEvent>(self);
423 : }
424 0 : }
425 :
426 : static void
427 0 : _objectMoved(JSObject* obj, const JSObject* old)
428 : {
429 0 : mozilla::dom::WheelEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::WheelEvent>(obj);
430 0 : if (self) {
431 0 : UpdateWrapper(self, self, obj, old);
432 : }
433 0 : }
434 :
435 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
436 : #if defined(__clang__)
437 : #pragma clang diagnostic push
438 : #pragma clang diagnostic ignored "-Wmissing-braces"
439 : #endif
440 : static const JSPropertySpec sAttributes_specs[] = {
441 : { "deltaX", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &deltaX_getterinfo, nullptr, nullptr },
442 : { "deltaY", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &deltaY_getterinfo, nullptr, nullptr },
443 : { "deltaZ", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &deltaZ_getterinfo, nullptr, nullptr },
444 : { "deltaMode", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &deltaMode_getterinfo, nullptr, nullptr },
445 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
446 : };
447 : #if defined(__clang__)
448 : #pragma clang diagnostic pop
449 : #endif
450 :
451 :
452 : // Can't be const because the pref-enabled boolean needs to be writable
453 : static Prefable<const JSPropertySpec> sAttributes[] = {
454 : { nullptr, &sAttributes_specs[0] },
455 : { nullptr, nullptr }
456 : };
457 :
458 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
459 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
460 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
461 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
462 :
463 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
464 : #if defined(__clang__)
465 : #pragma clang diagnostic push
466 : #pragma clang diagnostic ignored "-Wmissing-braces"
467 : #endif
468 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
469 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
470 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
471 : };
472 : #if defined(__clang__)
473 : #pragma clang diagnostic pop
474 : #endif
475 :
476 :
477 : // Can't be const because the pref-enabled boolean needs to be writable
478 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
479 : { nullptr, &sUnforgeableAttributes_specs[0] },
480 : { nullptr, nullptr }
481 : };
482 :
483 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
484 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
485 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
486 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
487 :
488 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
489 : #if defined(__clang__)
490 : #pragma clang diagnostic push
491 : #pragma clang diagnostic ignored "-Wmissing-braces"
492 : #endif
493 : static const ConstantSpec sConstants_specs[] = {
494 : { "DOM_DELTA_PIXEL", JS::NumberValue(0U) },
495 : { "DOM_DELTA_LINE", JS::NumberValue(1U) },
496 : { "DOM_DELTA_PAGE", JS::NumberValue(2U) },
497 : { 0, JS::UndefinedValue() }
498 : };
499 : #if defined(__clang__)
500 : #pragma clang diagnostic pop
501 : #endif
502 :
503 :
504 : // Can't be const because the pref-enabled boolean needs to be writable
505 : static Prefable<const ConstantSpec> sConstants[] = {
506 : { nullptr, &sConstants_specs[0] },
507 : { nullptr, nullptr }
508 : };
509 :
510 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
511 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
512 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
513 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
514 :
515 :
516 : static uint16_t sNativeProperties_sortedPropertyIndices[8];
517 : static PropertyInfo sNativeProperties_propertyInfos[8];
518 :
519 : static const NativePropertiesN<3> sNativeProperties = {
520 : false, 0,
521 : false, 0,
522 : false, 0,
523 : true, 0 /* sAttributes */,
524 : false, 0,
525 : true, 1 /* sUnforgeableAttributes */,
526 : true, 2 /* sConstants */,
527 : -1,
528 : 8,
529 : sNativeProperties_sortedPropertyIndices,
530 : {
531 : { sAttributes, &sNativeProperties_propertyInfos[0] },
532 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[4] },
533 : { sConstants, &sNativeProperties_propertyInfos[5] }
534 : }
535 : };
536 : static_assert(8 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
537 : "We have a property info count that is oversized");
538 :
539 : static bool
540 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
541 : {
542 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
543 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
544 0 : if (!args.isConstructing()) {
545 : // XXXbz wish I could get the name from the callee instead of
546 : // Adding more relocations
547 0 : return ThrowConstructorWithoutNew(cx, "WheelEvent");
548 : }
549 :
550 0 : GlobalObject global(cx, obj);
551 0 : if (global.Failed()) {
552 0 : return false;
553 : }
554 :
555 0 : JS::Rooted<JSObject*> desiredProto(cx);
556 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
557 0 : return false;
558 : }
559 :
560 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
561 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "WheelEvent");
562 : }
563 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
564 0 : binding_detail::FakeString arg0;
565 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
566 0 : return false;
567 : }
568 0 : binding_detail::FastWheelEventInit arg1;
569 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of WheelEvent.constructor", false)) {
570 0 : return false;
571 : }
572 0 : Maybe<JSAutoCompartment> ac;
573 0 : if (objIsXray) {
574 0 : obj = js::CheckedUnwrap(obj);
575 0 : if (!obj) {
576 0 : return false;
577 : }
578 0 : ac.emplace(cx, obj);
579 0 : if (!JS_WrapObject(cx, &desiredProto)) {
580 0 : return false;
581 : }
582 : }
583 0 : binding_detail::FastErrorResult rv;
584 0 : auto result(StrongOrRawPtr<mozilla::dom::WheelEvent>(mozilla::dom::WheelEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
585 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
586 0 : return false;
587 : }
588 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
589 : static_assert(!IsPointer<decltype(result)>::value,
590 : "NewObject implies that we need to keep the object alive with a strong reference.");
591 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
592 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
593 0 : return false;
594 : }
595 0 : return true;
596 : }
597 :
598 : static const js::ClassOps sInterfaceObjectClassOps = {
599 : nullptr, /* addProperty */
600 : nullptr, /* delProperty */
601 : nullptr, /* getProperty */
602 : nullptr, /* setProperty */
603 : nullptr, /* enumerate */
604 : nullptr, /* newEnumerate */
605 : nullptr, /* resolve */
606 : nullptr, /* mayResolve */
607 : nullptr, /* finalize */
608 : _constructor, /* call */
609 : nullptr, /* hasInstance */
610 : _constructor, /* construct */
611 : nullptr, /* trace */
612 : };
613 :
614 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
615 : {
616 : "Function",
617 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
618 : &sInterfaceObjectClassOps,
619 : JS_NULL_CLASS_SPEC,
620 : JS_NULL_CLASS_EXT,
621 : &sInterfaceObjectClassObjectOps
622 : },
623 : eInterface,
624 : true,
625 : prototypes::id::WheelEvent,
626 : PrototypeTraits<prototypes::id::WheelEvent>::Depth,
627 : sNativePropertyHooks,
628 : "function WheelEvent() {\n [native code]\n}",
629 : MouseEventBinding::GetConstructorObject
630 : };
631 :
632 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
633 : {
634 : "WheelEventPrototype",
635 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
636 : JS_NULL_CLASS_OPS,
637 : JS_NULL_CLASS_SPEC,
638 : JS_NULL_CLASS_EXT,
639 : JS_NULL_OBJECT_OPS
640 : },
641 : eInterfacePrototype,
642 : false,
643 : prototypes::id::WheelEvent,
644 : PrototypeTraits<prototypes::id::WheelEvent>::Depth,
645 : sNativePropertyHooks,
646 : "[object WheelEventPrototype]",
647 : MouseEventBinding::GetProtoObject
648 : };
649 :
650 : JSObject*
651 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
652 : {
653 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
654 : }
655 :
656 : static const js::ClassOps sClassOps = {
657 : _addProperty, /* addProperty */
658 : nullptr, /* delProperty */
659 : nullptr, /* getProperty */
660 : nullptr, /* setProperty */
661 : nullptr, /* enumerate */
662 : nullptr, /* newEnumerate */
663 : nullptr, /* resolve */
664 : nullptr, /* mayResolve */
665 : _finalize, /* finalize */
666 : nullptr, /* call */
667 : nullptr, /* hasInstance */
668 : nullptr, /* construct */
669 : nullptr, /* trace */
670 : };
671 :
672 : static const js::ClassExtension sClassExtension = {
673 : nullptr, /* weakmapKeyDelegateOp */
674 : _objectMoved /* objectMovedOp */
675 : };
676 :
677 : static const DOMJSClass sClass = {
678 : { "WheelEvent",
679 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
680 : &sClassOps,
681 : JS_NULL_CLASS_SPEC,
682 : &sClassExtension,
683 : JS_NULL_OBJECT_OPS
684 : },
685 : { prototypes::id::Event, prototypes::id::UIEvent, prototypes::id::MouseEvent, prototypes::id::WheelEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
686 : IsBaseOf<nsISupports, mozilla::dom::WheelEvent >::value,
687 : sNativePropertyHooks,
688 : FindAssociatedGlobalForNative<mozilla::dom::WheelEvent>::Get,
689 : GetProtoObjectHandle,
690 : GetCCParticipant<mozilla::dom::WheelEvent>::Get()
691 : };
692 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
693 : "Must have the right minimal number of reserved slots.");
694 : static_assert(1 >= 1,
695 : "Must have enough reserved slots.");
696 :
697 : const JSClass*
698 0 : GetJSClass()
699 : {
700 0 : return sClass.ToJSClass();
701 : }
702 :
703 : bool
704 0 : Wrap(JSContext* aCx, mozilla::dom::WheelEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
705 : {
706 : MOZ_ASSERT(static_cast<mozilla::dom::WheelEvent*>(aObject) ==
707 : reinterpret_cast<mozilla::dom::WheelEvent*>(aObject),
708 : "Multiple inheritance for mozilla::dom::WheelEvent is broken.");
709 : MOZ_ASSERT(static_cast<mozilla::dom::MouseEvent*>(aObject) ==
710 : reinterpret_cast<mozilla::dom::MouseEvent*>(aObject),
711 : "Multiple inheritance for mozilla::dom::MouseEvent is broken.");
712 : MOZ_ASSERT(static_cast<mozilla::dom::UIEvent*>(aObject) ==
713 : reinterpret_cast<mozilla::dom::UIEvent*>(aObject),
714 : "Multiple inheritance for mozilla::dom::UIEvent is broken.");
715 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
716 : reinterpret_cast<mozilla::dom::Event*>(aObject),
717 : "Multiple inheritance for mozilla::dom::Event is broken.");
718 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
719 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
720 0 : MOZ_ASSERT(!aCache->GetWrapper(),
721 : "You should probably not be using Wrap() directly; use "
722 : "GetOrCreateDOMReflector instead");
723 :
724 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
725 : "nsISupports must be on our primary inheritance chain");
726 :
727 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
728 0 : if (!global) {
729 0 : return false;
730 : }
731 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
732 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
733 :
734 : // That might have ended up wrapping us already, due to the wonders
735 : // of XBL. Check for that, and bail out as needed.
736 0 : aReflector.set(aCache->GetWrapper());
737 0 : if (aReflector) {
738 : #ifdef DEBUG
739 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
740 : #endif // DEBUG
741 0 : return true;
742 : }
743 :
744 0 : JSAutoCompartment ac(aCx, global);
745 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
746 0 : if (!canonicalProto) {
747 0 : return false;
748 : }
749 0 : JS::Rooted<JSObject*> proto(aCx);
750 0 : if (aGivenProto) {
751 0 : proto = aGivenProto;
752 : // Unfortunately, while aGivenProto was in the compartment of aCx
753 : // coming in, we changed compartments to that of "parent" so may need
754 : // to wrap the proto here.
755 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
756 0 : if (!JS_WrapObject(aCx, &proto)) {
757 0 : return false;
758 : }
759 : }
760 : } else {
761 0 : proto = canonicalProto;
762 : }
763 :
764 0 : BindingJSObjectCreator<mozilla::dom::WheelEvent> creator(aCx);
765 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
766 0 : if (!aReflector) {
767 0 : return false;
768 : }
769 :
770 0 : aCache->SetWrapper(aReflector);
771 :
772 : // Important: do unforgeable property setup after we have handed
773 : // over ownership of the C++ object to obj as needed, so that if
774 : // we fail and it ends up GCed it won't have problems in the
775 : // finalizer trying to drop its ownership of the C++ object.
776 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
777 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
778 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
779 0 : aCache->ReleaseWrapper(aObject);
780 0 : aCache->ClearWrapper();
781 0 : return false;
782 : }
783 0 : creator.InitializationSucceeded();
784 :
785 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
786 : aCache->GetWrapperPreserveColor() == aReflector);
787 : // If proto != canonicalProto, we have to preserve our wrapper;
788 : // otherwise we won't be able to properly recreate it later, since
789 : // we won't know what proto to use. Note that we don't check
790 : // aGivenProto here, since it's entirely possible (and even
791 : // somewhat common) to have a non-null aGivenProto which is the
792 : // same as canonicalProto.
793 0 : if (proto != canonicalProto) {
794 0 : PreserveWrapper(aObject);
795 : }
796 :
797 0 : return true;
798 : }
799 :
800 : const NativePropertyHooks sNativePropertyHooks[] = { {
801 : nullptr,
802 : nullptr,
803 : nullptr,
804 : { sNativeProperties.Upcast(), nullptr },
805 : prototypes::id::WheelEvent,
806 : constructors::id::WheelEvent,
807 : MouseEventBinding::sNativePropertyHooks,
808 : &DefaultXrayExpandoObjectClass
809 : } };
810 :
811 : void
812 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
813 : {
814 0 : JS::Handle<JSObject*> parentProto(MouseEventBinding::GetProtoObjectHandle(aCx));
815 0 : if (!parentProto) {
816 0 : return;
817 : }
818 :
819 0 : JS::Handle<JSObject*> constructorProto(MouseEventBinding::GetConstructorObjectHandle(aCx));
820 0 : if (!constructorProto) {
821 0 : return;
822 : }
823 :
824 : static bool sIdsInited = false;
825 0 : if (!sIdsInited && NS_IsMainThread()) {
826 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
827 0 : return;
828 : }
829 0 : sIdsInited = true;
830 : }
831 :
832 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WheelEvent);
833 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WheelEvent);
834 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
835 : &sPrototypeClass.mBase, protoCache,
836 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
837 : interfaceCache,
838 : sNativeProperties.Upcast(),
839 : nullptr,
840 : "WheelEvent", aDefineOnGlobal,
841 : nullptr,
842 0 : false);
843 :
844 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
845 : {
846 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
847 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
848 0 : if (!unforgeableHolder) {
849 0 : *protoCache = nullptr;
850 0 : if (interfaceCache) {
851 0 : *interfaceCache = nullptr;
852 : }
853 0 : return;
854 : }
855 : }
856 :
857 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
858 0 : *protoCache = nullptr;
859 0 : if (interfaceCache) {
860 0 : *interfaceCache = nullptr;
861 : }
862 0 : return;
863 : }
864 :
865 0 : if (*protoCache) {
866 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
867 0 : JS::ObjectValue(*unforgeableHolder));
868 : }
869 : }
870 :
871 : JS::Handle<JSObject*>
872 0 : GetProtoObjectHandle(JSContext* aCx)
873 : {
874 : /* Get the interface prototype object for this class. This will create the
875 : object as needed. */
876 0 : bool aDefineOnGlobal = true;
877 :
878 : /* Make sure our global is sane. Hopefully we can remove this sometime */
879 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
880 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
881 0 : return nullptr;
882 : }
883 :
884 : /* Check to see whether the interface objects are already installed */
885 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
886 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::WheelEvent)) {
887 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
888 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
889 : }
890 :
891 : /*
892 : * The object might _still_ be null, but that's OK.
893 : *
894 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
895 : * traced by TraceProtoAndIfaceCache() and its contents are never
896 : * changed after they have been set.
897 : *
898 : * Calling address() avoids the read read barrier that does gray
899 : * unmarking, but it's not possible for the object to be gray here.
900 : */
901 :
902 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::WheelEvent);
903 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
904 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
905 : }
906 :
907 : JS::Handle<JSObject*>
908 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
909 : {
910 : /* Get the interface object for this class. This will create the object as
911 : needed. */
912 :
913 : /* Make sure our global is sane. Hopefully we can remove this sometime */
914 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
915 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
916 0 : return nullptr;
917 : }
918 :
919 : /* Check to see whether the interface objects are already installed */
920 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
921 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::WheelEvent)) {
922 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
923 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
924 : }
925 :
926 : /*
927 : * The object might _still_ be null, but that's OK.
928 : *
929 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
930 : * traced by TraceProtoAndIfaceCache() and its contents are never
931 : * changed after they have been set.
932 : *
933 : * Calling address() avoids the read read barrier that does gray
934 : * unmarking, but it's not possible for the object to be gray here.
935 : */
936 :
937 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::WheelEvent);
938 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
939 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
940 : }
941 :
942 : JSObject*
943 0 : GetConstructorObject(JSContext* aCx)
944 : {
945 0 : return GetConstructorObjectHandle(aCx);
946 : }
947 :
948 : } // namespace WheelEventBinding
949 :
950 :
951 :
952 : } // namespace dom
953 : } // namespace mozilla
|