1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
use super::*;
/// The Response class.
/// [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Response {
inner: Any,
}
impl FromVal for Response {
fn from_val(v: &Any) -> Self {
Response {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for Response {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for Response {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for Response {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for Response {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<Response> for Any {
fn from(s: Response) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&Response> for Any {
fn from(s: &Response) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(Response);
impl Response {
/// Getter of the `type` attribute.
/// [`Response.type`](https://developer.mozilla.org/en-US/docs/Web/API/Response/type)
pub fn type_(&self) -> ResponseType {
self.inner.get("type").as_::<ResponseType>()
}
}
impl Response {
/// Getter of the `url` attribute.
/// [`Response.url`](https://developer.mozilla.org/en-US/docs/Web/API/Response/url)
pub fn url(&self) -> JsString {
self.inner.get("url").as_::<JsString>()
}
}
impl Response {
/// Getter of the `redirected` attribute.
/// [`Response.redirected`](https://developer.mozilla.org/en-US/docs/Web/API/Response/redirected)
pub fn redirected(&self) -> bool {
self.inner.get("redirected").as_::<bool>()
}
}
impl Response {
/// Getter of the `status` attribute.
/// [`Response.status`](https://developer.mozilla.org/en-US/docs/Web/API/Response/status)
pub fn status(&self) -> u16 {
self.inner.get("status").as_::<u16>()
}
}
impl Response {
/// Getter of the `ok` attribute.
/// [`Response.ok`](https://developer.mozilla.org/en-US/docs/Web/API/Response/ok)
pub fn ok(&self) -> bool {
self.inner.get("ok").as_::<bool>()
}
}
impl Response {
/// Getter of the `statusText` attribute.
/// [`Response.statusText`](https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText)
pub fn status_text(&self) -> JsString {
self.inner.get("statusText").as_::<JsString>()
}
}
impl Response {
/// Getter of the `headers` attribute.
/// [`Response.headers`](https://developer.mozilla.org/en-US/docs/Web/API/Response/headers)
pub fn headers(&self) -> Headers {
self.inner.get("headers").as_::<Headers>()
}
}
impl Response {
/// Getter of the `body` attribute.
/// [`Response.body`](https://developer.mozilla.org/en-US/docs/Web/API/Response/body)
pub fn body(&self) -> ReadableStream {
self.inner.get("body").as_::<ReadableStream>()
}
}
impl Response {
/// Getter of the `bodyUsed` attribute.
/// [`Response.bodyUsed`](https://developer.mozilla.org/en-US/docs/Web/API/Response/bodyUsed)
pub fn body_used(&self) -> bool {
self.inner.get("bodyUsed").as_::<bool>()
}
}
impl Response {
/// The `new Response(..)` constructor, creating a new Response instance
pub fn new() -> Response {
Self {
inner: Any::global("Response").new(&[]).as_::<Any>(),
}
}
}
impl Response {
/// The `new Response(..)` constructor, creating a new Response instance
pub fn new_with_body(body: &Any) -> Response {
Self {
inner: Any::global("Response").new(&[body.into()]).as_::<Any>(),
}
}
}
impl Response {
/// The `new Response(..)` constructor, creating a new Response instance
pub fn new_with_body_and_init(body: &Any, init: &ResponseInit) -> Response {
Self {
inner: Any::global("Response")
.new(&[body.into(), init.into()])
.as_::<Any>(),
}
}
}
impl Response {
/// The error method.
/// [`Response.error`](https://developer.mozilla.org/en-US/docs/Web/API/Response/error)
pub fn error() -> Response {
Any::global("Response").call("error", &[]).as_::<Response>()
}
}
impl Response {
/// The redirect method.
/// [`Response.redirect`](https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect)
pub fn redirect(url: &JsString) -> Response {
Any::global("Response")
.call("redirect", &[url.into()])
.as_::<Response>()
}
}
impl Response {
/// The redirect method.
/// [`Response.redirect`](https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect)
pub fn redirect_with_status(url: &JsString, status: u16) -> Response {
Any::global("Response")
.call("redirect", &[url.into(), status.into()])
.as_::<Response>()
}
}
impl Response {
/// The json method.
/// [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json)
pub fn json(data: &Any) -> Response {
Any::global("Response")
.call("json", &[data.into()])
.as_::<Response>()
}
}
impl Response {
/// The json method.
/// [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json)
pub fn json_with_init(data: &Any, init: &ResponseInit) -> Response {
Any::global("Response")
.call("json", &[data.into(), init.into()])
.as_::<Response>()
}
}
impl Response {
/// The clone method.
/// [`Response.clone`](https://developer.mozilla.org/en-US/docs/Web/API/Response/clone)
pub fn clone_(&self) -> Response {
self.inner.call("clone", &[]).as_::<Response>()
}
}
impl Response {
/// The arrayBuffer method.
/// [`Response.arrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/API/Response/arrayBuffer)
pub fn array_buffer(&self) -> Promise<ArrayBuffer> {
self.inner
.call("arrayBuffer", &[])
.as_::<Promise<ArrayBuffer>>()
}
}
impl Response {
/// The blob method.
/// [`Response.blob`](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob)
pub fn blob(&self) -> Promise<Blob> {
self.inner.call("blob", &[]).as_::<Promise<Blob>>()
}
}
impl Response {
/// The bytes method.
/// [`Response.bytes`](https://developer.mozilla.org/en-US/docs/Web/API/Response/bytes)
pub fn bytes(&self) -> Promise<Uint8Array> {
self.inner.call("bytes", &[]).as_::<Promise<Uint8Array>>()
}
}
impl Response {
/// The formData method.
/// [`Response.formData`](https://developer.mozilla.org/en-US/docs/Web/API/Response/formData)
pub fn form_data(&self) -> Promise<FormData> {
self.inner.call("formData", &[]).as_::<Promise<FormData>>()
}
}
impl Response {
/// The json method.
/// [`Response.json`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json)
pub fn json_2(&self) -> Promise<Any> {
self.inner.call("json", &[]).as_::<Promise<Any>>()
}
}
impl Response {
/// The text method.
/// [`Response.text`](https://developer.mozilla.org/en-US/docs/Web/API/Response/text)
pub fn text(&self) -> Promise<JsString> {
self.inner.call("text", &[]).as_::<Promise<JsString>>()
}
}