Skip to content

ffi: accept safe integer numbers for 64-bit arguments - #66197

Open
HoonDongKang wants to merge 2 commits into
nodejs:mainfrom
HoonDongKang:ffi/accept-safe-integer-for-64-bit
Open

HoonDongKang wants to merge 2 commits into
nodejs:mainfrom
HoonDongKang:ffi/accept-safe-integer-for-64-bit

Conversation

@HoonDongKang

@HoonDongKang HoonDongKang commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Accept safe integer numbers for int64/uint64 arguments alongside bigint values, allowing buffer lengths to be passed without explicit BigInt() conversions.

-functions.sum_buffer(bytes, BigInt(bytes.byteLength));
+functions.sum_buffer(bytes, bytes.byteLength);

Changes

  • Accept safe integer numbers for int64 and non-negative safe integer numbers for uint64.
  • Validate and convert arguments across Fast API, SharedBuffer, and generic C++ conversion paths.
  • Preserve existing bigint range checks and bigint return values.
  • Document the accepted number ranges.

Tests

The tests check that number and bigint arguments produce the same results, including when used together. A new single-argument test covers Fast API conversion before and after requesting V8 optimization.

Separate nine-argument tests exercise SharedBuffer conversion and generic fallback. Both check Number and BigInt boundaries, invalid inputs, and error messages.

// SharedBuffer: validates and converts the integer in JavaScript.
functions.passthrough_i64_9(0n, value, ...zeros);

// Generic fallback: validates and converts the integer in C++.
functions.passthrough_i64_9(buffer, value, ...zeros);

Validation

54 tests passed across the following files. Local lint and whitespace checks also passed.

./node --test \
  test/ffi/test-ffi-calls.js \
  test/ffi/test-ffi-fast-integer-validation.js \
  test/ffi/test-ffi-shared-buffer.js


 tests 54
 suites 0
 pass 54
 fail 0
 cancelled 0
 skipped 0
 todo 0
 duration_ms 934.82625

Refs: #66198
Assisted-by: Codex:Astra-medium

Allow safe integer numbers as int64 and uint64 arguments alongside
bigint values. Reject negative numbers for uint64 and numbers outside
the safe integer range. Keep 64-bit return values as bigint.

Apply validation and conversion across the Fast API, shared-buffer,
and generic argument conversion paths.

Add coverage for Number and BigInt boundaries, invalid inputs, and
single-argument calls before and after optimization.

Signed-off-by: HoonDongKang <d159123@naver.com>
Assisted-by: Codex:Astra-medium
Signed-off-by: HoonDongKang <d159123@naver.com>
Assisted-by: Codex:Astra-medium
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run. labels Sep 22, 2026
nguyensyquan731-arch

This comment was marked as off-topic.

@codecov

codecov Bot commented Sep 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.31%. Comparing base (dd9f4da) to head (0c5e7ae).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66197      +/-   ##
==========================================
+ Coverage   90.29%   90.31%   +0.02%     
==========================================
  Files         790      790              
  Lines      272508   272576      +68     
  Branches    52028    52066      +38     
==========================================
+ Hits       246071   246189     +118     
+ Misses      16905    16867      -38     
+ Partials     9532     9520      -12     
Files with missing lines Coverage Δ
lib/internal/ffi-shared-buffer.js 59.37% <100.00%> (+3.63%) ⬆️
lib/internal/ffi/fast-api.js 94.82% <100.00%> (+0.32%) ⬆️
src/ffi/types.cc 60.88% <100.00%> (+7.16%) ⬆️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants