Skip to content

Commit 2fa959b

Browse files
indutnyevanlucas
authored andcommitted
node: --no-browser-globals configure flag
Introduce `--no-browser-globals` configure flag. With this flag set, following globals won't be exported: - `setTimeout`, `clearTimeout`, `setInterval`, `clearInterval`, `setImmediate`, `clearImmediate` - `console` These are provided by the DOM implementation in browser, so the `--no-browser-globals` flag may be helpful when embedding node.js within chromium/webkit. Inspired-By: atom/node@82e10ce PR-URL: #5853 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rod Vagg <rod@vagg.org>
1 parent 8e8768e commit 2fa959b

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

configure

+8
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ parser.add_option('--enable-static',
373373
dest='enable_static',
374374
help='build as static library')
375375

376+
parser.add_option('--no-browser-globals',
377+
action='store_true',
378+
dest='no_browser_globals',
379+
help='do not export browser globals like setTimeout, console, etc. ' +
380+
'(This mode is not officially supported for regular applications)')
381+
376382
(options, args) = parser.parse_args()
377383

378384
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -765,6 +771,8 @@ def configure_node(o):
765771
if options.enable_static:
766772
o['variables']['node_target_type'] = 'static_library'
767773

774+
o['variables']['node_no_browser_globals'] = b(options.no_browser_globals)
775+
768776
if options.linked_module:
769777
o['variables']['library_files'] = options.linked_module
770778

lib/internal/bootstrap_node.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
setupProcessFatal();
3131

3232
setupGlobalVariables();
33-
setupGlobalTimeouts();
34-
setupGlobalConsole();
33+
if (!process._noBrowserGlobals) {
34+
setupGlobalTimeouts();
35+
setupGlobalConsole();
36+
}
3537

3638
const _process = NativeModule.require('internal/process');
3739

node.gyp

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'node_use_lttng%': 'false',
66
'node_use_etw%': 'false',
77
'node_use_perfctr%': 'false',
8+
'node_no_browser_globals%': 'false',
89
'node_has_winsdk%': 'false',
910
'node_shared_zlib%': 'false',
1011
'node_shared_http_parser%': 'false',
@@ -366,6 +367,9 @@
366367
'tools/msvs/genfiles/node_perfctr_provider.rc',
367368
]
368369
} ],
370+
[ 'node_no_browser_globals=="true"', {
371+
'defines': [ 'NODE_NO_BROWSER_GLOBALS' ],
372+
} ],
369373
[ 'v8_postmortem_support=="true"', {
370374
'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ],
371375
'conditions': [

src/node.cc

+5
Original file line numberDiff line numberDiff line change
@@ -3059,6 +3059,11 @@ void SetupProcessObject(Environment* env,
30593059
READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate()));
30603060
}
30613061

3062+
#ifdef NODE_NO_BROWSER_GLOBALS
3063+
// configure --no-browser-globals
3064+
READONLY_PROPERTY(process, "_noBrowserGlobals", True(env->isolate()));
3065+
#endif // NODE_NO_BROWSER_GLOBALS
3066+
30623067
// --prof-process
30633068
if (prof_process) {
30643069
READONLY_PROPERTY(process, "profProcess", True(env->isolate()));

0 commit comments

Comments
 (0)