-
- parensNesting++;
- break;
-
-
-
- }
- break;
-
- case 'STRN': // used for object lit detection..
- //if (this.mode == 'BUILDING_SYMBOL_TREE')
- //print("EXPR-STR:" + JSON.stringify(token, null, 4));
-
-
- break;
-
-
-
- case 'NAME':
- if (this.mode == 'BUILDING_SYMBOL_TREE') {
-
- //print("EXPR-NAME:" + JSON.stringify(token, null, 4));
- } else {
- //print("EXPR-NAME:" + token.toString());
- }
- symbol = token.data;
- //print("in NAME = " + token.toString());
- //print("in NAME 0: " + this.ts.look(0).toString());
- //print("in NAME 2: " + this.ts.lookTok(2).toString());
-
- //print(this.ts.lookTok(-1).data);
- // prefixed with '.'
- if (this.ts.lookTok(-1).data == ".") {
- //skip '.'
- break;
- }
- if (symbol == 'this') {
- break;
- }
-
- if (this.mode == 'PASS2_SYMBOL_TREE') {
-
- identifier = this.getIdentifier(symbol, scope, token);
- //println("<B>??</B>");
- if (identifier == false) {
-
- if (symbol.length <= 3 && Scope.builtin.indexOf(symbol) < 0) {
- // Here, we found an undeclared and un-namespaced symbol that is
- // 3 characters or less in length. Declare it in the global scope.
- // We don't need to declare longer symbols since they won't cause
- // any conflict with other munged symbols.
- this.globalScope.declareIdentifier(symbol, token);
- this.warn("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')', true);
- //print("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')');
- //throw "OOPS";
- } else {
- //print("undeclared:" + token.toString())
- }
-
-
- } else {
- //println("<B>++</B>");
- token.identifier = identifier;
- identifier.refcount++;
- }
-
- }
- break;
-
-
-
-
- //println("<B>EID</B>");
- case 'KEYW':
- //if (this.mode == 'BUILDING_SYMBOL_TREE')
- // print("EXPR-KEYW:" + JSON.stringify(token, null, 4));
-
- //print('EXPR-KEYW:' + token.toString());
- if (token.name == "FUNCTION") {
-
- this.parseFunctionDeclaration(scope);
- break;
- }
-
-
- symbol = token.data;
- if (this.mode == 'BUILDING_SYMBOL_TREE') {
-
- if (token.name == "EVAL") {
- //print(JSON.stringify(token,null,4));
- if (token.prefix && token.prefix.match(/eval:var:/g)) {
- // look for eval:var:noreplace\n
- // print("GOT MATCH?");
- var _t = this;
- token.prefix.replace(/eval:var:([a-z]+)/ig, function(m, a) {
-
- //print("PROTECT: " + a);
-
-
- var hi = _t.getIdentifier(a, scope, token);
- //println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
- if (hi) {
- // println("PROTECT "+a+" from munge");
- hi.toMunge = false;
- }
-
-
- });
-
- } else {
- this.protectScopeFromObfuscation(scope);
- this.warn("Using 'eval' is not recommended." + (this.munge ? " Moreover, using 'eval' reduces the level of compression!" : ""), true);
- }
-
-
- }
- break;
- }
- default:
- //if (this.mode == 'BUILDING_SYMBOL_TREE')
- // print("EXPR-SKIP:" + JSON.stringify(token, null, 4));
- break;
- }
-
- }
- //print("<< EXIT EXPRESSION");
- this.expN--;
- },
-
-
- parseCatch : function(scope) {
-
- var symbol;
- var token;
-
- var identifier;
-
- //token = getToken(-1);
- //assert token.getType() == Token.CATCH;
- token = this.ts.nextTok(1);
- token = this.ts.nextTok(1);
-
-
- //print(JSON.stringify(this.ts,null,4));
- //assert token.getType() == Token.LP; (
- //token = this.ts.nextTok();
- //assert token.getType() == Token.NAME;
-
- symbol = token.items[0][0].data;
-
-
- if (this.mode == 'BUILDING_SYMBOL_TREE') {
- // We must declare the exception identifier in the containing function
- // scope to avoid errors related to the obfuscation process. No need to
- // display a warning if the symbol was already declared here...
- scope.declareIdentifier(symbol, token.items[0][0]);
- } else {
- //?? why inc the refcount?? - that should be set when building the tree???
- identifier = this.getIdentifier(symbol, scope, token.items[0][0]);
- identifier.refcount++;
- }
-
- //token = this.ts.nextTok();
- //assert token.getType() == Token.RP; // )
- },
-
- parseFunctionDeclaration : function(scope)
- {
- //print("PARSE FUNCTION");
- var symbol;
- var token;
-
- var fnScope = false;
- var identifier;
- var b4braceNesting = this.braceNesting + 0;
-
- //this.logR("<B>PARSING FUNCTION</B>");
-
-
- token = this.ts.nextTok();
- if (token.type == "NAME") {
- if (this.mode == 'BUILDING_SYMBOL_TREE') {
- // Get the name of the function and declare it in the current scope.
- symbol = token.data;
- if (scope.getIdentifier(symbol,token) != false) {
- this.warn("The function " + symbol + " has already been declared in the same scope...", true);
- }
- scope.declareIdentifier(symbol,token);
- }
- token = this.ts.nextTok();
- }
-
-
- // return function() {....
- while (token.data != "(") {
- //print(token.toString());
- token = this.ts.nextTok();
-
- }
-
-
- //assert token.getType() == Token.LP;
- if (this.mode == 'BUILDING_SYMBOL_TREE') {
- fnScope = new Scope(1, scope, token.n, '', token);
-
- //println("STORING SCOPE" + this.ts.cursor);
-
- this.indexedScopes[token.id] = fnScope;
-
- } else {
- //qln("FETCHING SCOPE" + this.ts.cursor);
- fnScope = this.indexedScopes[token.id];
- }
- //if (this.mode == 'BUILDING_SYMBOL_TREE')
- // print('FUNC-PARSE:' + JSON.stringify(token,null,4));
- // Parse function arguments.
- var args = token.items;
- for (var argpos =0; argpos < args.length; argpos++) {
-
- token = args[argpos][0];
- //print ("FUNC ARGS: " + token.toString())
- //assert token.getType() == Token.NAME ||
- // token.getType() == Token.COMMA;
- if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
- symbol = token.data;
- identifier = fnScope.declareIdentifier(symbol,token);
- if (symbol == "$super" && argpos == 0) {
- // Exception for Prototype 1.6...
- identifier.preventMunging();
- }
- //argpos++;
- }
- }
-
- token = this.ts.nextTok();
- //print('FUNC-BODY:' + JSON.stringify(token.items,null,4));
- //Seed.quit();
- //print(token.toString());
- // assert token.getType() == Token.LC;
- //this.braceNesting++;
-
- //token = this.ts.nextTok();
- //print(token.toString());
- var outTS = this.ts;
- var _this = this;
- token.items.forEach(function(tar) {
- _this.ts = new TokenStream(tar);
- _this.parseScope(fnScope);
-
-
- });
-
- //print(JSON.stringify(this.ts,null,4));
- //this.parseScope(fnScope);
- this.ts = outTS;
- // now pop it off the stack!!!
-
- //this.braceNesting = b4braceNesting;
- //print("ENDFN -1: " + this.ts.lookTok(-1).toString());
- //print("ENDFN 0: " + this.ts.lookTok(0).toString());
- //print("ENDFN 1: " + this.ts.lookTok(1).toString());
- },
-
- protectScopeFromObfuscation : function(scope) {
- //assert scope != null;
-
- if (scope == this.globalScope) {
- // The global scope does not get obfuscated,
- // so we don't need to worry about it...
- return;
- }
-
- // Find the highest local scope containing the specified scope.
- while (scope && scope.parent != this.globalScope) {
- scope = scope.parent;
- }
-
- //assert scope.getParentScope() == globalScope;
- scope.preventMunging();
- },
-
- getIdentifier: function(symbol, scope, token) {
- var identifier;
- while (scope != false) {
- identifier = scope.getIdentifier(symbol, token);
- //println("ScopeParser.getIdentgetUsedSymbols("+symbol+")=" + scope.getUsedSymbols().join(','));
- if (identifier) {
- return identifier;
- }
- scope = scope.parent;
- }
- return false;
- }
+
+ parensNesting++;
+ break;
+
+
+
+ }
+ break;
+
+ case "STRN": // used for object lit detection..
+ //if (this.mode == 'BUILDING_SYMBOL_TREE')
+ //print("EXPR-STR:" + JSON.stringify(token, null, 4));
+
+
+ break;
+
+
+
+ case "NAME":
+ if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
+
+ //print("EXPR-NAME:" + JSON.stringify(token, null, 4));
+ } else {
+ //print("EXPR-NAME:" + token.toString());
+ }
+ var symbol = token.data;
+ //print("in NAME = " + token.toString());
+ //print("in NAME 0: " + this.ts.look(0).toString());
+ //print("in NAME 2: " + this.ts.lookTok(2).toString());
+
+ //print(this.ts.lookTok(-1).data);
+ // prefixed with '.'
+ if (this.ts.lookTok(-1).data == ".") {
+ //skip '.'
+ break;
+ }
+ if (symbol == "this") {
+ break;
+ }
+
+ if (this.mode == ScopeParserMode.PASS2_SYMBOL_TREE) {
+
+ var identifier = this.getIdentifier(symbol, scope, token);
+ //println("<B>??</B>");
+ if (identifier == false) {
+
+ if (symbol.length <= 3 && Scope.builtin.indexOf(symbol) < 0) {
+ // Here, we found an undeclared and un-namespaced symbol that is
+ // 3 characters or less in length. Declare it in the global scope.
+ // We don't need to declare longer symbols since they won't cause
+ // any conflict with other munged symbols.
+ this.globalScope.declareIdentifier(symbol, token);
+ this.warn("Found an undeclared symbol: " + symbol + " (line:" + token.line + ")", true);
+ //print("Found an undeclared symbol: " + symbol + ' (line:' + token.line + ')');
+ //throw "OOPS";
+ } else {
+ //print("undeclared:" + token.toString())
+ }
+
+
+ } else {
+ //println("<B>++</B>");
+ token.identifier = identifier;
+ identifier.refcount++;
+ }
+
+ }
+ break;
+
+
+
+
+ //println("<B>EID</B>");
+ case "KEYW":
+ //if (this.mode == 'BUILDING_SYMBOL_TREE')
+ // print("EXPR-KEYW:" + JSON.stringify(token, null, 4));
+
+ //print('EXPR-KEYW:' + token.toString());
+ if (token.name == "FUNCTION") {
+
+ this.parseFunctionDeclaration(scope);
+ break;
+ }
+
+
+ var symbol = token.data;
+ if (this.mode == ScopeParserMode.BUILDING_SYMBOL_TREE) {
+
+ if (token.name == "EVAL") {
+ //print(JSON.stringify(token,null,4));
+ if (token.prefix && token.prefix.match(/eval:var:/g)) {
+ // look for eval:var:noreplace\n
+ // print("GOT MATCH?");
+ var _t = this;
+ token.prefix.replace(/eval:var:([a-z]+)/ig, function(m, a) {
+
+ //print("PROTECT: " + a);
+
+
+ var hi = _t.getIdentifier(a, scope, token);
+ //println("PROTECT "+a+" from munge" + (hi ? "FOUND" : "MISSING"));
+ if (hi) {
+ // println("PROTECT "+a+" from munge");
+ hi.toMunge = false;
+ }
+
+
+ });
+
+ } else {
+ this.protectScopeFromObfuscation(scope);
+ this.warn("Using 'eval' is not recommended." + (this.munge ? " Moreover, using 'eval' reduces the level of compression!" : ""), true);
+ }
+
+
+ }
+ break;
+ }
+ default:
+ //if (this.mode == 'BUILDING_SYMBOL_TREE')
+ // print("EXPR-SKIP:" + JSON.stringify(token, null, 4));
+ break;
+ }
+
+ }
+ //print("<< EXIT EXPRESSION");
+ this.expN--;
+ }
+
+
+ parseCatch : function(scope) {
+
+ var symbol;
+ var token;
+
+ var identifier;
+
+ //token = getToken(-1);
+ //assert token.getType() == Token.CATCH;
+ token = this.ts.nextTok(1);
+ token = this.ts.nextTok(1);
+
+
+ //print(JSON.stringify(this.ts,null,4));
+ //assert token.getType() == Token.LP; (
+ //token = this.ts.nextTok();
+ //assert token.getType() == Token.NAME;
+
+ symbol = token.items[0][0].data;
+
+
+ if (this.mode == 'BUILDING_SYMBOL_TREE') {
+ // We must declare the exception identifier in the containing function
+ // scope to avoid errors related to the obfuscation process. No need to
+ // display a warning if the symbol was already declared here...
+ scope.declareIdentifier(symbol, token.items[0][0]);
+ } else {
+ //?? why inc the refcount?? - that should be set when building the tree???
+ identifier = this.getIdentifier(symbol, scope, token.items[0][0]);
+ identifier.refcount++;
+ }
+
+ //token = this.ts.nextTok();
+ //assert token.getType() == Token.RP; // )
+ },
+
+ parseFunctionDeclaration : function(scope)
+ {
+ //print("PARSE FUNCTION");
+ var symbol;
+ var token;
+
+ var fnScope = false;
+ var identifier;
+ var b4braceNesting = this.braceNesting + 0;
+
+ //this.logR("<B>PARSING FUNCTION</B>");
+
+
+ token = this.ts.nextTok();
+ if (token.type == "NAME") {
+ if (this.mode == 'BUILDING_SYMBOL_TREE') {
+ // Get the name of the function and declare it in the current scope.
+ symbol = token.data;
+ if (scope.getIdentifier(symbol,token) != false) {
+ this.warn("The function " + symbol + " has already been declared in the same scope...", true);
+ }
+ scope.declareIdentifier(symbol,token);
+ }
+ token = this.ts.nextTok();
+ }
+
+
+ // return function() {....
+ while (token.data != "(") {
+ //print(token.toString());
+ token = this.ts.nextTok();
+
+ }
+
+
+ //assert token.getType() == Token.LP;
+ if (this.mode == 'BUILDING_SYMBOL_TREE') {
+ fnScope = new Scope(1, scope, token.n, '', token);
+
+ //println("STORING SCOPE" + this.ts.cursor);
+
+ this.indexedScopes[token.id] = fnScope;
+
+ } else {
+ //qln("FETCHING SCOPE" + this.ts.cursor);
+ fnScope = this.indexedScopes[token.id];
+ }
+ //if (this.mode == 'BUILDING_SYMBOL_TREE')
+ // print('FUNC-PARSE:' + JSON.stringify(token,null,4));
+ // Parse function arguments.
+ var args = token.items;
+ for (var argpos =0; argpos < args.length; argpos++) {
+
+ token = args[argpos][0];
+ //print ("FUNC ARGS: " + token.toString())
+ //assert token.getType() == Token.NAME ||
+ // token.getType() == Token.COMMA;
+ if (token.type == 'NAME' && this.mode == 'BUILDING_SYMBOL_TREE') {
+ symbol = token.data;
+ identifier = fnScope.declareIdentifier(symbol,token);
+ if (symbol == "$super" && argpos == 0) {
+ // Exception for Prototype 1.6...
+ identifier.preventMunging();
+ }
+ //argpos++;
+ }
+ }
+
+ token = this.ts.nextTok();
+ //print('FUNC-BODY:' + JSON.stringify(token.items,null,4));
+ //Seed.quit();
+ //print(token.toString());
+ // assert token.getType() == Token.LC;
+ //this.braceNesting++;
+
+ //token = this.ts.nextTok();
+ //print(token.toString());
+ var outTS = this.ts;
+ var _this = this;
+ token.items.forEach(function(tar) {
+ _this.ts = new TokenStream(tar);
+ _this.parseScope(fnScope);
+
+
+ });
+
+ //print(JSON.stringify(this.ts,null,4));
+ //this.parseScope(fnScope);
+ this.ts = outTS;
+ // now pop it off the stack!!!
+
+ //this.braceNesting = b4braceNesting;
+ //print("ENDFN -1: " + this.ts.lookTok(-1).toString());
+ //print("ENDFN 0: " + this.ts.lookTok(0).toString());
+ //print("ENDFN 1: " + this.ts.lookTok(1).toString());
+ },
+
+ protectScopeFromObfuscation : function(scope) {
+ //assert scope != null;
+
+ if (scope == this.globalScope) {
+ // The global scope does not get obfuscated,
+ // so we don't need to worry about it...
+ return;
+ }
+
+ // Find the highest local scope containing the specified scope.
+ while (scope && scope.parent != this.globalScope) {
+ scope = scope.parent;
+ }
+
+ //assert scope.getParentScope() == globalScope;
+ scope.preventMunging();
+ },
+
+ getIdentifier: function(symbol, scope, token) {
+ var identifier;
+ while (scope != false) {
+ identifier = scope.getIdentifier(symbol, token);
+ //println("ScopeParser.getIdentgetUsedSymbols("+symbol+")=" + scope.getUsedSymbols().join(','));
+ if (identifier) {
+ return identifier;
+ }
+ scope = scope.parent;
+ }
+ return false;
+ }