Skip to content

Commit d124198

Browse files
committed
[INTERNAL] Use Object.create(null) for dynamic maps
1 parent 4d42a29 commit d124198

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

lib/ReaderCollectionPrioritized.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ReaderCollectionPrioritized extends AbstractReader {
3737
return Promise.all(this._readers.map(function(resourceLocator) {
3838
return resourceLocator._byGlob(pattern, options, trace);
3939
})).then((result) => {
40-
const files = {};
40+
const files = Object.create(null);
4141
const resources = [];
4242
// Prefer files found in preceding resource locators
4343
for (let i = 0; i < result.length; i++) {

lib/Resource.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@ class Resource {
368368
* @returns {object} Trace tree
369369
*/
370370
getPathTree() {
371-
const tree = {};
371+
const tree = Object.create(null);
372372

373-
let pointer = tree[this._path] = {};
373+
let pointer = tree[this._path] = Object.create(null);
374374

375375
for (let i = this._collections.length - 1; i >= 0; i--) {
376-
pointer = pointer[this._collections[i]] = {};
376+
pointer = pointer[this._collections[i]] = Object.create(null);
377377
}
378378

379379
return tree;

lib/ResourceTagCollection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ResourceTagCollection {
2929
this._allowedNamespacesRegExp = null;
3030
}
3131

32-
this._pathTags = tags || {};
32+
this._pathTags = tags || Object.create(null);
3333
}
3434

3535
setTag(resourcePath, tag, value = true) {
@@ -38,7 +38,7 @@ class ResourceTagCollection {
3838
this._validateValue(value);
3939

4040
if (!this._pathTags[resourcePath]) {
41-
this._pathTags[resourcePath] = {};
41+
this._pathTags[resourcePath] = Object.create(null);
4242
}
4343
this._pathTags[resourcePath][tag] = value;
4444
}

lib/adapters/Memory.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class Memory extends AbstractAdapter {
2323
*/
2424
constructor({virBasePath, project, excludes}) {
2525
super({virBasePath, project, excludes});
26-
this._virFiles = {}; // map full of files
27-
this._virDirs = {}; // map full of directories
26+
this._virFiles = Object.create(null); // map full of files
27+
this._virDirs = Object.create(null); // map full of directories
2828
}
2929

3030
/**

lib/tracing/Trace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Trace {
2121
this._startTime = process.hrtime();
2222
this._globCalls = 0;
2323
this._pathCalls = 0;
24-
this._collections = {};
24+
this._collections = Object.create(null);
2525
summaryTrace.traceStarted();
2626
}
2727

0 commit comments

Comments
 (0)