From 953bd2776390e0c8c2cf9201be63fc553fbeb48a Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:51:25 -0700 Subject: [PATCH] ffi: accept -0 for int32 and uint32 arguments ToFFIArgument validated int32/uint32 with IsInt32()/IsUint32(), which reject -0, while every other integer width and the Fast API and SharedBuffer paths accept it. Use the same validators as the 8- and 16-bit branches so behavior no longer depends on the JIT tier. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5.5 --- src/ffi/types.cc | 11 +++++++---- test/ffi/test-ffi-calls.js | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ffi/types.cc b/src/ffi/types.cc index 5a910e63a3e3..971ca8b6adbb 100644 --- a/src/ffi/types.cc +++ b/src/ffi/types.cc @@ -634,19 +634,22 @@ Maybe ToFFIArgument(Environment* env, *static_cast(ret) = static_cast(value); } else if (type == &ffi_type_sint32) { - if (!arg->IsInt32()) { + int64_t value; + if (!GetValidatedSignedInt(env, arg, INT32_MIN, INT32_MAX, "int32") + .To(&value)) { THROW_ERR_INVALID_ARG_VALUE(env, "Argument %u must be an int32", index); return {}; } - *static_cast(ret) = arg->Int32Value(context).FromJust(); + *static_cast(ret) = static_cast(value); } else if (type == &ffi_type_uint32) { - if (!arg->IsUint32()) { + uint64_t value; + if (!GetValidatedUnsignedInt(env, arg, UINT32_MAX, "uint32").To(&value)) { THROW_ERR_INVALID_ARG_VALUE(env, "Argument %u must be a uint32", index); return {}; } - *static_cast(ret) = arg->Uint32Value(context).FromJust(); + *static_cast(ret) = static_cast(value); } else if (type == &ffi_type_sint64) { if (arg->IsBigInt()) { bool lossless; diff --git a/test/ffi/test-ffi-calls.js b/test/ffi/test-ffi-calls.js index 0dbddb244b77..338a728bd227 100644 --- a/test/ffi/test-ffi-calls.js +++ b/test/ffi/test-ffi-calls.js @@ -20,6 +20,8 @@ test('ffi calls support integer arithmetic and char semantics', () => { assert.strictEqual(symbols.add_u16(65_530, 10), 4); assert.strictEqual(symbols.add_i32(-10, 52), 42); assert.strictEqual(symbols.add_u32(0xFFFFFFFF, 1), 0); + assert.strictEqual(symbols.add_i32(-0, 1), 1); + assert.strictEqual(symbols.add_u32(-0, 1), 1); assert.strictEqual(symbols.add_i64(20n, 22n), 42n); assert.strictEqual(symbols.add_u64(20n, 22n), 42n); assert.strictEqual(symbols.add_i64(20, 22), symbols.add_i64(20n, 22n));