Create a temp when a new expression is called with e.g. a closure
authorLars Knoll <lars.knoll@digia.com>
Sat, 8 Dec 2012 15:01:23 +0000 (07:01 -0800)
committerSimon Hausmann <simon.hausmann@digia.com>
Sat, 8 Dec 2012 16:25:23 +0000 (17:25 +0100)
Don't crash on e.g.
var x = new (function() { return this; })

Change-Id: I120410b40ecda7fdc41e1dcc2c17251397143bc1
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
qv4codegen.cpp

index 9555523..eefd3a3 100644 (file)
@@ -1239,7 +1239,13 @@ bool Codegen::visit(NestedExpression *ast)
 bool Codegen::visit(NewExpression *ast)
 {
     Result base = expression(ast->expression);
-    _expr.code = _block->NEW(*base, 0);
+    IR::Expr *expr = *base;
+    if (expr && !expr->asTemp() && !expr->asName() && !expr->asMember()) {
+        const unsigned t = _block->newTemp();
+        move(_block->TEMP(t), expr);
+        expr = _block->TEMP(t);
+    }
+    _expr.code = _block->NEW(expr, 0);
     return false;
 }