Skip to content

Commit 26d81fa

Browse files
committed
Merge pull request #74 from hakatashi/patch-1
Define shims as plain hash object
2 parents c99ef54 + 56adba7 commit 26d81fa

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function find_shims_in_package(pkgJson, cur_path, shims, browser) {
7777
function load_shims(paths, browser, cb) {
7878
// identify if our file should be replaced per the browser field
7979
// original filename|id -> replacement
80-
var shims = {};
80+
var shims = Object.create(null);
8181

8282
(function next() {
8383
var cur_path = paths.shift();
@@ -113,7 +113,7 @@ function load_shims(paths, browser, cb) {
113113
function load_shims_sync(paths, browser) {
114114
// identify if our file should be replaced per the browser field
115115
// original filename|id -> replacement
116-
var shims = {};
116+
var shims = Object.create(null);
117117
var cur_path;
118118

119119
while (cur_path = paths.shift()) {
@@ -239,7 +239,7 @@ function resolve(id, opts, cb) {
239239
id = shims[id];
240240
}
241241

242-
var modules = opts.modules || {};
242+
var modules = opts.modules || Object.create(null);
243243
var shim_path = modules[id];
244244
if (shim_path) {
245245
return cb(null, shim_path);
@@ -295,7 +295,7 @@ resolve.sync = function (id, opts) {
295295
id = shims[id];
296296
}
297297

298-
var modules = opts.modules || {};
298+
var modules = opts.modules || Object.create(null);
299299
var shim_path = modules[id];
300300
if (shim_path) {
301301
return shim_path;

test/fixtures/node_modules/toString/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/modules.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,12 @@ test('alt-browser fallback to "browser" on deps of deps', function(done) {
296296
done();
297297
});
298298
});
299+
300+
test('not fail on accessing path name defined in Object.prototype', function (done) {
301+
resolve('toString', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) {
302+
assert.ifError(err);
303+
assert.equal(path, require.resolve('./fixtures/node_modules/toString/index'));
304+
assert.strictEqual(pkg, undefined);
305+
done();
306+
});
307+
});

0 commit comments

Comments
 (0)