Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: test/cctest/test-parsing.cc

Issue 1077153005: Allow eval/arguments in arrow functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 9a585430b890edcb8318707a471ec261ff596d2b..86e042eced4ddf856bba7eacf7ae0bdde96f124f 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -3502,20 +3502,23 @@ TEST(ErrorsArrowFunctions) {
"(x, (y, z)) => 0",
"((x, y), z) => 0",
- // Parameter lists are always validated as strict, so those are errors.
- "eval => {}",
- "arguments => {}",
- "yield => {}",
- "interface => {}",
- "(eval) => {}",
- "(arguments) => {}",
- "(yield) => {}",
- "(interface) => {}",
- "(eval, bar) => {}",
- "(bar, eval) => {}",
- "(bar, arguments) => {}",
- "(bar, yield) => {}",
- "(bar, interface) => {}",
+ // Arrow function formal parameters are parsed as StrictFormalParameters,
+ // which confusingly only implies that there are no duplicates. Words
+ // reserved in strict mode, and eval or arguments, are indeed valid in
+ // sloppy mode.
+ "eval => { 'use strict'; 0 }",
+ "arguments => { 'use strict'; 0 }",
+ "yield => { 'use strict'; 0 }",
+ "interface => { 'use strict'; 0 }",
+ "(eval) => { 'use strict'; 0 }",
+ "(arguments) => { 'use strict'; 0 }",
+ "(yield) => { 'use strict'; 0 }",
+ "(interface) => { 'use strict'; 0 }",
+ "(eval, bar) => { 'use strict'; 0 }",
+ "(bar, eval) => { 'use strict'; 0 }",
+ "(bar, arguments) => { 'use strict'; 0 }",
+ "(bar, yield) => { 'use strict'; 0 }",
+ "(bar, interface) => { 'use strict'; 0 }",
// TODO(aperez): Detecting duplicates does not work in PreParser.
// "(bar, bar) => {}",
@@ -3622,6 +3625,66 @@ TEST(NoErrorsArrowFunctions) {
}
+TEST(ArrowFunctionsSloppyParameterNames) {
+ const char* strong_context_data[][2] = {
+ {"'use strong'; ", ";"},
+ {"'use strong'; bar ? (", ") : baz;"},
+ {"'use strong'; bar ? baz : (", ");"},
+ {"'use strong'; bar, ", ";"},
+ {"'use strong'; ", ", bar;"},
+ {NULL, NULL}
+ };
+
+ const char* strict_context_data[][2] = {
+ {"'use strict'; ", ";"},
+ {"'use strict'; bar ? (", ") : baz;"},
+ {"'use strict'; bar ? baz : (", ");"},
+ {"'use strict'; bar, ", ";"},
+ {"'use strict'; ", ", bar;"},
+ {NULL, NULL}
+ };
+
+ const char* sloppy_context_data[][2] = {
+ {"", ";"},
+ {"bar ? (", ") : baz;"},
+ {"bar ? baz : (", ");"},
+ {"bar, ", ";"},
+ {"", ", bar;"},
+ {NULL, NULL}
+ };
+
+ const char* statement_data[] = {
+ "eval => {}",
+ "arguments => {}",
+ "yield => {}",
+ "interface => {}",
+ "(eval) => {}",
+ "(arguments) => {}",
+ "(yield) => {}",
+ "(interface) => {}",
+ "(eval, bar) => {}",
+ "(bar, eval) => {}",
+ "(bar, arguments) => {}",
+ "(bar, yield) => {}",
+ "(bar, interface) => {}",
+ "(interface, eval) => {}",
+ "(interface, arguments) => {}",
+ "(eval, interface) => {}",
+ "(arguments, interface) => {}",
+ NULL
+ };
+
+ static const ParserFlag always_flags[] = { kAllowHarmonyArrowFunctions,
+ kAllowStrongMode};
+ RunParserSyncTest(strong_context_data, statement_data, kError, NULL, 0,
+ always_flags, arraysize(always_flags));
+ RunParserSyncTest(strict_context_data, statement_data, kError, NULL, 0,
+ always_flags, arraysize(always_flags));
+ RunParserSyncTest(sloppy_context_data, statement_data, kSuccess, NULL, 0,
+ always_flags, arraysize(always_flags));
+}
+
+
TEST(SuperNoErrors) {
// Tests that parser and preparser accept 'super' keyword in right places.
const char* context_data[][2] = {
« no previous file with comments | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698