Skip to content

napi: enforce the pending-exception gate in NAPI_PREAMBLE - #34137

Merged
Jarred-Sumner merged 4 commits into
mainfrom
farm/b23bf3dc/napi-pending-exception-gate
Jul 14, 2026
Merged

Jarred-Sumner merged 4 commits into
mainfrom
farm/b23bf3dc/napi-pending-exception-gate

napi: gate NAPI_PREAMBLE on env->hasPendingException()

1d45ca1
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Jul 14, 2026 in 19m 23s

Code review found 1 important issue

Found 3 candidates, confirmed 2. See review comments for details.

Details

Severity Count
🔴 Important 1
🟡 Nit 1
🟣 Pre-existing 0
Severity File:Line Issue
🔴 Important src/jsc/bindings/napi.cpp:91-94 NAPI_PREAMBLE change over-gates ~25 entry points that Node.js does NOT gate
🟡 Nit src/jsc/bindings/napi.cpp:1696-1699 napi_throw_error/type_error/range_error/syntax_error still not gated on pending exception

Annotations

Check failure on line 94 in src/jsc/bindings/napi.cpp

See this annotation in the file changed.

@claude claude / Claude Code Review

NAPI_PREAMBLE change over-gates ~25 entry points that Node.js does NOT gate

Changing `NAPI_PREAMBLE` to call `NAPI_RETURN_IF_EXCEPTION` over-gates ~25 entry points that Node.js does **not** gate on a pending exception — including `napi_get_cb_info`, `napi_get_global`, `napi_create_reference`, `napi_reference_ref`/`unref`, `napi_get_reference_value`, `napi_add_finalizer`, `napi_get_instance_data`, `napi_get_value_bigint_*`, `napi_create_bigint_int64`/`uint64`, `napi_create_symbol`, `napi_is_buffer`/`typedarray`, `napi_is_detached_arraybuffer`, `napi_detach_arraybuffer`, 

Check warning on line 1699 in src/jsc/bindings/napi.cpp

See this annotation in the file changed.

@claude claude / Claude Code Review

napi_throw_error/type_error/range_error/syntax_error still not gated on pending exception

Four `NAPI_PREAMBLE_NO_THROW_SCOPE` siblings that Node.js also gates with `NAPI_PREAMBLE` were missed: `napi_throw_error` (:1129), `napi_throw_type_error` (:1457), `napi_throw_range_error` (:1618), and `node_api_throw_syntax_error` (:1450). All four dispatch to `throwErrorWithCStrings()` which unconditionally overwrites `m_pendingException` and returns `napi_ok`, so a second `napi_throw_error` silently replaces the first exception where Node returns `napi_pending_exception` and preserves it. Pre