Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mordant-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"reimplemented_helper:src/runtime/api/bun/Terminal.rs" = 1
"reimplemented_helper:src/runtime/ffi/abi_type.rs" = 1
"reimplemented_helper:src/runtime/hw_exports.rs" = 1
"same_match_twice:src/runtime/api/YAMLObject.rs" = 1
"same_match_twice:src/runtime/api/bun/h2_frame_parser.rs" = 1
"same_match_twice:src/runtime/api/csrf_jsc.rs" = 1
"same_match_twice:src/runtime/bake/dev_server/mod.rs" = 1
Expand Down
34 changes: 20 additions & 14 deletions src/runtime/api/YAMLObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,13 @@ fn stringify(global: &JSGlobalObject, call_frame: &CallFrame) -> JsResult<JSValu

let mut stringifier = Stringifier::init(global, space_value)?;

if let Err(err) = stringifier.find_anchors_and_aliases(global, value, ValueOrigin::Root) {
return match err {
StringifyError::OutOfMemory => Err(JsError::OutOfMemory),
StringifyError::JsError => Err(JsError::Thrown),
StringifyError::StackOverflow => Err(global.throw_stack_overflow()),
};
}
stringifier
.find_anchors_and_aliases(global, value, ValueOrigin::Root)
.map_err(|err| err.to_js_error(global))?;

if let Err(err) = stringifier.stringify(global, value) {
return match err {
StringifyError::OutOfMemory => Err(JsError::OutOfMemory),
StringifyError::JsError => Err(JsError::Thrown),
StringifyError::StackOverflow => Err(global.throw_stack_overflow()),
};
}
stringifier
.stringify(global, value)
.map_err(|err| err.to_js_error(global))?;

stringifier.builder.to_string(global)
}
Expand Down Expand Up @@ -176,6 +168,20 @@ impl From<JsError> for StringifyError {
}
}

impl StringifyError {
/// `OutOfMemory` and `JsError` are already JS-shaped (the host-fn wrapper
/// throws the former, the latter's exception is pending); only
/// `StackOverflow` still has to be thrown here.
#[cold]
fn to_js_error(self, global: &JSGlobalObject) -> JsError {
match self {
StringifyError::OutOfMemory => JsError::OutOfMemory,
StringifyError::JsError => JsError::Thrown,
StringifyError::StackOverflow => global.throw_stack_overflow(),
}
}
}

bun_core::oom_from_alloc!(StringifyError);

impl Stringifier {
Expand Down
Loading