Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add bindings to run microtasks from Isolate #2793

Merged
merged 10 commits into from
Sep 12, 2019
Merged
Prev Previous commit
Next Next commit
revert to MicrotaskPolicy::kAuto
  • Loading branch information
bartlomieju committed Sep 12, 2019
commit 2fc6aa50972b6d54f2819780a90c6884864e2111
12 changes: 4 additions & 8 deletions core/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,20 +624,17 @@ impl Isolate {
}
}

#[allow(dead_code)]
struct LockerScope {
libdeno_isolate: *const libdeno::isolate,
}

#[allow(dead_code)]
impl LockerScope {
fn new(libdeno_isolate: *const libdeno::isolate) -> LockerScope {
unsafe { libdeno::deno_lock(libdeno_isolate) }
LockerScope { libdeno_isolate }
}
}

#[allow(dead_code)]
impl Drop for LockerScope {
fn drop(&mut self) {
unsafe { libdeno::deno_unlock(self.libdeno_isolate) }
Expand Down Expand Up @@ -681,22 +678,21 @@ impl Future for Isolate {

if self.shared.size() > 0 {
// Lock the current thread for V8.
// let locker = LockerScope::new(self.libdeno_isolate);
let locker = LockerScope::new(self.libdeno_isolate);
self.respond(None)?;
// The other side should have shifted off all the messages.
assert_eq!(self.shared.size(), 0);
// drop(locker);
drop(locker);
}

if overflow_response.is_some() {
// Lock the current thread for V8.
// let locker = LockerScope::new(self.libdeno_isolate);
let locker = LockerScope::new(self.libdeno_isolate);
let (op_id, buf) = overflow_response.take().unwrap();
self.respond(Some((op_id, &buf)))?;
// drop(locker);
drop(locker);
}

// self.run_microtasks();
self.check_promise_errors();
self.check_last_exception()?;

Expand Down
1 change: 0 additions & 1 deletion core/libdeno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ extern "C" {
pub fn deno_delete(i: *const isolate);
pub fn deno_last_exception(i: *const isolate) -> *const c_char;
pub fn deno_check_promise_errors(i: *const isolate);
#[allow(dead_code)]
pub fn deno_lock(i: *const isolate);
pub fn deno_unlock(i: *const isolate);
pub fn deno_respond(
Expand Down
3 changes: 0 additions & 3 deletions core/libdeno/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ void deno_execute(Deno* d_, void* user_data, const char* js_filename,
auto context = d->context_.Get(d->isolate_);
CHECK(!context.IsEmpty());
deno::Execute(context, js_filename, js_source);
isolate->RunMicrotasks();
}

void deno_pinned_buf_delete(deno_pinned_buf* buf) {
Expand All @@ -174,7 +173,6 @@ void deno_respond(Deno* d_, void* user_data, deno_op_id op_id, deno_buf buf) {
}

// Asynchronous response.
v8::Locker locker(d->isolate_);
deno::UserDataScope user_data_scope(d, user_data);
v8::Isolate::Scope isolate_scope(d->isolate_);
v8::HandleScope handle_scope(d->isolate_);
Expand All @@ -200,7 +198,6 @@ void deno_respond(Deno* d_, void* user_data, deno_op_id op_id, deno_buf buf) {
}

auto v = recv_->Call(context, context->Global(), argc, args);
d->isolate_->RunMicrotasks();

if (try_catch.HasCaught()) {
CHECK(v.IsEmpty());
Expand Down
1 change: 0 additions & 1 deletion core/libdeno/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,6 @@ v8::MaybeLocal<v8::Promise> HostImportModuleDynamicallyCallback(

void DenoIsolate::AddIsolate(v8::Isolate* isolate) {
isolate_ = isolate;
isolate_->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);
isolate_->SetCaptureStackTraceForUncaughtExceptions(
true, 10, v8::StackTrace::kDetailed);
isolate_->SetPromiseRejectCallback(deno::PromiseRejectCallback);
Expand Down
1 change: 0 additions & 1 deletion core/libdeno/modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ void deno_mod_evaluate(Deno* d_, void* user_data, deno_mod id) {
default:
FATAL("Unexpected module status: %d", static_cast<int>(status));
}
isolate->RunMicrotasks();
}

void deno_dyn_import_done(Deno* d_, void* user_data,
Expand Down