Fix delete operator on local variable and arguments
authorLars Knoll <lars.knoll@digia.com>
Fri, 14 Dec 2012 15:40:48 +0000 (16:40 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Fri, 14 Dec 2012 16:04:07 +0000 (17:04 +0100)
throw in strict mode, and ignore delete operations on
arguments otherwise.

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

index 6cf1d62..cc605d9 100644 (file)
@@ -1194,6 +1194,16 @@ bool Codegen::visit(ConditionalExpression *ast)
 bool Codegen::visit(DeleteExpression *ast)
 {
     Result expr = expression(ast->expression);
+    if ((*expr)->asTemp() && (*expr)->asTemp()->index < 0) {
+        // expr points to a function argument
+        if (_function->isStrict)
+            throwSyntaxError(ast->deleteToken, "Delete of an unqualified identifier in strict mode.");
+        // can't delete an argument, just evaluate expr for side effects
+        _expr.accept(nx);
+        return false;
+    }
+    if (_function->isStrict && (*expr)->asName())
+        throwSyntaxError(ast->deleteToken, "Delete of an unqualified identifier in strict mode.");
     IR::ExprList *args = _function->New<IR::ExprList>();
     args->init(reference(*expr));
     _expr.code = call(_block->NAME(IR::Name::builtin_delete, ast->deleteToken.startLine, ast->deleteToken.startColumn), args);