fix(bindings): handle errors from String.toJS() for oversized strings (#26213)

## Summary

- When a string exceeds `WTF::String::MaxLength` (~4GB),
`bun.String.createUninitialized()` returns a `.Dead` tag
- The C++ layer now properly throws `ERR_STRING_TOO_LONG` when this
happens
- Updated `String.toJS()` in Zig to return `bun.JSError!jsc.JSValue`
instead of just `jsc.JSValue`
- Updated ~40 Zig caller files to handle the error with `try`
- C++ callers updated with `RETURN_IF_EXCEPTION` checks

## Test plan

- [x] `bun bd test test/js/node/buffer.test.js` - 449 tests pass
- [x] `bun bd
test/js/node/test/parallel/test-buffer-tostring-rangeerror.js` - passes

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
This commit is contained in:
Jarred Sumner
2026-01-21 13:01:25 -08:00
committed by GitHub
parent 7f70b01259
commit b6b3626c14
78 changed files with 471 additions and 436 deletions

View File

@@ -241,7 +241,7 @@ fn SocketHandler(comptime ssl: bool) type {
) void {
const handshakeWasSuccessful = this.#connection.doHandshake(success, ssl_error) catch |err| return this.failFmt(err, "Failed to send handshake response", .{});
if (!handshakeWasSuccessful) {
this.failWithJSValue(ssl_error.toJS(this.#globalObject));
this.failWithJSValue(ssl_error.toJS(this.#globalObject) catch return);
}
}