Skip to content

Commit 9a0ad8a

Browse files
Nakshatra480Nakshatra Sharma
andauthored
feat(runtime): add Response.ok getter per Fetch Standard §7.1 (#5016)
## Summary Adds the `Response.ok` read-only getter to `JsResponse` in `boa_runtime`, aligning with the Fetch Standard §7.1. ## Changes - **response.rs**: Added `#[boa(getter)] fn ok()` - returns `true` if status is in the range 200–299, `false` otherwise (including no status). ## Behavior ```js const res = new Response('body', { status: 200 }); console.log(res.ok); // true const err = new Response('body', { status: 404 }); console.log(err.ok); // false ``` ## Testing - [x] `cargo check -p boa_runtime` passes - [x] `cargo clippy --all-features --all-targets -- -D warnings` passes (0 warnings) - [x] `cargo fmt --all -- --check` passes - [x] `cargo test -p boa_runtime` passes (70/70) ## Spec Reference - https://fetch.spec.whatwg.org/#dom-response-ok Co-authored-by: Nakshatra Sharma <nakshatrasharma@Nakshatras-MacBook-Air.local>
1 parent 5d77cf8 commit 9a0ad8a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

core/runtime/src/fetch/response.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ impl JsResponse {
176176
self.status.map_or(0, |s| s.as_u16())
177177
}
178178

179+
#[boa(getter)]
180+
fn ok(&self) -> bool {
181+
let status = self.status();
182+
(200..=299).contains(&status)
183+
}
184+
179185
#[boa(getter)]
180186
fn status_text(&self) -> JsString {
181187
if let Some(status) = self.status {

0 commit comments

Comments
 (0)