0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

fix(ext/ffi): Fix usize and isize FFI callback parameters missing match arm (#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.
This commit is contained in:
Aapo Alasuutari 2022-10-07 07:50:18 +03:00 committed by GitHub
parent 5733de8a2e
commit 19e4e821d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
{
@ -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()
@ -1520,9 +1520,7 @@ unsafe fn do_ffi_callback(
v8::Number::new(scope, result as f64).into()
}
}
_ => {
unreachable!()
}
NativeType::Void => unreachable!(),
};
params.push(value);
}