Skip to content

Commit c49d330

Browse files
committed
ffi: remove dead null check in callback arguments
InvokeCallback tested `args[i] == nullptr` and mapped the argument to JS `null`. `args` is libffi's avalue array, and libffi always points each slot at its own storage for the corresponding argument, so the slot pointers are never null and the branch never ran. The check also read as a guarantee the code does not provide: a NULL pointer argument surfaces as the BigInt `0n`, because ToJSArgument converts `ffi_type_pointer` values with BigInt::NewFromUnsigned. Drop the branch rather than reimplementing it in ToJSArgument, which would change behavior by making pointer parameters arrive as either a BigInt or `null`. Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Assisted-by: claude:opus-5
1 parent 7946f82 commit c49d330

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/node_ffi.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ using v8::Local;
3232
using v8::LocalVector;
3333
using v8::Maybe;
3434
using v8::MaybeLocal;
35-
using v8::Null;
3635
using v8::Object;
3736
using v8::PropertyAttribute;
3837
using v8::ReadOnly;
@@ -665,13 +664,11 @@ void DynamicLibrary::InvokeCallback(ffi_cif* cif,
665664
size_t expected_args = cb->args.size();
666665
LocalVector<Value> callback_args(isolate, expected_args);
667666

667+
// libffi always points `args[i]` at its own storage for the value of
668+
// argument `i`, so the slot pointers themselves are never null. A NULL
669+
// pointer argument surfaces as the BigInt `0n` via ToJSArgument.
668670
for (size_t i = 0; i < expected_args; i++) {
669-
if (args[i] == nullptr) {
670-
callback_args[i] = Null(isolate);
671-
continue;
672-
} else {
673-
callback_args[i] = ToJSArgument(isolate, cb->args[i], args[i]);
674-
}
671+
callback_args[i] = ToJSArgument(isolate, cb->args[i], args[i]);
675672
}
676673

677674
TryCatch try_catch(isolate);

0 commit comments

Comments
 (0)