Skip to content
This repository has been archived by the owner on Mar 4, 2020. 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 authored and kevinsawicki committed Jan 25, 2017
1 parent 4760abc commit 8416f53
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ using v8::Uint32Array;
using v8::V8;
using v8::Value;

bool g_standalone_mode = true;
bool g_upstream_node_mode = true;

static bool print_eval = false;
static bool force_repl = false;
static bool syntax_check_only = false;
Expand Down Expand Up @@ -1160,7 +1163,9 @@ void SetupPromises(const FunctionCallbackInfo<Value>& args) {

CHECK(args[0]->IsFunction());

if (g_standalone_mode) { // No indent to minimize diff.
isolate->SetPromiseRejectCallback(PromiseRejectCallback);
}
env->set_promise_reject_function(args[0].As<Function>());

env->process_object()->Delete(
Expand Down Expand Up @@ -3406,6 +3411,13 @@ static void RawDebug(const FunctionCallbackInfo<Value>& args) {


void LoadEnvironment(Environment* env) {
if (g_standalone_mode) {
env->isolate()->AddMessageListener(OnMessage);
}
if (g_upstream_node_mode) {
env->isolate()->SetFatalErrorHandler(OnFatalError);
}

HandleScope handle_scope(env->isolate());

TryCatch try_catch(env->isolate());
Expand Down Expand Up @@ -4213,8 +4225,10 @@ 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();
} // g_upstream_node_mode

// init async debug messages dispatching
// Main thread uses uv_default_loop
Expand Down Expand Up @@ -4243,6 +4257,7 @@ void Init(int* argc,
config_preserve_symlinks = (*preserve_symlinks == '1');
}

if (g_upstream_node_mode) { // No indent to minimize diff.
// Parse a few arguments which are specific to Node.
int v8_argc;
const char** v8_argv;
Expand Down Expand Up @@ -4295,16 +4310,19 @@ void Init(int* argc,
if (v8_argc > 1) {
exit(9);
}
} // g_upstream_node_mode

// Unconditionally force typed arrays to allocate outside the v8 heap. This
// is to prevent memory pointers from being moved around that are returned by
// Buffer::Data().
const char no_typed_array_heap[] = "--typed_array_max_size_in_heap=0";
V8::SetFlagsFromString(no_typed_array_heap, sizeof(no_typed_array_heap) - 1);

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
4 changes: 4 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ NODE_EXTERN extern bool enable_fips_crypto;
NODE_EXTERN extern bool force_fips_crypto;
#endif

// Whether node should open some low level hooks.
NODE_EXTERN extern bool g_standalone_mode;
NODE_EXTERN extern bool g_upstream_node_mode;

NODE_EXTERN int Start(int argc, char *argv[]);
NODE_EXTERN void Init(int* argc,
const char** argv,
Expand Down

0 comments on commit 8416f53

Please sign in to comment.