Reviewers: adamk,
Description:
Propagate switch statement value for 'eval'
This patch changes the switch scope desugaring to create blocks which
propagate their 'return value' for eval.
BUG=v8:4399
R=adamk
LOG=Y
Please review this at https://codereview.chromium.org/1309303006/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+14, -2 lines):
M src/parser.cc
A test/mjsunit/regress/regress-4399.js
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index
3f635c70df275ea837606aa81354f6daea36a882..e36e9258d385ae36d70d27bd570541c17b54ff00
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -2990,7 +2990,7 @@ Statement*
Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
// }
Block* switch_block =
- factory()->NewBlock(NULL, 2, true, RelocInfo::kNoPosition);
+ factory()->NewBlock(NULL, 2, false, RelocInfo::kNoPosition);
int switch_pos = peek_position();
Expect(Token::SWITCH, CHECK_OK);
@@ -3008,7 +3008,7 @@ Statement*
Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
switch_block->AddStatement(tag_statement, zone());
Block* cases_block =
- factory()->NewBlock(NULL, 1, true, RelocInfo::kNoPosition);
+ factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition);
Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE);
SwitchStatement* switch_statement =
Index: test/mjsunit/regress/regress-4399.js
diff --git a/test/mjsunit/regress/regress-4399.js
b/test/mjsunit/regress/regress-4399.js
new file mode 100644
index
0000000000000000000000000000000000000000..eb21c8c6df0da2d662e30c99c96b42ee96d11e98
--- /dev/null
+++ b/test/mjsunit/regress/regress-4399.js
@@ -0,0 +1,12 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Test that switch has the appropriate 'eval' value
+
+assertEquals("foo", eval('switch(1) { case 1: "foo" }'));
+assertEquals("foo", eval('{ switch(1) { case 1: "foo" } }'));
+assertEquals("foo", eval('switch(1) { case 1: { "foo" } }'));
+assertEquals("foo", eval('switch(1) { case 1: "foo"; break; case 2: "bar";
break }'));
+assertEquals("bar", eval('switch(2) { case 1: "foo"; break; case 2: "bar";
break }'));
+assertEquals("bar", eval('switch(1) { case 1: "foo"; case 2: "bar"; break
}'));
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.