From b91d363d2f222b696b51b230718cff65b48aea45 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 9 Mar 2022 14:41:46 +0100 Subject: [PATCH] Rolling to V8 10.0.139.6 (#915) Co-authored-by: Luca Casonato --- README.md | 2 +- examples/hello_world.rs | 2 +- src/V8.rs | 15 +++-- src/binding.cc | 63 ++++++++++--------- src/handle.rs | 5 -- src/isolate.rs | 22 +++---- src/lib.rs | 2 +- src/script_compiler.rs | 6 +- src/script_or_module.rs | 12 ++-- tests/test_api.rs | 14 +++-- tests/test_api_entropy_source.rs | 2 +- ...oncurrent_isolate_creation_and_disposal.rs | 2 +- .../test_single_threaded_default_platform.rs | 2 +- v8 | 2 +- 14 files changed, 77 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 36488cf6..1fb87d3a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rusty V8 Binding -V8 Version: 9.9.115.9 +V8 Version: 10.0.139.6 [![ci](https://github.com/denoland/rusty_v8/workflows/ci/badge.svg?branch=main)](https://github.com/denoland/rusty_v8/actions) [![crates](https://img.shields.io/crates/v/v8.svg)](https://crates.io/crates/v8) diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 02f03d6d..353a7e4c 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -66,5 +66,5 @@ fn main() { unsafe { v8::V8::dispose(); } - v8::V8::shutdown_platform(); + v8::V8::dispose_platform(); } diff --git a/src/V8.rs b/src/V8.rs index 6dd48ec0..c8abd61b 100644 --- a/src/V8.rs +++ b/src/V8.rs @@ -22,7 +22,7 @@ extern "C" { fn v8__V8__InitializePlatform(platform: *mut Platform); fn v8__V8__Initialize(); fn v8__V8__Dispose() -> bool; - fn v8__V8__ShutdownPlatform(); + fn v8__V8__DisposePlatform(); } /// EntropySource is used as a callback function when v8 needs a source @@ -234,13 +234,16 @@ pub unsafe fn dispose() -> bool { } /// Clears all references to the v8::Platform. This should be invoked after -/// V8 was disposed. -pub fn shutdown_platform() { +/// V8 was disposed. If it is called if V8 is not disposed, it will panic. +pub fn dispose_platform() { let mut global_state_guard = GLOBAL_STATE.lock().unwrap(); - // First shutdown platform, then drop platform - unsafe { v8__V8__ShutdownPlatform() }; + // First check that the global state is disposed. If it is we dispose the + // platform. We then drop the platform. *global_state_guard = match *global_state_guard { - Disposed(_) => PlatformShutdown, + Disposed(_) => { + unsafe { v8__V8__DisposePlatform() }; + PlatformShutdown + } _ => panic!("Invalid global state"), }; } diff --git a/src/binding.cc b/src/binding.cc index 60f35356..a0d17c69 100644 --- a/src/binding.cc +++ b/src/binding.cc @@ -98,24 +98,22 @@ enum InternalSlots { (isolate->GetNumberOfDataSlots() - 1 - slot) // This is an extern C calling convention compatible version of -// v8::HostImportModuleDynamicallyWithImportAssertionsCallback -typedef v8::Promise* ( - *v8__HostImportModuleDynamicallyWithImportAssertionsCallback)( - v8::Local context, v8::Local referrer, - v8::Local specifier, +// v8::HostImportModuleDynamicallyCallback +typedef v8::Promise* (*v8__HostImportModuleDynamicallyCallback)( + v8::Local context, v8::Local host_defined_options, + v8::Local resource_name, v8::Local specifier, v8::Local import_assertions); -v8::MaybeLocal -HostImportModuleDynamicallyWithImportAssertionsCallback( - v8::Local context, v8::Local referrer, - v8::Local specifier, +v8::MaybeLocal HostImportModuleDynamicallyCallback( + v8::Local context, v8::Local host_defined_options, + v8::Local resource_name, v8::Local specifier, v8::Local import_assertions) { auto* isolate = context->GetIsolate(); void* d = isolate->GetData(SLOT_INTERNAL(isolate, kSlotDynamicImport)); - auto* callback = reinterpret_cast< - v8__HostImportModuleDynamicallyWithImportAssertionsCallback>(d); + auto* callback = reinterpret_cast(d); assert(callback != nullptr); - auto* promise_ptr = callback(context, referrer, specifier, import_assertions); + auto* promise_ptr = callback(context, host_defined_options, resource_name, + specifier, import_assertions); if (promise_ptr == nullptr) { return v8::MaybeLocal(); } else { @@ -150,7 +148,7 @@ void v8__V8__Initialize() { v8::V8::Initialize(); } bool v8__V8__Dispose() { return v8::V8::Dispose(); } -void v8__V8__ShutdownPlatform() { v8::V8::ShutdownPlatform(); } +void v8__V8__DisposePlatform() { v8::V8::DisposePlatform(); } v8::Isolate* v8__Isolate__New(const v8::Isolate::CreateParams& params) { return v8::Isolate::New(params); @@ -256,12 +254,11 @@ void v8__Isolate__SetHostInitializeImportMetaObjectCallback( } void v8__Isolate__SetHostImportModuleDynamicallyCallback( - v8::Isolate* isolate, - v8__HostImportModuleDynamicallyWithImportAssertionsCallback callback) { + v8::Isolate* isolate, v8__HostImportModuleDynamicallyCallback callback) { isolate->SetData(SLOT_INTERNAL(isolate, kSlotDynamicImport), reinterpret_cast(callback)); isolate->SetHostImportModuleDynamicallyCallback( - HostImportModuleDynamicallyWithImportAssertionsCallback); + HostImportModuleDynamicallyCallback); } bool v8__Isolate__AddMessageListener(v8::Isolate* isolate, @@ -411,18 +408,18 @@ const v8::Script* v8__ScriptCompiler__Compile( return maybe_local_to_ptr(maybe_local); } -const v8::Function* v8__ScriptCompiler__CompileFunctionInContext( +const v8::Function* v8__ScriptCompiler__CompileFunction( const v8::Context* context, v8::ScriptCompiler::Source* source, size_t arguments_count, const v8::String** arguments, size_t context_extensions_count, const v8::Object** context_extensions, v8::ScriptCompiler::CompileOptions options, v8::ScriptCompiler::NoCacheReason no_cache_reason) { - return maybe_local_to_ptr(v8::ScriptCompiler::CompileFunctionInContext( + return maybe_local_to_ptr(v8::ScriptCompiler::CompileFunction( ptr_to_local(context), source, arguments_count, reinterpret_cast*>(arguments), context_extensions_count, reinterpret_cast*>(context_extensions), options, - no_cache_reason, nullptr)); + no_cache_reason)); } const v8::UnboundScript* v8__ScriptCompiler__CompileUnboundScript( @@ -687,7 +684,8 @@ const v8::Boolean* v8__Value__ToBoolean(const v8::Value& self, void v8__Value__InstanceOf(const v8::Value& self, const v8::Context& context, const v8::Object& object, v8::Maybe* out) { v8::Value* self_non_const = const_cast(&self); - *out = self_non_const->InstanceOf(ptr_to_local(&context), ptr_to_local(&object)); + *out = + self_non_const->InstanceOf(ptr_to_local(&context), ptr_to_local(&object)); } void v8__Value__NumberValue(const v8::Value& self, const v8::Context& context, @@ -1048,9 +1046,12 @@ void v8__ObjectTemplate__SetAccessorWithSetter( } void v8__ObjectTemplate__SetAccessorProperty(const v8::ObjectTemplate& self, - const v8::Name& key, - v8::FunctionTemplate& getter, v8::FunctionTemplate& setter, v8::PropertyAttribute attr) { - ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), ptr_to_local(&getter), ptr_to_local(&setter), attr); + const v8::Name& key, + v8::FunctionTemplate& getter, + v8::FunctionTemplate& setter, + v8::PropertyAttribute attr) { + ptr_to_local(&self)->SetAccessorProperty( + ptr_to_local(&key), ptr_to_local(&getter), ptr_to_local(&setter), attr); } const v8::Object* v8__Object__New(v8::Isolate* isolate) { @@ -1174,10 +1175,11 @@ MaybeBool v8__Object__HasIndex(const v8::Object& self, ptr_to_local(&self)->Has(ptr_to_local(&context), index)); } -MaybeBool v8__Object__HasOwnProperty(const v8::Object& self, const v8::Context& context, - const v8::Name& key) { - return maybe_to_maybe_bool( - ptr_to_local(&self)->HasOwnProperty(ptr_to_local(&context), ptr_to_local(&key))); +MaybeBool v8__Object__HasOwnProperty(const v8::Object& self, + const v8::Context& context, + const v8::Name& key) { + return maybe_to_maybe_bool(ptr_to_local(&self)->HasOwnProperty( + ptr_to_local(&context), ptr_to_local(&key))); } MaybeBool v8__Object__Delete(const v8::Object& self, const v8::Context& context, @@ -1894,7 +1896,8 @@ v8::ScriptCompiler::CachedData* v8__UnboundModuleScript__CreateCodeCache( ptr_to_local(&unbound_module_script)); } -v8::ScriptCompiler::CachedData* v8__Function__CreateCodeCache(const v8::Function& self) { +v8::ScriptCompiler::CachedData* v8__Function__CreateCodeCache( + const v8::Function& self) { return v8::ScriptCompiler::CreateCodeCacheForFunction(ptr_to_local(&self)); } @@ -1920,9 +1923,9 @@ const v8::Value* v8__ScriptOrModule__GetResourceName( return local_to_ptr(ptr_to_local(&self)->GetResourceName()); } -const v8::PrimitiveArray* v8__ScriptOrModule__GetHostDefinedOptions( +const v8::Data* v8__ScriptOrModule__HostDefinedOptions( const v8::ScriptOrModule& self) { - return local_to_ptr(ptr_to_local(&self)->GetHostDefinedOptions()); + return local_to_ptr(ptr_to_local(&self)->HostDefinedOptions()); } const v8::SharedArrayBuffer* v8__SharedArrayBuffer__New__with_byte_length( diff --git a/src/handle.rs b/src/handle.rs index 439a020b..8bc5f135 100644 --- a/src/handle.rs +++ b/src/handle.rs @@ -172,11 +172,6 @@ impl Global { pub fn open<'a>(&'a self, scope: &mut Isolate) -> &'a T { Handle::open(self, scope) } - - #[deprecated = "use Global::open() instead"] - pub fn get<'a>(&'a self, scope: &mut Isolate) -> &'a T { - Handle::open(self, scope) - } } impl Clone for Global { diff --git a/src/isolate.rs b/src/isolate.rs index 5172ad03..988ad208 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -15,6 +15,7 @@ use crate::wasm::WasmStreaming; use crate::Array; use crate::CallbackScope; use crate::Context; +use crate::Data; use crate::FixedArray; use crate::Function; use crate::HandleScope; @@ -23,7 +24,6 @@ use crate::Message; use crate::Module; use crate::Object; use crate::Promise; -use crate::ScriptOrModule; use crate::String; use crate::Value; @@ -96,7 +96,7 @@ pub type PromiseRejectCallback = extern "C" fn(PromiseRejectMessage); pub type HostInitializeImportMetaObjectCallback = extern "C" fn(Local, Local, Local); -/// HostImportModuleDynamicallyWithImportAssertionsCallback is called when we require the +/// HostImportModuleDynamicallyCallback is called when we require the /// embedder to load a module. This is used as part of the dynamic /// import syntax. /// @@ -114,13 +114,13 @@ pub type HostInitializeImportMetaObjectCallback = /// this promise with the exception. If the promise creation itself /// fails (e.g. due to stack overflow), the embedder must propagate /// that exception by returning an empty MaybeLocal. -pub type HostImportModuleDynamicallyWithImportAssertionsCallback = - extern "C" fn( - Local, - Local, - Local, - Local, - ) -> *mut Promise; +pub type HostImportModuleDynamicallyCallback = extern "C" fn( + Local, + Local, + Local, + Local, + Local, +) -> *mut Promise; pub type InterruptCallback = extern "C" fn(isolate: &mut Isolate, data: *mut c_void); @@ -213,7 +213,7 @@ extern "C" { ); fn v8__Isolate__SetHostImportModuleDynamicallyCallback( isolate: *mut Isolate, - callback: HostImportModuleDynamicallyWithImportAssertionsCallback, + callback: HostImportModuleDynamicallyCallback, ); fn v8__Isolate__RequestInterrupt( isolate: *const Isolate, @@ -581,7 +581,7 @@ impl Isolate { /// import() language feature to load modules. pub fn set_host_import_module_dynamically_callback( &mut self, - callback: HostImportModuleDynamicallyWithImportAssertionsCallback, + callback: HostImportModuleDynamicallyCallback, ) { unsafe { v8__Isolate__SetHostImportModuleDynamicallyCallback(self, callback) diff --git a/src/lib.rs b/src/lib.rs index 3a3421b5..f4594bba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,7 @@ pub use handle::Global; pub use handle::Handle; pub use handle::Local; pub use isolate::HeapStatistics; -pub use isolate::HostImportModuleDynamicallyWithImportAssertionsCallback; +pub use isolate::HostImportModuleDynamicallyCallback; pub use isolate::HostInitializeImportMetaObjectCallback; pub use isolate::Isolate; pub use isolate::IsolateHandle; diff --git a/src/script_compiler.rs b/src/script_compiler.rs index fe34cbc5..6419f349 100644 --- a/src/script_compiler.rs +++ b/src/script_compiler.rs @@ -38,7 +38,7 @@ extern "C" { options: CompileOptions, no_cache_reason: NoCacheReason, ) -> *const Script; - fn v8__ScriptCompiler__CompileFunctionInContext( + fn v8__ScriptCompiler__CompileFunction( context: *const Context, source: *mut Source, arguments_count: usize, @@ -255,7 +255,7 @@ pub fn compile<'s>( } } -pub fn compile_function_in_context<'s>( +pub fn compile_function<'s>( scope: &mut HandleScope<'s>, mut source: Source, arguments: &[Local], @@ -267,7 +267,7 @@ pub fn compile_function_in_context<'s>( let context_extensions = Local::slice_into_raw(context_extensions); unsafe { scope.cast_local(|sd| { - v8__ScriptCompiler__CompileFunctionInContext( + v8__ScriptCompiler__CompileFunction( &*sd.get_current_context(), &mut source, arguments.len(), diff --git a/src/script_or_module.rs b/src/script_or_module.rs index c09d6c95..8b6123e5 100644 --- a/src/script_or_module.rs +++ b/src/script_or_module.rs @@ -1,6 +1,6 @@ // Copyright 2019-2021 the Deno authors. All rights reserved. MIT license. +use crate::Data; use crate::Local; -use crate::PrimitiveArray; use crate::ScriptOrModule; use crate::Value; @@ -9,9 +9,9 @@ extern "C" { this: *const ScriptOrModule, ) -> *const Value; - fn v8__ScriptOrModule__GetHostDefinedOptions( + fn v8__ScriptOrModule__HostDefinedOptions( this: *const ScriptOrModule, - ) -> *const PrimitiveArray; + ) -> *const Data; } impl ScriptOrModule { @@ -29,12 +29,12 @@ impl ScriptOrModule { /// The options that were passed by the embedder as HostDefinedOptions to the /// ScriptOrigin. - pub fn get_host_defined_options(&self) -> Local { - // Note: the C++ `v8::ScriptOrModule::GetHostDefinedOptions()` does not + pub fn host_defined_options(&self) -> Local { + // Note: the C++ `v8::ScriptOrModule::HostDefinedOptions()` does not // actually return a local handle, but rather a handle whose lifetime is // bound to the related `ScriptOrModule` object. unsafe { - let ptr = v8__ScriptOrModule__GetHostDefinedOptions(self); + let ptr = v8__ScriptOrModule__HostDefinedOptions(self); Local::from_raw(ptr).unwrap() } } diff --git a/tests/test_api.rs b/tests/test_api.rs index 836d1fad..28d79819 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -2644,7 +2644,8 @@ fn import_assertions() { extern "C" fn dynamic_import_cb( context: v8::Local, - _referrer: v8::Local, + _host_defined_options: v8::Local, + _resource_name: v8::Local, _specifier: v8::Local, import_assertions: v8::Local, ) -> *mut v8::Promise { @@ -3224,7 +3225,8 @@ fn dynamic_import() { extern "C" fn dynamic_import_cb( context: v8::Local, - _referrer: v8::Local, + _host_defined_options: v8::Local, + _resource_name: v8::Local, specifier: v8::Local, _import_assertions: v8::Local, ) -> *mut v8::Promise { @@ -5607,7 +5609,7 @@ fn function_code_cache() { None, ); let word = v8::String::new(scope, "word").unwrap(); - let function = v8::script_compiler::compile_function_in_context( + let function = v8::script_compiler::compile_function( scope, source, &[word], @@ -5630,7 +5632,7 @@ fn function_code_cache() { code_cache, ); let word = v8::String::new(scope, "word").unwrap(); - let function = v8::script_compiler::compile_function_in_context( + let function = v8::script_compiler::compile_function( scope, source, &[word], @@ -5712,7 +5714,7 @@ fn code_cache_script() { } #[test] -fn compile_function_in_context() { +fn compile_function() { let _setup_guard = setup(); let isolate = &mut v8::Isolate::new(Default::default()); let scope = &mut v8::HandleScope::new(isolate); @@ -5729,7 +5731,7 @@ fn compile_function_in_context() { let source = v8::String::new(scope, "return x * y").unwrap(); let source = v8::script_compiler::Source::new(source, None); - let function = v8::script_compiler::compile_function_in_context( + let function = v8::script_compiler::compile_function( scope, source, &[argument], diff --git a/tests/test_api_entropy_source.rs b/tests/test_api_entropy_source.rs index d3db2d09..3611e4f0 100644 --- a/tests/test_api_entropy_source.rs +++ b/tests/test_api_entropy_source.rs @@ -39,7 +39,7 @@ fn set_entropy_source() { unsafe { v8::V8::dispose(); } - v8::V8::shutdown_platform(); + v8::V8::dispose_platform(); // All runs should have produced the same value. assert_eq!(results.len(), N); diff --git a/tests/test_concurrent_isolate_creation_and_disposal.rs b/tests/test_concurrent_isolate_creation_and_disposal.rs index 5cc1e2e0..ab645f56 100644 --- a/tests/test_concurrent_isolate_creation_and_disposal.rs +++ b/tests/test_concurrent_isolate_creation_and_disposal.rs @@ -28,5 +28,5 @@ fn concurrent_isolate_creation_and_disposal() { } unsafe { v8::V8::dispose() }; - v8::V8::shutdown_platform(); + v8::V8::dispose_platform(); } diff --git a/tests/test_single_threaded_default_platform.rs b/tests/test_single_threaded_default_platform.rs index 3e9e8152..84dccb59 100644 --- a/tests/test_single_threaded_default_platform.rs +++ b/tests/test_single_threaded_default_platform.rs @@ -18,5 +18,5 @@ fn single_threaded_default_platform() { } unsafe { v8::V8::dispose() }; - v8::V8::shutdown_platform(); + v8::V8::dispose_platform(); } diff --git a/v8 b/v8 index 54421808..12395308 160000 --- a/v8 +++ b/v8 @@ -1 +1 @@ -Subproject commit 54421808b7ceeed65cb1c376dcfcacb4a0ed2c0f +Subproject commit 12395308dcfabf28b339e2948eb34fb63954025a