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

@@ -1026,7 +1026,7 @@ merge(Compressor.prototype, {
if (hoist_funs || hoist_vars) {
var dirs = [];
var hoisted = [];
var vars = {}, vars_found = 0, var_decl = 0;
var vars = new Dictionary(), vars_found = 0, var_decl = 0;
// let's count var_decl first, we seem to waste a lot of
// space if we hoist `var` when there's only one.
self.walk(new TreeWalker(function(node){
@@ -1051,7 +1051,7 @@ merge(Compressor.prototype, {
}
if (node instanceof AST_Var && hoist_vars) {
node.definitions.forEach(function(def){
vars[def.name.name] = def;
vars.set(def.name.name, def);
++vars_found;
});
var seq = node.to_assignments();
@@ -1075,8 +1075,8 @@ merge(Compressor.prototype, {
);
self = self.transform(tt);
if (vars_found > 0) hoisted.unshift(make_node(AST_Var, self, {
definitions: Object.keys(vars).map(function(name){
var def = vars[name].clone();
definitions: vars.map(function(def){
def = def.clone();
def.value = null;
return def;
})