fix compressing benchmark.js (it tried to evaluate a statement)
authorMihai Bazon <mihai@bazon.net>
Sat, 13 Oct 2012 09:56:56 +0000 (12:56 +0300)
committerMihai Bazon <mihai@bazon.net>
Sat, 13 Oct 2012 09:57:10 +0000 (12:57 +0300)
the following code in benchmark.js triggered the issue:

    support.decompilation = Function(
      'return (' + (function(x) { return { 'x': '' + (1 + x) + '', 'y': 0 }; }) + ')'
    )()(0).x === '1';

technically that could be resolved into a constant expression, but seems
it's being used here for browser bugs detection :-\

lib/compress.js

index c13421e..78d9d0c 100644 (file)
@@ -534,7 +534,14 @@ merge(Compressor.prototype, {
             }
         });
         def(AST_Statement, function(){
-            throw new Error("Cannot evaluate a statement");
+            throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
+        });
+        def(AST_Function, function(){
+            // XXX: AST_Function inherits from AST_Scope, which itself
+            // inherits from AST_Statement; however, an AST_Function
+            // isn't really a statement.  This could byte in other
+            // places too. :-( Wish JS had multiple inheritance.
+            return [ this ];
         });
         function ev(node) {
             return node._eval();