@@ -4851,8 +4851,110 @@ JSString *status_message(JSObject *obj) {
4851
4851
return JS::GetReservedSlot (obj, Slots::StatusMessage).toString ();
4852
4852
}
4853
4853
4854
- JSObject *create (JSContext *cx, ResponseHandle response_handle, BodyHandle body_handle,
4855
- bool is_upstream);
4854
+ const unsigned ctor_length = 1 ;
4855
+
4856
+ bool check_receiver (JSContext *cx, HandleValue receiver, const char *method_name);
4857
+
4858
+ bool ok_get (JSContext *cx, unsigned argc, Value *vp) {
4859
+ METHOD_HEADER (0 )
4860
+
4861
+ uint16_t status = Response::status (self);
4862
+ args.rval ().setBoolean (status >= 200 && status < 300 );
4863
+ return true ;
4864
+ }
4865
+
4866
+ bool status_get (JSContext *cx, unsigned argc, Value *vp) {
4867
+ METHOD_HEADER (0 )
4868
+
4869
+ args.rval ().setInt32 (status (self));
4870
+ return true ;
4871
+ }
4872
+
4873
+ bool statusText_get (JSContext *cx, unsigned argc, Value *vp) {
4874
+ METHOD_HEADER (0 )
4875
+
4876
+ args.rval ().setString (status_message (self));
4877
+ return true ;
4878
+ }
4879
+
4880
+ bool url_get (JSContext *cx, unsigned argc, Value *vp) {
4881
+ METHOD_HEADER (0 )
4882
+
4883
+ args.rval ().set (RequestOrResponse::url (self));
4884
+ return true ;
4885
+ }
4886
+
4887
+ // TODO: store version client-side.
4888
+ bool version_get (JSContext *cx, unsigned argc, Value *vp) {
4889
+ METHOD_HEADER (0 )
4890
+
4891
+ uint32_t version = 0 ;
4892
+ if (!HANDLE_RESULT (cx, xqd_resp_version_get (response_handle (self), &version)))
4893
+ return false ;
4894
+
4895
+ args.rval ().setInt32 (version);
4896
+ return true ;
4897
+ }
4898
+
4899
+ JSString *type_default_atom;
4900
+ JSString *type_error_atom;
4901
+
4902
+ bool type_get (JSContext *cx, unsigned argc, Value *vp) {
4903
+ METHOD_HEADER (0 )
4904
+
4905
+ args.rval ().setString (status (self) == 0 ? type_error_atom : type_default_atom);
4906
+ return true ;
4907
+ }
4908
+
4909
+ bool headers_get (JSContext *cx, unsigned argc, Value *vp) {
4910
+ METHOD_HEADER (0 )
4911
+
4912
+ JSObject *headers = RequestOrResponse::headers<Headers::Mode::ProxyToResponse>(cx, self);
4913
+ if (!headers)
4914
+ return false ;
4915
+
4916
+ args.rval ().setObject (*headers);
4917
+ return true ;
4918
+ }
4919
+
4920
+ template <BodyReadResult result_type> bool bodyAll (JSContext *cx, unsigned argc, Value *vp) {
4921
+ METHOD_HEADER (0 )
4922
+ return RequestOrResponse::bodyAll<result_type>(cx, args, self);
4923
+ }
4924
+
4925
+ bool body_get (JSContext *cx, unsigned argc, Value *vp) {
4926
+ METHOD_HEADER (0 )
4927
+ return RequestOrResponse::body_get (cx, args, self, true );
4928
+ }
4929
+
4930
+ bool bodyUsed_get (JSContext *cx, unsigned argc, Value *vp) {
4931
+ METHOD_HEADER (0 )
4932
+ args.rval ().setBoolean (RequestOrResponse::body_used (self));
4933
+ return true ;
4934
+ }
4935
+
4936
+ const JSFunctionSpec methods[] = {
4937
+ JS_FN (" arrayBuffer" , bodyAll<BodyReadResult::ArrayBuffer>, 0 , JSPROP_ENUMERATE),
4938
+ JS_FN (" json" , bodyAll<BodyReadResult::JSON>, 0 , JSPROP_ENUMERATE),
4939
+ JS_FN (" text" , bodyAll<BodyReadResult::Text>, 0 , JSPROP_ENUMERATE), JS_FS_END};
4940
+
4941
+ const JSPropertySpec properties[] = {JS_PSG (" type" , type_get, JSPROP_ENUMERATE),
4942
+ JS_PSG (" url" , url_get, JSPROP_ENUMERATE),
4943
+ JS_PSG (" status" , status_get, JSPROP_ENUMERATE),
4944
+ JS_PSG (" ok" , ok_get, JSPROP_ENUMERATE),
4945
+ JS_PSG (" statusText" , statusText_get, 0 ),
4946
+ JS_PSG (" version" , version_get, JSPROP_ENUMERATE),
4947
+ JS_PSG (" headers" , headers_get, JSPROP_ENUMERATE),
4948
+ JS_PSG (" body" , body_get, JSPROP_ENUMERATE),
4949
+ JS_PSG (" bodyUsed" , bodyUsed_get, JSPROP_ENUMERATE),
4950
+ JS_PS_END};
4951
+
4952
+ bool constructor (JSContext *cx, unsigned argc, Value *vp);
4953
+
4954
+ CLASS_BOILERPLATE_CUSTOM_INIT (Response)
4955
+
4956
+ JSObject *create (JSContext *cx, HandleObject response, ResponseHandle response_handle,
4957
+ BodyHandle body_handle, bool is_upstream);
4856
4958
4857
4959
/* *
4858
4960
* The `Response` constructor https://fetch.spec.whatwg.org/#dom-response
@@ -4923,7 +5025,8 @@ bool constructor(JSContext *cx, unsigned argc, Value *vp) {
4923
5025
return false ;
4924
5026
}
4925
5027
4926
- RootedObject response (cx, create (cx, response_handle, body_handle, false ));
5028
+ RootedObject responseInstance (cx, JS_NewObjectForConstructor (cx, &class_, args));
5029
+ RootedObject response (cx, create (cx, responseInstance, response_handle, body_handle, false ));
4927
5030
if (!response) {
4928
5031
return false ;
4929
5032
}
@@ -4988,106 +5091,6 @@ bool constructor(JSContext *cx, unsigned argc, Value *vp) {
4988
5091
return true ;
4989
5092
}
4990
5093
4991
- const unsigned ctor_length = 1 ;
4992
-
4993
- bool check_receiver (JSContext *cx, HandleValue receiver, const char *method_name);
4994
-
4995
- bool ok_get (JSContext *cx, unsigned argc, Value *vp) {
4996
- METHOD_HEADER (0 )
4997
-
4998
- uint16_t status = Response::status (self);
4999
- args.rval ().setBoolean (status >= 200 && status < 300 );
5000
- return true ;
5001
- }
5002
-
5003
- bool status_get (JSContext *cx, unsigned argc, Value *vp) {
5004
- METHOD_HEADER (0 )
5005
-
5006
- args.rval ().setInt32 (status (self));
5007
- return true ;
5008
- }
5009
-
5010
- bool statusText_get (JSContext *cx, unsigned argc, Value *vp) {
5011
- METHOD_HEADER (0 )
5012
-
5013
- args.rval ().setString (status_message (self));
5014
- return true ;
5015
- }
5016
-
5017
- bool url_get (JSContext *cx, unsigned argc, Value *vp) {
5018
- METHOD_HEADER (0 )
5019
-
5020
- args.rval ().set (RequestOrResponse::url (self));
5021
- return true ;
5022
- }
5023
-
5024
- // TODO: store version client-side.
5025
- bool version_get (JSContext *cx, unsigned argc, Value *vp) {
5026
- METHOD_HEADER (0 )
5027
-
5028
- uint32_t version = 0 ;
5029
- if (!HANDLE_RESULT (cx, xqd_resp_version_get (response_handle (self), &version)))
5030
- return false ;
5031
-
5032
- args.rval ().setInt32 (version);
5033
- return true ;
5034
- }
5035
-
5036
- JSString *type_default_atom;
5037
- JSString *type_error_atom;
5038
-
5039
- bool type_get (JSContext *cx, unsigned argc, Value *vp) {
5040
- METHOD_HEADER (0 )
5041
-
5042
- args.rval ().setString (status (self) == 0 ? type_error_atom : type_default_atom);
5043
- return true ;
5044
- }
5045
-
5046
- bool headers_get (JSContext *cx, unsigned argc, Value *vp) {
5047
- METHOD_HEADER (0 )
5048
-
5049
- JSObject *headers = RequestOrResponse::headers<Headers::Mode::ProxyToResponse>(cx, self);
5050
- if (!headers)
5051
- return false ;
5052
-
5053
- args.rval ().setObject (*headers);
5054
- return true ;
5055
- }
5056
-
5057
- template <BodyReadResult result_type> bool bodyAll (JSContext *cx, unsigned argc, Value *vp) {
5058
- METHOD_HEADER (0 )
5059
- return RequestOrResponse::bodyAll<result_type>(cx, args, self);
5060
- }
5061
-
5062
- bool body_get (JSContext *cx, unsigned argc, Value *vp) {
5063
- METHOD_HEADER (0 )
5064
- return RequestOrResponse::body_get (cx, args, self, true );
5065
- }
5066
-
5067
- bool bodyUsed_get (JSContext *cx, unsigned argc, Value *vp) {
5068
- METHOD_HEADER (0 )
5069
- args.rval ().setBoolean (RequestOrResponse::body_used (self));
5070
- return true ;
5071
- }
5072
-
5073
- const JSFunctionSpec methods[] = {
5074
- JS_FN (" arrayBuffer" , bodyAll<BodyReadResult::ArrayBuffer>, 0 , JSPROP_ENUMERATE),
5075
- JS_FN (" json" , bodyAll<BodyReadResult::JSON>, 0 , JSPROP_ENUMERATE),
5076
- JS_FN (" text" , bodyAll<BodyReadResult::Text>, 0 , JSPROP_ENUMERATE), JS_FS_END};
5077
-
5078
- const JSPropertySpec properties[] = {JS_PSG (" type" , type_get, JSPROP_ENUMERATE),
5079
- JS_PSG (" url" , url_get, JSPROP_ENUMERATE),
5080
- JS_PSG (" status" , status_get, JSPROP_ENUMERATE),
5081
- JS_PSG (" ok" , ok_get, JSPROP_ENUMERATE),
5082
- JS_PSG (" statusText" , statusText_get, 0 ),
5083
- JS_PSG (" version" , version_get, JSPROP_ENUMERATE),
5084
- JS_PSG (" headers" , headers_get, JSPROP_ENUMERATE),
5085
- JS_PSG (" body" , body_get, JSPROP_ENUMERATE),
5086
- JS_PSG (" bodyUsed" , bodyUsed_get, JSPROP_ENUMERATE),
5087
- JS_PS_END};
5088
-
5089
- CLASS_BOILERPLATE_CUSTOM_INIT (Response)
5090
-
5091
5094
bool init_class (JSContext *cx, HandleObject global) {
5092
5095
if (!init_class_impl (cx, global)) {
5093
5096
return false ;
@@ -5099,12 +5102,8 @@ bool init_class(JSContext *cx, HandleObject global) {
5099
5102
(type_error_atom = JS_AtomizeAndPinString (cx, " error" ));
5100
5103
}
5101
5104
5102
- JSObject *create (JSContext *cx, ResponseHandle response_handle, BodyHandle body_handle,
5103
- bool is_upstream) {
5104
- RootedObject response (cx, JS_NewObjectWithGivenProto (cx, &class_, proto_obj));
5105
- if (!response)
5106
- return nullptr ;
5107
-
5105
+ JSObject *create (JSContext *cx, HandleObject response, ResponseHandle response_handle,
5106
+ BodyHandle body_handle, bool is_upstream) {
5108
5107
JS::SetReservedSlot (response, Slots::Response, JS::Int32Value (response_handle.handle ));
5109
5108
JS::SetReservedSlot (response, Slots::Headers, JS::NullValue ());
5110
5109
JS::SetReservedSlot (response, Slots::Body, JS::Int32Value (body_handle.handle ));
@@ -7633,7 +7632,12 @@ bool process_pending_requests(JSContext *cx) {
7633
7632
return JS::RejectPromise (cx, response_promise, exn);
7634
7633
}
7635
7634
7636
- RootedObject response (cx, Response::create (cx, response_handle, body, true ));
7635
+ RootedObject response_instance (
7636
+ cx, JS_NewObjectWithGivenProto (cx, &Response::class_, Response::proto_obj));
7637
+ if (!response_instance)
7638
+ return false ;
7639
+
7640
+ RootedObject response (cx, Response::create (cx, response_instance, response_handle, body, true ));
7637
7641
if (!response)
7638
7642
return false ;
7639
7643
0 commit comments