From 769925318334c0fe0370799bc85f54f1ee7138ce Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 18 Mar 2013 22:32:07 +0800 Subject: [PATCH] Add flags to control whether to set low level hooks and disable exceptions. --- src/node.cc | 23 +++++++++++++++++++---- src/node.h | 10 ++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/node.cc b/src/node.cc index 02df0d8a5b2..c268e9f380e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -108,6 +108,11 @@ using v8::V8; using v8::Value; using v8::kExternalUint32Array; +bool g_standalone_mode = true; +bool g_upstream_node_mode = true; +bool use_debug_agent = false; +bool debug_wait_connect = false; + static bool print_eval = false; static bool force_repl = false; static bool trace_deprecation = false; @@ -116,8 +121,6 @@ static bool abort_on_uncaught_exception = false; static const char* eval_string = nullptr; static unsigned int preload_module_count = 0; static const char** preload_modules = nullptr; -static bool use_debug_agent = false; -static bool debug_wait_connect = false; static int debug_port = 5858; static bool v8_is_profiling = false; static bool node_is_initialized = false; @@ -1089,6 +1092,7 @@ Handle MakeCallback(Environment* env, env->tick_callback_function()->Call(process, 0, nullptr); CHECK_EQ(env->context(), env->isolate()->GetCurrentContext()); + if (!g_standalone_mode) try_catch.Reset(); if (try_catch.HasCaught()) { return Undefined(env->isolate()); } @@ -1115,6 +1119,7 @@ Handle MakeCallback(Environment* env, tick_info->set_in_tick(false); + if (!g_standalone_mode) try_catch.Reset(); if (try_catch.HasCaught()) { tick_info->set_last_threw(true); return Undefined(env->isolate()); @@ -2891,8 +2896,12 @@ static void RawDebug(const FunctionCallbackInfo& args) { void LoadEnvironment(Environment* env) { HandleScope handle_scope(env->isolate()); + if (g_upstream_node_mode) { // No indent to minimize diff. env->isolate()->SetFatalErrorHandler(node::OnFatalError); + } // g_upstream_node_mode + if (g_standalone_mode) { // No indent to minimize diff. env->isolate()->AddMessageListener(OnMessage); + } // g_standalone_mode // Compile, execute the src/node.js file. (Which was included as static C // string in node_natives.h. 'natve_node' is the string containing that @@ -3188,7 +3197,7 @@ static void DispatchMessagesDebugAgentCallback(Environment* env) { } -static void StartDebug(Environment* env, bool wait) { +void StartDebug(Environment* env, bool wait) { CHECK(!debugger_running); env->debugger_agent()->set_dispatch_handler( @@ -3203,7 +3212,7 @@ static void StartDebug(Environment* env, bool wait) { // Called from the main thread. -static void EnableDebug(Environment* env) { +void EnableDebug(Environment* env) { CHECK(debugger_running); // Send message to enable debug in workers @@ -3531,6 +3540,7 @@ void Init(int* argc, // Initialize prog_start_time to get relative uptime. prog_start_time = static_cast(uv_now(uv_default_loop())); + if (g_upstream_node_mode) { // No indent to minimize diff. // Make inherited handles noninheritable. uv_disable_stdio_inheritance(); @@ -3595,12 +3605,17 @@ void Init(int* argc, const char expose_debug_as[] = "--expose_debug_as=v8debug"; V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1); } + } // g_upstream_node_mode +#if 0 V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton); +#endif + if (g_upstream_node_mode) { // No indent to minimize diff. if (!use_debug_agent) { RegisterDebugSignalHandler(); } + } // g_upstream_node_mode // We should set node_is_initialized here instead of in node::Start, // otherwise embedders using node::Init to initialize everything will not be diff --git a/src/node.h b/src/node.h index 28b40aa0721..d40e7b83f71 100644 --- a/src/node.h +++ b/src/node.h @@ -152,6 +152,13 @@ namespace node { NODE_EXTERN extern bool no_deprecation; +// Whether node should open some low level hooks. +NODE_EXTERN extern bool g_standalone_mode; +NODE_EXTERN extern bool g_upstream_node_mode; +// Expose the debug flags. +NODE_EXTERN extern bool use_debug_agent; +NODE_EXTERN extern bool debug_wait_connect; + NODE_EXTERN int Start(int argc, char *argv[]); NODE_EXTERN void Init(int* argc, const char** argv, @@ -184,6 +191,9 @@ NODE_EXTERN void EmitBeforeExit(Environment* env); NODE_EXTERN int EmitExit(Environment* env); NODE_EXTERN void RunAtExit(Environment* env); +NODE_EXTERN void StartDebug(Environment* env, bool wait); +NODE_EXTERN void EnableDebug(Environment* env); + /* Converts a unixtime to V8 Date */ #define NODE_UNIXTIME_V8(t) v8::Date::New(v8::Isolate::GetCurrent(), \ 1000 * static_cast(t))