Skip to content

Commit

Permalink
fix(ext/ffi): Fix usize and isize FFI callback parameters missing mat…
Browse files Browse the repository at this point in the history
…ch arm (denoland#16172)

Mea culpa. Back when I re-introduced parameter and return value types to
FFI callbacks I failed to properly account for the change in match arm
logic. As a result, usize and isize parameters in FFI callbacks
currently enter the branch meant for void only.

This PR changes the match arms to all be explicit, making sure that void
is the only arm marked unreachable and that it stays that way.
  • Loading branch information
aapoalas authored Oct 7, 2022
1 parent 5733de8 commit 19e4e82
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ext/ffi/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ unsafe fn do_ffi_callback(
let value = *((*val) as *const u32);
v8::Integer::new_from_unsigned(scope, value).into()
}
NativeType::I64 => {
NativeType::I64 | NativeType::ISize => {
let result = *((*val) as *const i64);
if result > MAX_SAFE_INTEGER as i64 || result < MIN_SAFE_INTEGER as i64
{
Expand All @@ -1504,7 +1504,7 @@ unsafe fn do_ffi_callback(
v8::Number::new(scope, result as f64).into()
}
}
NativeType::U64 => {
NativeType::U64 | NativeType::USize => {
let result = *((*val) as *const u64);
if result > MAX_SAFE_INTEGER as u64 {
v8::BigInt::new_from_u64(scope, result).into()
Expand All @@ -1520,9 +1520,7 @@ unsafe fn do_ffi_callback(
v8::Number::new(scope, result as f64).into()
}
}
_ => {
unreachable!()
}
NativeType::Void => unreachable!(),
};
params.push(value);
}
Expand Down

0 comments on commit 19e4e82

Please sign in to comment.