From 8363ede8551b7c30293901f79ea8204680bc9757 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Tue, 22 Mar 2016 21:05:54 -0400 Subject: [PATCH] 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: https://github.com/atom/node/commit/82e10ce94f3c90234dac187f04a47d4d357ffd31 PR-URL: https://github.com/nodejs/node/pull/5853 Reviewed-By: James M Snell Reviewed-By: Rod Vagg --- configure | 8 ++++++++ lib/internal/bootstrap_node.js | 6 ++++-- node.gyp | 4 ++++ src/node.cc | 5 +++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 2d767c77e3e819..23866b100374ae 100755 --- a/configure +++ b/configure @@ -373,6 +373,12 @@ parser.add_option('--enable-static', dest='enable_static', help='build as static library') +parser.add_option('--no-browser-globals', + action='store_true', + dest='no_browser_globals', + help='do not export browser globals like setTimeout, console, etc. ' + + '(This mode is not officially supported for regular applications)') + (options, args) = parser.parse_args() # Expand ~ in the install prefix now, it gets written to multiple files. @@ -762,6 +768,8 @@ def configure_node(o): if options.enable_static: o['variables']['node_target_type'] = 'static_library' + o['variables']['node_no_browser_globals'] = b(options.no_browser_globals) + if options.linked_module: o['variables']['library_files'] = options.linked_module diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index e4fd8d7dec24dd..21f71206771a38 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -40,8 +40,10 @@ setupProcessFatal(); setupGlobalVariables(); - setupGlobalTimeouts(); - setupGlobalConsole(); + if (!process._noBrowserGlobals) { + setupGlobalTimeouts(); + setupGlobalConsole(); + } const _process = NativeModule.require('internal/process'); diff --git a/node.gyp b/node.gyp index 510e8d89cbf61f..a8747a639e7047 100644 --- a/node.gyp +++ b/node.gyp @@ -5,6 +5,7 @@ 'node_use_lttng%': 'false', 'node_use_etw%': 'false', 'node_use_perfctr%': 'false', + 'node_no_browser_globals%': 'false', 'node_has_winsdk%': 'false', 'node_shared_zlib%': 'false', 'node_shared_http_parser%': 'false', @@ -367,6 +368,9 @@ 'tools/msvs/genfiles/node_perfctr_provider.rc', ] } ], + [ 'node_no_browser_globals=="true"', { + 'defines': [ 'NODE_NO_BROWSER_GLOBALS' ], + } ], [ 'v8_postmortem_support=="true"', { 'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ], 'conditions': [ diff --git a/src/node.cc b/src/node.cc index f0858744eedc76..0d059cc43f3323 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3070,6 +3070,11 @@ void SetupProcessObject(Environment* env, READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate())); } +#ifdef NODE_NO_BROWSER_GLOBALS + // configure --no-browser-globals + READONLY_PROPERTY(process, "_noBrowserGlobals", True(env->isolate())); +#endif // NODE_NO_BROWSER_GLOBALS + // --prof-process if (prof_process) { READONLY_PROPERTY(process, "profProcess", True(env->isolate()));