diff --git a/lib/internal/module.js b/lib/internal/module.js index 2f38618daac5f7..8fc8dfbf327e61 100644 --- a/lib/internal/module.js +++ b/lib/internal/module.js @@ -8,23 +8,22 @@ exports = module.exports = { exports.requireDepth = 0; -// Invoke with makeRequireFunction.call(module) where |module| is the -// Module object to use as the context for the require() function. -function makeRequireFunction() { - const Module = this.constructor; - const self = this; +// Invoke with makeRequireFunction(module) where |module| is the Module object +// to use as the context for the require() function. +function makeRequireFunction(mod) { + const Module = mod.constructor; function require(path) { try { exports.requireDepth += 1; - return self.require(path); + return mod.require(path); } finally { exports.requireDepth -= 1; } } function resolve(request) { - return Module._resolveFilename(request, self); + return Module._resolveFilename(request, mod); } require.resolve = resolve; diff --git a/lib/module.js b/lib/module.js index 8916b3b36c2e6f..1b9c2413b7ce9e 100644 --- a/lib/module.js +++ b/lib/module.js @@ -577,11 +577,11 @@ Module.prototype._compile = function(content, filename) { } } var dirname = path.dirname(filename); - var require = internalModule.makeRequireFunction.call(this); - var args = [this.exports, require, this, filename, dirname]; + var require = internalModule.makeRequireFunction(this); var depth = internalModule.requireDepth; if (depth === 0) stat.cache = new Map(); - var result = compiledWrapper.apply(this.exports, args); + var result = compiledWrapper.call(this.exports, this.exports, require, this, + filename, dirname); if (depth === 0) stat.cache = null; return result; }; diff --git a/lib/repl.js b/lib/repl.js index 3dd243b0b0cdbf..676fa105861d33 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -714,7 +714,7 @@ REPLServer.prototype.createContext = function() { const module = new Module(''); module.paths = Module._resolveLookupPaths('', parentModule)[1]; - const require = internalModule.makeRequireFunction.call(module); + const require = internalModule.makeRequireFunction(module); context.module = module; context.require = require;