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