Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b36debd

Browse filesBrowse files
indutnyrvagg
authored andcommitted
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: #2355 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
1 parent 395d736 commit b36debd
Copy full SHA for b36debd

File tree

Expand file treeCollapse file tree

4 files changed

+40
-26
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+40
-26
lines changed
Open diff view settings
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using v8::Local;
1010
using v8::Message;
1111
using v8::StackFrame;
1212
using v8::StackTrace;
13+
using v8::TryCatch;
1314

1415
void Environment::PrintSyncTrace() const {
1516
if (!trace_sync_io_)
@@ -55,4 +56,38 @@ void Environment::PrintSyncTrace() const {
5556
fflush(stderr);
5657
}
5758

59+
60+
bool Environment::KickNextTick() {
61+
TickInfo* info = tick_info();
62+
63+
if (info->in_tick()) {
64+
return true;
65+
}
66+
67+
if (info->length() == 0) {
68+
isolate()->RunMicrotasks();
69+
}
70+
71+
if (info->length() == 0) {
72+
info->set_index(0);
73+
return true;
74+
}
75+
76+
info->set_in_tick(true);
77+
78+
// process nextTicks after call
79+
TryCatch try_catch;
80+
try_catch.SetVerbose(true);
81+
tick_callback_function()->Call(process_object(), 0, nullptr);
82+
83+
info->set_in_tick(false);
84+
85+
if (try_catch.HasCaught()) {
86+
info->set_last_threw(true);
87+
return false;
88+
}
89+
90+
return true;
91+
}
92+
5893
} // namespace node
Collapse file

‎src/env.h‎

Copy file name to clipboardExpand all lines: src/env.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ class Environment {
424424
void PrintSyncTrace() const;
425425
inline void set_trace_sync_io(bool value);
426426

427+
bool KickNextTick();
428+
427429
inline uint32_t* heap_statistics_buffer() const;
428430
inline void set_heap_statistics_buffer(uint32_t* pointer);
429431

Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+1-26Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,6 @@ Handle<Value> MakeCallback(Environment* env,
10261026
// If you hit this assertion, you forgot to enter the v8::Context first.
10271027
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
10281028

1029-
Local<Object> process = env->process_object();
10301029
Local<Object> object, domain;
10311030
bool has_async_queue = false;
10321031
bool has_domain = false;
@@ -1092,32 +1091,8 @@ Handle<Value> MakeCallback(Environment* env,
10921091
return Undefined(env->isolate());
10931092
}
10941093

1095-
Environment::TickInfo* tick_info = env->tick_info();
1096-
1097-
if (tick_info->in_tick()) {
1098-
return ret;
1099-
}
1100-
1101-
if (tick_info->length() == 0) {
1102-
env->isolate()->RunMicrotasks();
1103-
}
1104-
1105-
if (tick_info->length() == 0) {
1106-
tick_info->set_index(0);
1107-
return ret;
1108-
}
1109-
1110-
tick_info->set_in_tick(true);
1111-
1112-
// process nextTicks after call
1113-
env->tick_callback_function()->Call(process, 0, nullptr);
1114-
1115-
tick_info->set_in_tick(false);
1116-
1117-
if (try_catch.HasCaught()) {
1118-
tick_info->set_last_threw(true);
1094+
if (!env->KickNextTick())
11191095
return Undefined(env->isolate());
1120-
}
11211096

11221097
return ret;
11231098
}
Collapse file

‎src/node_internals.h‎

Copy file name to clipboardExpand all lines: src/node_internals.h
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ v8::Handle<v8::Value> MakeCallback(Environment* env,
6969
int argc = 0,
7070
v8::Handle<v8::Value>* argv = nullptr);
7171

72+
bool KickNextTick();
73+
7274
// Convert a struct sockaddr to a { address: '1.2.3.4', port: 1234 } JS object.
7375
// Sets address and port properties on the info object and returns it.
7476
// If |info| is omitted, a new object is returned.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.