From b55c9d68aa713e75ff5077cd425cbaafde010b92 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 27 Mar 2014 00:30:49 +0400 Subject: [PATCH] configure: --v8-options option Introduce a way to set some v8 flags at compile time, the values should be separated by comma. --- configure | 12 ++++++++++++ node.gyp | 2 ++ src/node.cc | 22 ++++++++++++++++++++++ src/node.js | 6 +++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/configure b/configure index cfc28299f86349..842daa94a312d7 100755 --- a/configure +++ b/configure @@ -204,6 +204,12 @@ parser.add_option('--tag', dest='tag', help='custom build tag') +parser.add_option('--v8-options', + action='store', + dest='v8_options', + help='v8 options to pass, see `node --v8-options` for examples. ' + 'The flags should be separated by a comma') + parser.add_option('--with-arm-float-abi', action='store', dest='arm_float_abi', @@ -513,6 +519,12 @@ def configure_node(o): else: o['variables']['node_tag'] = '' + if options.v8_options: + opts = options.v8_options.split(',') + o['variables']['node_v8_options'] = '"' + '","'.join(opts) + '"' + else: + o['variables']['node_v8_options'] = '' + def configure_libz(o): o['variables']['node_shared_zlib'] = b(options.shared_zlib) diff --git a/node.gyp b/node.gyp index 82fa56b90a6445..86fa64a39534f2 100644 --- a/node.gyp +++ b/node.gyp @@ -13,6 +13,7 @@ 'node_use_openssl%': 'true', 'node_shared_openssl%': 'false', 'node_use_mdb%': 'false', + 'node_v8_options%': '', 'library_files': [ 'src/node.js', 'lib/_debugger.js', @@ -158,6 +159,7 @@ 'ARCH="<(target_arch)"', 'PLATFORM="<(OS)"', 'NODE_TAG="<(node_tag)"', + 'NODE_V8_OPTIONS=<(node_v8_options)', ], 'conditions': [ diff --git a/src/node.cc b/src/node.cc index 830d3c3c00ff5a..5c2a885cd2f790 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3062,6 +3062,26 @@ static void ParseArgs(int* argc, } +static void SetCompileTimeV8Options(const char** argv) { +#ifdef NODE_V8_OPTIONS + int v8_argc; + static const char* v8_argv[] = { NULL, NODE_V8_OPTIONS }; + if (ARRAY_SIZE(v8_argv) == 1) + return; + + v8_argv[0] = argv[0]; + v8_argc = ARRAY_SIZE(v8_argv); + V8::SetFlagsFromCommandLine(&v8_argc, const_cast(v8_argv), true); + + // Anything that's still in v8_argv is not a V8 or a node option. + for (int i = 1; i < v8_argc; i++) + fprintf(stderr, "%s: bad option: %s\n", argv[0], v8_argv[i]); + if (v8_argc > 1) + exit(9); +#endif // NODE_V8_OPTIONS +} + + // Called from V8 Debug Agent TCP thread. static void DispatchMessagesDebugAgentCallback() { uv_async_send(&dispatch_debug_messages_async); @@ -3355,6 +3375,8 @@ void Init(int* argc, DispatchDebugMessagesAsyncCallback); uv_unref(reinterpret_cast(&dispatch_debug_messages_async)); + SetCompileTimeV8Options(argv); + // Parse a few arguments which are specific to Node. int v8_argc; const char** v8_argv; diff --git a/src/node.js b/src/node.js index c9fcb4f4455ac0..6f8e53704a69f2 100644 --- a/src/node.js +++ b/src/node.js @@ -274,7 +274,11 @@ delete NativeModule._source.config; // strip the gyp comment line at the beginning - config = config.split('\n').slice(1).join('\n').replace(/'/g, '"'); + config = config.split('\n') + .slice(1) + .join('\n') + .replace(/"/g, '\\"') + .replace(/'/g, '"'); process.config = JSON.parse(config, function(key, value) { if (value === 'true') return true;