summaryrefslogtreecommitdiff
path: root/src/env.cc
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2015-08-26 04:37:50 -0700
committerFedor Indutny <fedor@indutny.com>2015-08-26 12:45:16 -0700
commitb2660743470be1562a782f850a28349ceaf039ad (patch)
tree67d8c6313ad968fc4feb9cf55ecac9367c26e2d1 /src/env.cc
parent972a57cb20ae7e9794e61d505ae334cb1e2b45a6 (diff)
downloadandroid-node-v8-b2660743470be1562a782f850a28349ceaf039ad.tar.gz
android-node-v8-b2660743470be1562a782f850a28349ceaf039ad.tar.bz2
android-node-v8-b2660743470be1562a782f850a28349ceaf039ad.zip
env: introduce `KickNextTick`
There might be a need to "kick off" the next tick queue and execute events on it. Normally it is done through the `MakeCallback` interface, but in case when it is not - we need a way to "kick them off" manually. PR-URL: https://github.com/nodejs/node/pull/2355 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Diffstat (limited to 'src/env.cc')
-rw-r--r--src/env.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/env.cc b/src/env.cc
index 3deb4db09e..e28866efd0 100644
--- a/src/env.cc
+++ b/src/env.cc
@@ -10,6 +10,7 @@ using v8::Local;
using v8::Message;
using v8::StackFrame;
using v8::StackTrace;
+using v8::TryCatch;
void Environment::PrintSyncTrace() const {
if (!trace_sync_io_)
@@ -55,4 +56,38 @@ void Environment::PrintSyncTrace() const {
fflush(stderr);
}
+
+bool Environment::KickNextTick() {
+ TickInfo* info = tick_info();
+
+ if (info->in_tick()) {
+ return true;
+ }
+
+ if (info->length() == 0) {
+ isolate()->RunMicrotasks();
+ }
+
+ if (info->length() == 0) {
+ info->set_index(0);
+ return true;
+ }
+
+ info->set_in_tick(true);
+
+ // process nextTicks after call
+ TryCatch try_catch;
+ try_catch.SetVerbose(true);
+ tick_callback_function()->Call(process_object(), 0, nullptr);
+
+ info->set_in_tick(false);
+
+ if (try_catch.HasCaught()) {
+ info->set_last_threw(true);
+ return false;
+ }
+
+ return true;
+}
+
} // namespace node