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:
Trivikram Kamat authored and Antoine du Hamel committed 2026-11-11 17:20:21 +01:00
1 parent 1f63811af7
commit 883c6a68f2
2 files changed
+8

No files matched your search

+4
View File
@@ -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()) {
+4
View File
@@ -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);