use a Dictionary object instead of plain object for hashes

to mitigate the `__proto__` issue

related to #30
This commit is contained in:
Mihai Bazon
2012-11-02 10:58:45 +02:00
parent dde57452aa
commit 8413787efc
3 changed files with 42 additions and 24 deletions

View File

@@ -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;
}
};