Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 7699253

Browse files
committed
Add flags to control whether to set low level hooks and disable exceptions.
1 parent 4845f9c commit 7699253

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/node.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ using v8::V8;
108108
using v8::Value;
109109
using v8::kExternalUint32Array;
110110

111+
bool g_standalone_mode = true;
112+
bool g_upstream_node_mode = true;
113+
bool use_debug_agent = false;
114+
bool debug_wait_connect = false;
115+
111116
static bool print_eval = false;
112117
static bool force_repl = false;
113118
static bool trace_deprecation = false;
@@ -116,8 +121,6 @@ static bool abort_on_uncaught_exception = false;
116121
static const char* eval_string = nullptr;
117122
static unsigned int preload_module_count = 0;
118123
static const char** preload_modules = nullptr;
119-
static bool use_debug_agent = false;
120-
static bool debug_wait_connect = false;
121124
static int debug_port = 5858;
122125
static bool v8_is_profiling = false;
123126
static bool node_is_initialized = false;
@@ -1089,6 +1092,7 @@ Handle<Value> MakeCallback(Environment* env,
10891092
env->tick_callback_function()->Call(process, 0, nullptr);
10901093
CHECK_EQ(env->context(), env->isolate()->GetCurrentContext());
10911094

1095+
if (!g_standalone_mode) try_catch.Reset();
10921096
if (try_catch.HasCaught()) {
10931097
return Undefined(env->isolate());
10941098
}
@@ -1115,6 +1119,7 @@ Handle<Value> MakeCallback(Environment* env,
11151119

11161120
tick_info->set_in_tick(false);
11171121

1122+
if (!g_standalone_mode) try_catch.Reset();
11181123
if (try_catch.HasCaught()) {
11191124
tick_info->set_last_threw(true);
11201125
return Undefined(env->isolate());
@@ -2891,8 +2896,12 @@ static void RawDebug(const FunctionCallbackInfo<Value>& args) {
28912896
void LoadEnvironment(Environment* env) {
28922897
HandleScope handle_scope(env->isolate());
28932898

2899+
if (g_upstream_node_mode) { // No indent to minimize diff.
28942900
env->isolate()->SetFatalErrorHandler(node::OnFatalError);
2901+
} // g_upstream_node_mode
2902+
if (g_standalone_mode) { // No indent to minimize diff.
28952903
env->isolate()->AddMessageListener(OnMessage);
2904+
} // g_standalone_mode
28962905

28972906
// Compile, execute the src/node.js file. (Which was included as static C
28982907
// string in node_natives.h. 'natve_node' is the string containing that
@@ -3188,7 +3197,7 @@ static void DispatchMessagesDebugAgentCallback(Environment* env) {
31883197
}
31893198

31903199

3191-
static void StartDebug(Environment* env, bool wait) {
3200+
void StartDebug(Environment* env, bool wait) {
31923201
CHECK(!debugger_running);
31933202

31943203
env->debugger_agent()->set_dispatch_handler(
@@ -3203,7 +3212,7 @@ static void StartDebug(Environment* env, bool wait) {
32033212

32043213

32053214
// Called from the main thread.
3206-
static void EnableDebug(Environment* env) {
3215+
void EnableDebug(Environment* env) {
32073216
CHECK(debugger_running);
32083217

32093218
// Send message to enable debug in workers
@@ -3531,6 +3540,7 @@ void Init(int* argc,
35313540
// Initialize prog_start_time to get relative uptime.
35323541
prog_start_time = static_cast<double>(uv_now(uv_default_loop()));
35333542

3543+
if (g_upstream_node_mode) { // No indent to minimize diff.
35343544
// Make inherited handles noninheritable.
35353545
uv_disable_stdio_inheritance();
35363546

@@ -3595,12 +3605,17 @@ void Init(int* argc,
35953605
const char expose_debug_as[] = "--expose_debug_as=v8debug";
35963606
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
35973607
}
3608+
} // g_upstream_node_mode
35983609

3610+
#if 0
35993611
V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton);
3612+
#endif
36003613

3614+
if (g_upstream_node_mode) { // No indent to minimize diff.
36013615
if (!use_debug_agent) {
36023616
RegisterDebugSignalHandler();
36033617
}
3618+
} // g_upstream_node_mode
36043619

36053620
// We should set node_is_initialized here instead of in node::Start,
36063621
// otherwise embedders using node::Init to initialize everything will not be

src/node.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ namespace node {
152152

153153
NODE_EXTERN extern bool no_deprecation;
154154

155+
// Whether node should open some low level hooks.
156+
NODE_EXTERN extern bool g_standalone_mode;
157+
NODE_EXTERN extern bool g_upstream_node_mode;
158+
// Expose the debug flags.
159+
NODE_EXTERN extern bool use_debug_agent;
160+
NODE_EXTERN extern bool debug_wait_connect;
161+
155162
NODE_EXTERN int Start(int argc, char *argv[]);
156163
NODE_EXTERN void Init(int* argc,
157164
const char** argv,
@@ -184,6 +191,9 @@ NODE_EXTERN void EmitBeforeExit(Environment* env);
184191
NODE_EXTERN int EmitExit(Environment* env);
185192
NODE_EXTERN void RunAtExit(Environment* env);
186193

194+
NODE_EXTERN void StartDebug(Environment* env, bool wait);
195+
NODE_EXTERN void EnableDebug(Environment* env);
196+
187197
/* Converts a unixtime to V8 Date */
188198
#define NODE_UNIXTIME_V8(t) v8::Date::New(v8::Isolate::GetCurrent(), \
189199
1000 * static_cast<double>(t))

0 commit comments

Comments
 (0)