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