Skip to content

Commit f58e596

Browse files
committed
lib: remove broken NODE_MODULE_CONTEXTS feature
This feature has no tests and has been broken for ages, see for example #1160. Don't bother fixing it, it's pretty much broken by design and there can't be too many users because it's almost undocumented. A quick Google search suggests that it causes more grief than joy to the few that do use it. Remove it. PR-URL: #1162 Reviewed-By: Colin Ihrig <[email protected]>
1 parent 2551c1d commit f58e596

File tree

4 files changed

+9
-50
lines changed

4 files changed

+9
-50
lines changed

doc/iojs.1

-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ and servers.
6868
.IP NODE_PATH
6969
\':\'\-separated list of directories prefixed to the module search path.
7070

71-
.IP NODE_MODULE_CONTEXTS
72-
If set to 1 then modules will load in their own global contexts.
73-
7471
.IP NODE_DISABLE_COLORS
7572
If set to 1 then colors will not be used in the REPL.
7673

lib/module.js

-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const NativeModule = require('native_module');
44
const util = require('util');
55
const runInThisContext = require('vm').runInThisContext;
6-
const runInNewContext = require('vm').runInNewContext;
76
const assert = require('assert').ok;
87
const fs = require('fs');
98
const path = require('path');
@@ -31,9 +30,6 @@ function Module(id, parent) {
3130
}
3231
module.exports = Module;
3332

34-
// Set the environ variable NODE_MODULE_CONTEXTS=1 to make node load all
35-
// modules in their own context.
36-
Module._contextLoad = (+process.env['NODE_MODULE_CONTEXTS'] > 0);
3733
Module._cache = {};
3834
Module._pathCache = {};
3935
Module._extensions = {};
@@ -391,36 +387,6 @@ Module.prototype._compile = function(content, filename) {
391387

392388
var dirname = path.dirname(filename);
393389

394-
if (Module._contextLoad) {
395-
if (self.id !== '.') {
396-
debug('load submodule');
397-
// not root module
398-
var sandbox = {};
399-
for (var k in global) {
400-
sandbox[k] = global[k];
401-
}
402-
sandbox.require = require;
403-
sandbox.exports = self.exports;
404-
sandbox.__filename = filename;
405-
sandbox.__dirname = dirname;
406-
sandbox.module = self;
407-
sandbox.global = sandbox;
408-
sandbox.root = root;
409-
410-
return runInNewContext(content, sandbox, { filename: filename });
411-
}
412-
413-
debug('load root module');
414-
// root module
415-
global.require = require;
416-
global.exports = self.exports;
417-
global.__filename = filename;
418-
global.__dirname = dirname;
419-
global.module = self;
420-
421-
return runInThisContext(content, { filename: filename });
422-
}
423-
424390
// create wrapper function
425391
var wrapper = Module.wrap(content);
426392

src/node.cc

-2
Original file line numberDiff line numberDiff line change
@@ -3012,8 +3012,6 @@ static void PrintHelp() {
30123012
"NODE_PATH ':'-separated list of directories\n"
30133013
#endif
30143014
" prefixed to the module search path.\n"
3015-
"NODE_MODULE_CONTEXTS Set to 1 to load modules in their own\n"
3016-
" global contexts.\n"
30173015
"NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL\n"
30183016
#if defined(NODE_HAVE_I18N_SUPPORT)
30193017
"NODE_ICU_DATA Data path for ICU (Intl object) data\n"

src/node.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -465,17 +465,15 @@
465465
module.filename = path.join(cwd, name);
466466
module.paths = Module._nodeModulePaths(cwd);
467467
var script = process._eval;
468-
if (!Module._contextLoad) {
469-
var body = script;
470-
script = 'global.__filename = ' + JSON.stringify(name) + ';\n' +
471-
'global.exports = exports;\n' +
472-
'global.module = module;\n' +
473-
'global.__dirname = __dirname;\n' +
474-
'global.require = require;\n' +
475-
'return require("vm").runInThisContext(' +
476-
JSON.stringify(body) + ', { filename: ' +
477-
JSON.stringify(name) + ' });\n';
478-
}
468+
var body = script;
469+
script = 'global.__filename = ' + JSON.stringify(name) + ';\n' +
470+
'global.exports = exports;\n' +
471+
'global.module = module;\n' +
472+
'global.__dirname = __dirname;\n' +
473+
'global.require = require;\n' +
474+
'return require("vm").runInThisContext(' +
475+
JSON.stringify(body) + ', { filename: ' +
476+
JSON.stringify(name) + ' });\n';
479477
var result = module._compile(script, name + '-wrapper');
480478
if (process._print_eval) console.log(result);
481479
}

0 commit comments

Comments
 (0)