mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
chore: upgrade rusty_v8 to 0.53.0 (#16272)
This commit is contained in:
parent
afcea6c233
commit
e7d7585065
5 changed files with 23 additions and 62 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -5465,9 +5465,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "v8"
|
name = "v8"
|
||||||
version = "0.52.0"
|
version = "0.53.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "44e483583f1b8da53083a47335afa9b7196f35cb91f92d78452bf56508121da0"
|
checksum = "848795d431651537e90408672ec8960fe402522bc2dd7b7bf928fdc32025869a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"fslock",
|
"fslock",
|
||||||
|
|
|
@ -34,7 +34,7 @@ serde_json = { version = "1.0.79", features = ["preserve_order"] }
|
||||||
serde_v8 = { version = "0.65.0", path = "../serde_v8" }
|
serde_v8 = { version = "0.65.0", path = "../serde_v8" }
|
||||||
sourcemap = "6.1"
|
sourcemap = "6.1"
|
||||||
url = { version = "2.3.1", features = ["serde", "expose_internals"] }
|
url = { version = "2.3.1", features = ["serde", "expose_internals"] }
|
||||||
v8 = { version = "0.52.0", default-features = false }
|
v8 = { version = "0.53.0", default-features = false }
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "http_bench_json_ops"
|
name = "http_bench_json_ops"
|
||||||
|
|
|
@ -228,16 +228,13 @@ pub extern "C" fn wasm_async_resolve_promise_callback(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "C" fn host_import_module_dynamically_callback(
|
pub fn host_import_module_dynamically_callback<'s>(
|
||||||
context: v8::Local<v8::Context>,
|
scope: &mut v8::HandleScope<'s>,
|
||||||
_host_defined_options: v8::Local<v8::Data>,
|
_host_defined_options: v8::Local<'s, v8::Data>,
|
||||||
resource_name: v8::Local<v8::Value>,
|
resource_name: v8::Local<'s, v8::Value>,
|
||||||
specifier: v8::Local<v8::String>,
|
specifier: v8::Local<'s, v8::String>,
|
||||||
import_assertions: v8::Local<v8::FixedArray>,
|
import_assertions: v8::Local<'s, v8::FixedArray>,
|
||||||
) -> *mut v8::Promise {
|
) -> Option<v8::Local<'s, v8::Promise>> {
|
||||||
// SAFETY: `CallbackScope` can be safely constructed from `Local<Context>`
|
|
||||||
let scope = &mut unsafe { v8::CallbackScope::new(context) };
|
|
||||||
|
|
||||||
// NOTE(bartlomieju): will crash for non-UTF-8 specifier
|
// NOTE(bartlomieju): will crash for non-UTF-8 specifier
|
||||||
let specifier_str = specifier
|
let specifier_str = specifier
|
||||||
.to_string(scope)
|
.to_string(scope)
|
||||||
|
@ -298,7 +295,7 @@ pub extern "C" fn host_import_module_dynamically_callback(
|
||||||
|
|
||||||
let promise = promise.catch(scope, map_err).unwrap();
|
let promise = promise.catch(scope, map_err).unwrap();
|
||||||
|
|
||||||
&*promise as *const _ as *mut _
|
Some(promise)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub extern "C" fn host_initialize_import_meta_object_callback(
|
pub extern "C" fn host_initialize_import_meta_object_callback(
|
||||||
|
|
|
@ -38,7 +38,6 @@ use std::collections::HashMap;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::ffi::c_void;
|
use std::ffi::c_void;
|
||||||
use std::mem::forget;
|
|
||||||
use std::option::Option;
|
use std::option::Option;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -81,8 +80,6 @@ pub struct JsRuntime {
|
||||||
// This is an Option<OwnedIsolate> instead of just OwnedIsolate to workaround
|
// This is an Option<OwnedIsolate> instead of just OwnedIsolate to workaround
|
||||||
// a safety issue with SnapshotCreator. See JsRuntime::drop.
|
// a safety issue with SnapshotCreator. See JsRuntime::drop.
|
||||||
v8_isolate: Option<v8::OwnedIsolate>,
|
v8_isolate: Option<v8::OwnedIsolate>,
|
||||||
snapshot_creator: Option<v8::SnapshotCreator>,
|
|
||||||
has_snapshotted: bool,
|
|
||||||
built_from_snapshot: bool,
|
built_from_snapshot: bool,
|
||||||
allocations: IsolateAllocations,
|
allocations: IsolateAllocations,
|
||||||
extensions: Vec<Extension>,
|
extensions: Vec<Extension>,
|
||||||
|
@ -190,28 +187,6 @@ pub(crate) struct JsRuntimeState {
|
||||||
waker: AtomicWaker,
|
waker: AtomicWaker,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for JsRuntime {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
if let Some(creator) = self.snapshot_creator.take() {
|
|
||||||
// TODO(ry): in rusty_v8, `SnapShotCreator::get_owned_isolate()` returns
|
|
||||||
// a `struct OwnedIsolate` which is not actually owned, hence the need
|
|
||||||
// here to leak the `OwnedIsolate` in order to avoid a double free and
|
|
||||||
// the segfault that it causes.
|
|
||||||
let v8_isolate = self.v8_isolate.take().unwrap();
|
|
||||||
forget(v8_isolate);
|
|
||||||
|
|
||||||
// TODO(ry) V8 has a strange assert which prevents a SnapshotCreator from
|
|
||||||
// being deallocated if it hasn't created a snapshot yet.
|
|
||||||
// https://github.com/v8/v8/blob/73212783fbd534fac76cc4b66aac899c13f71fc8/src/api.cc#L603
|
|
||||||
// If that assert is removed, this if guard could be removed.
|
|
||||||
// WARNING: There may be false positive LSAN errors here.
|
|
||||||
if self.has_snapshotted {
|
|
||||||
drop(creator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn v8_init(
|
fn v8_init(
|
||||||
v8_platform: Option<v8::SharedRef<v8::Platform>>,
|
v8_platform: Option<v8::SharedRef<v8::Platform>>,
|
||||||
predictable: bool,
|
predictable: bool,
|
||||||
|
@ -354,15 +329,11 @@ impl JsRuntime {
|
||||||
// SAFETY: we just asserted that layout has non-0 size.
|
// SAFETY: we just asserted that layout has non-0 size.
|
||||||
unsafe { std::alloc::alloc(layout) as *mut _ };
|
unsafe { std::alloc::alloc(layout) as *mut _ };
|
||||||
|
|
||||||
let (mut isolate, maybe_snapshot_creator) = if options.will_snapshot {
|
let mut isolate = if options.will_snapshot {
|
||||||
// TODO(ry) Support loading snapshots before snapshotting.
|
// TODO(ry) Support loading snapshots before snapshotting.
|
||||||
assert!(options.startup_snapshot.is_none());
|
assert!(options.startup_snapshot.is_none());
|
||||||
let mut creator = v8::SnapshotCreator::new(Some(refs));
|
let snapshot_creator = v8::Isolate::snapshot_creator(Some(refs));
|
||||||
// SAFETY: `get_owned_isolate` is unsafe because it may only be called
|
let mut isolate = JsRuntime::setup_isolate(snapshot_creator);
|
||||||
// once. This is the only place we call this function, so this call is
|
|
||||||
// safe.
|
|
||||||
let isolate = unsafe { creator.get_owned_isolate() };
|
|
||||||
let mut isolate = JsRuntime::setup_isolate(isolate);
|
|
||||||
{
|
{
|
||||||
// SAFETY: this is first use of `isolate_ptr` so we are sure we're
|
// SAFETY: this is first use of `isolate_ptr` so we are sure we're
|
||||||
// not overwriting an existing pointer.
|
// not overwriting an existing pointer.
|
||||||
|
@ -373,9 +344,9 @@ impl JsRuntime {
|
||||||
let scope = &mut v8::HandleScope::new(&mut isolate);
|
let scope = &mut v8::HandleScope::new(&mut isolate);
|
||||||
let context = bindings::initialize_context(scope, &op_ctxs, false);
|
let context = bindings::initialize_context(scope, &op_ctxs, false);
|
||||||
global_context = v8::Global::new(scope, context);
|
global_context = v8::Global::new(scope, context);
|
||||||
creator.set_default_context(context);
|
scope.set_default_context(context);
|
||||||
}
|
}
|
||||||
(isolate, Some(creator))
|
isolate
|
||||||
} else {
|
} else {
|
||||||
let mut params = options
|
let mut params = options
|
||||||
.create_params
|
.create_params
|
||||||
|
@ -414,7 +385,7 @@ impl JsRuntime {
|
||||||
global_context = v8::Global::new(scope, context);
|
global_context = v8::Global::new(scope, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
(isolate, None)
|
isolate
|
||||||
};
|
};
|
||||||
|
|
||||||
op_state.borrow_mut().put(isolate_ptr);
|
op_state.borrow_mut().put(isolate_ptr);
|
||||||
|
@ -458,8 +429,6 @@ impl JsRuntime {
|
||||||
|
|
||||||
let mut js_runtime = Self {
|
let mut js_runtime = Self {
|
||||||
v8_isolate: Some(isolate),
|
v8_isolate: Some(isolate),
|
||||||
snapshot_creator: maybe_snapshot_creator,
|
|
||||||
has_snapshotted: false,
|
|
||||||
built_from_snapshot: has_startup_snapshot,
|
built_from_snapshot: has_startup_snapshot,
|
||||||
allocations: IsolateAllocations::default(),
|
allocations: IsolateAllocations::default(),
|
||||||
event_loop_middlewares: Vec::with_capacity(options.extensions.len()),
|
event_loop_middlewares: Vec::with_capacity(options.extensions.len()),
|
||||||
|
@ -745,9 +714,7 @@ impl JsRuntime {
|
||||||
/// set to true.
|
/// set to true.
|
||||||
///
|
///
|
||||||
/// `Error` can usually be downcast to `JsError`.
|
/// `Error` can usually be downcast to `JsError`.
|
||||||
pub fn snapshot(&mut self) -> v8::StartupData {
|
pub fn snapshot(mut self) -> v8::StartupData {
|
||||||
assert!(self.snapshot_creator.is_some());
|
|
||||||
|
|
||||||
// Nuke Deno.core.ops.* to avoid ExternalReference snapshotting issues
|
// Nuke Deno.core.ops.* to avoid ExternalReference snapshotting issues
|
||||||
// TODO(@AaronO): make ops stable across snapshots
|
// TODO(@AaronO): make ops stable across snapshots
|
||||||
{
|
{
|
||||||
|
@ -796,13 +763,10 @@ impl JsRuntime {
|
||||||
state.js_nexttick_cbs.clear();
|
state.js_nexttick_cbs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
let snapshot_creator = self.snapshot_creator.as_mut().unwrap();
|
let snapshot_creator = self.v8_isolate.unwrap();
|
||||||
let snapshot = snapshot_creator
|
snapshot_creator
|
||||||
.create_blob(v8::FunctionCodeHandling::Keep)
|
.create_blob(v8::FunctionCodeHandling::Keep)
|
||||||
.unwrap();
|
.unwrap()
|
||||||
self.has_snapshotted = true;
|
|
||||||
|
|
||||||
snapshot
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the namespace object of a module.
|
/// Returns the namespace object of a module.
|
||||||
|
@ -3938,7 +3902,7 @@ Deno.core.opAsync('op_async_serialize_object_with_numbers_as_keys', {
|
||||||
#[test]
|
#[test]
|
||||||
fn js_realm_init_snapshot() {
|
fn js_realm_init_snapshot() {
|
||||||
let snapshot = {
|
let snapshot = {
|
||||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
let runtime = JsRuntime::new(RuntimeOptions {
|
||||||
will_snapshot: true,
|
will_snapshot: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,7 @@ derive_more = "0.99.17"
|
||||||
serde = { version = "1.0.136", features = ["derive"] }
|
serde = { version = "1.0.136", features = ["derive"] }
|
||||||
serde_bytes = "0.11"
|
serde_bytes = "0.11"
|
||||||
smallvec = { version = "1.8", features = ["union"] }
|
smallvec = { version = "1.8", features = ["union"] }
|
||||||
v8 = { version = "0.52.0", default-features = false }
|
v8 = { version = "0.53.0", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
bencher = "0.1"
|
bencher = "0.1"
|
||||||
|
|
Loading…
Reference in a new issue