mirror of
https://github.com/denoland/rusty_v8.git
synced 2024-11-24 15:19:31 -05:00
fastcall: Fix get_storage_if_aligned
for non-uint8arrays (#1077)
This commit is contained in:
parent
2ba52ed276
commit
c549b19df3
2 changed files with 5 additions and 9 deletions
|
@ -192,7 +192,8 @@ pub struct FastApiCallbackOptions<'a> {
|
|||
// https://source.chromium.org/chromium/chromium/src/+/main:v8/include/v8-fast-api-calls.h;l=336
|
||||
#[repr(C)]
|
||||
pub struct FastApiTypedArray<T: Default> {
|
||||
pub byte_length: usize,
|
||||
/// Returns the length in number of elements.
|
||||
pub length: usize,
|
||||
// This pointer should include the typed array offset applied.
|
||||
// It's not guaranteed that it's aligned to sizeof(T), it's only
|
||||
// guaranteed that it's 4-byte aligned, so for 8-byte types we need to
|
||||
|
@ -204,7 +205,7 @@ pub struct FastApiTypedArray<T: Default> {
|
|||
impl<T: Default> FastApiTypedArray<T> {
|
||||
#[inline]
|
||||
pub fn get(&self, index: usize) -> T {
|
||||
debug_assert!(index < self.byte_length);
|
||||
debug_assert!(index < self.length);
|
||||
let mut t: T = Default::default();
|
||||
unsafe {
|
||||
ptr::copy_nonoverlapping(self.data.add(index), &mut t, 1);
|
||||
|
@ -217,12 +218,7 @@ impl<T: Default> FastApiTypedArray<T> {
|
|||
if (self.data as usize) % align_of::<T>() != 0 {
|
||||
return None;
|
||||
}
|
||||
Some(unsafe {
|
||||
std::slice::from_raw_parts_mut(
|
||||
self.data,
|
||||
self.byte_length / align_of::<T>(),
|
||||
)
|
||||
})
|
||||
Some(unsafe { std::slice::from_raw_parts_mut(self.data, self.length) })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7560,7 +7560,7 @@ fn test_fast_calls_overload() {
|
|||
) {
|
||||
unsafe { WHO = "fast_buf" };
|
||||
let buf = unsafe { &*data };
|
||||
assert_eq!(buf.byte_length, 2);
|
||||
assert_eq!(buf.length, 2);
|
||||
assert_eq!(buf.get(0), 6);
|
||||
assert_eq!(buf.get(1), 9);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue