Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM Response.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "FetchBinding.h"
5 : #include "ResponseBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "jsapi.h"
8 : #include "mozilla/OwningNonNull.h"
9 : #include "mozilla/dom/BindingUtils.h"
10 : #include "mozilla/dom/DOMJSClass.h"
11 : #include "mozilla/dom/Headers.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/Promise.h"
15 : #include "mozilla/dom/Response.h"
16 : #include "mozilla/dom/ScriptSettings.h"
17 : #include "mozilla/dom/ToJSValue.h"
18 : #include "mozilla/dom/UnionConversions.h"
19 : #include "mozilla/dom/XrayExpandoClass.h"
20 : #include "nsContentUtils.h"
21 :
22 : namespace mozilla {
23 : namespace dom {
24 :
25 : namespace ResponseTypeValues {
26 : extern const EnumEntry strings[7] = {
27 : {"basic", 5},
28 : {"cors", 4},
29 : {"default", 7},
30 : {"error", 5},
31 : {"opaque", 6},
32 : {"opaqueredirect", 14},
33 : { nullptr, 0 }
34 : };
35 : } // namespace ResponseTypeValues
36 :
37 : bool
38 0 : ToJSValue(JSContext* aCx, ResponseType aArgument, JS::MutableHandle<JS::Value> aValue)
39 : {
40 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(ResponseTypeValues::strings));
41 : JSString* resultStr =
42 0 : JS_NewStringCopyN(aCx, ResponseTypeValues::strings[uint32_t(aArgument)].value,
43 0 : ResponseTypeValues::strings[uint32_t(aArgument)].length);
44 0 : if (!resultStr) {
45 0 : return false;
46 : }
47 0 : aValue.setString(resultStr);
48 0 : return true;
49 : }
50 :
51 :
52 :
53 0 : ResponseInit::ResponseInit()
54 : {
55 : // Safe to pass a null context if we pass a null value
56 0 : Init(nullptr, JS::NullHandleValue);
57 0 : }
58 :
59 :
60 : bool
61 0 : ResponseInit::InitIds(JSContext* cx, ResponseInitAtoms* atomsCache)
62 : {
63 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
64 :
65 : // Initialize these in reverse order so that any failure leaves the first one
66 : // uninitialized.
67 0 : if (!atomsCache->statusText_id.init(cx, "statusText") ||
68 0 : !atomsCache->status_id.init(cx, "status") ||
69 0 : !atomsCache->headers_id.init(cx, "headers")) {
70 0 : return false;
71 : }
72 0 : return true;
73 : }
74 :
75 : bool
76 0 : ResponseInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
77 : {
78 : // Passing a null JSContext is OK only if we're initing from null,
79 : // Since in that case we will not have to do any property gets
80 : // Also evaluate isNullOrUndefined in order to avoid false-positive
81 : // checkers by static analysis tools
82 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
83 0 : ResponseInitAtoms* atomsCache = nullptr;
84 0 : if (cx) {
85 0 : atomsCache = GetAtomCache<ResponseInitAtoms>(cx);
86 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
87 0 : return false;
88 : }
89 : }
90 :
91 0 : if (!IsConvertibleToDictionary(val)) {
92 0 : return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
93 : }
94 :
95 0 : bool isNull = val.isNullOrUndefined();
96 : // We only need these if !isNull, in which case we have |cx|.
97 0 : Maybe<JS::Rooted<JSObject *> > object;
98 0 : Maybe<JS::Rooted<JS::Value> > temp;
99 0 : if (!isNull) {
100 0 : MOZ_ASSERT(cx);
101 0 : object.emplace(cx, &val.toObject());
102 0 : temp.emplace(cx);
103 : }
104 0 : if (!isNull) {
105 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->headers_id, temp.ptr())) {
106 0 : return false;
107 : }
108 : }
109 0 : if (!isNull && !temp->isUndefined()) {
110 0 : mHeaders.Construct();
111 : {
112 0 : bool done = false, failed = false, tryNext;
113 0 : if (temp.ref().isObject()) {
114 0 : done = (failed = !(mHeaders.Value()).TrySetToHeaders(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
115 :
116 0 : if (!done) {
117 0 : done = (failed = !(mHeaders.Value()).TrySetToByteStringSequenceSequence(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
118 : }
119 0 : if (!done) {
120 0 : done = (failed = !(mHeaders.Value()).TrySetToByteStringByteStringRecord(cx, temp.ref(), tryNext, passedToJSImpl)) || !tryNext;
121 : }
122 : }
123 0 : if (failed) {
124 0 : return false;
125 : }
126 0 : if (!done) {
127 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "'headers' member of ResponseInit", "Headers, ByteStringSequenceSequence, ByteStringByteStringRecord");
128 0 : return false;
129 : }
130 : }
131 0 : mIsAnyMemberPresent = true;
132 : }
133 :
134 0 : if (!isNull) {
135 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->status_id, temp.ptr())) {
136 0 : return false;
137 : }
138 : }
139 0 : if (!isNull && !temp->isUndefined()) {
140 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, temp.ref(), &mStatus)) {
141 0 : return false;
142 : }
143 : } else {
144 0 : mStatus = 200;
145 : }
146 0 : mIsAnyMemberPresent = true;
147 :
148 0 : if (!isNull) {
149 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->statusText_id, temp.ptr())) {
150 0 : return false;
151 : }
152 : }
153 0 : if (!isNull && !temp->isUndefined()) {
154 0 : if (!ConvertJSValueToByteString(cx, temp.ref(), false, mStatusText)) {
155 0 : return false;
156 : }
157 : } else {
158 : static const char data[] = { 'O', 'K', 0 };
159 0 : mStatusText.Rebind(data, ArrayLength(data) - 1);
160 : }
161 0 : mIsAnyMemberPresent = true;
162 0 : return true;
163 : }
164 :
165 : bool
166 0 : ResponseInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
167 : {
168 0 : ResponseInitAtoms* atomsCache = GetAtomCache<ResponseInitAtoms>(cx);
169 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
170 0 : return false;
171 : }
172 :
173 0 : JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
174 0 : if (!obj) {
175 0 : return false;
176 : }
177 0 : rval.set(JS::ObjectValue(*obj));
178 :
179 0 : if (mHeaders.WasPassed()) {
180 : do {
181 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
182 0 : JS::Rooted<JS::Value> temp(cx);
183 0 : OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord const & currentValue = mHeaders.InternalValue();
184 0 : if (!currentValue.ToJSVal(cx, obj, &temp)) {
185 0 : return false;
186 : }
187 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->headers_id, temp, JSPROP_ENUMERATE)) {
188 0 : return false;
189 : }
190 0 : break;
191 : } while(0);
192 : }
193 :
194 : do {
195 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
196 0 : JS::Rooted<JS::Value> temp(cx);
197 0 : uint16_t const & currentValue = mStatus;
198 0 : temp.setInt32(int32_t(currentValue));
199 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->status_id, temp, JSPROP_ENUMERATE)) {
200 0 : return false;
201 : }
202 0 : break;
203 : } while(0);
204 :
205 : do {
206 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
207 0 : JS::Rooted<JS::Value> temp(cx);
208 0 : nsCString const & currentValue = mStatusText;
209 0 : if (!NonVoidByteStringToJsval(cx, currentValue, &temp)) {
210 0 : return false;
211 : }
212 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->statusText_id, temp, JSPROP_ENUMERATE)) {
213 0 : return false;
214 : }
215 0 : break;
216 : } while(0);
217 :
218 0 : return true;
219 : }
220 :
221 : void
222 0 : ResponseInit::TraceDictionary(JSTracer* trc)
223 : {
224 0 : }
225 :
226 : namespace binding_detail {
227 : } // namespace binding_detail
228 :
229 :
230 : namespace ResponseBinding {
231 :
232 : static bool
233 0 : error(JSContext* cx, unsigned argc, JS::Value* vp)
234 : {
235 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
236 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
237 :
238 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
239 0 : if (global.Failed()) {
240 0 : return false;
241 : }
242 :
243 0 : auto result(StrongOrRawPtr<mozilla::dom::Response>(mozilla::dom::Response::Error(global)));
244 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
245 : static_assert(!IsPointer<decltype(result)>::value,
246 : "NewObject implies that we need to keep the object alive with a strong reference.");
247 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
248 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
249 0 : return false;
250 : }
251 0 : return true;
252 : }
253 :
254 : static bool
255 0 : redirect(JSContext* cx, unsigned argc, JS::Value* vp)
256 : {
257 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
258 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
259 :
260 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
261 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Response.redirect");
262 : }
263 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
264 0 : if (global.Failed()) {
265 0 : return false;
266 : }
267 :
268 0 : binding_detail::FakeString arg0;
269 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
270 0 : return false;
271 : }
272 0 : NormalizeUSVString(arg0);
273 : uint16_t arg1;
274 0 : if (args.hasDefined(1)) {
275 0 : if (!ValueToPrimitive<uint16_t, eDefault>(cx, args[1], &arg1)) {
276 0 : return false;
277 : }
278 : } else {
279 0 : arg1 = 302;
280 : }
281 0 : binding_detail::FastErrorResult rv;
282 0 : auto result(StrongOrRawPtr<mozilla::dom::Response>(mozilla::dom::Response::Redirect(global, Constify(arg0), arg1, rv)));
283 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
284 0 : return false;
285 : }
286 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
287 : static_assert(!IsPointer<decltype(result)>::value,
288 : "NewObject implies that we need to keep the object alive with a strong reference.");
289 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
290 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
291 0 : return false;
292 : }
293 0 : return true;
294 : }
295 :
296 : static bool
297 0 : get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
298 : {
299 0 : ResponseType result(self->Type());
300 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
301 0 : if (!ToJSValue(cx, result, args.rval())) {
302 0 : return false;
303 : }
304 0 : return true;
305 : }
306 :
307 : static const JSJitInfo type_getterinfo = {
308 : { (JSJitGetterOp)get_type },
309 : { prototypes::id::Response },
310 : { PrototypeTraits<prototypes::id::Response>::Depth },
311 : JSJitInfo::Getter,
312 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
313 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
314 : false, /* isInfallible. False in setters. */
315 : false, /* isMovable. Not relevant for setters. */
316 : false, /* isEliminatable. Not relevant for setters. */
317 : false, /* isAlwaysInSlot. Only relevant for getters. */
318 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
319 : false, /* isTypedMethod. Only relevant for methods. */
320 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
321 : };
322 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
323 : static_assert(0 < 1, "There is no slot for us");
324 :
325 : static bool
326 0 : get_url(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
327 : {
328 0 : DOMString result;
329 0 : self->GetUrl(result);
330 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
331 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
332 0 : return false;
333 : }
334 0 : return true;
335 : }
336 :
337 : static const JSJitInfo url_getterinfo = {
338 : { (JSJitGetterOp)get_url },
339 : { prototypes::id::Response },
340 : { PrototypeTraits<prototypes::id::Response>::Depth },
341 : JSJitInfo::Getter,
342 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
343 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
344 : false, /* isInfallible. False in setters. */
345 : false, /* isMovable. Not relevant for setters. */
346 : false, /* isEliminatable. Not relevant for setters. */
347 : false, /* isAlwaysInSlot. Only relevant for getters. */
348 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
349 : false, /* isTypedMethod. Only relevant for methods. */
350 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
351 : };
352 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
353 : static_assert(0 < 1, "There is no slot for us");
354 :
355 : static bool
356 0 : get_redirected(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
357 : {
358 0 : bool result(self->Redirected());
359 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
360 0 : args.rval().setBoolean(result);
361 0 : return true;
362 : }
363 :
364 : static const JSJitInfo redirected_getterinfo = {
365 : { (JSJitGetterOp)get_redirected },
366 : { prototypes::id::Response },
367 : { PrototypeTraits<prototypes::id::Response>::Depth },
368 : JSJitInfo::Getter,
369 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
370 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
371 : true, /* isInfallible. False in setters. */
372 : false, /* isMovable. Not relevant for setters. */
373 : false, /* isEliminatable. Not relevant for setters. */
374 : false, /* isAlwaysInSlot. Only relevant for getters. */
375 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
376 : false, /* isTypedMethod. Only relevant for methods. */
377 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
378 : };
379 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
380 : static_assert(0 < 1, "There is no slot for us");
381 :
382 : static bool
383 0 : get_status(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
384 : {
385 0 : uint16_t result(self->Status());
386 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
387 0 : args.rval().setInt32(int32_t(result));
388 0 : return true;
389 : }
390 :
391 : static const JSJitInfo status_getterinfo = {
392 : { (JSJitGetterOp)get_status },
393 : { prototypes::id::Response },
394 : { PrototypeTraits<prototypes::id::Response>::Depth },
395 : JSJitInfo::Getter,
396 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
397 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
398 : true, /* isInfallible. False in setters. */
399 : false, /* isMovable. Not relevant for setters. */
400 : false, /* isEliminatable. Not relevant for setters. */
401 : false, /* isAlwaysInSlot. Only relevant for getters. */
402 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
403 : false, /* isTypedMethod. Only relevant for methods. */
404 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
405 : };
406 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
407 : static_assert(0 < 1, "There is no slot for us");
408 :
409 : static bool
410 0 : get_ok(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
411 : {
412 0 : bool result(self->Ok());
413 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
414 0 : args.rval().setBoolean(result);
415 0 : return true;
416 : }
417 :
418 : static const JSJitInfo ok_getterinfo = {
419 : { (JSJitGetterOp)get_ok },
420 : { prototypes::id::Response },
421 : { PrototypeTraits<prototypes::id::Response>::Depth },
422 : JSJitInfo::Getter,
423 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
424 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
425 : true, /* isInfallible. False in setters. */
426 : false, /* isMovable. Not relevant for setters. */
427 : false, /* isEliminatable. Not relevant for setters. */
428 : false, /* isAlwaysInSlot. Only relevant for getters. */
429 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
430 : false, /* isTypedMethod. Only relevant for methods. */
431 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
432 : };
433 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
434 : static_assert(0 < 1, "There is no slot for us");
435 :
436 : static bool
437 0 : get_statusText(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
438 : {
439 0 : nsCString result;
440 0 : self->GetStatusText(result);
441 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
442 0 : if (!NonVoidByteStringToJsval(cx, result, args.rval())) {
443 0 : return false;
444 : }
445 0 : return true;
446 : }
447 :
448 : static const JSJitInfo statusText_getterinfo = {
449 : { (JSJitGetterOp)get_statusText },
450 : { prototypes::id::Response },
451 : { PrototypeTraits<prototypes::id::Response>::Depth },
452 : JSJitInfo::Getter,
453 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
454 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
455 : false, /* isInfallible. False in setters. */
456 : false, /* isMovable. Not relevant for setters. */
457 : false, /* isEliminatable. Not relevant for setters. */
458 : false, /* isAlwaysInSlot. Only relevant for getters. */
459 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
460 : false, /* isTypedMethod. Only relevant for methods. */
461 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
462 : };
463 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
464 : static_assert(0 < 1, "There is no slot for us");
465 :
466 : static bool
467 0 : get_headers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
468 : {
469 0 : auto result(StrongOrRawPtr<mozilla::dom::Headers>(self->Headers_()));
470 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
471 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
472 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
473 0 : return false;
474 : }
475 0 : return true;
476 : }
477 :
478 : static const JSJitInfo headers_getterinfo = {
479 : { (JSJitGetterOp)get_headers },
480 : { prototypes::id::Response },
481 : { PrototypeTraits<prototypes::id::Response>::Depth },
482 : JSJitInfo::Getter,
483 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
484 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
485 : false, /* isInfallible. False in setters. */
486 : true, /* isMovable. Not relevant for setters. */
487 : true, /* isEliminatable. Not relevant for setters. */
488 : false, /* isAlwaysInSlot. Only relevant for getters. */
489 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
490 : false, /* isTypedMethod. Only relevant for methods. */
491 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
492 : };
493 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
494 : static_assert(0 < 1, "There is no slot for us");
495 :
496 : static bool
497 0 : clone(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
498 : {
499 0 : binding_detail::FastErrorResult rv;
500 0 : auto result(StrongOrRawPtr<mozilla::dom::Response>(self->Clone(rv)));
501 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
502 0 : return false;
503 : }
504 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
505 : static_assert(!IsPointer<decltype(result)>::value,
506 : "NewObject implies that we need to keep the object alive with a strong reference.");
507 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
508 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
509 0 : return false;
510 : }
511 0 : return true;
512 : }
513 :
514 : static const JSJitInfo clone_methodinfo = {
515 : { (JSJitGetterOp)clone },
516 : { prototypes::id::Response },
517 : { PrototypeTraits<prototypes::id::Response>::Depth },
518 : JSJitInfo::Method,
519 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
520 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
521 : false, /* isInfallible. False in setters. */
522 : false, /* isMovable. Not relevant for setters. */
523 : false, /* isEliminatable. Not relevant for setters. */
524 : false, /* isAlwaysInSlot. Only relevant for getters. */
525 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
526 : false, /* isTypedMethod. Only relevant for methods. */
527 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
528 : };
529 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
530 : static_assert(0 < 1, "There is no slot for us");
531 :
532 : static bool
533 0 : cloneUnfiltered(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
534 : {
535 0 : binding_detail::FastErrorResult rv;
536 0 : auto result(StrongOrRawPtr<mozilla::dom::Response>(self->CloneUnfiltered(rv)));
537 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
538 0 : return false;
539 : }
540 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
541 : static_assert(!IsPointer<decltype(result)>::value,
542 : "NewObject implies that we need to keep the object alive with a strong reference.");
543 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
544 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
545 0 : return false;
546 : }
547 0 : return true;
548 : }
549 :
550 : static const JSJitInfo cloneUnfiltered_methodinfo = {
551 : { (JSJitGetterOp)cloneUnfiltered },
552 : { prototypes::id::Response },
553 : { PrototypeTraits<prototypes::id::Response>::Depth },
554 : JSJitInfo::Method,
555 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
556 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
557 : false, /* isInfallible. False in setters. */
558 : false, /* isMovable. Not relevant for setters. */
559 : false, /* isEliminatable. Not relevant for setters. */
560 : false, /* isAlwaysInSlot. Only relevant for getters. */
561 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
562 : false, /* isTypedMethod. Only relevant for methods. */
563 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
564 : };
565 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
566 : static_assert(0 < 1, "There is no slot for us");
567 :
568 : static bool
569 0 : get_bodyUsed(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, JSJitGetterCallArgs args)
570 : {
571 0 : bool result(self->BodyUsed());
572 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
573 0 : args.rval().setBoolean(result);
574 0 : return true;
575 : }
576 :
577 : static const JSJitInfo bodyUsed_getterinfo = {
578 : { (JSJitGetterOp)get_bodyUsed },
579 : { prototypes::id::Response },
580 : { PrototypeTraits<prototypes::id::Response>::Depth },
581 : JSJitInfo::Getter,
582 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
583 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
584 : true, /* isInfallible. False in setters. */
585 : false, /* isMovable. Not relevant for setters. */
586 : false, /* isEliminatable. Not relevant for setters. */
587 : false, /* isAlwaysInSlot. Only relevant for getters. */
588 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
589 : false, /* isTypedMethod. Only relevant for methods. */
590 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
591 : };
592 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
593 : static_assert(0 < 1, "There is no slot for us");
594 :
595 : static bool
596 0 : arrayBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
597 : {
598 0 : binding_detail::FastErrorResult rv;
599 0 : auto result(StrongOrRawPtr<Promise>(self->ArrayBuffer(rv)));
600 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
601 0 : return false;
602 : }
603 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
604 0 : if (!ToJSValue(cx, result, args.rval())) {
605 0 : return false;
606 : }
607 0 : return true;
608 : }
609 :
610 : static bool
611 0 : arrayBuffer_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
612 : {
613 : // Make sure to save the callee before someone maybe messes
614 : // with rval().
615 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
616 0 : bool ok = arrayBuffer(cx, obj, self, args);
617 0 : if (ok) {
618 0 : return true;
619 : }
620 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
621 0 : args.rval());
622 : }
623 :
624 : static const JSJitInfo arrayBuffer_methodinfo = {
625 : { (JSJitGetterOp)arrayBuffer_promiseWrapper },
626 : { prototypes::id::Response },
627 : { PrototypeTraits<prototypes::id::Response>::Depth },
628 : JSJitInfo::Method,
629 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
630 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
631 : false, /* isInfallible. False in setters. */
632 : false, /* isMovable. Not relevant for setters. */
633 : false, /* isEliminatable. Not relevant for setters. */
634 : false, /* isAlwaysInSlot. Only relevant for getters. */
635 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
636 : false, /* isTypedMethod. Only relevant for methods. */
637 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
638 : };
639 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
640 : static_assert(0 < 1, "There is no slot for us");
641 :
642 : static bool
643 0 : blob(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
644 : {
645 0 : binding_detail::FastErrorResult rv;
646 0 : auto result(StrongOrRawPtr<Promise>(self->Blob(rv)));
647 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
648 0 : return false;
649 : }
650 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
651 0 : if (!ToJSValue(cx, result, args.rval())) {
652 0 : return false;
653 : }
654 0 : return true;
655 : }
656 :
657 : static bool
658 0 : blob_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
659 : {
660 : // Make sure to save the callee before someone maybe messes
661 : // with rval().
662 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
663 0 : bool ok = blob(cx, obj, self, args);
664 0 : if (ok) {
665 0 : return true;
666 : }
667 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
668 0 : args.rval());
669 : }
670 :
671 : static const JSJitInfo blob_methodinfo = {
672 : { (JSJitGetterOp)blob_promiseWrapper },
673 : { prototypes::id::Response },
674 : { PrototypeTraits<prototypes::id::Response>::Depth },
675 : JSJitInfo::Method,
676 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
677 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
678 : false, /* isInfallible. False in setters. */
679 : false, /* isMovable. Not relevant for setters. */
680 : false, /* isEliminatable. Not relevant for setters. */
681 : false, /* isAlwaysInSlot. Only relevant for getters. */
682 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
683 : false, /* isTypedMethod. Only relevant for methods. */
684 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
685 : };
686 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
687 : static_assert(0 < 1, "There is no slot for us");
688 :
689 : static bool
690 0 : formData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
691 : {
692 0 : binding_detail::FastErrorResult rv;
693 0 : auto result(StrongOrRawPtr<Promise>(self->FormData(rv)));
694 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
695 0 : return false;
696 : }
697 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
698 0 : if (!ToJSValue(cx, result, args.rval())) {
699 0 : return false;
700 : }
701 0 : return true;
702 : }
703 :
704 : static bool
705 0 : formData_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
706 : {
707 : // Make sure to save the callee before someone maybe messes
708 : // with rval().
709 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
710 0 : bool ok = formData(cx, obj, self, args);
711 0 : if (ok) {
712 0 : return true;
713 : }
714 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
715 0 : args.rval());
716 : }
717 :
718 : static const JSJitInfo formData_methodinfo = {
719 : { (JSJitGetterOp)formData_promiseWrapper },
720 : { prototypes::id::Response },
721 : { PrototypeTraits<prototypes::id::Response>::Depth },
722 : JSJitInfo::Method,
723 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
724 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
725 : false, /* isInfallible. False in setters. */
726 : false, /* isMovable. Not relevant for setters. */
727 : false, /* isEliminatable. Not relevant for setters. */
728 : false, /* isAlwaysInSlot. Only relevant for getters. */
729 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
730 : false, /* isTypedMethod. Only relevant for methods. */
731 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
732 : };
733 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
734 : static_assert(0 < 1, "There is no slot for us");
735 :
736 : static bool
737 1 : json(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
738 : {
739 2 : binding_detail::FastErrorResult rv;
740 2 : auto result(StrongOrRawPtr<Promise>(self->Json(rv)));
741 1 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
742 0 : return false;
743 : }
744 1 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
745 1 : if (!ToJSValue(cx, result, args.rval())) {
746 0 : return false;
747 : }
748 1 : return true;
749 : }
750 :
751 : static bool
752 1 : json_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
753 : {
754 : // Make sure to save the callee before someone maybe messes
755 : // with rval().
756 2 : JS::Rooted<JSObject*> callee(cx, &args.callee());
757 1 : bool ok = json(cx, obj, self, args);
758 1 : if (ok) {
759 1 : return true;
760 : }
761 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
762 0 : args.rval());
763 : }
764 :
765 : static const JSJitInfo json_methodinfo = {
766 : { (JSJitGetterOp)json_promiseWrapper },
767 : { prototypes::id::Response },
768 : { PrototypeTraits<prototypes::id::Response>::Depth },
769 : JSJitInfo::Method,
770 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
771 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
772 : false, /* isInfallible. False in setters. */
773 : false, /* isMovable. Not relevant for setters. */
774 : false, /* isEliminatable. Not relevant for setters. */
775 : false, /* isAlwaysInSlot. Only relevant for getters. */
776 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
777 : false, /* isTypedMethod. Only relevant for methods. */
778 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
779 : };
780 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
781 : static_assert(0 < 1, "There is no slot for us");
782 :
783 : static bool
784 0 : text(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
785 : {
786 0 : binding_detail::FastErrorResult rv;
787 0 : auto result(StrongOrRawPtr<Promise>(self->Text(rv)));
788 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
789 0 : return false;
790 : }
791 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
792 0 : if (!ToJSValue(cx, result, args.rval())) {
793 0 : return false;
794 : }
795 0 : return true;
796 : }
797 :
798 : static bool
799 0 : text_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Response* self, const JSJitMethodCallArgs& args)
800 : {
801 : // Make sure to save the callee before someone maybe messes
802 : // with rval().
803 0 : JS::Rooted<JSObject*> callee(cx, &args.callee());
804 0 : bool ok = text(cx, obj, self, args);
805 0 : if (ok) {
806 0 : return true;
807 : }
808 0 : return ConvertExceptionToPromise(cx, xpc::XrayAwareCalleeGlobal(callee),
809 0 : args.rval());
810 : }
811 :
812 : static const JSJitInfo text_methodinfo = {
813 : { (JSJitGetterOp)text_promiseWrapper },
814 : { prototypes::id::Response },
815 : { PrototypeTraits<prototypes::id::Response>::Depth },
816 : JSJitInfo::Method,
817 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
818 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
819 : false, /* isInfallible. False in setters. */
820 : false, /* isMovable. Not relevant for setters. */
821 : false, /* isEliminatable. Not relevant for setters. */
822 : false, /* isAlwaysInSlot. Only relevant for getters. */
823 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
824 : false, /* isTypedMethod. Only relevant for methods. */
825 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
826 : };
827 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
828 : static_assert(0 < 1, "There is no slot for us");
829 :
830 : static bool
831 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
832 : {
833 0 : mozilla::dom::Response* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Response>(obj);
834 : // We don't want to preserve if we don't have a wrapper, and we
835 : // obviously can't preserve if we're not initialized.
836 0 : if (self && self->GetWrapperPreserveColor()) {
837 0 : PreserveWrapper(self);
838 : }
839 0 : return true;
840 : }
841 :
842 : static void
843 0 : _finalize(js::FreeOp* fop, JSObject* obj)
844 : {
845 0 : mozilla::dom::Response* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Response>(obj);
846 0 : if (self) {
847 0 : ClearWrapper(self, self, obj);
848 0 : AddForDeferredFinalization<mozilla::dom::Response>(self);
849 : }
850 0 : }
851 :
852 : static void
853 0 : _objectMoved(JSObject* obj, const JSObject* old)
854 : {
855 0 : mozilla::dom::Response* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Response>(obj);
856 0 : if (self) {
857 0 : UpdateWrapper(self, self, obj, old);
858 : }
859 0 : }
860 :
861 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
862 : #if defined(__clang__)
863 : #pragma clang diagnostic push
864 : #pragma clang diagnostic ignored "-Wmissing-braces"
865 : #endif
866 : static const JSFunctionSpec sStaticMethods_specs[] = {
867 : JS_FNSPEC("error", error, nullptr, 0, JSPROP_ENUMERATE, nullptr),
868 : JS_FNSPEC("redirect", redirect, nullptr, 1, JSPROP_ENUMERATE, nullptr),
869 : JS_FS_END
870 : };
871 : #if defined(__clang__)
872 : #pragma clang diagnostic pop
873 : #endif
874 :
875 :
876 : // Can't be const because the pref-enabled boolean needs to be writable
877 : static Prefable<const JSFunctionSpec> sStaticMethods[] = {
878 : { nullptr, &sStaticMethods_specs[0] },
879 : { nullptr, nullptr }
880 : };
881 :
882 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
883 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
884 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
885 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
886 :
887 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
888 : #if defined(__clang__)
889 : #pragma clang diagnostic push
890 : #pragma clang diagnostic ignored "-Wmissing-braces"
891 : #endif
892 : static const JSFunctionSpec sMethods_specs[] = {
893 : JS_FNSPEC("clone", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&clone_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
894 : JS_FNSPEC("arrayBuffer", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&arrayBuffer_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
895 : JS_FNSPEC("blob", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&blob_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
896 : JS_FNSPEC("formData", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&formData_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
897 : JS_FNSPEC("json", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&json_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
898 : JS_FNSPEC("text", GenericPromiseReturningBindingMethod, reinterpret_cast<const JSJitInfo*>(&text_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
899 : JS_FS_END
900 : };
901 : #if defined(__clang__)
902 : #pragma clang diagnostic pop
903 : #endif
904 :
905 :
906 : // Can't be const because the pref-enabled boolean needs to be writable
907 : static Prefable<const JSFunctionSpec> sMethods[] = {
908 : { nullptr, &sMethods_specs[0] },
909 : { nullptr, nullptr }
910 : };
911 :
912 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
913 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
914 : static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
915 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
916 :
917 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
918 : #if defined(__clang__)
919 : #pragma clang diagnostic push
920 : #pragma clang diagnostic ignored "-Wmissing-braces"
921 : #endif
922 : static const JSFunctionSpec sChromeMethods_specs[] = {
923 : JS_FNSPEC("cloneUnfiltered", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&cloneUnfiltered_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
924 : JS_FS_END
925 : };
926 : #if defined(__clang__)
927 : #pragma clang diagnostic pop
928 : #endif
929 :
930 :
931 : // Can't be const because the pref-enabled boolean needs to be writable
932 : static Prefable<const JSFunctionSpec> sChromeMethods[] = {
933 : { nullptr, &sChromeMethods_specs[0] },
934 : { nullptr, nullptr }
935 : };
936 :
937 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
938 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
939 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
940 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
941 :
942 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
943 : #if defined(__clang__)
944 : #pragma clang diagnostic push
945 : #pragma clang diagnostic ignored "-Wmissing-braces"
946 : #endif
947 : static const JSPropertySpec sAttributes_specs[] = {
948 : { "type", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &type_getterinfo, nullptr, nullptr },
949 : { "url", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &url_getterinfo, nullptr, nullptr },
950 : { "redirected", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &redirected_getterinfo, nullptr, nullptr },
951 : { "status", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &status_getterinfo, nullptr, nullptr },
952 : { "ok", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &ok_getterinfo, nullptr, nullptr },
953 : { "statusText", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &statusText_getterinfo, nullptr, nullptr },
954 : { "headers", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &headers_getterinfo, nullptr, nullptr },
955 : { "bodyUsed", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &bodyUsed_getterinfo, nullptr, nullptr },
956 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
957 : };
958 : #if defined(__clang__)
959 : #pragma clang diagnostic pop
960 : #endif
961 :
962 :
963 : // Can't be const because the pref-enabled boolean needs to be writable
964 : static Prefable<const JSPropertySpec> sAttributes[] = {
965 : { nullptr, &sAttributes_specs[0] },
966 : { nullptr, nullptr }
967 : };
968 :
969 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
970 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
971 : static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
972 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
973 :
974 :
975 : static uint16_t sNativeProperties_sortedPropertyIndices[16];
976 : static PropertyInfo sNativeProperties_propertyInfos[16];
977 :
978 : static const NativePropertiesN<3> sNativeProperties = {
979 : true, 0 /* sStaticMethods */,
980 : false, 0,
981 : true, 1 /* sMethods */,
982 : true, 2 /* sAttributes */,
983 : false, 0,
984 : false, 0,
985 : false, 0,
986 : -1,
987 : 16,
988 : sNativeProperties_sortedPropertyIndices,
989 : {
990 : { sStaticMethods, &sNativeProperties_propertyInfos[0] },
991 : { sMethods, &sNativeProperties_propertyInfos[2] },
992 : { sAttributes, &sNativeProperties_propertyInfos[8] }
993 : }
994 : };
995 : static_assert(16 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
996 : "We have a property info count that is oversized");
997 :
998 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
999 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
1000 :
1001 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
1002 : false, 0,
1003 : false, 0,
1004 : true, 0 /* sChromeMethods */,
1005 : false, 0,
1006 : false, 0,
1007 : false, 0,
1008 : false, 0,
1009 : -1,
1010 : 1,
1011 : sChromeOnlyNativeProperties_sortedPropertyIndices,
1012 : {
1013 : { sChromeMethods, &sChromeOnlyNativeProperties_propertyInfos[0] }
1014 : }
1015 : };
1016 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
1017 : "We have a property info count that is oversized");
1018 :
1019 : static bool
1020 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
1021 : {
1022 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
1023 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
1024 0 : if (!args.isConstructing()) {
1025 : // XXXbz wish I could get the name from the callee instead of
1026 : // Adding more relocations
1027 0 : return ThrowConstructorWithoutNew(cx, "Response");
1028 : }
1029 :
1030 0 : GlobalObject global(cx, obj);
1031 0 : if (global.Failed()) {
1032 0 : return false;
1033 : }
1034 :
1035 0 : JS::Rooted<JSObject*> desiredProto(cx);
1036 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
1037 0 : return false;
1038 : }
1039 :
1040 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
1041 0 : Optional<BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVString> arg0;
1042 0 : Maybe<BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrUSVStringArgument> arg0_holder;
1043 0 : if (args.hasDefined(0)) {
1044 0 : arg0.Construct();
1045 0 : arg0_holder.emplace(arg0.Value());
1046 : {
1047 0 : bool done = false, failed = false, tryNext;
1048 0 : if (args[0].isObject()) {
1049 0 : done = (failed = !arg0_holder.ref().TrySetToBlob(cx, args[0], tryNext, false)) || !tryNext ||
1050 0 : (failed = !arg0_holder.ref().TrySetToArrayBufferView(cx, args[0], tryNext, false)) || !tryNext ||
1051 0 : (failed = !arg0_holder.ref().TrySetToArrayBuffer(cx, args[0], tryNext, false)) || !tryNext ||
1052 0 : (failed = !arg0_holder.ref().TrySetToFormData(cx, args[0], tryNext, false)) || !tryNext ||
1053 0 : (failed = !arg0_holder.ref().TrySetToURLSearchParams(cx, args[0], tryNext, false)) || !tryNext;
1054 :
1055 : }
1056 0 : if (!done) {
1057 : do {
1058 0 : done = (failed = !arg0_holder.ref().TrySetToUSVString(cx, args[0], tryNext)) || !tryNext;
1059 0 : break;
1060 : } while (0);
1061 : }
1062 0 : if (failed) {
1063 0 : return false;
1064 : }
1065 0 : if (!done) {
1066 0 : ThrowErrorMessage(cx, MSG_NOT_IN_UNION, "Argument 1 of Response.constructor", "Blob, ArrayBufferView, ArrayBuffer, FormData, URLSearchParams");
1067 0 : return false;
1068 : }
1069 : }
1070 : }
1071 0 : binding_detail::FastResponseInit arg1;
1072 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of Response.constructor", false)) {
1073 0 : return false;
1074 : }
1075 0 : Maybe<JSAutoCompartment> ac;
1076 0 : if (objIsXray) {
1077 0 : obj = js::CheckedUnwrap(obj);
1078 0 : if (!obj) {
1079 0 : return false;
1080 : }
1081 0 : ac.emplace(cx, obj);
1082 0 : if (!JS_WrapObject(cx, &desiredProto)) {
1083 0 : return false;
1084 : }
1085 0 : if (arg0.WasPassed()) {
1086 0 : if (arg0.Value().IsArrayBufferView()) {
1087 0 : if (!arg0.Value().GetAsArrayBufferView().WrapIntoNewCompartment(cx)) {
1088 0 : return false;
1089 : }
1090 : }
1091 0 : else if (arg0.Value().IsArrayBuffer()) {
1092 0 : if (!arg0.Value().GetAsArrayBuffer().WrapIntoNewCompartment(cx)) {
1093 0 : return false;
1094 : }
1095 : }
1096 : }
1097 : }
1098 0 : binding_detail::FastErrorResult rv;
1099 0 : auto result(StrongOrRawPtr<mozilla::dom::Response>(mozilla::dom::Response::Constructor(global, Constify(arg0), Constify(arg1), rv)));
1100 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
1101 0 : return false;
1102 : }
1103 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
1104 : static_assert(!IsPointer<decltype(result)>::value,
1105 : "NewObject implies that we need to keep the object alive with a strong reference.");
1106 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
1107 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
1108 0 : return false;
1109 : }
1110 0 : return true;
1111 : }
1112 :
1113 : static const js::ClassOps sInterfaceObjectClassOps = {
1114 : nullptr, /* addProperty */
1115 : nullptr, /* delProperty */
1116 : nullptr, /* getProperty */
1117 : nullptr, /* setProperty */
1118 : nullptr, /* enumerate */
1119 : nullptr, /* newEnumerate */
1120 : nullptr, /* resolve */
1121 : nullptr, /* mayResolve */
1122 : nullptr, /* finalize */
1123 : _constructor, /* call */
1124 : nullptr, /* hasInstance */
1125 : _constructor, /* construct */
1126 : nullptr, /* trace */
1127 : };
1128 :
1129 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1130 : {
1131 : "Function",
1132 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1133 : &sInterfaceObjectClassOps,
1134 : JS_NULL_CLASS_SPEC,
1135 : JS_NULL_CLASS_EXT,
1136 : &sInterfaceObjectClassObjectOps
1137 : },
1138 : eInterface,
1139 : true,
1140 : prototypes::id::Response,
1141 : PrototypeTraits<prototypes::id::Response>::Depth,
1142 : sNativePropertyHooks,
1143 : "function Response() {\n [native code]\n}",
1144 : JS::GetRealmFunctionPrototype
1145 : };
1146 :
1147 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1148 : {
1149 : "ResponsePrototype",
1150 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1151 : JS_NULL_CLASS_OPS,
1152 : JS_NULL_CLASS_SPEC,
1153 : JS_NULL_CLASS_EXT,
1154 : JS_NULL_OBJECT_OPS
1155 : },
1156 : eInterfacePrototype,
1157 : false,
1158 : prototypes::id::Response,
1159 : PrototypeTraits<prototypes::id::Response>::Depth,
1160 : sNativePropertyHooks,
1161 : "[object ResponsePrototype]",
1162 : JS::GetRealmObjectPrototype
1163 : };
1164 :
1165 : JSObject*
1166 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
1167 : {
1168 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
1169 : }
1170 :
1171 : static const js::ClassOps sClassOps = {
1172 : _addProperty, /* addProperty */
1173 : nullptr, /* delProperty */
1174 : nullptr, /* getProperty */
1175 : nullptr, /* setProperty */
1176 : nullptr, /* enumerate */
1177 : nullptr, /* newEnumerate */
1178 : nullptr, /* resolve */
1179 : nullptr, /* mayResolve */
1180 : _finalize, /* finalize */
1181 : nullptr, /* call */
1182 : nullptr, /* hasInstance */
1183 : nullptr, /* construct */
1184 : nullptr, /* trace */
1185 : };
1186 :
1187 : static const js::ClassExtension sClassExtension = {
1188 : nullptr, /* weakmapKeyDelegateOp */
1189 : _objectMoved /* objectMovedOp */
1190 : };
1191 :
1192 : static const DOMJSClass sClass = {
1193 : { "Response",
1194 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1195 : &sClassOps,
1196 : JS_NULL_CLASS_SPEC,
1197 : &sClassExtension,
1198 : JS_NULL_OBJECT_OPS
1199 : },
1200 : { prototypes::id::Response, 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 },
1201 : IsBaseOf<nsISupports, mozilla::dom::Response >::value,
1202 : sNativePropertyHooks,
1203 : FindAssociatedGlobalForNative<mozilla::dom::Response>::Get,
1204 : GetProtoObjectHandle,
1205 : GetCCParticipant<mozilla::dom::Response>::Get()
1206 : };
1207 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1208 : "Must have the right minimal number of reserved slots.");
1209 : static_assert(1 >= 1,
1210 : "Must have enough reserved slots.");
1211 :
1212 : const JSClass*
1213 0 : GetJSClass()
1214 : {
1215 0 : return sClass.ToJSClass();
1216 : }
1217 :
1218 : bool
1219 1 : Wrap(JSContext* aCx, mozilla::dom::Response* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1220 : {
1221 : MOZ_ASSERT(static_cast<mozilla::dom::Response*>(aObject) ==
1222 : reinterpret_cast<mozilla::dom::Response*>(aObject),
1223 : "Multiple inheritance for mozilla::dom::Response is broken.");
1224 1 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1225 1 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1226 1 : MOZ_ASSERT(!aCache->GetWrapper(),
1227 : "You should probably not be using Wrap() directly; use "
1228 : "GetOrCreateDOMReflector instead");
1229 :
1230 1 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1231 : "nsISupports must be on our primary inheritance chain");
1232 :
1233 2 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1234 1 : if (!global) {
1235 0 : return false;
1236 : }
1237 1 : MOZ_ASSERT(JS_IsGlobalObject(global));
1238 1 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1239 :
1240 : // That might have ended up wrapping us already, due to the wonders
1241 : // of XBL. Check for that, and bail out as needed.
1242 1 : aReflector.set(aCache->GetWrapper());
1243 1 : if (aReflector) {
1244 : #ifdef DEBUG
1245 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1246 : #endif // DEBUG
1247 0 : return true;
1248 : }
1249 :
1250 2 : JSAutoCompartment ac(aCx, global);
1251 1 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1252 1 : if (!canonicalProto) {
1253 0 : return false;
1254 : }
1255 2 : JS::Rooted<JSObject*> proto(aCx);
1256 1 : if (aGivenProto) {
1257 0 : proto = aGivenProto;
1258 : // Unfortunately, while aGivenProto was in the compartment of aCx
1259 : // coming in, we changed compartments to that of "parent" so may need
1260 : // to wrap the proto here.
1261 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1262 0 : if (!JS_WrapObject(aCx, &proto)) {
1263 0 : return false;
1264 : }
1265 : }
1266 : } else {
1267 1 : proto = canonicalProto;
1268 : }
1269 :
1270 2 : BindingJSObjectCreator<mozilla::dom::Response> creator(aCx);
1271 1 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1272 1 : if (!aReflector) {
1273 0 : return false;
1274 : }
1275 :
1276 1 : aCache->SetWrapper(aReflector);
1277 1 : creator.InitializationSucceeded();
1278 :
1279 1 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1280 : aCache->GetWrapperPreserveColor() == aReflector);
1281 : // If proto != canonicalProto, we have to preserve our wrapper;
1282 : // otherwise we won't be able to properly recreate it later, since
1283 : // we won't know what proto to use. Note that we don't check
1284 : // aGivenProto here, since it's entirely possible (and even
1285 : // somewhat common) to have a non-null aGivenProto which is the
1286 : // same as canonicalProto.
1287 1 : if (proto != canonicalProto) {
1288 0 : PreserveWrapper(aObject);
1289 : }
1290 :
1291 1 : return true;
1292 : }
1293 :
1294 : const NativePropertyHooks sNativePropertyHooks[] = { {
1295 : nullptr,
1296 : nullptr,
1297 : nullptr,
1298 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1299 : prototypes::id::Response,
1300 : constructors::id::Response,
1301 : nullptr,
1302 : &DefaultXrayExpandoObjectClass
1303 : } };
1304 :
1305 : void
1306 4 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1307 : {
1308 8 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
1309 4 : if (!parentProto) {
1310 0 : return;
1311 : }
1312 :
1313 8 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
1314 4 : if (!constructorProto) {
1315 0 : return;
1316 : }
1317 :
1318 : static bool sIdsInited = false;
1319 4 : if (!sIdsInited && NS_IsMainThread()) {
1320 1 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1321 0 : return;
1322 : }
1323 1 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1324 0 : return;
1325 : }
1326 1 : sIdsInited = true;
1327 : }
1328 :
1329 4 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Response);
1330 4 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Response);
1331 12 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1332 : &sPrototypeClass.mBase, protoCache,
1333 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1334 : interfaceCache,
1335 : sNativeProperties.Upcast(),
1336 4 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
1337 : "Response", aDefineOnGlobal,
1338 : nullptr,
1339 4 : false);
1340 : }
1341 :
1342 : JS::Handle<JSObject*>
1343 1 : GetProtoObjectHandle(JSContext* aCx)
1344 : {
1345 : /* Get the interface prototype object for this class. This will create the
1346 : object as needed. */
1347 1 : bool aDefineOnGlobal = true;
1348 :
1349 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1350 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1351 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1352 0 : return nullptr;
1353 : }
1354 :
1355 : /* Check to see whether the interface objects are already installed */
1356 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1357 1 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::Response)) {
1358 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1359 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1360 : }
1361 :
1362 : /*
1363 : * The object might _still_ be null, but that's OK.
1364 : *
1365 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1366 : * traced by TraceProtoAndIfaceCache() and its contents are never
1367 : * changed after they have been set.
1368 : *
1369 : * Calling address() avoids the read read barrier that does gray
1370 : * unmarking, but it's not possible for the object to be gray here.
1371 : */
1372 :
1373 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::Response);
1374 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1375 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1376 : }
1377 :
1378 : JS::Handle<JSObject*>
1379 4 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1380 : {
1381 : /* Get the interface object for this class. This will create the object as
1382 : needed. */
1383 :
1384 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1385 4 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1386 4 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1387 0 : return nullptr;
1388 : }
1389 :
1390 : /* Check to see whether the interface objects are already installed */
1391 4 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1392 4 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::Response)) {
1393 8 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1394 4 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1395 : }
1396 :
1397 : /*
1398 : * The object might _still_ be null, but that's OK.
1399 : *
1400 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1401 : * traced by TraceProtoAndIfaceCache() and its contents are never
1402 : * changed after they have been set.
1403 : *
1404 : * Calling address() avoids the read read barrier that does gray
1405 : * unmarking, but it's not possible for the object to be gray here.
1406 : */
1407 :
1408 4 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::Response);
1409 4 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1410 4 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1411 : }
1412 :
1413 : JSObject*
1414 4 : GetConstructorObject(JSContext* aCx)
1415 : {
1416 4 : return GetConstructorObjectHandle(aCx);
1417 : }
1418 :
1419 : } // namespace ResponseBinding
1420 :
1421 :
1422 :
1423 : } // namespace dom
1424 : } // namespace mozilla
|