utils: map changes.
This commit is contained in:
parent
5fb64e7bac
commit
80a1b95529
@ -17,7 +17,7 @@ function Map() {
|
|||||||
if (!(this instanceof Map))
|
if (!(this instanceof Map))
|
||||||
return new Map();
|
return new Map();
|
||||||
|
|
||||||
this.map = {};
|
this.map = Object.create(null);
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +55,8 @@ Map.prototype.values = function values() {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Map.prototype.get = function get(key) {
|
Map.prototype.get = function get(key) {
|
||||||
|
if (key === '__proto__')
|
||||||
|
return;
|
||||||
return this.map[key];
|
return this.map[key];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -65,6 +67,8 @@ Map.prototype.get = function get(key) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Map.prototype.has = function has(key) {
|
Map.prototype.has = function has(key) {
|
||||||
|
if (key === '__proto__')
|
||||||
|
return false;
|
||||||
return this.map[key] !== undefined;
|
return this.map[key] !== undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,6 +84,9 @@ Map.prototype.set = function set(key, value) {
|
|||||||
|
|
||||||
assert(value !== undefined);
|
assert(value !== undefined);
|
||||||
|
|
||||||
|
if (key === '__proto__')
|
||||||
|
return;
|
||||||
|
|
||||||
this.map[key] = value;
|
this.map[key] = value;
|
||||||
|
|
||||||
if (item === undefined) {
|
if (item === undefined) {
|
||||||
@ -113,10 +120,21 @@ Map.prototype.remove = function remove(key) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Map.prototype.reset = function reset() {
|
Map.prototype.reset = function reset() {
|
||||||
this.map = {};
|
this.map = Object.create(null);
|
||||||
this.size = 0;
|
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
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user