Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
configure: --v8-options option
Browse files Browse the repository at this point in the history
Introduce a way to set some v8 flags at compile time, the values should
be separated by comma.
  • Loading branch information
indutny committed Mar 29, 2014
1 parent 6d15b16 commit b55c9d6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
12 changes: 12 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -158,6 +159,7 @@
'ARCH="<(target_arch)"',
'PLATFORM="<(OS)"',
'NODE_TAG="<(node_tag)"',
'NODE_V8_OPTIONS=<(node_v8_options)',
],

'conditions': [
Expand Down
22 changes: 22 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<char**>(v8_argv), true);

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Mar 31, 2014

Member

Why didn't you use V8::SetFlagsFromString() here? Besides being more elegant it also removes the requirement that arguments are separated with commas, just ./configure --v8-options="--foo --bar" would do in that case which seems like a more natural notation.

This comment has been minimized.

Copy link
@indutny

indutny Mar 31, 2014

Author Member

This is a good question, indeed! I think it should be faster to do it this way, also in the most of situation this function call will be eliminated by the compiler.

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Apr 1, 2014

Member

I don't understand the performance argument. This is hardly a critical code path and it's opt-in anyway.

Another reason to use V8::SetFlagsFromString() is that the current approach won't work for flags that take a comma-separated list of arguments.

This comment has been minimized.

Copy link
@indutny

indutny Apr 1, 2014

Author Member

I guess this makes sense, want to open a PR for it?

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Apr 1, 2014

Member

I'll do that.


// 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);
Expand Down Expand Up @@ -3355,6 +3375,8 @@ void Init(int* argc,
DispatchDebugMessagesAsyncCallback);
uv_unref(reinterpret_cast<uv_handle_t*>(&dispatch_debug_messages_async));

SetCompileTimeV8Options(argv);

// Parse a few arguments which are specific to Node.
int v8_argc;
const char** v8_argv;
Expand Down
6 changes: 5 additions & 1 deletion src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b55c9d6

Please sign in to comment.