Skip to content

Commit

Permalink
Upgrade to rusty_v8 v0.3.3 (#4119)
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Feb 26, 2020
1 parent e53064c commit b62aa70
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 264 deletions.
4 changes: 2 additions & 2 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 core/Cargo.toml
Expand Up @@ -21,7 +21,7 @@ libc = "0.2.66"
log = "0.4.8"
serde_json = "1.0.44"
url = "2.1.0"
rusty_v8 = "0.2.1"
rusty_v8 = "0.3.3"

[[example]]
name = "deno_core_http_bench"
Expand Down
16 changes: 12 additions & 4 deletions core/bindings.rs
@@ -1,6 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

use crate::es_isolate::EsIsolate;
use crate::isolate::encode_message_as_json;
use crate::isolate::handle_exception;
use crate::isolate::Isolate;
use crate::isolate::ZeroCopyBuf;

Expand Down Expand Up @@ -278,13 +280,19 @@ pub extern "C" fn message_callback(
unsafe { &mut *(scope.isolate().get_data(0) as *mut Isolate) };

// TerminateExecution was called
if scope.isolate().is_execution_terminating() {
// TODO(piscisaureus): rusty_v8 should implement the
// `is_execution_terminating()` method on struct `Isolate` also.
if scope
.isolate()
.thread_safe_handle()
.is_execution_terminating()
{
let undefined = v8::undefined(scope).into();
deno_isolate.handle_exception(scope, undefined);
handle_exception(scope, undefined, &mut deno_isolate.last_exception);
return;
}

let json_str = deno_isolate.encode_message_as_json(scope, message);
let json_str = encode_message_as_json(scope, message);
deno_isolate.last_exception = Some(json_str);
}

Expand Down Expand Up @@ -668,7 +676,7 @@ pub fn encode_message_as_object<'a>(
s: &mut impl v8::ToLocal<'a>,
message: v8::Local<v8::Message>,
) -> v8::Local<'a, v8::Object> {
let context = s.isolate().get_current_context();
let context = s.get_current_context().unwrap();
let json_obj = v8::Object::new(s);

let exception_str = message.get(s);
Expand Down
96 changes: 45 additions & 51 deletions core/es_isolate.rs
Expand Up @@ -25,6 +25,8 @@ use std::rc::Rc;
use std::task::Context;
use std::task::Poll;

use crate::isolate::attach_handle_to_error;
use crate::isolate::exception_to_err_result;
use crate::isolate::Isolate;
use crate::isolate::StartupData;
use crate::module_specifier::ModuleSpecifier;
Expand Down Expand Up @@ -82,23 +84,6 @@ impl DerefMut for EsIsolate {

unsafe impl Send for EsIsolate {}

impl Drop for EsIsolate {
fn drop(&mut self) {
let isolate = self.core_isolate.v8_isolate.as_ref().unwrap();
// Clear persistent handles we own.
{
let mut locker = v8::Locker::new(&isolate);
let scope = locker.enter();
for module in self.modules.info.values_mut() {
module.handle.reset(scope);
}
for handle in self.dyn_import_map.values_mut() {
handle.reset(scope);
}
}
}
}

impl EsIsolate {
pub fn new(
loader: Rc<dyn Loader + Unpin>,
Expand Down Expand Up @@ -147,13 +132,14 @@ impl EsIsolate {
name: &str,
source: &str,
) -> Result<ModuleId, ErrBox> {
let isolate = self.core_isolate.v8_isolate.as_ref().unwrap();
let mut locker = v8::Locker::new(&isolate);
let core_isolate = &mut self.core_isolate;
let isolate = core_isolate.v8_isolate.as_mut().unwrap();
let js_error_create_fn = &*core_isolate.js_error_create_fn;

let mut hs = v8::HandleScope::new(locker.enter());
let mut hs = v8::HandleScope::new(isolate);
let scope = hs.enter();
assert!(!self.core_isolate.global_context.is_empty());
let context = self.core_isolate.global_context.get(scope).unwrap();
assert!(!core_isolate.global_context.is_empty());
let context = core_isolate.global_context.get(scope).unwrap();
let mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter();

Expand All @@ -166,13 +152,15 @@ impl EsIsolate {
let mut try_catch = v8::TryCatch::new(scope);
let tc = try_catch.enter();

let maybe_module = v8::script_compiler::compile_module(&isolate, source);
let maybe_module = v8::script_compiler::compile_module(scope, source);

if tc.has_caught() {
assert!(maybe_module.is_none());
return self
.core_isolate
.exception_to_err_result(scope, tc.exception().unwrap());
return exception_to_err_result(
scope,
tc.exception().unwrap(),
js_error_create_fn,
);
}

let module = maybe_module.unwrap();
Expand Down Expand Up @@ -201,9 +189,10 @@ impl EsIsolate {
/// the V8 exception. By default this type is CoreJSError, however it may be a
/// different type if Isolate::set_js_error_create() has been used.
fn mod_instantiate(&mut self, id: ModuleId) -> Result<(), ErrBox> {
let isolate = self.core_isolate.v8_isolate.as_ref().unwrap();
let mut locker = v8::Locker::new(isolate);
let mut hs = v8::HandleScope::new(locker.enter());
let isolate = self.core_isolate.v8_isolate.as_mut().unwrap();
let js_error_create_fn = &*self.core_isolate.js_error_create_fn;

let mut hs = v8::HandleScope::new(isolate);
let scope = hs.enter();
assert!(!self.core_isolate.global_context.is_empty());
let context = self.core_isolate.global_context.get(scope).unwrap();
Expand All @@ -221,7 +210,11 @@ impl EsIsolate {
let mut module = module_info.handle.get(scope).unwrap();

if module.get_status() == v8::ModuleStatus::Errored {
self.exception_to_err_result(scope, module.get_exception())?
exception_to_err_result(
scope,
module.get_exception(),
js_error_create_fn,
)?
}

let result =
Expand All @@ -230,7 +223,7 @@ impl EsIsolate {
Some(_) => Ok(()),
None => {
let exception = tc.exception().unwrap();
self.exception_to_err_result(scope, exception)
exception_to_err_result(scope, exception, js_error_create_fn)
}
}
}
Expand All @@ -241,9 +234,10 @@ impl EsIsolate {
&mut self,
id: ModuleId,
) -> Result<(), ErrBox> {
let isolate = self.core_isolate.v8_isolate.as_ref().unwrap();
let mut locker = v8::Locker::new(isolate);
let mut hs = v8::HandleScope::new(locker.enter());
let isolate = self.core_isolate.v8_isolate.as_mut().unwrap();
let js_error_create_fn = &*self.core_isolate.js_error_create_fn;

let mut hs = v8::HandleScope::new(isolate);
let scope = hs.enter();
assert!(!self.core_isolate.global_context.is_empty());
let context = self.core_isolate.global_context.get(scope).unwrap();
Expand Down Expand Up @@ -271,10 +265,9 @@ impl EsIsolate {
match status {
v8::ModuleStatus::Evaluated => Ok(()),
v8::ModuleStatus::Errored => {
let i = &mut self.core_isolate;
let exception = module.get_exception();
i.exception_to_err_result(scope, exception)
.map_err(|err| i.attach_handle_to_error(scope, err, exception))
exception_to_err_result(scope, exception, js_error_create_fn)
.map_err(|err| attach_handle_to_error(scope, err, exception))
}
other => panic!("Unexpected module status {:?}", other),
}
Expand All @@ -286,12 +279,14 @@ impl EsIsolate {
/// the V8 exception. By default this type is CoreJSError, however it may be a
/// different type if Isolate::set_js_error_create() has been used.
pub fn mod_evaluate(&mut self, id: ModuleId) -> Result<(), ErrBox> {
let isolate = self.core_isolate.v8_isolate.as_ref().unwrap();
let mut locker = v8::Locker::new(isolate);
let mut hs = v8::HandleScope::new(locker.enter());
let core_isolate = &mut self.core_isolate;
let isolate = core_isolate.v8_isolate.as_mut().unwrap();
let js_error_create_fn = &*core_isolate.js_error_create_fn;

let mut hs = v8::HandleScope::new(isolate);
let scope = hs.enter();
assert!(!self.core_isolate.global_context.is_empty());
let context = self.core_isolate.global_context.get(scope).unwrap();
assert!(!core_isolate.global_context.is_empty());
let context = core_isolate.global_context.get(scope).unwrap();
let mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter();

Expand All @@ -316,9 +311,8 @@ impl EsIsolate {
match status {
v8::ModuleStatus::Evaluated => Ok(()),
v8::ModuleStatus::Errored => {
let i = &mut self.core_isolate;
let exception = module.get_exception();
i.exception_to_err_result(scope, exception)
exception_to_err_result(scope, exception, js_error_create_fn)
}
other => panic!("Unexpected module status {:?}", other),
}
Expand Down Expand Up @@ -362,11 +356,12 @@ impl EsIsolate {
id: DynImportId,
err: ErrBox,
) -> Result<(), ErrBox> {
let isolate = self.core_isolate.v8_isolate.as_ref().unwrap();
let mut locker = v8::Locker::new(isolate);
let mut hs = v8::HandleScope::new(locker.enter());
let core_isolate = &mut self.core_isolate;
let isolate = core_isolate.v8_isolate.as_mut().unwrap();

let mut hs = v8::HandleScope::new(isolate);
let scope = hs.enter();
let context = self.core_isolate.global_context.get(scope).unwrap();
let context = core_isolate.global_context.get(scope).unwrap();
let mut cs = v8::ContextScope::new(scope, context);
let scope = cs.enter();

Expand Down Expand Up @@ -403,9 +398,8 @@ impl EsIsolate {
) -> Result<(), ErrBox> {
debug!("dyn_import_done {} {:?}", id, mod_id);
assert!(mod_id != 0);
let isolate = self.core_isolate.v8_isolate.as_ref().unwrap();
let mut locker = v8::Locker::new(isolate);
let mut hs = v8::HandleScope::new(locker.enter());
let isolate = self.core_isolate.v8_isolate.as_mut().unwrap();
let mut hs = v8::HandleScope::new(isolate);
let scope = hs.enter();
assert!(!self.core_isolate.global_context.is_empty());
let context = self.core_isolate.global_context.get(scope).unwrap();
Expand Down

0 comments on commit b62aa70

Please sign in to comment.