From e095c54422f7ec5b53b64b105d446ebcb8bd3f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 26 Nov 2022 16:35:46 +0100 Subject: [PATCH] chore: update rusty_v8 to 0.56.0 (#16814) Co-authored-by: Divy Srivastava --- Cargo.lock | 5 ++--- Cargo.toml | 2 +- ops/lib.rs | 44 +++++++++++++++++++++++++++++++++----------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 788716af16..f5091c5456 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5387,14 +5387,13 @@ dependencies = [ [[package]] name = "v8" -version = "0.55.0" +version = "0.56.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46cd4f562bce7520fbb511850c5488366264caf346be221cf7e908f51ac33dbc" +checksum = "4182d3112bf61cc6bbc4839b728c27d5aa5c6b12ee26b91b039308715a61c208" dependencies = [ "bitflags", "fslock", "lazy_static", - "libc", "which", ] diff --git a/Cargo.toml b/Cargo.toml index 37df295aca..034536d251 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ license = "MIT" repository = "https://github.com/denoland/deno" [workspace.dependencies] -v8 = { version = "0.55.0", default-features = false } +v8 = { version = "0.56.0", default-features = false } deno_ast = { version = "0.21.0", features = ["transpiling"] } deno_core = { version = "0.161.0", path = "./core" } diff --git a/ops/lib.rs b/ops/lib.rs index 6b57e1cd99..9b0cc6a8ae 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -458,9 +458,13 @@ fn codegen_u8_slice(core: &TokenStream2, idx: usize) -> TokenStream2 { match #core::v8::Local::<#core::v8::ArrayBuffer>::try_from(value) { Ok(b) => { let byte_length = b.byte_length(); - let store = b.data() as *mut u8; - // SAFETY: rust guarantees that lifetime of slice is no longer than the call. - unsafe { ::std::slice::from_raw_parts_mut(store, byte_length) } + if let Some(data) = b.data() { + let store = data.cast::().as_ptr(); + // SAFETY: rust guarantees that lifetime of slice is no longer than the call. + unsafe { ::std::slice::from_raw_parts_mut(store, byte_length) } + } else { + &mut [] + } }, Err(_) => { if let Ok(view) = #core::v8::Local::<#core::v8::ArrayBufferView>::try_from(value) { @@ -472,9 +476,13 @@ fn codegen_u8_slice(core: &TokenStream2, idx: usize) -> TokenStream2 { return #core::_ops::throw_type_error(scope, format!("Expected ArrayBufferView at position {}", #idx)); } }; - let store = buffer.data() as *mut u8; - // SAFETY: rust guarantees that lifetime of slice is no longer than the call. - unsafe { ::std::slice::from_raw_parts_mut(store.add(offset), len) } + if let Some(data) = buffer.data() { + let store = data.cast::().as_ptr(); + // SAFETY: rust guarantees that lifetime of slice is no longer than the call. + unsafe { ::std::slice::from_raw_parts_mut(store.add(offset), len) } + } else { + &mut [] + } } else { return #core::_ops::throw_type_error(scope, format!("Expected ArrayBufferView at position {}", #idx)); } @@ -487,7 +495,13 @@ fn codegen_u8_ptr(core: &TokenStream2, idx: usize) -> TokenStream2 { quote! {{ let value = args.get(#idx as i32); match #core::v8::Local::<#core::v8::ArrayBuffer>::try_from(value) { - Ok(b) => b.data() as *const u8, + Ok(b) => { + if let Some(data) = b.data() { + data.cast::().as_ptr() + } else { + std::ptr::null::() + } + }, Err(_) => { if let Ok(view) = #core::v8::Local::<#core::v8::ArrayBufferView>::try_from(value) { let offset = view.byte_offset(); @@ -497,7 +511,11 @@ fn codegen_u8_ptr(core: &TokenStream2, idx: usize) -> TokenStream2 { return #core::_ops::throw_type_error(scope, format!("Expected ArrayBufferView at position {}", #idx)); } }; - let store = buffer.data() as *mut u8; + let store = if let Some(data) = buffer.data() { + data.cast::().as_ptr() + } else { + std::ptr::null_mut::() + }; unsafe { store.add(offset) } } else { return #core::_ops::throw_type_error(scope, format!("Expected ArrayBufferView at position {}", #idx)); @@ -517,9 +535,13 @@ fn codegen_u32_mut_slice(core: &TokenStream2, idx: usize) -> TokenStream2 { return #core::_ops::throw_type_error(scope, format!("Expected Uint32Array at position {}", #idx)); } }; - let store = buffer.data() as *mut u8; - // SAFETY: buffer from Uint32Array. Rust guarantees that lifetime of slice is no longer than the call. - unsafe { ::std::slice::from_raw_parts_mut(store.add(offset) as *mut u32, len / 4) } + if let Some(data) = buffer.data() { + let store = data.cast::().as_ptr(); + // SAFETY: buffer from Uint32Array. Rust guarantees that lifetime of slice is no longer than the call. + unsafe { ::std::slice::from_raw_parts_mut(store.add(offset) as *mut u32, len / 4) } + } else { + &mut [] + } } else { return #core::_ops::throw_type_error(scope, format!("Expected Uint32Array at position {}", #idx)); }