(&self, ctx: Ctx<'js>)
| 387 | } |
| 388 | |
| 389 | pub fn text(&self, ctx: Ctx<'js>) -> Result<Promise<'js>> { |
| 390 | let body = match self.take_body_sync(&ctx) { |
| 391 | Ok(b) => b, |
| 392 | Err(e) => return reject_with_error(&ctx, e), |
| 393 | }; |
| 394 | let ctx_clone = ctx.clone(); |
| 395 | Promise::wrap_future(&ctx, async move { |
| 396 | let bytes_opt = resolve_body_taken(&ctx_clone, body).await?; |
| 397 | if let Some(bytes) = bytes_opt { |
| 398 | let bytes = strip_bom(bytes); |
| 399 | return Result::<String>::Ok(match String::from_utf8(bytes.into()) { |
| 400 | Ok(s) => s, |
| 401 | Err(e) => String::from_utf8_lossy(e.as_bytes()).into_owned(), |
| 402 | }); |
| 403 | } |
| 404 | Ok(String::new()) |
| 405 | }) |
| 406 | } |
| 407 | |
| 408 | pub fn json(&self, ctx: Ctx<'js>) -> Result<Promise<'js>> { |
| 409 | let body = match self.take_body_sync(&ctx) { |
nothing calls this directly
no test coverage detected