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