From f1488bb24c74c436d59c785463c0c447fd1bf82c Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Fri, 11 Mar 2016 12:55:59 -0700 Subject: [PATCH] src,http_parser: remove KickNextTick call Now that HTTPParser uses MakeCallback it is unnecessary to manually process the nextTickQueue. The KickNextTick function is now no longer needed so code has moved back to node::MakeCallback to simplify implementation. Include minor cleanup moving Environment::tick_info() call below the early return to save an operation. PR-URL: https://github.com/nodejs/node/pull/5756 Reviewed-By: Ben Noordhuis Reviewed-By: Andreas Madsen --- src/async-wrap.cc | 7 ++++--- src/env.cc | 23 ----------------------- src/env.h | 2 -- src/node.cc | 18 +++++++++++++++++- src/node_http_parser.cc | 4 ---- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/async-wrap.cc b/src/async-wrap.cc index e2054031014680..dde07aa0756a3e 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -181,7 +181,6 @@ Local AsyncWrap::MakeCallback(const Local cb, Local post_fn = env()->async_hooks_post_function(); Local uid = Integer::New(env()->isolate(), get_uid()); Local context = object(); - Local process = env()->process_object(); Local domain; bool has_domain = false; @@ -233,16 +232,18 @@ Local AsyncWrap::MakeCallback(const Local cb, } } - Environment::TickInfo* tick_info = env()->tick_info(); - if (callback_scope.in_makecallback()) { return ret; } + Environment::TickInfo* tick_info = env()->tick_info(); + if (tick_info->length() == 0) { env()->isolate()->RunMicrotasks(); } + Local process = env()->process_object(); + if (tick_info->length() == 0) { tick_info->set_index(0); return ret; diff --git a/src/env.cc b/src/env.cc index 5fb4489007c484..8ba72ac2e0023e 100644 --- a/src/env.cc +++ b/src/env.cc @@ -64,27 +64,4 @@ void Environment::PrintSyncTrace() const { fflush(stderr); } - -bool Environment::KickNextTick(Environment::AsyncCallbackScope* scope) { - TickInfo* info = tick_info(); - - if (scope->in_makecallback()) { - return true; - } - - if (info->length() == 0) { - isolate()->RunMicrotasks(); - } - - if (info->length() == 0) { - info->set_index(0); - return true; - } - - Local ret = - tick_callback_function()->Call(process_object(), 0, nullptr); - - return !ret.IsEmpty(); -} - } // namespace node diff --git a/src/env.h b/src/env.h index 9e5b50302ba12b..6c05b17df29219 100644 --- a/src/env.h +++ b/src/env.h @@ -467,8 +467,6 @@ class Environment { inline int64_t get_async_wrap_uid(); - bool KickNextTick(AsyncCallbackScope* scope); - inline uint32_t* heap_statistics_buffer() const; inline void set_heap_statistics_buffer(uint32_t* pointer); diff --git a/src/node.cc b/src/node.cc index dc648a4a5452c3..9d48581d5f29e8 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1204,7 +1204,23 @@ Local MakeCallback(Environment* env, } } - if (!env->KickNextTick(&callback_scope)) { + if (callback_scope.in_makecallback()) { + return ret; + } + + Environment::TickInfo* tick_info = env->tick_info(); + + if (tick_info->length() == 0) { + env->isolate()->RunMicrotasks(); + } + + Local process = env->process_object(); + + if (tick_info->length() == 0) { + tick_info->set_index(0); + } + + if (env->tick_callback_function()->Call(process, 0, nullptr).IsEmpty()) { return Undefined(env->isolate()); } diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc index 0b363ca6c310f7..12ae9e1443f534 100644 --- a/src/node_http_parser.cc +++ b/src/node_http_parser.cc @@ -587,8 +587,6 @@ class Parser : public AsyncWrap { if (!cb->IsFunction()) return; - Environment::AsyncCallbackScope callback_scope(parser->env()); - // Hooks for GetCurrentBuffer parser->current_buffer_len_ = nread; parser->current_buffer_data_ = buf->base; @@ -597,8 +595,6 @@ class Parser : public AsyncWrap { parser->current_buffer_len_ = 0; parser->current_buffer_data_ = nullptr; - - parser->env()->KickNextTick(&callback_scope); }