Skip to content
Open
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
11 changes: 7 additions & 4 deletions src/ffi/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -634,19 +634,22 @@ Maybe<FFIArgumentCategory> ToFFIArgument(Environment* env,

*static_cast<uint16_t*>(ret) = static_cast<uint16_t>(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<int32_t*>(ret) = arg->Int32Value(context).FromJust();
*static_cast<int32_t*>(ret) = static_cast<int32_t>(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<uint32_t*>(ret) = arg->Uint32Value(context).FromJust();
*static_cast<uint32_t*>(ret) = static_cast<uint32_t>(value);
} else if (type == &ffi_type_sint64) {
if (arg->IsBigInt()) {
bool lossless;
Expand Down
2 changes: 2 additions & 0 deletions test/ffi/test-ffi-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading