Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ deno_error = { version = "0.7.0", features = ["serde_json", "serde", "url", "tok
deno_ops = { version = "0.237.0", path = "./ops" }
deno_unsync = "0.4.2"
serde_v8 = { version = "0.270.0", path = "./serde_v8" }
v8 = { version = "140.1.1", default-features = false }
v8 = { version = "140.2.0", default-features = false }

anyhow = "1"
bencher = "0.1"
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ default = ["include_icu_data", "v8_use_custom_libcxx"]
include_icu_data = ["deno_core_icudata"]
v8_use_custom_libcxx = ["v8/use_custom_libcxx"]
v8_enable_pointer_compression = ["v8/v8_enable_pointer_compression"]
v8_enable_v8_checks = ["v8/v8_enable_v8_checks"]
include_js_files_for_snapshotting = []
unsafe_runtime_options = []
unsafe_use_unprotected_platform = []
Expand Down
16 changes: 9 additions & 7 deletions core/benches/ops/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ deno_core::extension!(
);

#[op2(fast)]
pub fn op_call_promise_resolver(scope: &mut v8::HandleScope, f: &v8::Function) {
pub fn op_call_promise_resolver(scope: &mut v8::PinScope, f: &v8::Function) {
let recv = v8::undefined(scope).into();
f.call(scope, recv, &[]);
}

#[op2]
pub fn op_resolve_promise<'s>(
scope: &'s mut v8::HandleScope,
scope: &'s mut v8::PinScope,
) -> v8::Local<'s, v8::Promise> {
let resolver = v8::PromiseResolver::new(scope).unwrap();
let value = v8::undefined(scope).into();
Expand Down Expand Up @@ -146,11 +146,13 @@ fn bench_op(
let run = runtime.execute_script("", ascii_str!("run()")).unwrap();
#[allow(deprecated)]
let bench = tokio.block_on(runtime.resolve_value(run)).unwrap();
let mut scope = runtime.handle_scope();
let bench: v8::Local<v8::Function> =
v8::Local::new(&mut scope, bench).try_into().unwrap();
let bench = v8::Global::new(&mut scope, bench);
drop(scope);
let bench = {
deno_core::jsruntime_scope!(scope, &mut runtime);
let bench: v8::Local<v8::Function> =
v8::Local::new(scope, bench).try_into().unwrap();

v8::Global::new(scope, bench)
};
drop(guard);
b.iter(move || do_benchmark(&bench, &tokio, &mut runtime));
}
Expand Down
19 changes: 11 additions & 8 deletions core/benches/ops/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ pub fn op_string_option_u32(#[string] s: &str) -> Option<u32> {
pub fn op_local(_s: v8::Local<v8::String>) {}

#[op2(fast)]
pub fn op_local_scope(_scope: &mut v8::HandleScope, _s: v8::Local<v8::String>) {
pub fn op_local_scope<'s>(
_scope: &mut v8::PinScope<'s, '_>,
_s: v8::Local<'s, v8::String>,
) {
}

#[op2(nofast)]
Expand All @@ -113,16 +116,16 @@ pub fn op_global(#[global] _s: v8::Global<v8::String>) {}

#[op2]
pub fn op_global_scope(
_scope: &mut v8::HandleScope,
_scope: &mut v8::PinScope,
#[global] _s: v8::Global<v8::String>,
) {
}

#[op2(fast)]
pub fn op_scope(_scope: &mut v8::HandleScope) {}
pub fn op_scope(_scope: &mut v8::PinScope) {}

#[op2(nofast)]
pub fn op_isolate_nofast(_isolate: *mut v8::Isolate) {}
pub fn op_isolate_nofast(_isolate: v8::UnsafeRawIsolatePtr) {}

#[op2(fast)]
pub fn op_make_external() -> *const c_void {
Expand Down Expand Up @@ -212,15 +215,15 @@ fn bench_op(
.map_err(err_mapper)
.unwrap();
let bench = runtime.execute_script("", ascii_str!("bench")).unwrap();
let mut scope = runtime.handle_scope();
deno_core::jsruntime_scope!(scope, &mut runtime);
#[allow(clippy::unnecessary_fallible_conversions)]
let bench: v8::Local<v8::Function> =
v8::Local::<v8::Value>::new(&mut scope, bench)
v8::Local::<v8::Value>::new(scope, bench)
.try_into()
.unwrap();
b.iter(|| {
let recv = v8::undefined(&mut scope).into();
bench.call(&mut scope, recv, &[]);
let recv = v8::undefined(scope).into();
bench.call(scope, recv, &[]);
});
}

Expand Down
116 changes: 58 additions & 58 deletions core/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use std::convert::Infallible;
/// // Any error type that implements `std::error::Error` can be used here.
/// type Error = std::convert::Infallible;
///
/// fn to_v8(self, scope: &mut v8::HandleScope<'a>) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
/// fn to_v8(self, scope: &mut &mut v8::PinScope<'a, '_>) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
/// // For performance, pass this value as a `v8::Integer` (i.e. a `smi`).
/// // The `Smi` wrapper type implements this conversion for you.
/// Smi(self.0).to_v8(scope)
Expand Down Expand Up @@ -67,9 +67,9 @@ pub trait ToV8<'a> {
type Error: std::error::Error + Send + Sync + 'static;

/// Converts the value to a V8 value.
fn to_v8(
fn to_v8<'i>(
self,
scope: &mut v8::HandleScope<'a>,
scope: &mut v8::PinScope<'a, 'i>,
) -> Result<v8::Local<'a, v8::Value>, Self::Error>;
}

Expand Down Expand Up @@ -98,7 +98,7 @@ pub trait ToV8<'a> {
/// // Any error type that implements `std::error::Error` can be used here.
/// type Error = JsErrorBox;
///
/// fn from_v8(scope: &mut v8::HandleScope<'a>, value: v8::Local<'a, v8::Value>) -> Result<Self, Self::Error> {
/// fn from_v8(scope: &mut &mut v8::PinScope<'a, '_>, value: v8::Local<'a, v8::Value>) -> Result<Self, Self::Error> {
/// /// We expect this value to be a `v8::Integer`, so we use the [`Smi`][deno_core::convert::Smi] wrapper type to convert it.
/// Smi::from_v8(scope, value).map(|Smi(v)| Foo(v))
/// }
Expand All @@ -114,8 +114,8 @@ pub trait FromV8<'a>: Sized {
type Error: std::error::Error + Send + Sync + 'static;

/// Converts a V8 value to a Rust value.
fn from_v8(
scope: &mut v8::HandleScope<'a>,
fn from_v8<'i>(
scope: &mut v8::PinScope<'a, 'i>,
value: v8::Local<'a, v8::Value>,
) -> Result<Self, Self::Error>;
}
Expand Down Expand Up @@ -158,25 +158,25 @@ macro_rules! impl_smallint {

impl_smallint!(for u8, u16, u32, u64, usize, i8, i16, i32, i64, isize);

impl<'a, T: SmallInt> ToV8<'a> for Smi<T> {
impl<'s, T: SmallInt> ToV8<'s> for Smi<T> {
type Error = Infallible;

#[inline]
fn to_v8(
fn to_v8<'i>(
self,
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
scope: &mut v8::PinScope<'s, 'i>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
Ok(v8::Integer::new(scope, self.0.as_i32()).into())
}
}

impl<'a, T: SmallInt> FromV8<'a> for Smi<T> {
impl<'s, T: SmallInt> FromV8<'s> for Smi<T> {
type Error = JsErrorBox;

#[inline]
fn from_v8(
_scope: &mut v8::HandleScope<'a>,
value: v8::Local<'a, v8::Value>,
fn from_v8<'i>(
_scope: &mut v8::PinScope<'s, 'i>,
value: v8::Local<'s, v8::Value>,
) -> Result<Self, Self::Error> {
let v = ops::to_i32_option(&value)
.ok_or_else(|| JsErrorBox::type_error(format!("Expected {}", T::NAME)))?;
Expand Down Expand Up @@ -228,47 +228,47 @@ impl_numeric!(
isize : ops::to_i64_option
);

impl<'a, T: Numeric> ToV8<'a> for Number<T> {
impl<'s, T: Numeric> ToV8<'s> for Number<T> {
type Error = Infallible;
#[inline]
fn to_v8(
fn to_v8<'i>(
self,
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
scope: &mut v8::PinScope<'s, 'i>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
Ok(v8::Number::new(scope, self.0.as_f64()).into())
}
}

impl<'a, T: Numeric> FromV8<'a> for Number<T> {
impl<'s, T: Numeric> FromV8<'s> for Number<T> {
type Error = JsErrorBox;
#[inline]
fn from_v8(
_scope: &mut v8::HandleScope<'a>,
value: v8::Local<'a, v8::Value>,
fn from_v8<'i>(
_scope: &mut v8::PinScope<'s, 'i>,
value: v8::Local<'s, v8::Value>,
) -> Result<Self, Self::Error> {
T::from_value(&value)
.map(Number)
.ok_or_else(|| JsErrorBox::type_error(format!("Expected {}", T::NAME)))
}
}

impl<'a> ToV8<'a> for bool {
impl<'s> ToV8<'s> for bool {
type Error = Infallible;
#[inline]
fn to_v8(
fn to_v8<'i>(
self,
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
scope: &mut v8::PinScope<'s, 'i>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
Ok(v8::Boolean::new(scope, self).into())
}
}

impl<'a> FromV8<'a> for bool {
impl<'s> FromV8<'s> for bool {
type Error = JsErrorBox;
#[inline]
fn from_v8(
_scope: &mut v8::HandleScope<'a>,
value: v8::Local<'a, v8::Value>,
fn from_v8<'i>(
_scope: &mut v8::PinScope<'s, 'i>,
value: v8::Local<'s, v8::Value>,
) -> Result<Self, Self::Error> {
value
.try_cast::<v8::Boolean>()
Expand All @@ -277,23 +277,23 @@ impl<'a> FromV8<'a> for bool {
}
}

impl<'a> FromV8<'a> for String {
impl<'s> FromV8<'s> for String {
type Error = Infallible;
#[inline]
fn from_v8(
scope: &mut v8::HandleScope<'a>,
value: v8::Local<'a, v8::Value>,
fn from_v8<'i>(
scope: &mut v8::PinScope<'s, 'i>,
value: v8::Local<'s, v8::Value>,
) -> Result<String, Self::Error> {
Ok(value.to_rust_string_lossy(scope))
}
}
impl<'a> ToV8<'a> for String {
impl<'s> ToV8<'s> for String {
type Error = Infallible;
#[inline]
fn to_v8(
fn to_v8<'i>(
self,
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
scope: &mut v8::PinScope<'s, 'i>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
Ok(v8::String::new(scope, &self).unwrap().into()) // TODO
}
}
Expand All @@ -315,32 +315,32 @@ impl<T> From<OptionNull<T>> for Option<T> {
}
}

impl<'a, T> ToV8<'a> for OptionNull<T>
impl<'s, T> ToV8<'s> for OptionNull<T>
where
T: ToV8<'a>,
T: ToV8<'s>,
{
type Error = T::Error;

fn to_v8(
fn to_v8<'i>(
self,
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
scope: &mut v8::PinScope<'s, 'i>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
match self.0 {
Some(value) => value.to_v8(scope),
None => Ok(v8::null(scope).into()),
}
}
}

impl<'a, T> FromV8<'a> for OptionNull<T>
impl<'s, T> FromV8<'s> for OptionNull<T>
where
T: FromV8<'a>,
T: FromV8<'s>,
{
type Error = T::Error;

fn from_v8(
scope: &mut v8::HandleScope<'a>,
value: v8::Local<'a, v8::Value>,
fn from_v8<'i>(
scope: &mut v8::PinScope<'s, 'i>,
value: v8::Local<'s, v8::Value>,
) -> Result<Self, Self::Error> {
if value.is_null() {
Ok(OptionNull(None))
Expand All @@ -367,32 +367,32 @@ impl<T> From<OptionUndefined<T>> for Option<T> {
}
}

impl<'a, T> ToV8<'a> for OptionUndefined<T>
impl<'s, T> ToV8<'s> for OptionUndefined<T>
where
T: ToV8<'a>,
T: ToV8<'s>,
{
type Error = T::Error;

fn to_v8(
fn to_v8<'i>(
self,
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, Self::Error> {
scope: &mut v8::PinScope<'s, 'i>,
) -> Result<v8::Local<'s, v8::Value>, Self::Error> {
match self.0 {
Some(value) => value.to_v8(scope),
None => Ok(v8::undefined(scope).into()),
}
}
}

impl<'a, T> FromV8<'a> for OptionUndefined<T>
impl<'s, T> FromV8<'s> for OptionUndefined<T>
where
T: FromV8<'a>,
T: FromV8<'s>,
{
type Error = T::Error;

fn from_v8(
scope: &mut v8::HandleScope<'a>,
value: v8::Local<'a, v8::Value>,
fn from_v8<'i>(
scope: &mut v8::PinScope<'s, 'i>,
value: v8::Local<'s, v8::Value>,
) -> Result<Self, Self::Error> {
if value.is_undefined() {
Ok(OptionUndefined(None))
Expand Down
Loading
Loading