diff --git a/lib/module.js b/lib/module.js index bd6af190f642b1..8916b3b36c2e6f 100644 --- a/lib/module.js +++ b/lib/module.js @@ -33,14 +33,6 @@ const internalModuleReadFile = process.binding('fs').internalModuleReadFile; const internalModuleStat = process.binding('fs').internalModuleStat; const preserveSymlinks = !!process.binding('config').preserveSymlinks; -// If obj.hasOwnProperty has been overridden, then calling -// obj.hasOwnProperty(prop) will break. -// See: https://github.com/joyent/node/issues/1707 -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -} - - function stat(filename) { filename = path._makeLong(filename); const cache = stat.cache; @@ -95,12 +87,12 @@ const debug = Module._debug; // -> a/index. // check if the directory is a package.json dir -const packageMainCache = {}; +const packageMainCache = Object.create(null); function readPackage(requestPath) { - if (hasOwnProperty(packageMainCache, requestPath)) { - return packageMainCache[requestPath]; - } + const entry = packageMainCache[requestPath]; + if (entry) + return entry; const jsonPath = path.resolve(requestPath, 'package.json'); const json = internalModuleReadFile(path._makeLong(jsonPath));