Skip to content

Commit

Permalink
use v8::MicrotaskPolicy::kExplicit
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed Aug 19, 2019
1 parent 4faab6a commit 838e811
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ impl Isolate {
self.check_last_exception()
}

fn run_microtasks(&self) -> Result<(), ErrBox> {
unsafe { libdeno::deno_run_microtasks(self.libdeno_isolate) };
self.check_last_exception()
}

fn check_last_exception(&self) -> Result<(), ErrBox> {
let ptr = unsafe { libdeno::deno_last_exception(self.libdeno_isolate) };
if ptr.is_null() {
Expand Down Expand Up @@ -690,6 +695,7 @@ impl Future for Isolate {
drop(locker);
}

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

Expand Down
1 change: 1 addition & 0 deletions core/libdeno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ extern "C" {
js_source: *const c_char,
);
pub fn deno_terminate_execution(i: *const isolate);
pub fn deno_run_microtasks(i: *const isolate);

// Modules

Expand Down
7 changes: 7 additions & 0 deletions core/libdeno/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,11 @@ void deno_terminate_execution(Deno* d_) {
deno::DenoIsolate* d = reinterpret_cast<deno::DenoIsolate*>(d_);
d->isolate_->TerminateExecution();
}

void deno_run_microtasks(Deno* d_) {
deno::DenoIsolate* d = reinterpret_cast<deno::DenoIsolate*>(d_);
v8::Locker locker(d->isolate_);
v8::Isolate::Scope isolate_scope(d->isolate_);
d->isolate_->RunMicrotasks();
}
}
1 change: 1 addition & 0 deletions core/libdeno/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ 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: 1 addition & 0 deletions core/libdeno/deno.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const char* deno_last_exception(Deno* d);

void deno_terminate_execution(Deno* d);

void deno_run_microtasks(Deno* d);
// Module API

typedef int deno_mod;
Expand Down

0 comments on commit 838e811

Please sign in to comment.