Handle v8::MicrotasksScope in the main process

This commit is contained in:
Cheng Zhao 2016-06-24 14:45:31 +09:00
parent 5826a8f9a9
commit ee28f4fc32
7 changed files with 27 additions and 25 deletions

View file

@ -16,11 +16,8 @@ v8::Local<v8::Value> CallEmitWithArgs(v8::Isolate* isolate,
v8::Local<v8::Object> obj,
ValueVector* args) {
// Perform microtask checkpoint after running JavaScript.
std::unique_ptr<v8::MicrotasksScope> script_scope(
Locker::IsBrowserProcess() ?
nullptr :
new v8::MicrotasksScope(isolate,
v8::MicrotasksScope::kRunMicrotasks));
v8::MicrotasksScope script_scope(
isolate, v8::MicrotasksScope::kRunMicrotasks);
// Use node::MakeCallback to call the callback, and it will also run pending
// tasks in Node.js.
return node::MakeCallback(

View file

@ -48,11 +48,8 @@ struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
v8::EscapableHandleScope handle_scope(isolate);
if (!function.IsAlive())
return v8::Null(isolate);
std::unique_ptr<v8::MicrotasksScope> script_scope(
Locker::IsBrowserProcess() ?
nullptr :
new v8::MicrotasksScope(isolate,
v8::MicrotasksScope::kRunMicrotasks));
v8::MicrotasksScope script_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::Local<v8::Function> holder = function.NewHandle(isolate);
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
@ -71,11 +68,8 @@ struct V8FunctionInvoker<void(ArgTypes...)> {
v8::HandleScope handle_scope(isolate);
if (!function.IsAlive())
return;
std::unique_ptr<v8::MicrotasksScope> script_scope(
Locker::IsBrowserProcess() ?
nullptr :
new v8::MicrotasksScope(isolate,
v8::MicrotasksScope::kRunMicrotasks));
v8::MicrotasksScope script_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::Local<v8::Function> holder = function.NewHandle(isolate);
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
@ -94,11 +88,8 @@ struct V8FunctionInvoker<ReturnType(ArgTypes...)> {
ReturnType ret = ReturnType();
if (!function.IsAlive())
return ret;
std::unique_ptr<v8::MicrotasksScope> script_scope(
Locker::IsBrowserProcess() ?
nullptr :
new v8::MicrotasksScope(isolate,
v8::MicrotasksScope::kRunMicrotasks));
v8::MicrotasksScope script_scope(isolate,
v8::MicrotasksScope::kRunMicrotasks);
v8::Local<v8::Function> holder = function.NewHandle(isolate);
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);

View file

@ -226,10 +226,8 @@ void NodeBindings::UvRunOnce() {
v8::Context::Scope context_scope(env->context());
// Perform microtask checkpoint after running JavaScript.
std::unique_ptr<v8::MicrotasksScope> script_scope(is_browser_ ?
nullptr :
new v8::MicrotasksScope(env->isolate(),
v8::MicrotasksScope::kRunMicrotasks));
v8::MicrotasksScope script_scope(env->isolate(),
v8::MicrotasksScope::kRunMicrotasks);
// Deal with uv events.
int r = uv_run(uv_loop_, UV_RUN_NOWAIT);