From 0d093a02f658781d52e6d70d138768fc19a79d54 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 18 Jan 2021 21:46:44 +0100 Subject: [PATCH] Upgrade V8 to 8.9.255.3 (#567) This floats https://chromium-review.googlesource.com/c/v8/v8/+/2608209 because it just missed the merge window for 8.9. --- .gitmodules | 3 ++- README.md | 2 +- examples/shell.rs | 21 ++++++++------- src/binding.cc | 25 +++++++++--------- src/isolate_create_params.rs | 35 +++++++++++++++++++++++-- src/script.rs | 50 ++++++++++++++++++----------------- tests/test_api.rs | 51 ++++++++++++++++++++++++------------ v8 | 2 +- 8 files changed, 121 insertions(+), 68 deletions(-) diff --git a/.gitmodules b/.gitmodules index bab7f071..f2512030 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,7 @@ [submodule "v8"] path = v8 - url = https://chromium.googlesource.com/v8/v8 + #url = https://chromium.googlesource.com/v8/v8 + url = https://github.com/bnoordhuis/v8 [submodule "build"] path = build url = https://github.com/denoland/chromium_build.git diff --git a/README.md b/README.md index 199a9001..1ed719fb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rusty V8 Binding -V8 Version: 8.8.278.2 +V8 Version: 8.9.255.3 [![ci](https://github.com/denoland/rusty_v8/workflows/ci/badge.svg?branch=master)](https://github.com/denoland/rusty_v8/actions) [![crates](https://img.shields.io/crates/v/rusty_v8.svg)](https://crates.io/crates/rusty_v8) diff --git a/examples/shell.rs b/examples/shell.rs index ed8b5436..296de638 100644 --- a/examples/shell.rs +++ b/examples/shell.rs @@ -108,17 +108,20 @@ fn execute_string( ) { let mut scope = v8::TryCatch::new(scope); + let filename = v8::String::new(&mut scope, filename).unwrap(); + let undefined = v8::undefined(&mut scope); let script = v8::String::new(&mut scope, script).unwrap(); let origin = v8::ScriptOrigin::new( - v8::String::new(&mut scope, filename).unwrap().into(), - v8::Integer::new(&mut scope, 0), - v8::Integer::new(&mut scope, 0), - v8::Boolean::new(&mut scope, false), - v8::Integer::new(&mut scope, 0), - v8::undefined(&mut scope).into(), - v8::Boolean::new(&mut scope, false), - v8::Boolean::new(&mut scope, false), - v8::Boolean::new(&mut scope, false), + &mut scope, + filename.into(), + 0, + 0, + false, + 0, + undefined.into(), + false, + false, + false, ); let script = if let Some(script) = diff --git a/src/binding.cc b/src/binding.cc index 6147a5c4..4be1f46a 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -22,7 +22,7 @@ static_assert(sizeof(two_pointers_t) == sizeof(std::shared_ptr), "std::shared_ptr size mismatch"); -static_assert(sizeof(v8::ScriptOrigin) == sizeof(size_t) * 7, +static_assert(sizeof(v8::ScriptOrigin) <= sizeof(size_t) * 8, "ScriptOrigin size mismatch"); static_assert(sizeof(v8::HandleScope) == sizeof(size_t) * 3, @@ -36,7 +36,7 @@ static_assert(sizeof(v8::PromiseRejectMessage) == sizeof(size_t) * 3, static_assert(sizeof(v8::Locker) == sizeof(size_t) * 2, "Locker size mismatch"); -static_assert(sizeof(v8::ScriptCompiler::Source) == sizeof(size_t) * 8, +static_assert(sizeof(v8::ScriptCompiler::Source) <= sizeof(size_t) * 8, "Source size mismatch"); static_assert(sizeof(v8::FunctionCallbackInfo) == sizeof(size_t) * 3, @@ -1560,19 +1560,18 @@ const v8::Value* v8__Script__Run(const v8::Script& script, } void v8__ScriptOrigin__CONSTRUCT( + v8::Isolate* isolate, uninit_t* buf, const v8::Value& resource_name, - const v8::Integer& resource_line_offset, - const v8::Integer& resource_column_offset, - const v8::Boolean& resource_is_shared_cross_origin, - const v8::Integer& script_id, const v8::Value& source_map_url, - const v8::Boolean& resource_is_opaque, const v8::Boolean& is_wasm, - const v8::Boolean& is_module) { + int resource_line_offset, int resource_column_offset, + bool resource_is_shared_cross_origin, int script_id, + const v8::Value& source_map_url, + bool resource_is_opaque, bool is_wasm, bool is_module) { construct_in_place( - buf, ptr_to_local(&resource_name), ptr_to_local(&resource_line_offset), - ptr_to_local(&resource_column_offset), - ptr_to_local(&resource_is_shared_cross_origin), ptr_to_local(&script_id), - ptr_to_local(&source_map_url), ptr_to_local(&resource_is_opaque), - ptr_to_local(&is_wasm), ptr_to_local(&is_module)); + buf, isolate, ptr_to_local(&resource_name), + resource_line_offset, resource_column_offset, + resource_is_shared_cross_origin, script_id, + ptr_to_local(&source_map_url), + resource_is_opaque, is_wasm, is_module); } const v8::Value* v8__ScriptOrModule__GetResourceName( diff --git a/src/isolate_create_params.rs b/src/isolate_create_params.rs index 9d6d4a2c..019c398f 100644 --- a/src/isolate_create_params.rs +++ b/src/isolate_create_params.rs @@ -170,6 +170,10 @@ struct CreateParamAllocations { pub(crate) mod raw { use super::*; + use crate::support::long; + use crate::support::Shared; + use crate::support::SharedPtrBase; + use crate::support::UniquePtr; #[repr(C)] #[derive(Debug)] @@ -187,6 +191,10 @@ pub(crate) mod raw { pub only_terminate_in_safe_scope: bool, pub embedder_wrapper_type_index: int, pub embedder_wrapper_object_index: int, + pub cpp_heap_params: SharedPtr, + // This is an std::vector. It's usually no bigger + // than three or four words but let's take a generous upper bound. + pub supported_import_assertions: [usize; 8], } extern "C" { @@ -199,7 +207,7 @@ pub(crate) mod raw { impl Default for CreateParams { fn default() -> Self { let size = unsafe { v8__Isolate__CreateParams__SIZEOF() }; - assert_eq!(size_of::(), size); + assert!(size <= size_of::()); let mut buf = MaybeUninit::::uninit(); unsafe { v8__Isolate__CreateParams__CONSTRUCT(&mut buf) }; unsafe { buf.assume_init() } @@ -228,7 +236,6 @@ pub(crate) mod raw { code_range_size_: usize, max_old_generation_size_: usize, max_young_generation_size_: usize, - max_zone_pool_size_: usize, initial_old_generation_size_: usize, initial_young_generation_size_: usize, stack_limit_: *mut u32, @@ -257,4 +264,28 @@ pub(crate) mod raw { }; } } + + #[repr(C)] + #[derive(Debug)] + pub(crate) struct CppHeapCreateParams(Opaque); + + impl Shared for CppHeapCreateParams { + fn clone(_: &SharedPtrBase) -> SharedPtrBase { + todo!() + } + + fn from_unique_ptr(_: UniquePtr) -> SharedPtrBase { + todo!() + } + + fn get(_: &SharedPtrBase) -> *const Self { + todo!() + } + + fn reset(_: &mut SharedPtrBase) {} + + fn use_count(_: &SharedPtrBase) -> long { + 0 + } + } } diff --git a/src/script.rs b/src/script.rs index 9b444400..833f9ec1 100644 --- a/src/script.rs +++ b/src/script.rs @@ -2,10 +2,9 @@ use std::marker::PhantomData; use std::mem::MaybeUninit; use std::ptr::null; -use crate::Boolean; use crate::Context; use crate::HandleScope; -use crate::Integer; +use crate::Isolate; use crate::Local; use crate::Script; use crate::String; @@ -15,7 +14,7 @@ use crate::Value; /// The origin, within a file, of a script. #[repr(C)] #[derive(Debug)] -pub struct ScriptOrigin<'s>([usize; 7], PhantomData<&'s ()>); +pub struct ScriptOrigin<'s>([usize; 8], PhantomData<&'s ()>); extern "C" { fn v8__Script__Compile( @@ -32,16 +31,17 @@ extern "C" { ) -> *const Value; fn v8__ScriptOrigin__CONSTRUCT( + isolate: *mut Isolate, buf: *mut MaybeUninit, resource_name: *const Value, - resource_line_offset: *const Integer, - resource_column_offset: *const Integer, - resource_is_shared_cross_origin: *const Boolean, - script_id: *const Integer, + resource_line_offset: i32, + resource_column_offset: i32, + resource_is_shared_cross_origin: bool, + script_id: i32, source_map_url: *const Value, - resource_is_opaque: *const Boolean, - is_wasm: *const Boolean, - is_module: *const Boolean, + resource_is_opaque: bool, + is_wasm: bool, + is_module: bool, ); } @@ -92,29 +92,31 @@ impl Script { impl<'s> ScriptOrigin<'s> { #[allow(clippy::too_many_arguments)] pub fn new( + scope: &mut HandleScope<'s, ()>, resource_name: Local<'s, Value>, - resource_line_offset: Local<'s, Integer>, - resource_column_offset: Local<'s, Integer>, - resource_is_shared_cross_origin: Local<'s, Boolean>, - script_id: Local<'s, Integer>, + resource_line_offset: i32, + resource_column_offset: i32, + resource_is_shared_cross_origin: bool, + script_id: i32, source_map_url: Local<'s, Value>, - resource_is_opaque: Local<'s, Boolean>, - is_wasm: Local<'s, Boolean>, - is_module: Local<'s, Boolean>, + resource_is_opaque: bool, + is_wasm: bool, + is_module: bool, ) -> Self { unsafe { let mut buf = std::mem::MaybeUninit::::uninit(); v8__ScriptOrigin__CONSTRUCT( + scope.get_isolate_ptr(), &mut buf, &*resource_name, - &*resource_line_offset, - &*resource_column_offset, - &*resource_is_shared_cross_origin, - &*script_id, + resource_line_offset, + resource_column_offset, + resource_is_shared_cross_origin, + script_id, &*source_map_url, - &*resource_is_opaque, - &*is_wasm, - &*is_module, + resource_is_opaque, + is_wasm, + is_module, ); buf.assume_init() } diff --git a/tests/test_api.rs b/tests/test_api.rs index ad4a65a6..3f239f3a 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -744,9 +744,24 @@ fn throw_exception() { fn isolate_termination_methods() { let _setup_guard = setup(); let isolate = v8::Isolate::new(Default::default()); - assert_eq!(false, isolate.is_execution_terminating()); - assert_eq!(true, isolate.terminate_execution()); - assert_eq!(true, isolate.cancel_terminate_execution()); + let handle = isolate.thread_safe_handle(); + drop(isolate); + assert_eq!(false, handle.terminate_execution()); + assert_eq!(false, handle.cancel_terminate_execution()); + assert_eq!(false, handle.is_execution_terminating()); + static CALL_COUNT: AtomicUsize = AtomicUsize::new(0); + extern "C" fn callback( + _isolate: &mut v8::Isolate, + data: *mut std::ffi::c_void, + ) { + assert_eq!(data, std::ptr::null_mut()); + CALL_COUNT.fetch_add(1, Ordering::SeqCst); + } + assert_eq!( + false, + handle.request_interrupt(callback, std::ptr::null_mut()) + ); + assert_eq!(CALL_COUNT.load(Ordering::SeqCst), 0); } #[test] @@ -971,16 +986,17 @@ fn script_origin() { let scope = &mut v8::ContextScope::new(scope, context); let resource_name = v8::String::new(scope, "foo.js").unwrap(); - let resource_line_offset = v8::Integer::new(scope, 4); - let resource_column_offset = v8::Integer::new(scope, 5); - let resource_is_shared_cross_origin = v8::Boolean::new(scope, true); - let script_id = v8::Integer::new(scope, 123); + let resource_line_offset = 4; + let resource_column_offset = 5; + let resource_is_shared_cross_origin = true; + let script_id = 123; let source_map_url = v8::String::new(scope, "source_map_url").unwrap(); - let resource_is_opaque = v8::Boolean::new(scope, true); - let is_wasm = v8::Boolean::new(scope, false); - let is_module = v8::Boolean::new(scope, false); + let resource_is_opaque = true; + let is_wasm = false; + let is_module = false; let script_origin = v8::ScriptOrigin::new( + scope, resource_name.into(), resource_line_offset, resource_column_offset, @@ -1865,15 +1881,16 @@ fn mock_script_origin<'s>( resource_name_: &str, ) -> v8::ScriptOrigin<'s> { let resource_name = v8::String::new(scope, resource_name_).unwrap(); - let resource_line_offset = v8::Integer::new(scope, 0); - let resource_column_offset = v8::Integer::new(scope, 0); - let resource_is_shared_cross_origin = v8::Boolean::new(scope, true); - let script_id = v8::Integer::new(scope, 123); + let resource_line_offset = 0; + let resource_column_offset = 0; + let resource_is_shared_cross_origin = true; + let script_id = 123; let source_map_url = v8::String::new(scope, "source_map_url").unwrap(); - let resource_is_opaque = v8::Boolean::new(scope, true); - let is_wasm = v8::Boolean::new(scope, false); - let is_module = v8::Boolean::new(scope, true); + let resource_is_opaque = true; + let is_wasm = false; + let is_module = true; v8::ScriptOrigin::new( + scope, resource_name.into(), resource_line_offset, resource_column_offset, diff --git a/v8 b/v8 index ecf7c5b9..12b4fabf 160000 --- a/v8 +++ b/v8 @@ -1 +1 @@ -Subproject commit ecf7c5b959f91043241bb2442932ca4da7fe7d00 +Subproject commit 12b4fabf964b4646d607cb147ac5292d60ffc3b3