Repository navigation
napi: map Float16Array in napi_get_typedarray_info/napi_create_typedarray - #34144
Conversation
|
Updated 2:25 PM PT - Jul 14th, 2026
❌ @robobun, your commit 7cc3ab5 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 34144That installs a local version of the PR into your bun-34144 --bun |
|
This PR may be a duplicate of:
🤖 Generated with Claude Code |
|
Not a duplicate: #34141 is the test-addon dedup only, this PR is the Float16Array napi mapping fix. The dedup is included here because the napi test addon does not compile on |
WalkthroughAdds N-API Float16 typed-array enum support, maps ChangesFloat16 typed-array support
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@test/napi/napi-app/standalone_tests.cpp`:
- Around line 2661-2686: Guard the napi_instanceof call in the created-handle
validation block so it executes only when napi_create_typedarray returned
napi_ok. Preserve the existing default is_instance value and output, allowing
creation failures to be reported through create_status without passing the null
created handle to napi_instanceof.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5a1e56a7-e762-46a7-83e0-3a22027b8610
📒 Files selected for processing (7)
src/jsc/bindings/napi.cppsrc/runtime/napi/js_native_api_types.hsrc/runtime/napi/napi_body.rstest/napi/napi-app/js_test_helpers.cpptest/napi/napi-app/module.jstest/napi/napi-app/standalone_tests.cpptest/napi/napi.test.ts
💤 Files with no reviewable changes (1)
- test/napi/napi-app/js_test_helpers.cpp
There was a problem hiding this comment.
LGTM — the Windows CRLF fix in ee4e350 addresses my earlier comment.
Checked: the three napi.cpp switch arms map to existing JSC::TypeFloat16/JSC::JSFloat16Array, matching sibling cases exactly; jsc::JSType::Float16Array exists for the Rust match arm; enum ordinal 11 matches upstream Node's napi_float16_array.
Verified fp16(1.5) = 0x3E00 for the test's expected output, and checkSameOutput cross-validates against Node.
The js_test_helpers.cpp/module.js dedup is byte-identical to #34141 as stated.
Extended reasoning...
Overview
Adds napi_float16_array support to Bun's N-API layer: one enum member in the vendored js_native_api_types.h, one Rust enum variant + match arm in napi_body.rs, and three switch-case arms in napi.cpp (getTypedArrayTypeFromNAPI, createArrayBufferView, and the napi_create_typedarray range guard). A native test helper in standalone_tests.cpp plus a checkSameOutput case in napi.test.ts exercise both directions. Also carries the #34141 test-addon dedup so the addon compiles.
Security risks
None. This is an enum-table extension in the N-API compatibility layer; no new allocations, lifetimes, or untrusted-input parsing.
Level of scrutiny
Low-to-medium. The production diff is purely mechanical — every added arm copies the exact shape of the adjacent napi_biguint64_array case with the type name swapped. I verified JSC::TypedArrayType::TypeFloat16, JSC::JSFloat16Array, and jsc::JSType::Float16Array all already exist in the codebase, and that the enum value 11 (following biguint64_array = 10) matches upstream Node.js. The #define NODE_API_HAS_FLOAT16_ARRAY marker mirrors Node's header. No CODEOWNERS cover these paths.
Other factors
Both prior review comments are addressed and resolved: CodeRabbit's napi_instanceof null-guard (1df2842) and my Windows CRLF split (ee4e350). The bug-hunting system found nothing on the current revision. The test is strong — checkSameOutput runs the same native helper under both Bun and an ABI-matching Node and asserts byte-identical stdout, so any divergence in type id, length, byte offset, data pointer arithmetic, or instanceof result would fail. The fp16 bit pattern for 1.5 (0x3E00) checks out.
|
CI on ee4e350: the new The reds are unrelated to this diff:
Ready for review. |
…rray napi_is_typedarray already reported true for a Float16Array, but both napi_get_typedarray_info and napi_create_typedarray(napi_float16_array) returned napi_invalid_arg because the napi_typedarray_type <-> JSC type tables stopped at biguint64. Add napi_float16_array (= 11, matching Node's js_native_api_types.h) to the vendored header, to the Rust napi_typedarray_type enum and its from_js_type mapping, and to the three switches in napi.cpp that drive napi_create_typedarray. Also dedup a get_all_property_names helper in the napi test addon that was left doubly defined after #34126 and #34130 both added one; the addon did not compile on main.
ee4e350 to
7cc3ab5
Compare
There was a problem hiding this comment.
LGTM — mechanical enum-table extension for napi_float16_array, prior review feedback addressed and CI green.
What was reviewed:
- The three C++ switch arms and the Rust
from_js_typearm follow the sibling entries exactly;JSC::TypeFloat16/JSFloat16Array/jsc::JSType::Float16Arrayall already exist. - Grepped for other
napi_typedarray_type⇄ JSC mapping tables — none missed (array_buffer.rsalready handles Float16 independently). - Test compares byte-for-byte against Node via
checkSameOutput; the Windows CRLF and null-creatednapi_instanceofconcerns from earlier review rounds are both fixed in the current diff.
Extended reasoning...
Overview
Adds napi_float16_array (= 11) to the N-API typed-array enum and wires it through every mapping table that previously stopped at napi_biguint64_array: the vendored js_native_api_types.h header (with the upstream NODE_API_HAS_FLOAT16_ARRAY marker), the Rust napi_typedarray_type enum and its from_js_type match, and three switches in napi.cpp (getTypedArrayTypeFromNAPI, createArrayBufferView, and the napi_create_typedarray range guard). A native test helper and a checkSameOutput test in napi.test.ts exercise both napi_get_typedarray_info and napi_create_typedarray against Node.
Security risks
None. This is a type-mapping table extension for a typed-array kind JSC already supports; no new parsing of untrusted input, no allocation-size arithmetic, no auth/crypto surface.
Level of scrutiny
Low-to-moderate. Each new arm is a one-line copy of the immediately preceding sibling with the type name substituted. I verified via grep that JSC::TypedArrayType::TypeFloat16, JSC::JSFloat16Array, and jsc::JSType::Float16Array are all pre-existing types already used in array_buffer.rs, JSType.rs, and other bindings, so there is no risk of a dangling reference. I also grepped src/ for every occurrence of napi_typedarray_type and napi_biguint64_array to confirm no other mapping table was missed — the only hits are the three files this PR touches plus a stale layering comment in array_buffer.rs.
Other factors
- Both prior review comments (my Windows CRLF note and CodeRabbit's
napi_instanceofnull-handle guard) are addressed and marked resolved; the current diff reflects both fixes. - The test asserts exact status codes, type=11, length/byte_offset, the fp16 bit pattern
0x3E00for 1.5, andinstanceof Float16Array, all cross-checked against Node in the same run. - The author reports the new test passed on every CI lane; remaining reds are unrelated pre-existing flakes.
- No CODEOWNERS entries cover
src/runtime/napi/orsrc/jsc/bindings/napi.cpp. - The earlier
js_test_helpers.cpp/module.jsdedup hunks were dropped after #34133 landed, so the diff is now purely the Float16 change.
|
CI on 7cc3ab5 (rebased): the new Float16Array test passed on every lane of build 72991. The only red annotation is |
Resolve conflicts with #34144 (napi_float16_array): add Float16Array to the NAPI_TYPED_ARRAY_CASE switch in napi_create_typedarray, keep both the new view-validation tests and main's test_napi_float16_array, and simplify the napi_get_typedarray_info guard now that from_js_type covers every typed-array JSType.
What
napi_is_typedarrayreportstruefor aFloat16Array, butnapi_get_typedarray_infoon that same value returnsnapi_invalid_arg(leaving every out-param untouched), andnapi_create_typedarray(napi_float16_array, ...)also returnsnapi_invalid_arg. Node.js v26 shipsnapi_float16_arrayunconditionally (NODE_API_HAS_FLOAT16_ARRAY), so any addon that accepts user-supplied typed arrays works on Node and errors on Bun the moment aFloat16Arraycrosses the ABI.Why
The
napi_typedarray_type⇄ JSC type tables stop atnapi_biguint64_array:napi_typedarray_type::from_js_typeinsrc/runtime/napi/napi_body.rshas noFloat16Arrayarm, sonapi_get_typedarray_infobails withinvalid_argwhen the caller asks for the type.getTypedArrayTypeFromNAPI,createArrayBufferView, and the enum-range guard innapi_create_typedarray(src/jsc/bindings/napi.cpp) have nonapi_float16_arraycase, so creation is rejected before reaching JSC.src/runtime/napi/js_native_api_types.hpredates the enum member entirely.Fix
Add
napi_float16_array(= 11) to the vendored header with theNODE_API_HAS_FLOAT16_ARRAYmarker to match upstream, add the variant to the Rust enum and itsfrom_js_typemapping, and add thenapi_float16_array⇄JSC::TypeFloat16/JSC::JSFloat16Arrayarms to the three switches innapi.cpp.Test
test/napi/napi.test.ts(napi_get_typedarray_info > maps Float16Array to napi_float16_array ...) runs a native addon helper under both Bun and Node and asserts identical output:is_typedarray=1,info_status=0 type=11 length=4 byte_offset=4, first element bytes0x3E00(fp16 for 1.5),create_status=0, andcreated instanceof Float16Array=1. Before the fix, Bun reportsinfo_status=1 type=999and never gets to the create call.no test proof · iteration 4 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/napi/napi.test.ts