Skip to content

Commit

Permalink
Upgrade to V8 12.1.285.6 (#1374)
Browse files Browse the repository at this point in the history
1. [[exceptions] Unify pending and scheduled exceptions](https://chromium-review.googlesource.com/c/v8/v8/+/5050065)

Reset no longer clears exception if it was rethrown. The test had to be adjusted for the same.

2. [[api] Allow passing CppHeap on Isolate creation](https://chromium-review.googlesource.com/c/v8/v8/+/4989254)

`AttachCppHeap` was deprecated but the alternative of passing `CppHeap` via Isolate CreateParams hard crashes (SIGSEGV). There are no tests for this in V8 and it seems the [Chromium CL](https://chromium-review.googlesource.com/c/chromium/src/+/4992764) is also crashing. For now I've just suppressed the deprecation warning until the crash is fixed in V8.

3. v8::Serializer impl must not throw more than one exception. 

I changed `get_shared_buffer_id()` to not throw and return `None`. V8 internally calls data clone error when it's the SAB is not clonable.

Other changes:

- `v8::ScriptCompiler` size increased by 3 words with `v8::ScriptCompiler::CompilationDetails`.
- `v8::ObjectTemplate::SetAccessor` & `v8::ObjectTemplate::SetAccessorProperty` signature changed and also deprecated.
- `v8::Context::SetContinuationPreservedEmbedderData` deprecated. Use `v8::Isolate::GetContinuationPreservedEmbedderData` instead.
- `GetStalledTopLevelAwaitMessage` deprecated. Use `GetStalledTopLevelAwaitMessages` instead.
- `v8::Isolate::AttachCppHeap` deprecated. Set the heap on Isolate creation using CreateParams instead. 
- `v8::ScriptOrigin` deprecated. Use constructor without the isolate.
- `v8::SnapshotCreator` is deprecated. Use the version that passes CreateParams instead.
- `v8::Isolate` assertion failures.

Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
littledivy and bartlomieju authored Jan 5, 2024
1 parent 60e0859 commit 3de6823
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 144 deletions.
1 change: 0 additions & 1 deletion examples/cppgc-object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ fn main() {
DEFAULT_CPP_GC_EMBEDDER_ID,
)),
);

isolate.attach_cpp_heap(&heap);

let handle_scope = &mut v8::HandleScope::new(isolate);
Expand Down
199 changes: 108 additions & 91 deletions src/binding.cc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl Isolate {
// Byte offset inside `Isolate` where the isolate data slots are stored. This
// should be the same as the value of `kIsolateEmbedderDataOffset` which is
// defined in `v8-internal.h`.
const EMBEDDER_DATA_OFFSET: usize = size_of::<[*const (); 67]>();
const EMBEDDER_DATA_OFFSET: usize = size_of::<[*const (); 65]>();

// Isolate data slots used internally by rusty_v8.
const ANNEX_SLOT: u32 = 0;
Expand Down
8 changes: 4 additions & 4 deletions src/isolate_create_params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::array_buffer;
use crate::array_buffer::Allocator as ArrayBufferAllocator;
use crate::cppgc::Heap;
use crate::support::char;
use crate::support::int;
use crate::support::intptr_t;
Expand Down Expand Up @@ -212,10 +213,9 @@ pub(crate) mod raw {
pub only_terminate_in_safe_scope: bool,
pub embedder_wrapper_type_index: int,
pub embedder_wrapper_object_index: int,
// NOTE(bartlomieju): this field is deprecated in V8 API.
// This is an std::vector<std::string>. It's usually no bigger
// than three or four words but let's take a generous upper bound.
pub supported_import_assertions: [usize; 8],
_fatal_error_handler: *const Opaque, // FatalErrorCallback
_oom_error_handler: *const Opaque, // OOMErrorCallback
pub cpp_heap: *const Heap,
}

extern "C" {
Expand Down
8 changes: 4 additions & 4 deletions src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<'s> HandleScope<'s> {
unsafe {
let sd = data::ScopeData::get_mut(self);
raw::v8__Context__SetContinuationPreservedEmbedderData(
sd.get_current_context(),
sd.get_isolate_ptr(),
&*data,
);
}
Expand All @@ -341,7 +341,7 @@ impl<'s> HandleScope<'s> {
self
.cast_local(|sd| {
raw::v8__Context__GetContinuationPreservedEmbedderData(
sd.get_current_context(),
sd.get_isolate_ptr(),
)
})
.unwrap()
Expand Down Expand Up @@ -2100,11 +2100,11 @@ mod raw {
resolve_hook: *const Function,
);
pub(super) fn v8__Context__SetContinuationPreservedEmbedderData(
this: *const Context,
this: *mut Isolate,
value: *const Value,
);
pub(super) fn v8__Context__GetContinuationPreservedEmbedderData(
this: *const Context,
this: *mut Isolate,
) -> *const Value;

pub(super) fn v8__HandleScope__CONSTRUCT(
Expand Down
6 changes: 2 additions & 4 deletions src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::ptr::null;

use crate::Context;
use crate::HandleScope;
use crate::Isolate;
use crate::Local;
use crate::Script;
use crate::String;
Expand All @@ -31,7 +30,6 @@ extern "C" {
) -> *const Value;

fn v8__ScriptOrigin__CONSTRUCT(
isolate: *mut Isolate,
buf: *mut MaybeUninit<ScriptOrigin>,
resource_name: *const Value,
resource_line_offset: i32,
Expand Down Expand Up @@ -103,7 +101,8 @@ impl<'s> ScriptOrigin<'s> {
#[allow(clippy::too_many_arguments)]
#[inline(always)]
pub fn new(
scope: &mut HandleScope<'s, ()>,
// TODO(littledivy): remove
_scope: &mut HandleScope<'s, ()>,
resource_name: Local<'s, Value>,
resource_line_offset: i32,
resource_column_offset: i32,
Expand All @@ -117,7 +116,6 @@ impl<'s> ScriptOrigin<'s> {
unsafe {
let mut buf = std::mem::MaybeUninit::<ScriptOrigin>::uninit();
v8__ScriptOrigin__CONSTRUCT(
scope.get_isolate_ptr(),
&mut buf,
&*resource_name,
resource_line_offset,
Expand Down
1 change: 1 addition & 0 deletions src/script_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct Source {
_consume_cache_task: usize,
_compile_hint_callback: usize,
_compile_hint_callback_data: usize,
_compilation_details: [usize; 3],
}

/// Compilation data that the embedder can cache and pass back to speed up future
Expand Down
34 changes: 9 additions & 25 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use crate::isolate_create_params::raw;
use crate::scope::data::ScopeData;
use crate::support::char;
use crate::support::int;
use crate::support::intptr_t;
use crate::support::Allocated;
use crate::support::Allocation;
use crate::Context;
use crate::Data;
use crate::Isolate;
Expand All @@ -16,13 +14,11 @@ use std::borrow::Borrow;
use std::convert::TryFrom;
use std::mem::MaybeUninit;
use std::ops::Deref;
use std::ptr::null;

extern "C" {
fn v8__SnapshotCreator__CONSTRUCT(
buf: *mut MaybeUninit<SnapshotCreator>,
external_references: *const intptr_t,
existing_blob: *const raw::StartupData,
params: *const raw::CreateParams,
);
fn v8__SnapshotCreator__DESTRUCT(this: *mut SnapshotCreator);
fn v8__SnapshotCreator__GetIsolate(
Expand Down Expand Up @@ -131,38 +127,26 @@ impl SnapshotCreator {
existing_snapshot_blob: Option<impl Allocated<[u8]>>,
) -> OwnedIsolate {
let mut snapshot_creator: MaybeUninit<Self> = MaybeUninit::uninit();
let external_references_ptr = if let Some(er) = external_references {
er.as_ptr()
} else {
std::ptr::null()
};

let snapshot_blob_ptr;
let snapshot_allocations;
let mut params = crate::CreateParams::default();
if let Some(external_refs) = external_references {
params = params.external_references(&**external_refs);
}
if let Some(snapshot_blob) = existing_snapshot_blob {
let data = Allocation::of(snapshot_blob);
let header = Allocation::of(raw::StartupData::boxed_header(&data));
snapshot_blob_ptr = &*header as *const _;
snapshot_allocations = Some((header, data));
} else {
snapshot_blob_ptr = null();
snapshot_allocations = None;
params = params.snapshot_blob(snapshot_blob);
}
let (raw_create_params, create_param_allocations) = params.finalize();

let snapshot_creator = unsafe {
v8__SnapshotCreator__CONSTRUCT(
&mut snapshot_creator,
external_references_ptr,
snapshot_blob_ptr,
);
v8__SnapshotCreator__CONSTRUCT(&mut snapshot_creator, &raw_create_params);
snapshot_creator.assume_init()
};

let isolate_ptr =
unsafe { v8__SnapshotCreator__GetIsolate(&snapshot_creator) };
let mut owned_isolate = OwnedIsolate::new(isolate_ptr);
ScopeData::new_root(&mut owned_isolate);
owned_isolate.create_annex(Box::new(snapshot_allocations));
owned_isolate.create_annex(create_param_allocations);
owned_isolate.set_snapshot_creator(snapshot_creator);
owned_isolate
}
Expand Down
9 changes: 1 addition & 8 deletions src/value_serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,9 @@ pub trait ValueSerializerImpl {

fn get_shared_array_buffer_id<'s>(
&mut self,
scope: &mut HandleScope<'s>,
_scope: &mut HandleScope<'s>,
_shared_array_buffer: Local<'s, SharedArrayBuffer>,
) -> Option<u32> {
let msg = String::new(
scope,
"Deno serializer: get_shared_array_buffer_id not implemented",
)
.unwrap();
let exc = Exception::error(scope, msg);
scope.throw_exception(exc);
None
}

Expand Down
7 changes: 4 additions & 3 deletions tests/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,9 @@ fn try_catch() {
assert!(tc2.has_caught());
assert!(tc2.rethrow().is_some());
tc2.reset();
assert!(!tc2.has_caught());
// Reset does not clear exception on rethrow.
// https://chromium-review.googlesource.com/c/v8/v8/+/5050065
assert!(tc2.has_caught());
}
assert!(tc1.has_caught());
};
Expand Down Expand Up @@ -2538,7 +2540,6 @@ fn object_template_set_named_property_handler() {
assert!(eval(scope, "'panicOnGet' in obj")
.unwrap()
.boolean_value(scope));
assert!(eval(scope, "obj.panicOnGet").unwrap().is_string());

// Test `v8::NamedPropertyHandlerConfiguration::*_raw()` methods
{
Expand Down Expand Up @@ -2566,7 +2567,6 @@ fn object_template_set_named_property_handler() {
assert!(eval(scope, "'panicOnGet' in obj")
.unwrap()
.boolean_value(scope));
assert!(eval(scope, "obj.panicOnGet").unwrap().is_string());
}
}
}
Expand Down Expand Up @@ -8083,6 +8083,7 @@ impl v8::ValueSerializerImpl for Custom2Value {
scope: &mut v8::HandleScope<'s>,
message: v8::Local<'s, v8::String>,
) {
let scope = &mut v8::TryCatch::new(scope);
let error = v8::Exception::error(scope, message);
scope.throw_exception(error);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cppgc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn cppgc_object_wrap() {
}

{
let isolate = &mut v8::Isolate::new(Default::default());
let isolate = &mut v8::Isolate::new(v8::CreateParams::default());
// Create a managed heap.
let heap = v8::cppgc::Heap::create(
guard.platform.clone(),
Expand All @@ -82,7 +82,6 @@ fn cppgc_object_wrap() {
DEFAULT_CPP_GC_EMBEDDER_ID,
)),
);

isolate.attach_cpp_heap(&heap);

let handle_scope = &mut v8::HandleScope::new(isolate);
Expand Down
2 changes: 1 addition & 1 deletion v8
Submodule v8 updated 1010 files

0 comments on commit 3de6823

Please sign in to comment.