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