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