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

Commit

Permalink
Add flags to control whether to set low level hooks and disable excep…
Browse files Browse the repository at this point in the history
…tions.
  • Loading branch information
zcbenz committed Apr 20, 2015
1 parent 4845f9c commit 7699253
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -1089,6 +1092,7 @@ Handle<Value> 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());
}
Expand All @@ -1115,6 +1119,7 @@ Handle<Value> 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());
Expand Down Expand Up @@ -2891,8 +2896,12 @@ static void RawDebug(const FunctionCallbackInfo<Value>& 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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -3531,6 +3540,7 @@ void Init(int* argc,
// Initialize prog_start_time to get relative uptime.
prog_start_time = static_cast<double>(uv_now(uv_default_loop()));

if (g_upstream_node_mode) { // No indent to minimize diff.
// Make inherited handles noninheritable.
uv_disable_stdio_inheritance();

Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<double>(t))
Expand Down

0 comments on commit 7699253

Please sign in to comment.