use a Dictionary object instead of plain object for hashes
to mitigate the `__proto__` issue related to #30
This commit is contained in:
20
lib/utils.js
20
lib/utils.js
@@ -244,3 +244,23 @@ function makePredicate(words) {
|
||||
}
|
||||
return new Function("str", f);
|
||||
};
|
||||
|
||||
function Dictionary() {
|
||||
this._values = Object.create(null);
|
||||
};
|
||||
Dictionary.prototype = {
|
||||
set: function(key, val) { return this._values["$" + key] = val, this },
|
||||
get: function(key) { return this._values["$" + key] },
|
||||
del: function(key) { return delete this._values["$" + key], this },
|
||||
has: function(key) { return ("$" + key) in this._values },
|
||||
each: function(f) {
|
||||
for (var i in this._values)
|
||||
f(this._values[i], i.substr(1));
|
||||
},
|
||||
map: function(f) {
|
||||
var ret = [];
|
||||
for (var i in this._values)
|
||||
ret.push(f(this._values[i], i.substr(1)));
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user