Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM PointerEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "MouseEventBinding.h"
5 : #include "PointerEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/FloatingPoint.h"
8 : #include "mozilla/OwningNonNull.h"
9 : #include "mozilla/Preferences.h"
10 : #include "mozilla/dom/BindingUtils.h"
11 : #include "mozilla/dom/DOMJSClass.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/PointerEvent.h"
14 : #include "mozilla/dom/PrimitiveConversions.h"
15 : #include "mozilla/dom/ScriptSettings.h"
16 : #include "mozilla/dom/SimpleGlobalObject.h"
17 : #include "mozilla/dom/XrayExpandoClass.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 :
23 0 : PointerEventInit::PointerEventInit()
24 0 : : MouseEventInit(FastDictionaryInitializer())
25 : {
26 : // Safe to pass a null context if we pass a null value
27 0 : Init(nullptr, JS::NullHandleValue);
28 0 : }
29 :
30 :
31 :
32 : bool
33 0 : PointerEventInit::InitIds(JSContext* cx, PointerEventInitAtoms* atomsCache)
34 : {
35 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
36 :
37 : // Initialize these in reverse order so that any failure leaves the first one
38 : // uninitialized.
39 0 : if (!atomsCache->width_id.init(cx, "width") ||
40 0 : !atomsCache->twist_id.init(cx, "twist") ||
41 0 : !atomsCache->tiltY_id.init(cx, "tiltY") ||
42 0 : !atomsCache->tiltX_id.init(cx, "tiltX") ||
43 0 : !atomsCache->tangentialPressure_id.init(cx, "tangentialPressure") ||
44 0 : !atomsCache->pressure_id.init(cx, "pressure") ||
45 0 : !atomsCache->pointerType_id.init(cx, "pointerType") ||
46 0 : !atomsCache->pointerId_id.init(cx, "pointerId") ||
47 0 : !atomsCache->isPrimary_id.init(cx, "isPrimary") ||
48 0 : !atomsCache->height_id.init(cx, "height")) {
49 0 : return false;
50 : }
51 0 : return true;
52 : }
53 :
54 : bool
55 0 : PointerEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
56 : {
57 : // Passing a null JSContext is OK only if we're initing from null,
58 : // Since in that case we will not have to do any property gets
59 : // Also evaluate isNullOrUndefined in order to avoid false-positive
60 : // checkers by static analysis tools
61 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
62 0 : PointerEventInitAtoms* atomsCache = nullptr;
63 0 : if (cx) {
64 0 : atomsCache = GetAtomCache<PointerEventInitAtoms>(cx);
65 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
66 0 : return false;
67 : }
68 : }
69 :
70 : // Per spec, we init the parent's members first
71 0 : if (!MouseEventInit::Init(cx, val)) {
72 0 : return false;
73 : }
74 :
75 0 : bool isNull = val.isNullOrUndefined();
76 : // We only need these if !isNull, in which case we have |cx|.
77 0 : Maybe<JS::Rooted<JSObject *> > object;
78 0 : Maybe<JS::Rooted<JS::Value> > temp;
79 0 : if (!isNull) {
80 0 : MOZ_ASSERT(cx);
81 0 : object.emplace(cx, &val.toObject());
82 0 : temp.emplace(cx);
83 : }
84 0 : if (!isNull) {
85 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->height_id, temp.ptr())) {
86 0 : return false;
87 : }
88 : }
89 0 : if (!isNull && !temp->isUndefined()) {
90 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mHeight)) {
91 0 : return false;
92 : }
93 : } else {
94 0 : mHeight = 1;
95 : }
96 0 : mIsAnyMemberPresent = true;
97 :
98 0 : if (!isNull) {
99 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->isPrimary_id, temp.ptr())) {
100 0 : return false;
101 : }
102 : }
103 0 : if (!isNull && !temp->isUndefined()) {
104 0 : if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mIsPrimary)) {
105 0 : return false;
106 : }
107 : } else {
108 0 : mIsPrimary = false;
109 : }
110 0 : mIsAnyMemberPresent = true;
111 :
112 0 : if (!isNull) {
113 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->pointerId_id, temp.ptr())) {
114 0 : return false;
115 : }
116 : }
117 0 : if (!isNull && !temp->isUndefined()) {
118 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mPointerId)) {
119 0 : return false;
120 : }
121 : } else {
122 0 : mPointerId = 0;
123 : }
124 0 : mIsAnyMemberPresent = true;
125 :
126 0 : if (!isNull) {
127 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->pointerType_id, temp.ptr())) {
128 0 : return false;
129 : }
130 : }
131 0 : if (!isNull && !temp->isUndefined()) {
132 0 : if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mPointerType)) {
133 0 : return false;
134 : }
135 : } else {
136 : static const char16_t data[] = { 0 };
137 0 : mPointerType.Rebind(data, ArrayLength(data) - 1);
138 : }
139 0 : mIsAnyMemberPresent = true;
140 :
141 0 : if (!isNull) {
142 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->pressure_id, temp.ptr())) {
143 0 : return false;
144 : }
145 : }
146 0 : if (!isNull && !temp->isUndefined()) {
147 0 : if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &mPressure)) {
148 0 : return false;
149 0 : } else if (!mozilla::IsFinite(mPressure)) {
150 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'pressure' member of PointerEventInit");
151 0 : return false;
152 : }
153 : } else {
154 0 : mPressure = 0.0F;
155 : }
156 0 : mIsAnyMemberPresent = true;
157 :
158 0 : if (!isNull) {
159 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->tangentialPressure_id, temp.ptr())) {
160 0 : return false;
161 : }
162 : }
163 0 : if (!isNull && !temp->isUndefined()) {
164 0 : if (!ValueToPrimitive<float, eDefault>(cx, temp.ref(), &mTangentialPressure)) {
165 0 : return false;
166 0 : } else if (!mozilla::IsFinite(mTangentialPressure)) {
167 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "'tangentialPressure' member of PointerEventInit");
168 0 : return false;
169 : }
170 : } else {
171 0 : mTangentialPressure = 0.0F;
172 : }
173 0 : mIsAnyMemberPresent = true;
174 :
175 0 : if (!isNull) {
176 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->tiltX_id, temp.ptr())) {
177 0 : return false;
178 : }
179 : }
180 0 : if (!isNull && !temp->isUndefined()) {
181 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mTiltX)) {
182 0 : return false;
183 : }
184 : } else {
185 0 : mTiltX = 0;
186 : }
187 0 : mIsAnyMemberPresent = true;
188 :
189 0 : if (!isNull) {
190 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->tiltY_id, temp.ptr())) {
191 0 : return false;
192 : }
193 : }
194 0 : if (!isNull && !temp->isUndefined()) {
195 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mTiltY)) {
196 0 : return false;
197 : }
198 : } else {
199 0 : mTiltY = 0;
200 : }
201 0 : mIsAnyMemberPresent = true;
202 :
203 0 : if (!isNull) {
204 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->twist_id, temp.ptr())) {
205 0 : return false;
206 : }
207 : }
208 0 : if (!isNull && !temp->isUndefined()) {
209 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mTwist)) {
210 0 : return false;
211 : }
212 : } else {
213 0 : mTwist = 0;
214 : }
215 0 : mIsAnyMemberPresent = true;
216 :
217 0 : if (!isNull) {
218 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->width_id, temp.ptr())) {
219 0 : return false;
220 : }
221 : }
222 0 : if (!isNull && !temp->isUndefined()) {
223 0 : if (!ValueToPrimitive<int32_t, eDefault>(cx, temp.ref(), &mWidth)) {
224 0 : return false;
225 : }
226 : } else {
227 0 : mWidth = 1;
228 : }
229 0 : mIsAnyMemberPresent = true;
230 0 : return true;
231 : }
232 :
233 : bool
234 0 : PointerEventInit::Init(const nsAString& aJSON)
235 : {
236 0 : AutoJSAPI jsapi;
237 0 : JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
238 0 : if (!cleanGlobal) {
239 0 : return false;
240 : }
241 0 : if (!jsapi.Init(cleanGlobal)) {
242 0 : return false;
243 : }
244 0 : JSContext* cx = jsapi.cx();
245 0 : JS::Rooted<JS::Value> json(cx);
246 0 : bool ok = ParseJSON(cx, aJSON, &json);
247 0 : NS_ENSURE_TRUE(ok, false);
248 0 : return Init(cx, json);
249 : }
250 :
251 : bool
252 0 : PointerEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
253 : {
254 0 : PointerEventInitAtoms* atomsCache = GetAtomCache<PointerEventInitAtoms>(cx);
255 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
256 0 : return false;
257 : }
258 :
259 : // Per spec, we define the parent's members first
260 0 : if (!MouseEventInit::ToObjectInternal(cx, rval)) {
261 0 : return false;
262 : }
263 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
264 :
265 : do {
266 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
267 0 : JS::Rooted<JS::Value> temp(cx);
268 0 : int32_t const & currentValue = mHeight;
269 0 : temp.setInt32(int32_t(currentValue));
270 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->height_id, temp, JSPROP_ENUMERATE)) {
271 0 : return false;
272 : }
273 0 : break;
274 : } while(0);
275 :
276 : do {
277 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
278 0 : JS::Rooted<JS::Value> temp(cx);
279 0 : bool const & currentValue = mIsPrimary;
280 0 : temp.setBoolean(currentValue);
281 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->isPrimary_id, temp, JSPROP_ENUMERATE)) {
282 0 : return false;
283 : }
284 0 : break;
285 : } while(0);
286 :
287 : do {
288 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
289 0 : JS::Rooted<JS::Value> temp(cx);
290 0 : int32_t const & currentValue = mPointerId;
291 0 : temp.setInt32(int32_t(currentValue));
292 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->pointerId_id, temp, JSPROP_ENUMERATE)) {
293 0 : return false;
294 : }
295 0 : break;
296 : } while(0);
297 :
298 : do {
299 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
300 0 : JS::Rooted<JS::Value> temp(cx);
301 0 : nsString const & currentValue = mPointerType;
302 0 : if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
303 0 : return false;
304 : }
305 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->pointerType_id, temp, JSPROP_ENUMERATE)) {
306 0 : return false;
307 : }
308 0 : break;
309 : } while(0);
310 :
311 : do {
312 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
313 0 : JS::Rooted<JS::Value> temp(cx);
314 0 : float const & currentValue = mPressure;
315 0 : temp.set(JS_NumberValue(double(currentValue)));
316 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->pressure_id, temp, JSPROP_ENUMERATE)) {
317 0 : return false;
318 : }
319 0 : break;
320 : } while(0);
321 :
322 : do {
323 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
324 0 : JS::Rooted<JS::Value> temp(cx);
325 0 : float const & currentValue = mTangentialPressure;
326 0 : temp.set(JS_NumberValue(double(currentValue)));
327 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->tangentialPressure_id, temp, JSPROP_ENUMERATE)) {
328 0 : return false;
329 : }
330 0 : break;
331 : } while(0);
332 :
333 : do {
334 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
335 0 : JS::Rooted<JS::Value> temp(cx);
336 0 : int32_t const & currentValue = mTiltX;
337 0 : temp.setInt32(int32_t(currentValue));
338 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->tiltX_id, temp, JSPROP_ENUMERATE)) {
339 0 : return false;
340 : }
341 0 : break;
342 : } while(0);
343 :
344 : do {
345 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
346 0 : JS::Rooted<JS::Value> temp(cx);
347 0 : int32_t const & currentValue = mTiltY;
348 0 : temp.setInt32(int32_t(currentValue));
349 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->tiltY_id, temp, JSPROP_ENUMERATE)) {
350 0 : return false;
351 : }
352 0 : break;
353 : } while(0);
354 :
355 : do {
356 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
357 0 : JS::Rooted<JS::Value> temp(cx);
358 0 : int32_t const & currentValue = mTwist;
359 0 : temp.setInt32(int32_t(currentValue));
360 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->twist_id, temp, JSPROP_ENUMERATE)) {
361 0 : return false;
362 : }
363 0 : break;
364 : } while(0);
365 :
366 : do {
367 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
368 0 : JS::Rooted<JS::Value> temp(cx);
369 0 : int32_t const & currentValue = mWidth;
370 0 : temp.setInt32(int32_t(currentValue));
371 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->width_id, temp, JSPROP_ENUMERATE)) {
372 0 : return false;
373 : }
374 0 : break;
375 : } while(0);
376 :
377 0 : return true;
378 : }
379 :
380 : bool
381 0 : PointerEventInit::ToJSON(nsAString& aJSON) const
382 : {
383 0 : AutoJSAPI jsapi;
384 0 : jsapi.Init();
385 0 : JSContext *cx = jsapi.cx();
386 : // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
387 : // because we'll only be creating objects, in ways that have no
388 : // side-effects, followed by a call to JS::ToJSONMaybeSafely,
389 : // which likewise guarantees no side-effects for the sorts of
390 : // things we will pass it.
391 0 : JSAutoCompartment ac(cx, binding_detail::UnprivilegedJunkScopeOrWorkerGlobal());
392 0 : JS::Rooted<JS::Value> val(cx);
393 0 : if (!ToObjectInternal(cx, &val)) {
394 0 : return false;
395 : }
396 0 : JS::Rooted<JSObject*> obj(cx, &val.toObject());
397 0 : return StringifyToJSON(cx, obj, aJSON);
398 : }
399 :
400 : void
401 0 : PointerEventInit::TraceDictionary(JSTracer* trc)
402 : {
403 0 : MouseEventInit::TraceDictionary(trc);
404 0 : }
405 :
406 : PointerEventInit&
407 0 : PointerEventInit::operator=(const PointerEventInit& aOther)
408 : {
409 0 : MouseEventInit::operator=(aOther);
410 0 : mHeight = aOther.mHeight;
411 0 : mIsPrimary = aOther.mIsPrimary;
412 0 : mPointerId = aOther.mPointerId;
413 0 : mPointerType = aOther.mPointerType;
414 0 : mPressure = aOther.mPressure;
415 0 : mTangentialPressure = aOther.mTangentialPressure;
416 0 : mTiltX = aOther.mTiltX;
417 0 : mTiltY = aOther.mTiltY;
418 0 : mTwist = aOther.mTwist;
419 0 : mWidth = aOther.mWidth;
420 0 : return *this;
421 : }
422 :
423 : namespace binding_detail {
424 : } // namespace binding_detail
425 :
426 :
427 : namespace PointerEventBinding {
428 :
429 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MouseEventBinding::NativeType>::value,
430 : "Can't inherit from an interface with a different ownership model.");
431 :
432 : static bool
433 0 : get_pointerId(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
434 : {
435 0 : int32_t result(self->PointerId());
436 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
437 0 : args.rval().setInt32(int32_t(result));
438 0 : return true;
439 : }
440 :
441 : static const JSJitInfo pointerId_getterinfo = {
442 : { (JSJitGetterOp)get_pointerId },
443 : { prototypes::id::PointerEvent },
444 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
445 : JSJitInfo::Getter,
446 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
447 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
448 : true, /* isInfallible. False in setters. */
449 : false, /* isMovable. Not relevant for setters. */
450 : false, /* isEliminatable. Not relevant for setters. */
451 : false, /* isAlwaysInSlot. Only relevant for getters. */
452 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
453 : false, /* isTypedMethod. Only relevant for methods. */
454 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
455 : };
456 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
457 : static_assert(0 < 1, "There is no slot for us");
458 :
459 : static bool
460 0 : get_width(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
461 : {
462 0 : int32_t result(self->Width());
463 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
464 0 : args.rval().setInt32(int32_t(result));
465 0 : return true;
466 : }
467 :
468 : static const JSJitInfo width_getterinfo = {
469 : { (JSJitGetterOp)get_width },
470 : { prototypes::id::PointerEvent },
471 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
472 : JSJitInfo::Getter,
473 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
474 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
475 : true, /* isInfallible. False in setters. */
476 : false, /* isMovable. Not relevant for setters. */
477 : false, /* isEliminatable. Not relevant for setters. */
478 : false, /* isAlwaysInSlot. Only relevant for getters. */
479 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
480 : false, /* isTypedMethod. Only relevant for methods. */
481 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
482 : };
483 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
484 : static_assert(0 < 1, "There is no slot for us");
485 :
486 : static bool
487 0 : get_height(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
488 : {
489 0 : int32_t result(self->Height());
490 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
491 0 : args.rval().setInt32(int32_t(result));
492 0 : return true;
493 : }
494 :
495 : static const JSJitInfo height_getterinfo = {
496 : { (JSJitGetterOp)get_height },
497 : { prototypes::id::PointerEvent },
498 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
499 : JSJitInfo::Getter,
500 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
501 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
502 : true, /* isInfallible. False in setters. */
503 : false, /* isMovable. Not relevant for setters. */
504 : false, /* isEliminatable. Not relevant for setters. */
505 : false, /* isAlwaysInSlot. Only relevant for getters. */
506 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
507 : false, /* isTypedMethod. Only relevant for methods. */
508 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
509 : };
510 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
511 : static_assert(0 < 1, "There is no slot for us");
512 :
513 : static bool
514 0 : get_pressure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
515 : {
516 0 : float result(self->Pressure());
517 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
518 0 : args.rval().set(JS_NumberValue(double(result)));
519 0 : return true;
520 : }
521 :
522 : static const JSJitInfo pressure_getterinfo = {
523 : { (JSJitGetterOp)get_pressure },
524 : { prototypes::id::PointerEvent },
525 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
526 : JSJitInfo::Getter,
527 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
528 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
529 : true, /* isInfallible. False in setters. */
530 : false, /* isMovable. Not relevant for setters. */
531 : false, /* isEliminatable. Not relevant for setters. */
532 : false, /* isAlwaysInSlot. Only relevant for getters. */
533 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
534 : false, /* isTypedMethod. Only relevant for methods. */
535 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
536 : };
537 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
538 : static_assert(0 < 1, "There is no slot for us");
539 :
540 : static bool
541 0 : get_tangentialPressure(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
542 : {
543 0 : float result(self->TangentialPressure());
544 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
545 0 : args.rval().set(JS_NumberValue(double(result)));
546 0 : return true;
547 : }
548 :
549 : static const JSJitInfo tangentialPressure_getterinfo = {
550 : { (JSJitGetterOp)get_tangentialPressure },
551 : { prototypes::id::PointerEvent },
552 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
553 : JSJitInfo::Getter,
554 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
555 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
556 : true, /* isInfallible. False in setters. */
557 : false, /* isMovable. Not relevant for setters. */
558 : false, /* isEliminatable. Not relevant for setters. */
559 : false, /* isAlwaysInSlot. Only relevant for getters. */
560 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
561 : false, /* isTypedMethod. Only relevant for methods. */
562 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
563 : };
564 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
565 : static_assert(0 < 1, "There is no slot for us");
566 :
567 : static bool
568 0 : get_tiltX(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
569 : {
570 0 : int32_t result(self->TiltX());
571 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
572 0 : args.rval().setInt32(int32_t(result));
573 0 : return true;
574 : }
575 :
576 : static const JSJitInfo tiltX_getterinfo = {
577 : { (JSJitGetterOp)get_tiltX },
578 : { prototypes::id::PointerEvent },
579 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
580 : JSJitInfo::Getter,
581 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
582 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
583 : true, /* isInfallible. False in setters. */
584 : false, /* isMovable. Not relevant for setters. */
585 : false, /* isEliminatable. Not relevant for setters. */
586 : false, /* isAlwaysInSlot. Only relevant for getters. */
587 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
588 : false, /* isTypedMethod. Only relevant for methods. */
589 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
590 : };
591 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
592 : static_assert(0 < 1, "There is no slot for us");
593 :
594 : static bool
595 0 : get_tiltY(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
596 : {
597 0 : int32_t result(self->TiltY());
598 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
599 0 : args.rval().setInt32(int32_t(result));
600 0 : return true;
601 : }
602 :
603 : static const JSJitInfo tiltY_getterinfo = {
604 : { (JSJitGetterOp)get_tiltY },
605 : { prototypes::id::PointerEvent },
606 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
607 : JSJitInfo::Getter,
608 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
609 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
610 : true, /* isInfallible. False in setters. */
611 : false, /* isMovable. Not relevant for setters. */
612 : false, /* isEliminatable. Not relevant for setters. */
613 : false, /* isAlwaysInSlot. Only relevant for getters. */
614 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
615 : false, /* isTypedMethod. Only relevant for methods. */
616 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
617 : };
618 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
619 : static_assert(0 < 1, "There is no slot for us");
620 :
621 : static bool
622 0 : get_twist(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
623 : {
624 0 : int32_t result(self->Twist());
625 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
626 0 : args.rval().setInt32(int32_t(result));
627 0 : return true;
628 : }
629 :
630 : static const JSJitInfo twist_getterinfo = {
631 : { (JSJitGetterOp)get_twist },
632 : { prototypes::id::PointerEvent },
633 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
634 : JSJitInfo::Getter,
635 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
636 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
637 : true, /* isInfallible. False in setters. */
638 : false, /* isMovable. Not relevant for setters. */
639 : false, /* isEliminatable. Not relevant for setters. */
640 : false, /* isAlwaysInSlot. Only relevant for getters. */
641 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
642 : false, /* isTypedMethod. Only relevant for methods. */
643 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
644 : };
645 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
646 : static_assert(0 < 1, "There is no slot for us");
647 :
648 : static bool
649 0 : get_pointerType(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
650 : {
651 0 : DOMString result;
652 0 : self->GetPointerType(result);
653 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
654 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
655 0 : return false;
656 : }
657 0 : return true;
658 : }
659 :
660 : static const JSJitInfo pointerType_getterinfo = {
661 : { (JSJitGetterOp)get_pointerType },
662 : { prototypes::id::PointerEvent },
663 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
664 : JSJitInfo::Getter,
665 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
666 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
667 : false, /* isInfallible. False in setters. */
668 : false, /* isMovable. Not relevant for setters. */
669 : false, /* isEliminatable. Not relevant for setters. */
670 : false, /* isAlwaysInSlot. Only relevant for getters. */
671 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
672 : false, /* isTypedMethod. Only relevant for methods. */
673 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
674 : };
675 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
676 : static_assert(0 < 1, "There is no slot for us");
677 :
678 : static bool
679 0 : get_isPrimary(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
680 : {
681 0 : bool result(self->IsPrimary());
682 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
683 0 : args.rval().setBoolean(result);
684 0 : return true;
685 : }
686 :
687 : static const JSJitInfo isPrimary_getterinfo = {
688 : { (JSJitGetterOp)get_isPrimary },
689 : { prototypes::id::PointerEvent },
690 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
691 : JSJitInfo::Getter,
692 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
693 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
694 : true, /* isInfallible. False in setters. */
695 : false, /* isMovable. Not relevant for setters. */
696 : false, /* isEliminatable. Not relevant for setters. */
697 : false, /* isAlwaysInSlot. Only relevant for getters. */
698 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
699 : false, /* isTypedMethod. Only relevant for methods. */
700 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
701 : };
702 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
703 : static_assert(0 < 1, "There is no slot for us");
704 :
705 : static bool
706 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::PointerEvent* self, JSJitGetterCallArgs args)
707 : {
708 0 : bool result(self->IsTrusted());
709 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
710 0 : args.rval().setBoolean(result);
711 0 : return true;
712 : }
713 :
714 : static const JSJitInfo isTrusted_getterinfo = {
715 : { (JSJitGetterOp)get_isTrusted },
716 : { prototypes::id::PointerEvent },
717 : { PrototypeTraits<prototypes::id::PointerEvent>::Depth },
718 : JSJitInfo::Getter,
719 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
720 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
721 : true, /* isInfallible. False in setters. */
722 : true, /* isMovable. Not relevant for setters. */
723 : true, /* isEliminatable. Not relevant for setters. */
724 : false, /* isAlwaysInSlot. Only relevant for getters. */
725 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
726 : false, /* isTypedMethod. Only relevant for methods. */
727 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
728 : };
729 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
730 : static_assert(0 < 1, "There is no slot for us");
731 :
732 : static bool
733 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
734 : {
735 0 : mozilla::dom::PointerEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PointerEvent>(obj);
736 : // We don't want to preserve if we don't have a wrapper, and we
737 : // obviously can't preserve if we're not initialized.
738 0 : if (self && self->GetWrapperPreserveColor()) {
739 0 : PreserveWrapper(self);
740 : }
741 0 : return true;
742 : }
743 :
744 : static void
745 0 : _finalize(js::FreeOp* fop, JSObject* obj)
746 : {
747 0 : mozilla::dom::PointerEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PointerEvent>(obj);
748 0 : if (self) {
749 0 : ClearWrapper(self, self, obj);
750 0 : AddForDeferredFinalization<mozilla::dom::PointerEvent>(self);
751 : }
752 0 : }
753 :
754 : static void
755 0 : _objectMoved(JSObject* obj, const JSObject* old)
756 : {
757 0 : mozilla::dom::PointerEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::PointerEvent>(obj);
758 0 : if (self) {
759 0 : UpdateWrapper(self, self, obj, old);
760 : }
761 0 : }
762 :
763 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
764 : #if defined(__clang__)
765 : #pragma clang diagnostic push
766 : #pragma clang diagnostic ignored "-Wmissing-braces"
767 : #endif
768 : static const JSPropertySpec sAttributes_specs[] = {
769 : { "pointerId", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &pointerId_getterinfo, nullptr, nullptr },
770 : { "width", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &width_getterinfo, nullptr, nullptr },
771 : { "height", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &height_getterinfo, nullptr, nullptr },
772 : { "pressure", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &pressure_getterinfo, nullptr, nullptr },
773 : { "tangentialPressure", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &tangentialPressure_getterinfo, nullptr, nullptr },
774 : { "tiltX", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &tiltX_getterinfo, nullptr, nullptr },
775 : { "tiltY", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &tiltY_getterinfo, nullptr, nullptr },
776 : { "twist", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &twist_getterinfo, nullptr, nullptr },
777 : { "pointerType", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &pointerType_getterinfo, nullptr, nullptr },
778 : { "isPrimary", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &isPrimary_getterinfo, nullptr, nullptr },
779 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
780 : };
781 : #if defined(__clang__)
782 : #pragma clang diagnostic pop
783 : #endif
784 :
785 :
786 : // Can't be const because the pref-enabled boolean needs to be writable
787 : static Prefable<const JSPropertySpec> sAttributes[] = {
788 : { nullptr, &sAttributes_specs[0] },
789 : { nullptr, nullptr }
790 : };
791 :
792 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
793 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
794 : static_assert(10 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
795 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
796 :
797 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
798 : #if defined(__clang__)
799 : #pragma clang diagnostic push
800 : #pragma clang diagnostic ignored "-Wmissing-braces"
801 : #endif
802 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
803 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
804 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
805 : };
806 : #if defined(__clang__)
807 : #pragma clang diagnostic pop
808 : #endif
809 :
810 :
811 : // Can't be const because the pref-enabled boolean needs to be writable
812 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
813 : { nullptr, &sUnforgeableAttributes_specs[0] },
814 : { nullptr, nullptr }
815 : };
816 :
817 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
818 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
819 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
820 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
821 :
822 :
823 : static uint16_t sNativeProperties_sortedPropertyIndices[11];
824 : static PropertyInfo sNativeProperties_propertyInfos[11];
825 :
826 : static const NativePropertiesN<2> sNativeProperties = {
827 : false, 0,
828 : false, 0,
829 : false, 0,
830 : true, 0 /* sAttributes */,
831 : false, 0,
832 : true, 1 /* sUnforgeableAttributes */,
833 : false, 0,
834 : -1,
835 : 11,
836 : sNativeProperties_sortedPropertyIndices,
837 : {
838 : { sAttributes, &sNativeProperties_propertyInfos[0] },
839 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[10] }
840 : }
841 : };
842 : static_assert(11 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
843 : "We have a property info count that is oversized");
844 :
845 : static bool
846 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
847 : {
848 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
849 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
850 0 : if (!args.isConstructing()) {
851 : // XXXbz wish I could get the name from the callee instead of
852 : // Adding more relocations
853 0 : return ThrowConstructorWithoutNew(cx, "PointerEvent");
854 : }
855 :
856 0 : GlobalObject global(cx, obj);
857 0 : if (global.Failed()) {
858 0 : return false;
859 : }
860 :
861 0 : JS::Rooted<JSObject*> desiredProto(cx);
862 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
863 0 : return false;
864 : }
865 :
866 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
867 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "PointerEvent");
868 : }
869 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
870 0 : binding_detail::FakeString arg0;
871 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
872 0 : return false;
873 : }
874 0 : binding_detail::FastPointerEventInit arg1;
875 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of PointerEvent.constructor", false)) {
876 0 : return false;
877 : }
878 0 : Maybe<JSAutoCompartment> ac;
879 0 : if (objIsXray) {
880 0 : obj = js::CheckedUnwrap(obj);
881 0 : if (!obj) {
882 0 : return false;
883 : }
884 0 : ac.emplace(cx, obj);
885 0 : if (!JS_WrapObject(cx, &desiredProto)) {
886 0 : return false;
887 : }
888 : }
889 0 : binding_detail::FastErrorResult rv;
890 0 : auto result(StrongOrRawPtr<mozilla::dom::PointerEvent>(mozilla::dom::PointerEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
891 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
892 0 : return false;
893 : }
894 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
895 : static_assert(!IsPointer<decltype(result)>::value,
896 : "NewObject implies that we need to keep the object alive with a strong reference.");
897 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
898 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
899 0 : return false;
900 : }
901 0 : return true;
902 : }
903 :
904 : static const js::ClassOps sInterfaceObjectClassOps = {
905 : nullptr, /* addProperty */
906 : nullptr, /* delProperty */
907 : nullptr, /* getProperty */
908 : nullptr, /* setProperty */
909 : nullptr, /* enumerate */
910 : nullptr, /* newEnumerate */
911 : nullptr, /* resolve */
912 : nullptr, /* mayResolve */
913 : nullptr, /* finalize */
914 : _constructor, /* call */
915 : nullptr, /* hasInstance */
916 : _constructor, /* construct */
917 : nullptr, /* trace */
918 : };
919 :
920 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
921 : {
922 : "Function",
923 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
924 : &sInterfaceObjectClassOps,
925 : JS_NULL_CLASS_SPEC,
926 : JS_NULL_CLASS_EXT,
927 : &sInterfaceObjectClassObjectOps
928 : },
929 : eInterface,
930 : true,
931 : prototypes::id::PointerEvent,
932 : PrototypeTraits<prototypes::id::PointerEvent>::Depth,
933 : sNativePropertyHooks,
934 : "function PointerEvent() {\n [native code]\n}",
935 : MouseEventBinding::GetConstructorObject
936 : };
937 :
938 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
939 : {
940 : "PointerEventPrototype",
941 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
942 : JS_NULL_CLASS_OPS,
943 : JS_NULL_CLASS_SPEC,
944 : JS_NULL_CLASS_EXT,
945 : JS_NULL_OBJECT_OPS
946 : },
947 : eInterfacePrototype,
948 : false,
949 : prototypes::id::PointerEvent,
950 : PrototypeTraits<prototypes::id::PointerEvent>::Depth,
951 : sNativePropertyHooks,
952 : "[object PointerEventPrototype]",
953 : MouseEventBinding::GetProtoObject
954 : };
955 :
956 : bool
957 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
958 : {
959 : static bool sPrefValue;
960 : static bool sPrefCacheSetUp = false;
961 0 : if (!sPrefCacheSetUp) {
962 0 : sPrefCacheSetUp = true;
963 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.w3c_pointer_events.enabled");
964 : }
965 :
966 0 : return sPrefValue;
967 : }
968 :
969 : JSObject*
970 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
971 : {
972 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
973 : }
974 :
975 : static const js::ClassOps sClassOps = {
976 : _addProperty, /* addProperty */
977 : nullptr, /* delProperty */
978 : nullptr, /* getProperty */
979 : nullptr, /* setProperty */
980 : nullptr, /* enumerate */
981 : nullptr, /* newEnumerate */
982 : nullptr, /* resolve */
983 : nullptr, /* mayResolve */
984 : _finalize, /* finalize */
985 : nullptr, /* call */
986 : nullptr, /* hasInstance */
987 : nullptr, /* construct */
988 : nullptr, /* trace */
989 : };
990 :
991 : static const js::ClassExtension sClassExtension = {
992 : nullptr, /* weakmapKeyDelegateOp */
993 : _objectMoved /* objectMovedOp */
994 : };
995 :
996 : static const DOMJSClass sClass = {
997 : { "PointerEvent",
998 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
999 : &sClassOps,
1000 : JS_NULL_CLASS_SPEC,
1001 : &sClassExtension,
1002 : JS_NULL_OBJECT_OPS
1003 : },
1004 : { prototypes::id::Event, prototypes::id::UIEvent, prototypes::id::MouseEvent, prototypes::id::PointerEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1005 : IsBaseOf<nsISupports, mozilla::dom::PointerEvent >::value,
1006 : sNativePropertyHooks,
1007 : FindAssociatedGlobalForNative<mozilla::dom::PointerEvent>::Get,
1008 : GetProtoObjectHandle,
1009 : GetCCParticipant<mozilla::dom::PointerEvent>::Get()
1010 : };
1011 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1012 : "Must have the right minimal number of reserved slots.");
1013 : static_assert(1 >= 1,
1014 : "Must have enough reserved slots.");
1015 :
1016 : const JSClass*
1017 0 : GetJSClass()
1018 : {
1019 0 : return sClass.ToJSClass();
1020 : }
1021 :
1022 : bool
1023 0 : Wrap(JSContext* aCx, mozilla::dom::PointerEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1024 : {
1025 : MOZ_ASSERT(static_cast<mozilla::dom::PointerEvent*>(aObject) ==
1026 : reinterpret_cast<mozilla::dom::PointerEvent*>(aObject),
1027 : "Multiple inheritance for mozilla::dom::PointerEvent is broken.");
1028 : MOZ_ASSERT(static_cast<mozilla::dom::MouseEvent*>(aObject) ==
1029 : reinterpret_cast<mozilla::dom::MouseEvent*>(aObject),
1030 : "Multiple inheritance for mozilla::dom::MouseEvent is broken.");
1031 : MOZ_ASSERT(static_cast<mozilla::dom::UIEvent*>(aObject) ==
1032 : reinterpret_cast<mozilla::dom::UIEvent*>(aObject),
1033 : "Multiple inheritance for mozilla::dom::UIEvent is broken.");
1034 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
1035 : reinterpret_cast<mozilla::dom::Event*>(aObject),
1036 : "Multiple inheritance for mozilla::dom::Event is broken.");
1037 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1038 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1039 0 : MOZ_ASSERT(!aCache->GetWrapper(),
1040 : "You should probably not be using Wrap() directly; use "
1041 : "GetOrCreateDOMReflector instead");
1042 :
1043 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1044 : "nsISupports must be on our primary inheritance chain");
1045 :
1046 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1047 0 : if (!global) {
1048 0 : return false;
1049 : }
1050 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
1051 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1052 :
1053 : // That might have ended up wrapping us already, due to the wonders
1054 : // of XBL. Check for that, and bail out as needed.
1055 0 : aReflector.set(aCache->GetWrapper());
1056 0 : if (aReflector) {
1057 : #ifdef DEBUG
1058 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1059 : #endif // DEBUG
1060 0 : return true;
1061 : }
1062 :
1063 0 : JSAutoCompartment ac(aCx, global);
1064 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1065 0 : if (!canonicalProto) {
1066 0 : return false;
1067 : }
1068 0 : JS::Rooted<JSObject*> proto(aCx);
1069 0 : if (aGivenProto) {
1070 0 : proto = aGivenProto;
1071 : // Unfortunately, while aGivenProto was in the compartment of aCx
1072 : // coming in, we changed compartments to that of "parent" so may need
1073 : // to wrap the proto here.
1074 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1075 0 : if (!JS_WrapObject(aCx, &proto)) {
1076 0 : return false;
1077 : }
1078 : }
1079 : } else {
1080 0 : proto = canonicalProto;
1081 : }
1082 :
1083 0 : BindingJSObjectCreator<mozilla::dom::PointerEvent> creator(aCx);
1084 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1085 0 : if (!aReflector) {
1086 0 : return false;
1087 : }
1088 :
1089 0 : aCache->SetWrapper(aReflector);
1090 :
1091 : // Important: do unforgeable property setup after we have handed
1092 : // over ownership of the C++ object to obj as needed, so that if
1093 : // we fail and it ends up GCed it won't have problems in the
1094 : // finalizer trying to drop its ownership of the C++ object.
1095 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
1096 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
1097 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
1098 0 : aCache->ReleaseWrapper(aObject);
1099 0 : aCache->ClearWrapper();
1100 0 : return false;
1101 : }
1102 0 : creator.InitializationSucceeded();
1103 :
1104 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1105 : aCache->GetWrapperPreserveColor() == aReflector);
1106 : // If proto != canonicalProto, we have to preserve our wrapper;
1107 : // otherwise we won't be able to properly recreate it later, since
1108 : // we won't know what proto to use. Note that we don't check
1109 : // aGivenProto here, since it's entirely possible (and even
1110 : // somewhat common) to have a non-null aGivenProto which is the
1111 : // same as canonicalProto.
1112 0 : if (proto != canonicalProto) {
1113 0 : PreserveWrapper(aObject);
1114 : }
1115 :
1116 0 : return true;
1117 : }
1118 :
1119 : const NativePropertyHooks sNativePropertyHooks[] = { {
1120 : nullptr,
1121 : nullptr,
1122 : nullptr,
1123 : { sNativeProperties.Upcast(), nullptr },
1124 : prototypes::id::PointerEvent,
1125 : constructors::id::PointerEvent,
1126 : MouseEventBinding::sNativePropertyHooks,
1127 : &DefaultXrayExpandoObjectClass
1128 : } };
1129 :
1130 : void
1131 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1132 : {
1133 0 : JS::Handle<JSObject*> parentProto(MouseEventBinding::GetProtoObjectHandle(aCx));
1134 0 : if (!parentProto) {
1135 0 : return;
1136 : }
1137 :
1138 0 : JS::Handle<JSObject*> constructorProto(MouseEventBinding::GetConstructorObjectHandle(aCx));
1139 0 : if (!constructorProto) {
1140 0 : return;
1141 : }
1142 :
1143 : static bool sIdsInited = false;
1144 0 : if (!sIdsInited && NS_IsMainThread()) {
1145 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1146 0 : return;
1147 : }
1148 0 : sIdsInited = true;
1149 : }
1150 :
1151 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::PointerEvent);
1152 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::PointerEvent);
1153 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1154 : &sPrototypeClass.mBase, protoCache,
1155 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
1156 : interfaceCache,
1157 : sNativeProperties.Upcast(),
1158 : nullptr,
1159 : "PointerEvent", aDefineOnGlobal,
1160 : nullptr,
1161 0 : false);
1162 :
1163 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
1164 : {
1165 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1166 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1167 0 : if (!unforgeableHolder) {
1168 0 : *protoCache = nullptr;
1169 0 : if (interfaceCache) {
1170 0 : *interfaceCache = nullptr;
1171 : }
1172 0 : return;
1173 : }
1174 : }
1175 :
1176 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1177 0 : *protoCache = nullptr;
1178 0 : if (interfaceCache) {
1179 0 : *interfaceCache = nullptr;
1180 : }
1181 0 : return;
1182 : }
1183 :
1184 0 : if (*protoCache) {
1185 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1186 0 : JS::ObjectValue(*unforgeableHolder));
1187 : }
1188 : }
1189 :
1190 : JS::Handle<JSObject*>
1191 0 : GetProtoObjectHandle(JSContext* aCx)
1192 : {
1193 : /* Get the interface prototype object for this class. This will create the
1194 : object as needed. */
1195 0 : bool aDefineOnGlobal = true;
1196 :
1197 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1198 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1199 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1200 0 : return nullptr;
1201 : }
1202 :
1203 : /* Check to see whether the interface objects are already installed */
1204 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1205 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::PointerEvent)) {
1206 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1207 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1208 : }
1209 :
1210 : /*
1211 : * The object might _still_ be null, but that's OK.
1212 : *
1213 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1214 : * traced by TraceProtoAndIfaceCache() and its contents are never
1215 : * changed after they have been set.
1216 : *
1217 : * Calling address() avoids the read read barrier that does gray
1218 : * unmarking, but it's not possible for the object to be gray here.
1219 : */
1220 :
1221 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::PointerEvent);
1222 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1223 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1224 : }
1225 :
1226 : JS::Handle<JSObject*>
1227 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1228 : {
1229 : /* Get the interface object for this class. This will create the object as
1230 : needed. */
1231 :
1232 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1233 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1234 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1235 0 : return nullptr;
1236 : }
1237 :
1238 : /* Check to see whether the interface objects are already installed */
1239 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1240 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::PointerEvent)) {
1241 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1242 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1243 : }
1244 :
1245 : /*
1246 : * The object might _still_ be null, but that's OK.
1247 : *
1248 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1249 : * traced by TraceProtoAndIfaceCache() and its contents are never
1250 : * changed after they have been set.
1251 : *
1252 : * Calling address() avoids the read read barrier that does gray
1253 : * unmarking, but it's not possible for the object to be gray here.
1254 : */
1255 :
1256 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::PointerEvent);
1257 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1258 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1259 : }
1260 :
1261 : JSObject*
1262 0 : GetConstructorObject(JSContext* aCx)
1263 : {
1264 0 : return GetConstructorObjectHandle(aCx);
1265 : }
1266 :
1267 : } // namespace PointerEventBinding
1268 :
1269 :
1270 :
1271 : } // namespace dom
1272 : } // namespace mozilla
|