From 3ff7aa0ea98bd2a9dca97d7faf4685ac709774ef Mon Sep 17 00:00:00 2001 From: "mmaly@chromium.org" Date: Tue, 22 Feb 2011 17:20:25 +0000 Subject: [PATCH] Fix for bug http://code.google.com/p/v8/issues/detail?id=1176. Review URL: http://codereview.chromium.org/6469083/ git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6904 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/codegen-arm.cc | 4 ++-- src/arm/full-codegen-arm.cc | 4 ++-- src/ia32/codegen-ia32.cc | 15 ++++++--------- src/ia32/full-codegen-ia32.cc | 4 ++-- src/x64/codegen-x64.cc | 15 ++++++--------- src/x64/full-codegen-x64.cc | 4 ++-- test/mjsunit/regress/regress-1176.js | 33 +++++++++++++++++++++++++++++++++ test/mjsunit/strict-mode.js | 7 +++++++ 8 files changed, 60 insertions(+), 26 deletions(-) create mode 100644 test/mjsunit/regress/regress-1176.js diff --git a/src/arm/codegen-arm.cc b/src/arm/codegen-arm.cc index a3921d8..3e125a3 100644 --- a/src/arm/codegen-arm.cc +++ b/src/arm/codegen-arm.cc @@ -5850,8 +5850,8 @@ void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { } else if (variable != NULL) { // Delete of an unqualified identifier is disallowed in strict mode - // so this code can only be reached in non-strict mode. - ASSERT(strict_mode_flag() == kNonStrictMode); + // but "delete this" is. + ASSERT(strict_mode_flag() == kNonStrictMode || variable->is_this()); Slot* slot = variable->AsSlot(); if (variable->is_global()) { LoadGlobal(); diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 9b589e6..9d57076 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -3373,8 +3373,8 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { } } else if (var != NULL) { // Delete of an unqualified identifier is disallowed in strict mode - // so this code can only be reached in non-strict mode. - ASSERT(strict_mode_flag() == kNonStrictMode); + // but "delete this" is. + ASSERT(strict_mode_flag() == kNonStrictMode || var->is_this()); if (var->is_global()) { __ ldr(r2, GlobalObjectOperand()); __ mov(r1, Operand(var->name())); diff --git a/src/ia32/codegen-ia32.cc b/src/ia32/codegen-ia32.cc index 02e2919..ae544dc 100644 --- a/src/ia32/codegen-ia32.cc +++ b/src/ia32/codegen-ia32.cc @@ -8234,8 +8234,8 @@ void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { Variable* variable = node->expression()->AsVariableProxy()->AsVariable(); if (variable != NULL) { // Delete of an unqualified identifier is disallowed in strict mode - // so this code can only be reached in non-strict mode. - ASSERT(strict_mode_flag() == kNonStrictMode); + // but "delete this" is. + ASSERT(strict_mode_flag() == kNonStrictMode || variable->is_this()); Slot* slot = variable->AsSlot(); if (variable->is_global()) { LoadGlobal(); @@ -8244,7 +8244,6 @@ void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { Result answer = frame_->InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, 3); frame_->Push(&answer); - return; } else if (slot != NULL && slot->type() == Slot::LOOKUP) { // Call the runtime to delete from the context holding the named @@ -8255,13 +8254,11 @@ void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { frame_->EmitPush(Immediate(variable->name())); Result answer = frame_->CallRuntime(Runtime::kDeleteContextSlot, 2); frame_->Push(&answer); - return; + } else { + // Default: Result of deleting non-global, not dynamically + // introduced variables is false. + frame_->Push(Factory::false_value()); } - - // Default: Result of deleting non-global, not dynamically - // introduced variables is false. - frame_->Push(Factory::false_value()); - } else { // Default: Result of deleting expressions is true. Load(node->expression()); // may have side-effects diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc index d32e9aa..3cdca4c 100644 --- a/src/ia32/full-codegen-ia32.cc +++ b/src/ia32/full-codegen-ia32.cc @@ -3743,8 +3743,8 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { } } else if (var != NULL) { // Delete of an unqualified identifier is disallowed in strict mode - // so this code can only be reached in non-strict mode. - ASSERT(strict_mode_flag() == kNonStrictMode); + // but "delete this" is. + ASSERT(strict_mode_flag() == kNonStrictMode || var->is_this()); if (var->is_global()) { __ push(GlobalObjectOperand()); __ push(Immediate(var->name())); diff --git a/src/x64/codegen-x64.cc b/src/x64/codegen-x64.cc index 150ed66..c07bcf9 100644 --- a/src/x64/codegen-x64.cc +++ b/src/x64/codegen-x64.cc @@ -7239,8 +7239,8 @@ void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { Variable* variable = node->expression()->AsVariableProxy()->AsVariable(); if (variable != NULL) { // Delete of an unqualified identifier is disallowed in strict mode - // so this code can only be reached in non-strict mode. - ASSERT(strict_mode_flag() == kNonStrictMode); + // but "delete this" is. + ASSERT(strict_mode_flag() == kNonStrictMode || variable->is_this()); Slot* slot = variable->AsSlot(); if (variable->is_global()) { LoadGlobal(); @@ -7249,7 +7249,6 @@ void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { Result answer = frame_->InvokeBuiltin(Builtins::DELETE, CALL_FUNCTION, 3); frame_->Push(&answer); - return; } else if (slot != NULL && slot->type() == Slot::LOOKUP) { // Call the runtime to delete from the context holding the named @@ -7260,13 +7259,11 @@ void CodeGenerator::VisitUnaryOperation(UnaryOperation* node) { frame_->EmitPush(variable->name()); Result answer = frame_->CallRuntime(Runtime::kDeleteContextSlot, 2); frame_->Push(&answer); - return; + } else { + // Default: Result of deleting non-global, not dynamically + // introduced variables is false. + frame_->Push(Factory::false_value()); } - - // Default: Result of deleting non-global, not dynamically - // introduced variables is false. - frame_->Push(Factory::false_value()); - } else { // Default: Result of deleting expressions is true. Load(node->expression()); // may have side-effects diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index 11b07d7..8711f42 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -3075,8 +3075,8 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) { } } else if (var != NULL) { // Delete of an unqualified identifier is disallowed in strict mode - // so this code can only be reached in non-strict mode. - ASSERT(strict_mode_flag() == kNonStrictMode); + // but "delete this" is. + ASSERT(strict_mode_flag() == kNonStrictMode || var->is_this()); if (var->is_global()) { __ push(GlobalObjectOperand()); __ Push(var->name()); diff --git a/test/mjsunit/regress/regress-1176.js b/test/mjsunit/regress/regress-1176.js new file mode 100644 index 0000000..58eda1b --- /dev/null +++ b/test/mjsunit/regress/regress-1176.js @@ -0,0 +1,33 @@ +// Copyright 2011 the V8 project authors. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following +// disclaimer in the documentation and/or other materials provided +// with the distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived +// from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"use strict"; +function strict_delete_this() { + // "delete this" is allowed in strict mode. + delete this; +} +strict_delete_this(); diff --git a/test/mjsunit/strict-mode.js b/test/mjsunit/strict-mode.js index bcd6e90..ab3e535 100644 --- a/test/mjsunit/strict-mode.js +++ b/test/mjsunit/strict-mode.js @@ -291,6 +291,13 @@ CheckStrictMode("function strict() { var variable; delete variable; }", SyntaxError); CheckStrictMode("var variable; delete variable;", SyntaxError); +(function TestStrictDelete() { + "use strict"; + // "delete this" is allowed in strict mode and should work. + function strict_delete() { delete this; } + strict_delete(); +})(); + // Prefix unary operators other than delete, ++, -- are valid in strict mode (function StrictModeUnaryOperators() { "use strict"; -- 2.7.4