From c44f0f678f183f956e743a026cf32285286f2c33 Mon Sep 17 00:00:00 2001 From: HoonDongKang Date: Wed, 23 Sep 2026 11:59:31 +0900 Subject: [PATCH 1/2] ffi: use type errors for invalid signatures Signed-off-by: HoonDongKang --- src/ffi/types.cc | 6 +++--- test/ffi/test-ffi-dynamic-library.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ffi/types.cc b/src/ffi/types.cc index 83be0f48eccd..bf3e7e675ed6 100644 --- a/src/ffi/types.cc +++ b/src/ffi/types.cc @@ -107,7 +107,7 @@ Maybe 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 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 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 c7741a9eed55..37bec6beaa8a 100644 --- a/test/ffi/test-ffi-dynamic-library.js +++ b/test/ffi/test-ffi-dynamic-library.js @@ -432,6 +432,27 @@ 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', + message: 'Return value type of function add_i32 must be a string', + }); + + assert.throws(() => { + lib.getFunction('add_i32', { return: 'i32', arguments: 'i32' }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'Arguments list of function add_i32 must be an array', + }); + + assert.throws(() => { + lib.getFunction('add_i32', { return: 'i32', arguments: [1] }); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'Argument 0 of function add_i32 must be a string', + }); + assert.throws(() => { lib.getFunctions('not an object'); }, { From f981fef5fc64eafc82198d784674afc25952b822 Mon Sep 17 00:00:00 2001 From: HoonDongKang Date: Thu, 24 Sep 2026 22:24:18 +0900 Subject: [PATCH 2/2] ffi: check only error codes in assertions Signed-off-by: HoonDongKang --- test/ffi/test-ffi-dynamic-library.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/ffi/test-ffi-dynamic-library.js b/test/ffi/test-ffi-dynamic-library.js index 37bec6beaa8a..3240f194972c 100644 --- a/test/ffi/test-ffi-dynamic-library.js +++ b/test/ffi/test-ffi-dynamic-library.js @@ -436,21 +436,18 @@ test('dynamic library APIs validate failures and bad signatures', () => { lib.getFunction('add_i32', { return: 1, arguments: [] }); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'Return value type of function add_i32 must be a string', }); assert.throws(() => { lib.getFunction('add_i32', { return: 'i32', arguments: 'i32' }); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'Arguments list of function add_i32 must be an array', }); assert.throws(() => { lib.getFunction('add_i32', { return: 'i32', arguments: [1] }); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'Argument 0 of function add_i32 must be a string', }); assert.throws(() => {