diff --git a/lib/utils/map.js b/lib/utils/map.js index fb491989..f6070383 100644 --- a/lib/utils/map.js +++ b/lib/utils/map.js @@ -17,7 +17,7 @@ function Map() { if (!(this instanceof Map)) return new Map(); - this.map = {}; + this.map = Object.create(null); this.size = 0; } @@ -55,6 +55,8 @@ Map.prototype.values = function values() { */ Map.prototype.get = function get(key) { + if (key === '__proto__') + return; return this.map[key]; }; @@ -65,6 +67,8 @@ Map.prototype.get = function get(key) { */ Map.prototype.has = function has(key) { + if (key === '__proto__') + return false; return this.map[key] !== undefined; }; @@ -80,6 +84,9 @@ Map.prototype.set = function set(key, value) { assert(value !== undefined); + if (key === '__proto__') + return; + this.map[key] = value; if (item === undefined) { @@ -113,10 +120,21 @@ Map.prototype.remove = function remove(key) { */ Map.prototype.reset = function reset() { - this.map = {}; + this.map = Object.create(null); this.size = 0; }; +/** + * Insert a key. + * Equivalent to `this.set([key], true)`. + * @param {String} key + * @returns {Boolean} + */ + +Map.prototype.insert = function insert(key) { + return this.set(key, true); +}; + /* * Expose */