/work/obj-fuzz/dom/bindings/DOMParserBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM DOMParser.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "DOMParserBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "jsapi.h" |
6 | | #include "jsfriendapi.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/dom/BindingUtils.h" |
9 | | #include "mozilla/dom/DOMJSClass.h" |
10 | | #include "mozilla/dom/DOMParser.h" |
11 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
12 | | #include "mozilla/dom/Nullable.h" |
13 | | #include "mozilla/dom/PrimitiveConversions.h" |
14 | | #include "mozilla/dom/TypedArray.h" |
15 | | #include "mozilla/dom/XrayExpandoClass.h" |
16 | | #include "nsContentUtils.h" |
17 | | #include "nsIDocument.h" |
18 | | #include "nsIInputStream.h" |
19 | | #include "nsISupports.h" |
20 | | #include "xpcjsid.h" |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | |
25 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
26 | | using namespace mozilla::dom::binding_detail; |
27 | | |
28 | | |
29 | | namespace SupportedTypeValues { |
30 | | extern const EnumEntry strings[6] = { |
31 | | {"text/html", 9}, |
32 | | {"text/xml", 8}, |
33 | | {"application/xml", 15}, |
34 | | {"application/xhtml+xml", 21}, |
35 | | {"image/svg+xml", 13}, |
36 | | { nullptr, 0 } |
37 | | }; |
38 | | } // namespace SupportedTypeValues |
39 | | |
40 | | bool |
41 | | ToJSValue(JSContext* aCx, SupportedType aArgument, JS::MutableHandle<JS::Value> aValue) |
42 | 0 | { |
43 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(SupportedTypeValues::strings)); |
44 | 0 | JSString* resultStr = |
45 | 0 | JS_NewStringCopyN(aCx, SupportedTypeValues::strings[uint32_t(aArgument)].value, |
46 | 0 | SupportedTypeValues::strings[uint32_t(aArgument)].length); |
47 | 0 | if (!resultStr) { |
48 | 0 | return false; |
49 | 0 | } |
50 | 0 | aValue.setString(resultStr); |
51 | 0 | return true; |
52 | 0 | } |
53 | | |
54 | | |
55 | | namespace DOMParser_Binding { |
56 | | |
57 | | MOZ_CAN_RUN_SCRIPT static bool |
58 | | parseFromString(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMParser* self, const JSJitMethodCallArgs& args) |
59 | 0 | { |
60 | 0 | AUTO_PROFILER_LABEL_FAST("DOMParser.parseFromString", DOM, cx); |
61 | 0 |
|
62 | 0 | if (MOZ_UNLIKELY(args.length() < 2)) { |
63 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DOMParser.parseFromString"); |
64 | 0 | } |
65 | 0 | binding_detail::FakeString arg0; |
66 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
67 | 0 | return false; |
68 | 0 | } |
69 | 0 | SupportedType arg1; |
70 | 0 | { |
71 | 0 | int index; |
72 | 0 | if (!FindEnumStringIndex<true>(cx, args[1], SupportedTypeValues::strings, "SupportedType", "Argument 2 of DOMParser.parseFromString", &index)) { |
73 | 0 | return false; |
74 | 0 | } |
75 | 0 | MOZ_ASSERT(index >= 0); |
76 | 0 | arg1 = static_cast<SupportedType>(index); |
77 | 0 | } |
78 | 0 | FastErrorResult rv; |
79 | 0 | auto result(StrongOrRawPtr<nsIDocument>(self->ParseFromString(NonNullHelper(Constify(arg0)), arg1, rv))); |
80 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
81 | 0 | return false; |
82 | 0 | } |
83 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
84 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
85 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
86 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
87 | 0 | MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing"); |
88 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
89 | 0 | return false; |
90 | 0 | } |
91 | 0 | return true; |
92 | 0 | } |
93 | | |
94 | | static const JSJitInfo parseFromString_methodinfo = { |
95 | | { (JSJitGetterOp)parseFromString }, |
96 | | { prototypes::id::DOMParser }, |
97 | | { PrototypeTraits<prototypes::id::DOMParser>::Depth }, |
98 | | JSJitInfo::Method, |
99 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
100 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
101 | | false, /* isInfallible. False in setters. */ |
102 | | false, /* isMovable. Not relevant for setters. */ |
103 | | false, /* isEliminatable. Not relevant for setters. */ |
104 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
105 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
106 | | false, /* isTypedMethod. Only relevant for methods. */ |
107 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
108 | | }; |
109 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
110 | | static_assert(0 < 1, "There is no slot for us"); |
111 | | |
112 | | MOZ_CAN_RUN_SCRIPT static bool |
113 | | parseFromBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMParser* self, const JSJitMethodCallArgs& args) |
114 | 0 | { |
115 | 0 | AUTO_PROFILER_LABEL_FAST("DOMParser.parseFromBuffer", DOM, cx); |
116 | 0 |
|
117 | 0 | unsigned argcount = std::min(args.length(), 2u); |
118 | 0 | switch (argcount) { |
119 | 0 | case 2: { |
120 | 0 | if (args[0].isObject()) { |
121 | 0 | do { |
122 | 0 | RootedSpiderMonkeyInterface<Uint8Array> arg0(cx); |
123 | 0 | if (!arg0.Init(&args[0].toObject())) { |
124 | 0 | break; |
125 | 0 | } |
126 | 0 | SupportedType arg1; |
127 | 0 | { |
128 | 0 | int index; |
129 | 0 | if (!FindEnumStringIndex<true>(cx, args[1], SupportedTypeValues::strings, "SupportedType", "Argument 2 of DOMParser.parseFromBuffer", &index)) { |
130 | 0 | return false; |
131 | 0 | } |
132 | 0 | MOZ_ASSERT(index >= 0); |
133 | 0 | arg1 = static_cast<SupportedType>(index); |
134 | 0 | } |
135 | 0 | FastErrorResult rv; |
136 | 0 | auto result(StrongOrRawPtr<nsIDocument>(self->ParseFromBuffer(Constify(arg0), arg1, rv))); |
137 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
138 | 0 | return false; |
139 | 0 | } |
140 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
141 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
142 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
143 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
144 | 0 | MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing"); |
145 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
146 | 0 | return false; |
147 | 0 | } |
148 | 0 | return true; |
149 | 0 | } while (false); |
150 | 0 | do { |
151 | 0 | binding_detail::AutoSequence<uint8_t> arg0; |
152 | 0 | JS::ForOfIterator iter(cx); |
153 | 0 | if (!iter.init(args[0], JS::ForOfIterator::AllowNonIterable)) { |
154 | 0 | return false; |
155 | 0 | } |
156 | 0 | if (!iter.valueIsIterable()) { |
157 | 0 | break; |
158 | 0 | } |
159 | 0 | binding_detail::AutoSequence<uint8_t> &arr = arg0; |
160 | 0 | JS::Rooted<JS::Value> temp(cx); |
161 | 0 | while (true) { |
162 | 0 | bool done; |
163 | 0 | if (!iter.next(&temp, &done)) { |
164 | 0 | return false; |
165 | 0 | } |
166 | 0 | if (done) { |
167 | 0 | break; |
168 | 0 | } |
169 | 0 | uint8_t* slotPtr = arr.AppendElement(mozilla::fallible); |
170 | 0 | if (!slotPtr) { |
171 | 0 | JS_ReportOutOfMemory(cx); |
172 | 0 | return false; |
173 | 0 | } |
174 | 0 | uint8_t& slot = *slotPtr; |
175 | 0 | if (!ValueToPrimitive<uint8_t, eDefault>(cx, temp, &slot)) { |
176 | 0 | return false; |
177 | 0 | } |
178 | 0 | } |
179 | 0 | SupportedType arg1; |
180 | 0 | { |
181 | 0 | int index; |
182 | 0 | if (!FindEnumStringIndex<true>(cx, args[1], SupportedTypeValues::strings, "SupportedType", "Argument 2 of DOMParser.parseFromBuffer", &index)) { |
183 | 0 | return false; |
184 | 0 | } |
185 | 0 | MOZ_ASSERT(index >= 0); |
186 | 0 | arg1 = static_cast<SupportedType>(index); |
187 | 0 | } |
188 | 0 | FastErrorResult rv; |
189 | 0 | auto result(StrongOrRawPtr<nsIDocument>(self->ParseFromBuffer(Constify(arg0), arg1, rv))); |
190 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
191 | 0 | return false; |
192 | 0 | } |
193 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
194 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
195 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
196 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
197 | 0 | MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing"); |
198 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
199 | 0 | return false; |
200 | 0 | } |
201 | 0 | return true; |
202 | 0 | } while (false); |
203 | 0 | } |
204 | 0 | return ThrowErrorMessage(cx, MSG_OVERLOAD_RESOLUTION_FAILED, "1", "2", "DOMParser.parseFromBuffer"); |
205 | 0 | break; |
206 | 0 | } |
207 | 0 | default: { |
208 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DOMParser.parseFromBuffer"); |
209 | 0 | break; |
210 | 0 | } |
211 | 0 | } |
212 | 0 | MOZ_CRASH("We have an always-returning default case"); |
213 | 0 | return false; |
214 | 0 | } |
215 | | |
216 | | static const JSJitInfo parseFromBuffer_methodinfo = { |
217 | | { (JSJitGetterOp)parseFromBuffer }, |
218 | | { prototypes::id::DOMParser }, |
219 | | { PrototypeTraits<prototypes::id::DOMParser>::Depth }, |
220 | | JSJitInfo::Method, |
221 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
222 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
223 | | false, /* isInfallible. False in setters. */ |
224 | | false, /* isMovable. Not relevant for setters. */ |
225 | | false, /* isEliminatable. Not relevant for setters. */ |
226 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
227 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
228 | | false, /* isTypedMethod. Only relevant for methods. */ |
229 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
230 | | }; |
231 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
232 | | static_assert(0 < 1, "There is no slot for us"); |
233 | | |
234 | | MOZ_CAN_RUN_SCRIPT static bool |
235 | | parseFromStream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMParser* self, const JSJitMethodCallArgs& args) |
236 | 0 | { |
237 | 0 | AUTO_PROFILER_LABEL_FAST("DOMParser.parseFromStream", DOM, cx); |
238 | 0 |
|
239 | 0 | if (MOZ_UNLIKELY(args.length() < 4)) { |
240 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DOMParser.parseFromStream"); |
241 | 0 | } |
242 | 0 | nsIInputStream* arg0; |
243 | 0 | RefPtr<nsIInputStream> arg0_holder; |
244 | 0 | if (args[0].isObject()) { |
245 | 0 | JS::Rooted<JSObject*> source(cx, &args[0].toObject()); |
246 | 0 | if (NS_FAILED(UnwrapArg<nsIInputStream>(cx, source, getter_AddRefs(arg0_holder)))) { |
247 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of DOMParser.parseFromStream", "InputStream"); |
248 | 0 | return false; |
249 | 0 | } |
250 | 0 | MOZ_ASSERT(arg0_holder); |
251 | 0 | arg0 = arg0_holder; |
252 | 0 | } else { |
253 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of DOMParser.parseFromStream"); |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | binding_detail::FakeString arg1; |
257 | 0 | if (!ConvertJSValueToString(cx, args[1], eNull, eNull, arg1)) { |
258 | 0 | return false; |
259 | 0 | } |
260 | 0 | int32_t arg2; |
261 | 0 | if (!ValueToPrimitive<int32_t, eDefault>(cx, args[2], &arg2)) { |
262 | 0 | return false; |
263 | 0 | } |
264 | 0 | SupportedType arg3; |
265 | 0 | { |
266 | 0 | int index; |
267 | 0 | if (!FindEnumStringIndex<true>(cx, args[3], SupportedTypeValues::strings, "SupportedType", "Argument 4 of DOMParser.parseFromStream", &index)) { |
268 | 0 | return false; |
269 | 0 | } |
270 | 0 | MOZ_ASSERT(index >= 0); |
271 | 0 | arg3 = static_cast<SupportedType>(index); |
272 | 0 | } |
273 | 0 | FastErrorResult rv; |
274 | 0 | auto result(StrongOrRawPtr<nsIDocument>(self->ParseFromStream(MOZ_KnownLive(NonNullHelper(arg0)), NonNullHelper(Constify(arg1)), arg2, arg3, rv))); |
275 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
276 | 0 | return false; |
277 | 0 | } |
278 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
279 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
280 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
281 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
282 | 0 | MOZ_CRASH("Looks like bug 1488480/1405521, with getting the reflector failing"); |
283 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
284 | 0 | return false; |
285 | 0 | } |
286 | 0 | return true; |
287 | 0 | } |
288 | | |
289 | | static const JSJitInfo parseFromStream_methodinfo = { |
290 | | { (JSJitGetterOp)parseFromStream }, |
291 | | { prototypes::id::DOMParser }, |
292 | | { PrototypeTraits<prototypes::id::DOMParser>::Depth }, |
293 | | JSJitInfo::Method, |
294 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
295 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
296 | | false, /* isInfallible. False in setters. */ |
297 | | false, /* isMovable. Not relevant for setters. */ |
298 | | false, /* isEliminatable. Not relevant for setters. */ |
299 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
300 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
301 | | false, /* isTypedMethod. Only relevant for methods. */ |
302 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
303 | | }; |
304 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
305 | | static_assert(0 < 1, "There is no slot for us"); |
306 | | |
307 | | MOZ_CAN_RUN_SCRIPT static bool |
308 | | forceEnableXULXBL(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DOMParser* self, const JSJitMethodCallArgs& args) |
309 | 0 | { |
310 | 0 | AUTO_PROFILER_LABEL_FAST("DOMParser.forceEnableXULXBL", DOM, cx); |
311 | 0 |
|
312 | 0 | self->ForceEnableXULXBL(); |
313 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
314 | 0 | args.rval().setUndefined(); |
315 | 0 | return true; |
316 | 0 | } |
317 | | |
318 | | static const JSJitInfo forceEnableXULXBL_methodinfo = { |
319 | | { (JSJitGetterOp)forceEnableXULXBL }, |
320 | | { prototypes::id::DOMParser }, |
321 | | { PrototypeTraits<prototypes::id::DOMParser>::Depth }, |
322 | | JSJitInfo::Method, |
323 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
324 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
325 | | true, /* isInfallible. False in setters. */ |
326 | | false, /* isMovable. Not relevant for setters. */ |
327 | | false, /* isEliminatable. Not relevant for setters. */ |
328 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
329 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
330 | | false, /* isTypedMethod. Only relevant for methods. */ |
331 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
332 | | }; |
333 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
334 | | static_assert(0 < 1, "There is no slot for us"); |
335 | | |
336 | | static bool |
337 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
338 | 0 | { |
339 | 0 | mozilla::dom::DOMParser* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMParser>(obj); |
340 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
341 | 0 | // obviously can't preserve if we're not initialized. |
342 | 0 | if (self && self->GetWrapperPreserveColor()) { |
343 | 0 | PreserveWrapper(self); |
344 | 0 | } |
345 | 0 | return true; |
346 | 0 | } |
347 | | |
348 | | static void |
349 | | _finalize(js::FreeOp* fop, JSObject* obj) |
350 | 0 | { |
351 | 0 | mozilla::dom::DOMParser* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMParser>(obj); |
352 | 0 | if (self) { |
353 | 0 | ClearWrapper(self, self, obj); |
354 | 0 | AddForDeferredFinalization<mozilla::dom::DOMParser>(self); |
355 | 0 | } |
356 | 0 | } |
357 | | |
358 | | static size_t |
359 | | _objectMoved(JSObject* obj, JSObject* old) |
360 | 0 | { |
361 | 0 | mozilla::dom::DOMParser* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DOMParser>(obj); |
362 | 0 | if (self) { |
363 | 0 | UpdateWrapper(self, self, obj, old); |
364 | 0 | } |
365 | 0 |
|
366 | 0 | return 0; |
367 | 0 | } |
368 | | |
369 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
370 | | #if defined(__clang__) |
371 | | #pragma clang diagnostic push |
372 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
373 | | #endif |
374 | | static const JSFunctionSpec sMethods_specs[] = { |
375 | | JS_FNSPEC("parseFromString", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&parseFromString_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
376 | | JS_FS_END |
377 | | }; |
378 | | #if defined(__clang__) |
379 | | #pragma clang diagnostic pop |
380 | | #endif |
381 | | |
382 | | |
383 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
384 | | { nullptr, &sMethods_specs[0] }, |
385 | | { nullptr, nullptr } |
386 | | }; |
387 | | |
388 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
389 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
390 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
391 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
392 | | |
393 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
394 | | #if defined(__clang__) |
395 | | #pragma clang diagnostic push |
396 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
397 | | #endif |
398 | | static const JSFunctionSpec sChromeMethods_specs[] = { |
399 | | JS_FNSPEC("parseFromBuffer", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&parseFromBuffer_methodinfo), 2, JSPROP_ENUMERATE, nullptr), |
400 | | JS_FNSPEC("parseFromStream", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&parseFromStream_methodinfo), 4, JSPROP_ENUMERATE, nullptr), |
401 | | JS_FNSPEC("forceEnableXULXBL", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&forceEnableXULXBL_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
402 | | JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr), |
403 | | JS_FS_END |
404 | | }; |
405 | | #if defined(__clang__) |
406 | | #pragma clang diagnostic pop |
407 | | #endif |
408 | | |
409 | | |
410 | | static const Prefable<const JSFunctionSpec> sChromeMethods[] = { |
411 | | { nullptr, &sChromeMethods_specs[0] }, |
412 | | { nullptr, nullptr } |
413 | | }; |
414 | | |
415 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
416 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
417 | | static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
418 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
419 | | |
420 | | |
421 | | static uint16_t sNativeProperties_sortedPropertyIndices[1]; |
422 | | static PropertyInfo sNativeProperties_propertyInfos[1]; |
423 | | |
424 | | static const NativePropertiesN<1> sNativeProperties = { |
425 | | false, 0, |
426 | | false, 0, |
427 | | true, 0 /* sMethods */, |
428 | | false, 0, |
429 | | false, 0, |
430 | | false, 0, |
431 | | false, 0, |
432 | | -1, |
433 | | 1, |
434 | | sNativeProperties_sortedPropertyIndices, |
435 | | { |
436 | | { sMethods, &sNativeProperties_propertyInfos[0] } |
437 | | } |
438 | | }; |
439 | | static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
440 | | "We have a property info count that is oversized"); |
441 | | |
442 | | static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[4]; |
443 | | static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[4]; |
444 | | |
445 | | static const NativePropertiesN<1> sChromeOnlyNativeProperties = { |
446 | | false, 0, |
447 | | false, 0, |
448 | | true, 0 /* sChromeMethods */, |
449 | | false, 0, |
450 | | false, 0, |
451 | | false, 0, |
452 | | false, 0, |
453 | | -1, |
454 | | 4, |
455 | | sChromeOnlyNativeProperties_sortedPropertyIndices, |
456 | | { |
457 | | { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] } |
458 | | } |
459 | | }; |
460 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount), |
461 | | "We have a property info count that is oversized"); |
462 | | |
463 | | static bool |
464 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
465 | 0 | { |
466 | 0 | AUTO_PROFILER_LABEL_FAST("DOMParser constructor", DOM, cx); |
467 | 0 |
|
468 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
469 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
470 | 0 | if (!args.isConstructing()) { |
471 | 0 | // XXXbz wish I could get the name from the callee instead of |
472 | 0 | // Adding more relocations |
473 | 0 | return ThrowConstructorWithoutNew(cx, "DOMParser"); |
474 | 0 | } |
475 | 0 | |
476 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
477 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
478 | 0 | return false; |
479 | 0 | } |
480 | 0 | |
481 | 0 | GlobalObject global(cx, obj); |
482 | 0 | if (global.Failed()) { |
483 | 0 | return false; |
484 | 0 | } |
485 | 0 | |
486 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
487 | 0 | Maybe<JSAutoRealm> ar; |
488 | 0 | if (objIsXray) { |
489 | 0 | obj = js::CheckedUnwrap(obj); |
490 | 0 | if (!obj) { |
491 | 0 | return false; |
492 | 0 | } |
493 | 0 | ar.emplace(cx, obj); |
494 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
495 | 0 | return false; |
496 | 0 | } |
497 | 0 | } |
498 | 0 | FastErrorResult rv; |
499 | 0 | auto result(StrongOrRawPtr<mozilla::dom::DOMParser>(mozilla::dom::DOMParser::Constructor(global, rv))); |
500 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
501 | 0 | return false; |
502 | 0 | } |
503 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
504 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
505 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
506 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
507 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
508 | 0 | return false; |
509 | 0 | } |
510 | 0 | return true; |
511 | 0 | } |
512 | | |
513 | | static const js::ClassOps sInterfaceObjectClassOps = { |
514 | | nullptr, /* addProperty */ |
515 | | nullptr, /* delProperty */ |
516 | | nullptr, /* enumerate */ |
517 | | nullptr, /* newEnumerate */ |
518 | | nullptr, /* resolve */ |
519 | | nullptr, /* mayResolve */ |
520 | | nullptr, /* finalize */ |
521 | | _constructor, /* call */ |
522 | | nullptr, /* hasInstance */ |
523 | | _constructor, /* construct */ |
524 | | nullptr, /* trace */ |
525 | | }; |
526 | | |
527 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
528 | | { |
529 | | "Function", |
530 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
531 | | &sInterfaceObjectClassOps, |
532 | | JS_NULL_CLASS_SPEC, |
533 | | JS_NULL_CLASS_EXT, |
534 | | &sInterfaceObjectClassObjectOps |
535 | | }, |
536 | | eInterface, |
537 | | true, |
538 | | prototypes::id::DOMParser, |
539 | | PrototypeTraits<prototypes::id::DOMParser>::Depth, |
540 | | sNativePropertyHooks, |
541 | | "function DOMParser() {\n [native code]\n}", |
542 | | JS::GetRealmFunctionPrototype |
543 | | }; |
544 | | |
545 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
546 | | { |
547 | | "DOMParserPrototype", |
548 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
549 | | JS_NULL_CLASS_OPS, |
550 | | JS_NULL_CLASS_SPEC, |
551 | | JS_NULL_CLASS_EXT, |
552 | | JS_NULL_OBJECT_OPS |
553 | | }, |
554 | | eInterfacePrototype, |
555 | | false, |
556 | | prototypes::id::DOMParser, |
557 | | PrototypeTraits<prototypes::id::DOMParser>::Depth, |
558 | | sNativePropertyHooks, |
559 | | "[object DOMParserPrototype]", |
560 | | JS::GetRealmObjectPrototype |
561 | | }; |
562 | | |
563 | | static const js::ClassOps sClassOps = { |
564 | | _addProperty, /* addProperty */ |
565 | | nullptr, /* delProperty */ |
566 | | nullptr, /* enumerate */ |
567 | | nullptr, /* newEnumerate */ |
568 | | nullptr, /* resolve */ |
569 | | nullptr, /* mayResolve */ |
570 | | _finalize, /* finalize */ |
571 | | nullptr, /* call */ |
572 | | nullptr, /* hasInstance */ |
573 | | nullptr, /* construct */ |
574 | | nullptr, /* trace */ |
575 | | }; |
576 | | |
577 | | static const js::ClassExtension sClassExtension = { |
578 | | nullptr, /* weakmapKeyDelegateOp */ |
579 | | _objectMoved /* objectMovedOp */ |
580 | | }; |
581 | | |
582 | | static const DOMJSClass sClass = { |
583 | | { "DOMParser", |
584 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
585 | | &sClassOps, |
586 | | JS_NULL_CLASS_SPEC, |
587 | | &sClassExtension, |
588 | | JS_NULL_OBJECT_OPS |
589 | | }, |
590 | | { prototypes::id::DOMParser, 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 }, |
591 | | IsBaseOf<nsISupports, mozilla::dom::DOMParser >::value, |
592 | | sNativePropertyHooks, |
593 | | FindAssociatedGlobalForNative<mozilla::dom::DOMParser>::Get, |
594 | | GetProtoObjectHandle, |
595 | | GetCCParticipant<mozilla::dom::DOMParser>::Get() |
596 | | }; |
597 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
598 | | "Must have the right minimal number of reserved slots."); |
599 | | static_assert(1 >= 1, |
600 | | "Must have enough reserved slots."); |
601 | | |
602 | | const JSClass* |
603 | | GetJSClass() |
604 | 0 | { |
605 | 0 | return sClass.ToJSClass(); |
606 | 0 | } |
607 | | |
608 | | bool |
609 | | Wrap(JSContext* aCx, mozilla::dom::DOMParser* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
610 | 0 | { |
611 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DOMParser>::value, |
612 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
613 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::DOMParser*>(aObject) == |
614 | 0 | reinterpret_cast<mozilla::dom::DOMParser*>(aObject), |
615 | 0 | "Multiple inheritance for mozilla::dom::DOMParser is broken."); |
616 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
617 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
618 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
619 | 0 | "You should probably not be using Wrap() directly; use " |
620 | 0 | "GetOrCreateDOMReflector instead"); |
621 | 0 |
|
622 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
623 | 0 | "nsISupports must be on our primary inheritance chain"); |
624 | 0 |
|
625 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
626 | 0 | if (!global) { |
627 | 0 | return false; |
628 | 0 | } |
629 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
630 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
631 | 0 |
|
632 | 0 | // That might have ended up wrapping us already, due to the wonders |
633 | 0 | // of XBL. Check for that, and bail out as needed. |
634 | 0 | aReflector.set(aCache->GetWrapper()); |
635 | 0 | if (aReflector) { |
636 | | #ifdef DEBUG |
637 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
638 | | #endif // DEBUG |
639 | | return true; |
640 | 0 | } |
641 | 0 |
|
642 | 0 | JSAutoRealm ar(aCx, global); |
643 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
644 | 0 | if (!canonicalProto) { |
645 | 0 | return false; |
646 | 0 | } |
647 | 0 | JS::Rooted<JSObject*> proto(aCx); |
648 | 0 | if (aGivenProto) { |
649 | 0 | proto = aGivenProto; |
650 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
651 | 0 | // coming in, we changed compartments to that of "parent" so may need |
652 | 0 | // to wrap the proto here. |
653 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
654 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
655 | 0 | return false; |
656 | 0 | } |
657 | 0 | } |
658 | 0 | } else { |
659 | 0 | proto = canonicalProto; |
660 | 0 | } |
661 | 0 |
|
662 | 0 | BindingJSObjectCreator<mozilla::dom::DOMParser> creator(aCx); |
663 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
664 | 0 | if (!aReflector) { |
665 | 0 | return false; |
666 | 0 | } |
667 | 0 | |
668 | 0 | aCache->SetWrapper(aReflector); |
669 | 0 | creator.InitializationSucceeded(); |
670 | 0 |
|
671 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
672 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
673 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
674 | 0 | // otherwise we won't be able to properly recreate it later, since |
675 | 0 | // we won't know what proto to use. Note that we don't check |
676 | 0 | // aGivenProto here, since it's entirely possible (and even |
677 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
678 | 0 | // same as canonicalProto. |
679 | 0 | if (proto != canonicalProto) { |
680 | 0 | PreserveWrapper(aObject); |
681 | 0 | } |
682 | 0 |
|
683 | 0 | return true; |
684 | 0 | } |
685 | | |
686 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
687 | | nullptr, |
688 | | nullptr, |
689 | | nullptr, |
690 | | { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() }, |
691 | | prototypes::id::DOMParser, |
692 | | constructors::id::DOMParser, |
693 | | nullptr, |
694 | | &DefaultXrayExpandoObjectClass |
695 | | } }; |
696 | | |
697 | | void |
698 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
699 | 0 | { |
700 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
701 | 0 | if (!parentProto) { |
702 | 0 | return; |
703 | 0 | } |
704 | 0 | |
705 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
706 | 0 | if (!constructorProto) { |
707 | 0 | return; |
708 | 0 | } |
709 | 0 | |
710 | 0 | static bool sIdsInited = false; |
711 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
712 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
713 | 0 | return; |
714 | 0 | } |
715 | 0 | if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) { |
716 | 0 | return; |
717 | 0 | } |
718 | 0 | sIdsInited = true; |
719 | 0 | } |
720 | 0 |
|
721 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DOMParser); |
722 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DOMParser); |
723 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
724 | 0 | &sPrototypeClass.mBase, protoCache, |
725 | 0 | nullptr, |
726 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
727 | 0 | interfaceCache, |
728 | 0 | sNativeProperties.Upcast(), |
729 | 0 | sChromeOnlyNativeProperties.Upcast(), |
730 | 0 | "DOMParser", aDefineOnGlobal, |
731 | 0 | nullptr, |
732 | 0 | false); |
733 | 0 | } |
734 | | |
735 | | JSObject* |
736 | | GetConstructorObject(JSContext* aCx) |
737 | 0 | { |
738 | 0 | return GetConstructorObjectHandle(aCx); |
739 | 0 | } |
740 | | |
741 | | } // namespace DOMParser_Binding |
742 | | |
743 | | |
744 | | |
745 | | } // namespace dom |
746 | | } // namespace mozilla |