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
15 changes: 15 additions & 0 deletions src/bun.js/bindings/napi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,21 @@ extern "C" napi_status napi_get_and_clear_last_exception(napi_env env,
return napi_ok;
}

extern "C" napi_status napi_fatal_exception(napi_env env,
napi_value err)
{
auto globalObject = toJS(env);
JSC::JSValue value = JSC::JSValue::decode(reinterpret_cast<JSC::EncodedJSValue>(err));
JSC::JSObject* obj = value.getObject();
if (UNLIKELY(obj == nullptr || !obj->isErrorInstance())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a subtle difference between an exception and an error and I'm not sure this satisfies that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm also not sure if the value passed here is expected to be a JSC::Exception

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this since its better than the present state regardless

return napi_invalid_arg;
}

Bun__reportUnhandledError(globalObject, JSValue::encode(value));

return napi_ok;
}

extern "C" napi_status napi_throw(napi_env env, napi_value error)
{
auto globalObject = toJS(env);
Expand Down
1 change: 1 addition & 0 deletions src/napi/napi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ pub fn fixDeadCodeElimination() void {
std.mem.doNotOptimizeAway(&napi_get_value_bigint_int64);
std.mem.doNotOptimizeAway(&napi_get_value_bigint_uint64);
std.mem.doNotOptimizeAway(&napi_fatal_error);
std.mem.doNotOptimizeAway(&napi_fatal_exception);
std.mem.doNotOptimizeAway(&napi_create_buffer);
std.mem.doNotOptimizeAway(&napi_create_external_buffer);
std.mem.doNotOptimizeAway(&napi_create_buffer_copy);
Expand Down
1 change: 1 addition & 0 deletions src/symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ _napi_delete_reference
_napi_detach_arraybuffer
_napi_escape_handle
_napi_fatal_error
_napi_fatal_exception
_napi_get_all_property_names
_napi_get_and_clear_last_exception
_napi_get_array_length
Expand Down