Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM TouchList.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "TouchListBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/DOMJSClass.h"
8 : #include "mozilla/dom/DOMJSProxyHandler.h"
9 : #include "mozilla/dom/NonRefcountedDOMObject.h"
10 : #include "mozilla/dom/Nullable.h"
11 : #include "mozilla/dom/PrimitiveConversions.h"
12 : #include "mozilla/dom/Touch.h"
13 : #include "mozilla/dom/TouchEvent.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 : #include "nsISupports.h"
16 : #include "xpcjsid.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : namespace TouchListBinding {
22 :
23 : static bool
24 0 : get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TouchList* self, JSJitGetterCallArgs args)
25 : {
26 0 : uint32_t result(self->Length());
27 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
28 0 : args.rval().setNumber(result);
29 0 : return true;
30 : }
31 :
32 : static const JSJitInfo length_getterinfo = {
33 : { (JSJitGetterOp)get_length },
34 : { prototypes::id::TouchList },
35 : { PrototypeTraits<prototypes::id::TouchList>::Depth },
36 : JSJitInfo::Getter,
37 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
38 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
39 : true, /* isInfallible. False in setters. */
40 : true, /* isMovable. Not relevant for setters. */
41 : true, /* isEliminatable. Not relevant for setters. */
42 : false, /* isAlwaysInSlot. Only relevant for getters. */
43 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
44 : false, /* isTypedMethod. Only relevant for methods. */
45 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
46 : };
47 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
48 : static_assert(0 < 1, "There is no slot for us");
49 :
50 : static bool
51 0 : item(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::TouchList* self, const JSJitMethodCallArgs& args)
52 : {
53 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
54 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "TouchList.item");
55 : }
56 : uint32_t arg0;
57 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
58 0 : return false;
59 : }
60 0 : auto result(StrongOrRawPtr<mozilla::dom::Touch>(self->Item(arg0)));
61 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
62 0 : if (!result) {
63 0 : args.rval().setNull();
64 0 : return true;
65 : }
66 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
67 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
68 0 : return false;
69 : }
70 0 : return true;
71 : }
72 :
73 : static const JSJitInfo item_methodinfo = {
74 : { (JSJitGetterOp)item },
75 : { prototypes::id::TouchList },
76 : { PrototypeTraits<prototypes::id::TouchList>::Depth },
77 : JSJitInfo::Method,
78 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
79 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
80 : false, /* isInfallible. False in setters. */
81 : false, /* isMovable. Not relevant for setters. */
82 : false, /* isEliminatable. Not relevant for setters. */
83 : false, /* isAlwaysInSlot. Only relevant for getters. */
84 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
85 : false, /* isTypedMethod. Only relevant for methods. */
86 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
87 : };
88 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
89 : static_assert(0 < 1, "There is no slot for us");
90 :
91 : static void
92 0 : _objectMoved(JSObject* obj, const JSObject* old)
93 : {
94 0 : mozilla::dom::TouchList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TouchList>(obj);
95 0 : if (self) {
96 0 : UpdateWrapper(self, self, obj, old);
97 : }
98 0 : }
99 :
100 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
101 : #if defined(__clang__)
102 : #pragma clang diagnostic push
103 : #pragma clang diagnostic ignored "-Wmissing-braces"
104 : #endif
105 : static const JSFunctionSpec sMethods_specs[] = {
106 : JS_FNSPEC("item", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
107 : JS_FS_END,
108 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
109 : JS_FS_END,
110 : JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
111 : JS_FS_END
112 : };
113 : #if defined(__clang__)
114 : #pragma clang diagnostic pop
115 : #endif
116 :
117 : static PrefableDisablers sMethods_disablers2 = {
118 : true, false, 0, &WantsQueryInterface<mozilla::dom::TouchList>::Enabled
119 : };
120 :
121 : // Can't be const because the pref-enabled boolean needs to be writable
122 : static Prefable<const JSFunctionSpec> sMethods[] = {
123 : { nullptr, &sMethods_specs[0] },
124 : { &sMethods_disablers2, &sMethods_specs[2] },
125 : { nullptr, &sMethods_specs[4] },
126 : { nullptr, nullptr }
127 : };
128 :
129 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
130 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
131 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
132 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
133 :
134 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
135 : #if defined(__clang__)
136 : #pragma clang diagnostic push
137 : #pragma clang diagnostic ignored "-Wmissing-braces"
138 : #endif
139 : static const JSPropertySpec sAttributes_specs[] = {
140 : { "length", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &length_getterinfo, nullptr, nullptr },
141 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
142 : };
143 : #if defined(__clang__)
144 : #pragma clang diagnostic pop
145 : #endif
146 :
147 :
148 : // Can't be const because the pref-enabled boolean needs to be writable
149 : static Prefable<const JSPropertySpec> sAttributes[] = {
150 : { nullptr, &sAttributes_specs[0] },
151 : { nullptr, nullptr }
152 : };
153 :
154 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
155 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
156 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
157 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
158 :
159 :
160 : static uint16_t sNativeProperties_sortedPropertyIndices[4];
161 : static PropertyInfo sNativeProperties_propertyInfos[4];
162 :
163 : static const NativePropertiesN<2> sNativeProperties = {
164 : false, 0,
165 : false, 0,
166 : true, 0 /* sMethods */,
167 : true, 1 /* sAttributes */,
168 : false, 0,
169 : false, 0,
170 : false, 0,
171 : -1,
172 : 4,
173 : sNativeProperties_sortedPropertyIndices,
174 : {
175 : { sMethods, &sNativeProperties_propertyInfos[0] },
176 : { sAttributes, &sNativeProperties_propertyInfos[3] }
177 : }
178 : };
179 : static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
180 : "We have a property info count that is oversized");
181 :
182 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
183 : {
184 : "Function",
185 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
186 : &sBoringInterfaceObjectClassClassOps,
187 : JS_NULL_CLASS_SPEC,
188 : JS_NULL_CLASS_EXT,
189 : &sInterfaceObjectClassObjectOps
190 : },
191 : eInterface,
192 : true,
193 : prototypes::id::TouchList,
194 : PrototypeTraits<prototypes::id::TouchList>::Depth,
195 : sNativePropertyHooks,
196 : "function TouchList() {\n [native code]\n}",
197 : JS::GetRealmFunctionPrototype
198 : };
199 :
200 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
201 : {
202 : "TouchListPrototype",
203 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
204 : JS_NULL_CLASS_OPS,
205 : JS_NULL_CLASS_SPEC,
206 : JS_NULL_CLASS_EXT,
207 : JS_NULL_OBJECT_OPS
208 : },
209 : eInterfacePrototype,
210 : false,
211 : prototypes::id::TouchList,
212 : PrototypeTraits<prototypes::id::TouchList>::Depth,
213 : sNativePropertyHooks,
214 : "[object TouchListPrototype]",
215 : JS::GetRealmObjectPrototype
216 : };
217 :
218 : bool
219 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
220 : {
221 0 : return mozilla::dom::TouchList::PrefEnabled(aCx, aObj);
222 : }
223 :
224 : JSObject*
225 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
226 : {
227 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
228 : }
229 :
230 : static_assert(IsBaseOf<nsISupports, mozilla::dom::TouchList >::value,
231 : "We don't support non-nsISupports native classes for "
232 : "proxy-based bindings yet");
233 :
234 :
235 : class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
236 : {
237 : public:
238 : explicit constexpr DOMProxyHandler()
239 : {
240 : }
241 :
242 : virtual bool
243 : getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
244 :
245 : virtual bool
246 : defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
247 :
248 : using mozilla::dom::DOMProxyHandler::defineProperty;
249 :
250 : virtual bool
251 : ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
252 :
253 : virtual bool
254 : hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
255 :
256 : virtual bool
257 : get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
258 :
259 : virtual const char*
260 : className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
261 :
262 : virtual bool
263 : finalizeInBackground(const JS::Value& priv) const override;
264 :
265 : virtual void
266 : finalize(JSFreeOp* fop, JSObject* proxy) const override;
267 :
268 : static const DOMProxyHandler*
269 : getInstance();
270 :
271 : virtual bool
272 : delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
273 :
274 : virtual bool
275 : getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
276 : };
277 :
278 : MOZ_ALWAYS_INLINE bool
279 0 : IsProxy(JSObject* obj)
280 : {
281 0 : return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
282 : }
283 :
284 : MOZ_ALWAYS_INLINE mozilla::dom::TouchList*
285 0 : UnwrapProxy(JSObject* obj)
286 : {
287 0 : MOZ_ASSERT(js::IsProxy(obj));
288 0 : if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
289 0 : MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
290 0 : obj = js::UncheckedUnwrap(obj);
291 : }
292 0 : MOZ_ASSERT(IsProxy(obj));
293 0 : return static_cast<mozilla::dom::TouchList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
294 : }
295 :
296 : bool
297 0 : DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
298 : {
299 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
300 0 : uint32_t index = GetArrayIndexFromId(cx, id);
301 0 : if (IsArrayIndex(index)) {
302 0 : mozilla::dom::TouchList* self = UnwrapProxy(proxy);
303 0 : bool found = false;
304 0 : auto result(StrongOrRawPtr<mozilla::dom::Touch>(self->IndexedGetter(index, found)));
305 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
306 :
307 0 : if (found) {
308 0 : if (!result) {
309 0 : desc.value().setNull();
310 0 : FillPropertyDescriptor(desc, proxy, true);
311 0 : return true;
312 : }
313 0 : if (!GetOrCreateDOMReflector(cx, result, desc.value())) {
314 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
315 0 : return false;
316 : }
317 0 : FillPropertyDescriptor(desc, proxy, true);
318 0 : return true;
319 : }
320 : }
321 :
322 0 : JS::Rooted<JSObject*> expando(cx);
323 0 : if (!isXray && (expando = GetExpandoObject(proxy))) {
324 0 : if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
325 0 : return false;
326 : }
327 0 : if (desc.object()) {
328 : // Pretend the property lives on the wrapper.
329 0 : desc.object().set(proxy);
330 0 : return true;
331 : }
332 : }
333 :
334 0 : desc.object().set(nullptr);
335 0 : return true;
336 : }
337 :
338 : bool
339 0 : DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
340 : {
341 0 : if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
342 0 : *defined = true;
343 0 : return opresult.failNoIndexedSetter();
344 : }
345 0 : return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined);
346 : }
347 :
348 :
349 : bool
350 0 : DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
351 : {
352 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
353 :
354 0 : uint32_t length = UnwrapProxy(proxy)->Length();
355 0 : MOZ_ASSERT(int32_t(length) >= 0);
356 0 : for (int32_t i = 0; i < int32_t(length); ++i) {
357 0 : if (!props.append(INT_TO_JSID(i))) {
358 0 : return false;
359 : }
360 : }
361 :
362 0 : JS::Rooted<JSObject*> expando(cx);
363 0 : if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
364 0 : !js::GetPropertyKeys(cx, expando, flags, &props)) {
365 0 : return false;
366 : }
367 :
368 0 : return true;
369 : }
370 :
371 : bool
372 0 : DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
373 : {
374 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
375 : "Should not have a XrayWrapper here");
376 :
377 0 : uint32_t index = GetArrayIndexFromId(cx, id);
378 0 : if (IsArrayIndex(index)) {
379 0 : bool found = false;
380 0 : mozilla::dom::TouchList* self = UnwrapProxy(proxy);
381 0 : auto result(StrongOrRawPtr<mozilla::dom::Touch>(self->IndexedGetter(index, found)));
382 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
383 : (void)result;
384 :
385 0 : *bp = found;
386 0 : return true;
387 : }
388 :
389 :
390 0 : JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
391 0 : if (expando) {
392 0 : bool b = true;
393 0 : bool ok = JS_HasPropertyById(cx, expando, id, &b);
394 0 : *bp = !!b;
395 0 : if (!ok || *bp) {
396 0 : return ok;
397 : }
398 : }
399 :
400 0 : *bp = false;
401 0 : return true;
402 : }
403 :
404 : bool
405 0 : DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
406 : {
407 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
408 : "Should not have a XrayWrapper here");
409 :
410 0 : uint32_t index = GetArrayIndexFromId(cx, id);
411 0 : if (IsArrayIndex(index)) {
412 0 : mozilla::dom::TouchList* self = UnwrapProxy(proxy);
413 0 : bool found = false;
414 0 : auto result(StrongOrRawPtr<mozilla::dom::Touch>(self->IndexedGetter(index, found)));
415 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
416 :
417 0 : if (found) {
418 0 : if (!result) {
419 0 : vp.setNull();
420 0 : return true;
421 : }
422 0 : if (!GetOrCreateDOMReflector(cx, result, vp)) {
423 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
424 0 : return false;
425 : }
426 0 : return true;
427 : }
428 : // Even if we don't have this index, we don't forward the
429 : // get on to our expando object.
430 : } else {
431 : { // Scope for expando
432 0 : JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
433 0 : if (expando) {
434 : bool hasProp;
435 0 : if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
436 0 : return false;
437 : }
438 :
439 0 : if (hasProp) {
440 : // Forward the get to the expando object, but our receiver is whatever our
441 : // receiver is.
442 0 : return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp);
443 : }
444 : }
445 : }
446 : }
447 :
448 : bool foundOnPrototype;
449 0 : if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
450 0 : return false;
451 : }
452 :
453 0 : if (foundOnPrototype) {
454 0 : return true;
455 : }
456 :
457 0 : vp.setUndefined();
458 0 : return true;
459 : }
460 :
461 : const char*
462 0 : DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
463 : {
464 0 : return "TouchList";
465 : }
466 :
467 : bool
468 0 : DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
469 : {
470 0 : return false;
471 : }
472 :
473 : void
474 0 : DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
475 : {
476 0 : mozilla::dom::TouchList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::TouchList>(proxy);
477 0 : if (self) {
478 0 : ClearWrapper(self, self, proxy);
479 0 : AddForDeferredFinalization<mozilla::dom::TouchList>(self);
480 : }
481 0 : }
482 :
483 : const DOMProxyHandler*
484 0 : DOMProxyHandler::getInstance()
485 : {
486 : static const DOMProxyHandler instance;
487 0 : return &instance;
488 : }
489 :
490 : bool
491 0 : DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
492 : {
493 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
494 : "Should not have a XrayWrapper here");
495 :
496 0 : uint32_t index = GetArrayIndexFromId(cx, id);
497 0 : if (IsArrayIndex(index)) {
498 : bool deleteSucceeded;
499 0 : bool found = false;
500 0 : mozilla::dom::TouchList* self = UnwrapProxy(proxy);
501 0 : auto result(StrongOrRawPtr<mozilla::dom::Touch>(self->IndexedGetter(index, found)));
502 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
503 : (void)result;
504 0 : deleteSucceeded = !found;
505 0 : return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
506 : }
507 :
508 0 : return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
509 : }
510 :
511 : bool
512 0 : DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
513 : {
514 0 : JS::Rooted<JS::Value> temp(cx);
515 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
516 : "Should not have a XrayWrapper here");
517 :
518 0 : mozilla::dom::TouchList* self = UnwrapProxy(proxy);
519 0 : uint32_t length = self->Length();
520 : // Compute the end of the indices we'll get ourselves
521 0 : uint32_t ourEnd = std::max(begin, std::min(end, length));
522 :
523 0 : for (uint32_t index = begin; index < ourEnd; ++index) {
524 0 : bool found = false;
525 0 : auto result(StrongOrRawPtr<mozilla::dom::Touch>(self->IndexedGetter(index, found)));
526 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
527 :
528 0 : MOZ_ASSERT(found);
529 0 : if (!result) {
530 0 : temp.setNull();
531 0 : if (!adder->append(cx, temp)) return false;
532 0 : continue;
533 : }
534 0 : if (!GetOrCreateDOMReflector(cx, result, &temp)) {
535 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
536 0 : return false;
537 : }
538 0 : if (!adder->append(cx, temp)) return false;
539 0 : continue;
540 : }
541 :
542 0 : if (end > ourEnd) {
543 0 : JS::Rooted<JSObject*> proto(cx);
544 0 : if (!js::GetObjectProto(cx, proxy, &proto)) {
545 0 : return false;
546 : }
547 0 : return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
548 : }
549 :
550 0 : return true;
551 : }
552 :
553 : static const js::ClassExtension sClassExtension = PROXY_MAKE_EXT(
554 : _objectMoved
555 : );
556 :
557 : static const DOMJSClass sClass = {
558 : PROXY_CLASS_WITH_EXT("TouchList",
559 : JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
560 : &sClassExtension),
561 : { prototypes::id::TouchList, 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 },
562 : IsBaseOf<nsISupports, mozilla::dom::TouchList >::value,
563 : sNativePropertyHooks,
564 : FindAssociatedGlobalForNative<mozilla::dom::TouchList>::Get,
565 : GetProtoObjectHandle,
566 : GetCCParticipant<mozilla::dom::TouchList>::Get()
567 : };
568 :
569 : bool
570 0 : Wrap(JSContext* aCx, mozilla::dom::TouchList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
571 : {
572 : MOZ_ASSERT(static_cast<mozilla::dom::TouchList*>(aObject) ==
573 : reinterpret_cast<mozilla::dom::TouchList*>(aObject),
574 : "Multiple inheritance for mozilla::dom::TouchList is broken.");
575 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
576 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
577 0 : MOZ_ASSERT(!aCache->GetWrapper(),
578 : "You should probably not be using Wrap() directly; use "
579 : "GetOrCreateDOMReflector instead");
580 :
581 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
582 : "nsISupports must be on our primary inheritance chain");
583 :
584 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
585 0 : if (!global) {
586 0 : return false;
587 : }
588 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
589 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
590 :
591 : // That might have ended up wrapping us already, due to the wonders
592 : // of XBL. Check for that, and bail out as needed.
593 0 : aReflector.set(aCache->GetWrapper());
594 0 : if (aReflector) {
595 : #ifdef DEBUG
596 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
597 : #endif // DEBUG
598 0 : return true;
599 : }
600 :
601 0 : JSAutoCompartment ac(aCx, global);
602 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
603 0 : if (!canonicalProto) {
604 0 : return false;
605 : }
606 0 : JS::Rooted<JSObject*> proto(aCx);
607 0 : if (aGivenProto) {
608 0 : proto = aGivenProto;
609 : // Unfortunately, while aGivenProto was in the compartment of aCx
610 : // coming in, we changed compartments to that of "parent" so may need
611 : // to wrap the proto here.
612 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
613 0 : if (!JS_WrapObject(aCx, &proto)) {
614 0 : return false;
615 : }
616 : }
617 : } else {
618 0 : proto = canonicalProto;
619 : }
620 :
621 0 : BindingJSObjectCreator<mozilla::dom::TouchList> creator(aCx);
622 0 : JS::Rooted<JS::Value> expandoValue(aCx, JS::UndefinedValue());
623 0 : creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
624 0 : proto, aObject, expandoValue, aReflector);
625 0 : if (!aReflector) {
626 0 : return false;
627 : }
628 :
629 :
630 0 : aCache->SetWrapper(aReflector);
631 0 : creator.InitializationSucceeded();
632 :
633 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
634 : aCache->GetWrapperPreserveColor() == aReflector);
635 : // If proto != canonicalProto, we have to preserve our wrapper;
636 : // otherwise we won't be able to properly recreate it later, since
637 : // we won't know what proto to use. Note that we don't check
638 : // aGivenProto here, since it's entirely possible (and even
639 : // somewhat common) to have a non-null aGivenProto which is the
640 : // same as canonicalProto.
641 0 : if (proto != canonicalProto) {
642 0 : PreserveWrapper(aObject);
643 : }
644 :
645 0 : return true;
646 : }
647 :
648 : static bool
649 0 : ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
650 : {
651 0 : return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
652 : }
653 :
654 : static bool
655 0 : EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
656 : {
657 0 : return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
658 : }
659 :
660 : const NativePropertyHooks sNativePropertyHooks[] = { {
661 : ResolveOwnProperty,
662 : EnumerateOwnProperties,
663 : nullptr,
664 : { sNativeProperties.Upcast(), nullptr },
665 : prototypes::id::TouchList,
666 : constructors::id::TouchList,
667 : nullptr,
668 : &DefaultXrayExpandoObjectClass
669 : } };
670 :
671 : void
672 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
673 : {
674 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
675 0 : if (!parentProto) {
676 0 : return;
677 : }
678 :
679 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
680 0 : if (!constructorProto) {
681 0 : return;
682 : }
683 :
684 : static bool sIdsInited = false;
685 0 : if (!sIdsInited && NS_IsMainThread()) {
686 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
687 0 : return;
688 : }
689 0 : sIdsInited = true;
690 : }
691 :
692 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::TouchList);
693 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::TouchList);
694 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
695 : &sPrototypeClass.mBase, protoCache,
696 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
697 : interfaceCache,
698 : sNativeProperties.Upcast(),
699 : nullptr,
700 : "TouchList", aDefineOnGlobal,
701 : nullptr,
702 0 : false);
703 : }
704 :
705 : JS::Handle<JSObject*>
706 0 : GetProtoObjectHandle(JSContext* aCx)
707 : {
708 : /* Get the interface prototype object for this class. This will create the
709 : object as needed. */
710 0 : bool aDefineOnGlobal = true;
711 :
712 : /* Make sure our global is sane. Hopefully we can remove this sometime */
713 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
714 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
715 0 : return nullptr;
716 : }
717 :
718 : /* Check to see whether the interface objects are already installed */
719 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
720 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::TouchList)) {
721 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
722 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
723 : }
724 :
725 : /*
726 : * The object might _still_ be null, but that's OK.
727 : *
728 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
729 : * traced by TraceProtoAndIfaceCache() and its contents are never
730 : * changed after they have been set.
731 : *
732 : * Calling address() avoids the read read barrier that does gray
733 : * unmarking, but it's not possible for the object to be gray here.
734 : */
735 :
736 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::TouchList);
737 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
738 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
739 : }
740 :
741 : JS::Handle<JSObject*>
742 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
743 : {
744 : /* Get the interface object for this class. This will create the object as
745 : needed. */
746 :
747 : /* Make sure our global is sane. Hopefully we can remove this sometime */
748 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
749 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
750 0 : return nullptr;
751 : }
752 :
753 : /* Check to see whether the interface objects are already installed */
754 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
755 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::TouchList)) {
756 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
757 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
758 : }
759 :
760 : /*
761 : * The object might _still_ be null, but that's OK.
762 : *
763 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
764 : * traced by TraceProtoAndIfaceCache() and its contents are never
765 : * changed after they have been set.
766 : *
767 : * Calling address() avoids the read read barrier that does gray
768 : * unmarking, but it's not possible for the object to be gray here.
769 : */
770 :
771 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::TouchList);
772 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
773 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
774 : }
775 :
776 : JSObject*
777 0 : GetConstructorObject(JSContext* aCx)
778 : {
779 0 : return GetConstructorObjectHandle(aCx);
780 : }
781 :
782 : } // namespace TouchListBinding
783 :
784 :
785 :
786 : } // namespace dom
787 : } // namespace mozilla
|