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

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

Issue 1429983002: [es6] early error when Identifier is an escaped reserved word (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 1 month 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
« src/scanner.cc ('K') | « src/scanner.cc ('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 ec5d5f9d9badc157b88a26b9e543642ccd5b0712..d1e000ef5278745d2eaa631c619750974c304d5d 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -7235,3 +7235,118 @@ TEST(LetSloppyOnly) {
RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags,
arraysize(fail_flags));
}
+
+
+TEST(EscapedKeywords) {
adamk 2015/11/03 23:00:57 I think you also want some more non-error cases: y
caitp (gmail) 2015/11/04 04:49:25 I've added sloppy vs strict tests for the future r
+ // clang-format off
+ const char* sloppy_context_data[][2] = {
+ {"", ""},
+ {NULL, NULL}
+ };
+
+ const char* strict_context_data[][2] = {
+ {"'use strict';", ""},
+ {NULL, NULL}
+ };
+
+ const char* fail_data[] = {
+ "for (var i = 0; i < 100; ++i) { br\\u0065ak; }",
caitp (gmail) 2015/11/03 17:19:13 There are probably some good test cases missing, l
+ "cl\\u0061ss Foo {}",
+ "var x = cl\\u0061ss {}",
+ "\\u0063onst foo = 1;",
+ "while (i < 10) { if (i++ & 1) c\\u006fntinue; this.x++; }",
+ "d\\u0065bugger;",
+ "d\\u0065lete this.a;",
+ "\\u0063o { } while(0)",
+ "if (d\\u006f { true }) {}",
+ "if (false) { this.a = 1; } \\u0065lse { this.b = 1; }",
+ "e\\u0078port var foo;",
adamk 2015/11/03 23:00:57 This would already be failing since you're not par
caitp (gmail) 2015/11/04 04:49:25 I've added a helper for testing module parsing, an
+ "try { } catch (e) {} f\\u0069nally { }",
+ "f\\u006fr (var i = 0; i < 10; ++i);",
+ "f\\u0075nction fn() {}",
+ "var f = f\\u0075nction() {}",
+ "\\u0069f (true) { }",
+ "\\u0069mport blah from './foo.js';",
adamk 2015/11/03 23:00:57 same here as above for export
caitp (gmail) 2015/11/04 04:49:25 These would have been errors before, but only beca
+ "n\\u0065w function f() {}",
+ "(function() { r\\u0065turn; })()",
+ "class C extends function() {} { constructor() { sup\\u0065r() } }",
+ "class C extends function() {} { constructor() { sup\\u0065r.a = 1 } }",
+ "sw\\u0069tch (this.a) {}",
+ "var x = th\\u0069s;",
+ "th\\u0069s.a = 1;",
+ "thr\\u006fw 'boo';",
+ "t\\u0072y { true } catch (e) {}",
+ "var x = typ\\u0065of 'blah'",
+ "v\\u0061r a = true",
+ "var v\\u0061r = true",
+ "(function() { return v\\u006fid 0; })()",
+ "wh\\u0069le (true) { }",
+ "w\\u0069th (this.scope) { }",
+ "(function*() { y\\u0069eld 1; })()",
+
+ "var \\u0065num = 1;",
+ "var { \\u0065num } = {}",
+ "(\\u0065num = 1);",
+
+ // Null / Boolean literals
+ "(x === n\\u0075ll);",
+ "var x = n\\u0075ll;",
+ "var n\\u0075ll = 1;",
+ "var { n\\u0075ll } = { 1 };",
+ "n\\u0075ll = 1;",
+ "(x === tr\\u0075e);",
+ "var x = tr\\u0075e;",
+ "var tr\\u0075e = 1;",
+ "var { tr\\u0075e } = {};",
+ "tr\\u0075e = 1;",
+ "(x === f\\u0061lse);",
+ "var x = f\\u0061lse;",
+ "var f\\u0061lse = 1;",
+ "var { f\\u0061lse } = {};",
+ "f\\u0061lse = 1;",
+
+ // TODO(caitp): consistent error messages for labeled statements and
+ // expressions
+ "switch (this.a) { c\\u0061se 6: break; }",
+ "try { } c\\u0061tch (e) {}",
+ "switch (this.a) { d\\u0065fault: break; }",
+ "class C \\u0065xtends function B() {} {}",
+ "for (var a i\\u006e this) {}",
+ "if ('foo' \\u0069n this) {}",
+ "if (this \\u0069nstanceof Array) {}",
+ "(n\\u0065w function f() {})",
+ "(typ\\u0065of 123)",
+ "(v\\u006fid 0)",
+ "do { ; } wh\\u0069le (true) { }",
+ "(function*() { return (n++, y\\u0069eld 1); })()",
+ "class C { st\\u0061tic bar() {} }",
+ NULL
+ };
+ // clang-format on
+
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonySloppy, kAllowHarmonyDestructuring};
+ RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0,
+ always_flags, arraysize(always_flags));
+ RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0,
+ always_flags, arraysize(always_flags));
+
+ // clang-format off
+ const char* let_data[] = {
+ "var l\\u0065t = 1;",
+ "l\\u0065t = 1;",
+ "(l\\u0065t === 1);",
+ NULL
+ };
+ // clang-format on
+
+ RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0,
+ always_flags, arraysize(always_flags));
+ RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0,
+ always_flags, arraysize(always_flags));
+
+ static const ParserFlag sloppy_let_flags[] = {
+ kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowHarmonyDestructuring};
+ RunParserSyncTest(sloppy_context_data, let_data, kError, NULL, 0,
+ sloppy_let_flags, arraysize(sloppy_let_flags));
+}
« src/scanner.cc ('K') | « src/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698