aboutsummaryrefslogtreecommitdiff
path: root/lib/scope.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/scope.js')
-rw-r--r--lib/scope.js38
1 files changed, 18 insertions, 20 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 910ce5ad..fcd9de18 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -75,7 +75,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
// pass 1: setup scope chaining and handle definitions
var self = this;
var scope = self.parent_scope = null;
- var labels = Object.create(null);
+ var labels = new Dictionary();
var tw = new TreeWalker(function(node, descend){
if (node instanceof AST_Scope) {
node.init_scope_vars();
@@ -97,11 +97,11 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
}
if (node instanceof AST_LabeledStatement) {
var l = node.label;
- if (labels[l.name])
+ if (labels.has(l.name))
throw new Error(string_template("Label {name} defined twice", l));
- labels[l.name] = l;
+ labels.set(l.name, l);
descend();
- delete labels[l.name];
+ labels.del(l.name);
return true; // no descend again
}
if (node instanceof AST_SymbolDeclaration) {
@@ -151,7 +151,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
scope.def_variable(node);
}
if (node instanceof AST_LabelRef) {
- var sym = labels[node.name];
+ var sym = labels.get(node.name);
if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", {
name: node.name,
line: node.start.line,
@@ -164,7 +164,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
// pass 2: find back references and eval
var func = null;
- var globals = self.globals = Object.create(null);
+ var globals = self.globals = new Dictionary();
var tw = new TreeWalker(function(node, descend){
if (node instanceof AST_Lambda) {
var prev_func = func;
@@ -182,12 +182,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
var sym = node.scope.find_variable(name);
if (!sym) {
var g;
- if (globals[name]) {
- g = globals[name];
+ if (globals.has(name)) {
+ g = globals.get(name);
} else {
g = new SymbolDef(self, node);
g.undeclared = true;
- globals[name] = g;
+ globals.set(name, g);
}
node.thedef = g;
if (name == "eval" && tw.parent() instanceof AST_Call) {
@@ -209,8 +209,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
AST_Scope.DEFMETHOD("init_scope_vars", function(){
this.directives = []; // contains the directives defined in this scope, i.e. "use strict"
- this.variables = Object.create(null); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
- this.functions = Object.create(null); // map name to AST_SymbolDefun (functions defined in this scope)
+ this.variables = new Dictionary(); // map name to AST_SymbolVar (variables defined in this scope; includes functions)
+ this.functions = new Dictionary(); // map name to AST_SymbolDefun (functions defined in this scope)
this.uses_with = false; // will be set to true if this or some nested scope uses the `with` statement
this.uses_eval = false; // will be set to true if this or nested scope uses the global `eval`
this.parent_scope = null; // the parent scope
@@ -252,7 +252,7 @@ AST_LabelRef.DEFMETHOD("reference", function(){
AST_Scope.DEFMETHOD("find_variable", function(name){
if (name instanceof AST_Symbol) name = name.name;
- return this.variables[name]
+ return this.variables.get(name)
|| (this.parent_scope && this.parent_scope.find_variable(name));
});
@@ -262,17 +262,17 @@ AST_Scope.DEFMETHOD("has_directive", function(value){
});
AST_Scope.DEFMETHOD("def_function", function(symbol){
- this.functions[symbol.name] = this.def_variable(symbol);
+ this.functions.set(symbol.name, this.def_variable(symbol));
});
AST_Scope.DEFMETHOD("def_variable", function(symbol){
var def;
- if (!this.variables[symbol.name]) {
+ if (!this.variables.has(symbol.name)) {
def = new SymbolDef(this, symbol);
- this.variables[symbol.name] = def;
+ this.variables.set(symbol.name, def);
def.global = !this.parent_scope;
} else {
- def = this.variables[symbol.name];
+ def = this.variables.get(symbol.name);
def.orig.push(symbol);
}
return symbol.thedef = def;
@@ -355,15 +355,13 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
if (node instanceof AST_Scope) {
var p = tw.parent();
var is_setget = p instanceof AST_ObjectSetter || p instanceof AST_ObjectGetter;
- var a = node.variables;
- for (var i in a) {
- var symbol = a[i];
+ node.variables.each(function(symbol){
if (!(is_setget && symbol instanceof AST_SymbolLambda)) {
if (options.except.indexOf(symbol.name) < 0) {
to_mangle.push(symbol);
}
}
- }
+ });
return;
}
if (node instanceof AST_Label) {