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