mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
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>
This commit is contained in:
1 parent
e76358e3f1
commit
ad63e9ef29
2 files changed
+21
-3
No files matched your search
+3
-3
@@ -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 {};
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}, {
|
||||
|
||||
Reference in new issue
Block a user