Commit ad63e9ef29d for nodejs
commit ad63e9ef29d3f70081dda871da46f9fa187d38fd
Author: Donghoon Kang <d159123@naver.com>
Date: Sat Sep 26 03:58:21 2026 +0900
ffi: use type errors for invalid signatures
Signed-off-by: HoonDongKang <d159123@naver.com>
PR-URL: https://github.com/nodejs/node/pull/66222
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
diff --git a/src/ffi/types.cc b/src/ffi/types.cc
index 83be0f48ecc..bf3e7e675ed 100644
--- a/src/ffi/types.cc
+++ b/src/ffi/types.cc
@@ -107,7 +107,7 @@ Maybe<FunctionSignature> ParseFunctionSignature(Environment* env,
}
if (!return_type_val->IsString()) {
- THROW_ERR_INVALID_ARG_VALUE(
+ THROW_ERR_INVALID_ARG_TYPE(
env, "Return value type of function %s must be a string", name);
return {};
}
@@ -132,7 +132,7 @@ Maybe<FunctionSignature> ParseFunctionSignature(Environment* env,
}
if (!arguments_val->IsArray()) {
- THROW_ERR_INVALID_ARG_VALUE(
+ THROW_ERR_INVALID_ARG_TYPE(
env, "Arguments list of function %s must be an array", name);
return {};
}
@@ -148,7 +148,7 @@ Maybe<FunctionSignature> ParseFunctionSignature(Environment* env,
}
if (!arg->IsString()) {
- THROW_ERR_INVALID_ARG_VALUE(
+ THROW_ERR_INVALID_ARG_TYPE(
env, "Argument %u of function %s must be a string", i, name);
return {};
}
diff --git a/test/ffi/test-ffi-dynamic-library.js b/test/ffi/test-ffi-dynamic-library.js
index c7741a9eed5..3240f194972 100644
--- a/test/ffi/test-ffi-dynamic-library.js
+++ b/test/ffi/test-ffi-dynamic-library.js
@@ -432,6 +432,24 @@ test('dynamic library APIs validate failures and bad signatures', () => {
lib.getFunction('add_i32', { return: 'i32', arguments: ['i32\0bad'] });
}, /Argument 0 of function add_i32 must not contain null bytes/);
+ assert.throws(() => {
+ lib.getFunction('add_i32', { return: 1, arguments: [] });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+
+ assert.throws(() => {
+ lib.getFunction('add_i32', { return: 'i32', arguments: 'i32' });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+
+ assert.throws(() => {
+ lib.getFunction('add_i32', { return: 'i32', arguments: [1] });
+ }, {
+ code: 'ERR_INVALID_ARG_TYPE',
+ });
+
assert.throws(() => {
lib.getFunctions('not an object');
}, {