utils: map changes.

This commit is contained in:
Christopher Jeffrey 2017-01-05 13:10:05 -08:00
parent 5fb64e7bac
commit 80a1b95529
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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
*/