Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions src/ffi/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand All @@ -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 {};
}
Expand All @@ -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 {};
}
Expand Down
21 changes: 21 additions & 0 deletions test/ffi/test-ffi-dynamic-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Comment thread
daeyeon marked this conversation as resolved.
Resolved
});

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');
}, {
Expand Down
Loading