mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
ffi: reject arguments after callback in registerCallback
Passing the signature after the callback silently created a `void ()` callback, so native callers got no arguments forwarded and an undefined return value. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5.5 PR-URL: https://github.com/nodejs/node/pull/66997 Fixes: https://github.com/nodejs/node/issues/66996 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
1 parent
c9dddad6df
commit
e4879ef5fe
2 files changed
+8
No files matched your search
@@ -1083,6 +1083,10 @@ void DynamicLibrary::RegisterCallback(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
|
||||
if (args[0]->IsFunction()) {
|
||||
if (args.Length() > 1) {
|
||||
THROW_ERR_INVALID_ARG_TYPE(env, "Callback must be the last argument");
|
||||
return;
|
||||
}
|
||||
fn = args[0].As<Function>();
|
||||
} else {
|
||||
if (!args[0]->IsObject() || args[0]->IsArray()) {
|
||||
|
||||
@@ -63,6 +63,10 @@ test('ffi callback ref and unref APIs work', () => {
|
||||
return 0;
|
||||
},
|
||||
);
|
||||
assert.throws(() => lib.registerCallback(() => {}, { arguments: ['i32'], return: 'i32' }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'Callback must be the last argument',
|
||||
});
|
||||
|
||||
try {
|
||||
lib.unrefCallback(voidCallback);
|
||||
|
||||
Reference in new issue
Block a user