mirror of
https://github.com/denoland/deno.git
synced 2025-01-05 13:59:01 -05:00
fix(ext/ffi): Callbacks panic on returning isize (#19022)
This commit is contained in:
parent
1b610bfdad
commit
6e72ae7a09
1 changed files with 26 additions and 25 deletions
|
@ -320,17 +320,6 @@ unsafe fn do_ffi_callback(
|
|||
};
|
||||
*(result as *mut bool) = value;
|
||||
}
|
||||
NativeType::I32 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
value.value() as i32
|
||||
} else {
|
||||
// Fallthrough, probably UB.
|
||||
value
|
||||
.int32_value(scope)
|
||||
.expect("Unable to deserialize result parameter.")
|
||||
};
|
||||
*(result as *mut i32) = value;
|
||||
}
|
||||
NativeType::F32 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Number>::try_from(value) {
|
||||
value.value() as f32
|
||||
|
@ -392,7 +381,7 @@ unsafe fn do_ffi_callback(
|
|||
*(result as *mut *mut c_void) = pointer;
|
||||
}
|
||||
NativeType::I8 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Int32>::try_from(value) {
|
||||
value.value() as i8
|
||||
} else {
|
||||
// Fallthrough, essentially UB.
|
||||
|
@ -403,7 +392,7 @@ unsafe fn do_ffi_callback(
|
|||
*(result as *mut i8) = value;
|
||||
}
|
||||
NativeType::U8 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Uint32>::try_from(value) {
|
||||
value.value() as u8
|
||||
} else {
|
||||
// Fallthrough, essentially UB.
|
||||
|
@ -414,7 +403,7 @@ unsafe fn do_ffi_callback(
|
|||
*(result as *mut u8) = value;
|
||||
}
|
||||
NativeType::I16 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Int32>::try_from(value) {
|
||||
value.value() as i16
|
||||
} else {
|
||||
// Fallthrough, essentially UB.
|
||||
|
@ -425,7 +414,7 @@ unsafe fn do_ffi_callback(
|
|||
*(result as *mut i16) = value;
|
||||
}
|
||||
NativeType::U16 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Uint32>::try_from(value) {
|
||||
value.value() as u16
|
||||
} else {
|
||||
// Fallthrough, essentially UB.
|
||||
|
@ -435,9 +424,20 @@ unsafe fn do_ffi_callback(
|
|||
};
|
||||
*(result as *mut u16) = value;
|
||||
}
|
||||
NativeType::I32 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Int32>::try_from(value) {
|
||||
value.value()
|
||||
} else {
|
||||
// Fallthrough, essentially UB.
|
||||
value
|
||||
.int32_value(scope)
|
||||
.expect("Unable to deserialize result parameter.")
|
||||
};
|
||||
*(result as *mut i32) = value;
|
||||
}
|
||||
NativeType::U32 => {
|
||||
let value = if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
value.value() as u32
|
||||
let value = if let Ok(value) = v8::Local::<v8::Uint32>::try_from(value) {
|
||||
value.value()
|
||||
} else {
|
||||
// Fallthrough, essentially UB.
|
||||
value
|
||||
|
@ -446,21 +446,25 @@ unsafe fn do_ffi_callback(
|
|||
};
|
||||
*(result as *mut u32) = value;
|
||||
}
|
||||
NativeType::I64 => {
|
||||
NativeType::I64 | NativeType::ISize => {
|
||||
if let Ok(value) = v8::Local::<v8::BigInt>::try_from(value) {
|
||||
*(result as *mut i64) = value.i64_value().0;
|
||||
} else if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
*(result as *mut i64) = value.value();
|
||||
} else if let Ok(value) = v8::Local::<v8::Int32>::try_from(value) {
|
||||
*(result as *mut i64) = value.value() as i64;
|
||||
} else if let Ok(value) = v8::Local::<v8::Number>::try_from(value) {
|
||||
*(result as *mut i64) = value.value() as i64;
|
||||
} else {
|
||||
*(result as *mut i64) = value
|
||||
.integer_value(scope)
|
||||
.expect("Unable to deserialize result parameter.");
|
||||
}
|
||||
}
|
||||
NativeType::U64 => {
|
||||
NativeType::U64 | NativeType::USize => {
|
||||
if let Ok(value) = v8::Local::<v8::BigInt>::try_from(value) {
|
||||
*(result as *mut u64) = value.u64_value().0;
|
||||
} else if let Ok(value) = v8::Local::<v8::Integer>::try_from(value) {
|
||||
} else if let Ok(value) = v8::Local::<v8::Uint32>::try_from(value) {
|
||||
*(result as *mut u64) = value.value() as u64;
|
||||
} else if let Ok(value) = v8::Local::<v8::Number>::try_from(value) {
|
||||
*(result as *mut u64) = value.value() as u64;
|
||||
} else {
|
||||
*(result as *mut u64) = value
|
||||
|
@ -501,9 +505,6 @@ unsafe fn do_ffi_callback(
|
|||
NativeType::Void => {
|
||||
// nop
|
||||
}
|
||||
_ => {
|
||||
unreachable!();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue