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..3240f194972c 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'); }, {