@@ -4086,19 +4086,6 @@ bool apply_cache_override(JSContext *cx, HandleObject self) {
4086
4086
sk_chars.get (), sk_len));
4087
4087
}
4088
4088
4089
- JSObject *create (JSContext *cx, HandleValue input, HandleValue init);
4090
-
4091
- bool constructor (JSContext *cx, unsigned argc, Value *vp) {
4092
- REQUEST_HANDLER_ONLY (" The Request builtin" );
4093
- CTOR_HEADER (" Request" , 1 );
4094
- RootedObject request (cx, create (cx, args[0 ], args.get (1 )));
4095
- if (!request)
4096
- return false ;
4097
-
4098
- args.rval ().setObject (*request);
4099
- return true ;
4100
- }
4101
-
4102
4089
const unsigned ctor_length = 1 ;
4103
4090
4104
4091
bool check_receiver (JSContext *cx, HandleValue receiver, const char *method_name);
@@ -4183,6 +4170,8 @@ const JSPropertySpec properties[] = {JS_PSG("method", method_get, JSPROP_ENUMERA
4183
4170
JS_PSG (" bodyUsed" , bodyUsed_get, JSPROP_ENUMERATE),
4184
4171
JS_PS_END};
4185
4172
4173
+ bool constructor (JSContext *cx, unsigned argc, Value *vp);
4174
+
4186
4175
CLASS_BOILERPLATE_CUSTOM_INIT (Request)
4187
4176
4188
4177
JSString *GET_atom;
@@ -4198,23 +4187,19 @@ bool init_class(JSContext *cx, HandleObject global) {
4198
4187
return !!GET_atom;
4199
4188
}
4200
4189
4201
- JSObject *create (JSContext *cx, RequestHandle request_handle, BodyHandle body_handle,
4202
- bool is_downstream) {
4203
- RootedObject request (cx, JS_NewObjectWithGivenProto (cx, &class_, proto_obj));
4204
- if (!request)
4205
- return nullptr ;
4206
-
4207
- JS::SetReservedSlot (request, Slots::Request, JS::Int32Value (request_handle.handle ));
4208
- JS::SetReservedSlot (request, Slots::Headers, JS::NullValue ());
4209
- JS::SetReservedSlot (request, Slots::Body, JS::Int32Value (body_handle.handle ));
4210
- JS::SetReservedSlot (request, Slots::BodyStream, JS::NullValue ());
4211
- JS::SetReservedSlot (request, Slots::HasBody, JS::FalseValue ());
4212
- JS::SetReservedSlot (request, Slots::BodyUsed, JS::FalseValue ());
4213
- JS::SetReservedSlot (request, Slots::Method, JS::StringValue (GET_atom));
4214
- JS::SetReservedSlot (request, Slots::CacheOverride, JS::NullValue ());
4215
- JS::SetReservedSlot (request, Slots::IsDownstream, JS::BooleanValue (is_downstream));
4190
+ JSObject *create (JSContext *cx, HandleObject requestInstance, RequestHandle request_handle,
4191
+ BodyHandle body_handle, bool is_downstream) {
4192
+ JS::SetReservedSlot (requestInstance, Slots::Request, JS::Int32Value (request_handle.handle ));
4193
+ JS::SetReservedSlot (requestInstance, Slots::Headers, JS::NullValue ());
4194
+ JS::SetReservedSlot (requestInstance, Slots::Body, JS::Int32Value (body_handle.handle ));
4195
+ JS::SetReservedSlot (requestInstance, Slots::BodyStream, JS::NullValue ());
4196
+ JS::SetReservedSlot (requestInstance, Slots::HasBody, JS::FalseValue ());
4197
+ JS::SetReservedSlot (requestInstance, Slots::BodyUsed, JS::FalseValue ());
4198
+ JS::SetReservedSlot (requestInstance, Slots::Method, JS::StringValue (GET_atom));
4199
+ JS::SetReservedSlot (requestInstance, Slots::CacheOverride, JS::NullValue ());
4200
+ JS::SetReservedSlot (requestInstance, Slots::IsDownstream, JS::BooleanValue (is_downstream));
4216
4201
4217
- return request ;
4202
+ return requestInstance ;
4218
4203
}
4219
4204
4220
4205
/* *
@@ -4224,7 +4209,8 @@ JSObject *create(JSContext *cx, RequestHandle request_handle, BodyHandle body_ha
4224
4209
* "Roughly" because not all aspects of Request handling make sense in C@E.
4225
4210
* The places where we deviate from the spec are called out inline.
4226
4211
*/
4227
- JSObject *create (JSContext *cx, HandleValue input, HandleValue init_val) {
4212
+ JSObject *create (JSContext *cx, HandleObject requestInstance, HandleValue input,
4213
+ HandleValue init_val) {
4228
4214
RequestHandle request_handle = {INVALID_HANDLE};
4229
4215
if (!HANDLE_RESULT (cx, xqd_req_new (&request_handle))) {
4230
4216
return nullptr ;
@@ -4235,7 +4221,7 @@ JSObject *create(JSContext *cx, HandleValue input, HandleValue init_val) {
4235
4221
return nullptr ;
4236
4222
}
4237
4223
4238
- RootedObject request (cx, create (cx, request_handle, body_handle, false ));
4224
+ RootedObject request (cx, create (cx, requestInstance, request_handle, body_handle, false ));
4239
4225
if (!request) {
4240
4226
return nullptr ;
4241
4227
}
@@ -4652,6 +4638,18 @@ JSObject *create(JSContext *cx, HandleValue input, HandleValue init_val) {
4652
4638
4653
4639
return request;
4654
4640
}
4641
+
4642
+ bool constructor (JSContext *cx, unsigned argc, Value *vp) {
4643
+ REQUEST_HANDLER_ONLY (" The Request builtin" );
4644
+ CTOR_HEADER (" Request" , 1 );
4645
+ RootedObject requestInstance (cx, JS_NewObjectForConstructor (cx, &class_, args));
4646
+ RootedObject request (cx, create (cx, requestInstance, args[0 ], args.get (1 )));
4647
+ if (!request)
4648
+ return false ;
4649
+
4650
+ args.rval ().setObject (*request);
4651
+ return true ;
4652
+ }
4655
4653
} // namespace Request
4656
4654
4657
4655
namespace Response {
@@ -6287,7 +6285,12 @@ bool client_get(JSContext *cx, unsigned argc, Value *vp) {
6287
6285
* initialized. It's filled in at runtime using `init_downstream_request`.
6288
6286
*/
6289
6287
static JSObject *prepare_downstream_request (JSContext *cx) {
6290
- return Request::create (cx, RequestHandle{INVALID_HANDLE}, BodyHandle{INVALID_HANDLE}, true );
6288
+ RootedObject requestInstance (
6289
+ cx, JS_NewObjectWithGivenProto (cx, &Request::class_, Request::proto_obj));
6290
+ if (!requestInstance)
6291
+ return nullptr ;
6292
+ return Request::create (cx, requestInstance, RequestHandle{INVALID_HANDLE},
6293
+ BodyHandle{INVALID_HANDLE}, true );
6291
6294
}
6292
6295
6293
6296
/* *
@@ -7318,7 +7321,12 @@ bool fetch(JSContext *cx, unsigned argc, Value *vp) {
7318
7321
return ReturnPromiseRejectedWithPendingError (cx, args);
7319
7322
}
7320
7323
7321
- RootedObject request (cx, Request::create (cx, args[0 ], args.get (1 )));
7324
+ RootedObject requestInstance (
7325
+ cx, JS_NewObjectWithGivenProto (cx, &Request::class_, Request::proto_obj));
7326
+ if (!requestInstance)
7327
+ return false ;
7328
+
7329
+ RootedObject request (cx, Request::create (cx, requestInstance, args[0 ], args.get (1 )));
7322
7330
if (!request) {
7323
7331
return ReturnPromiseRejectedWithPendingError (cx, args);
7324
7332
}
0 commit comments