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

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

Issue 1107053002: Parsing binding patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: CR feedback 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
« src/preparser.h ('K') | « src/preparser.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 bd3247e044a738947d859880a7a84ccb708bacbc..0d9129297cc8d3f0a199bf0be65594820095bc2d 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1381,8 +1381,9 @@ enum ParserFlag {
kAllowHarmonySloppy,
kAllowHarmonyUnicode,
kAllowHarmonyComputedPropertyNames,
- kAllowStrongMode,
- kAllowHarmonySpreadCalls
+ kAllowHarmonySpreadCalls,
+ kAllowHarmonyDestructuring,
+ kAllowStrongMode
};
@@ -1411,6 +1412,8 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
parser->set_allow_harmony_computed_property_names(
flags.Contains(kAllowHarmonyComputedPropertyNames));
+ parser->set_allow_harmony_destructuring(
+ flags.Contains(kAllowHarmonyDestructuring));
parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
}
@@ -6344,3 +6347,129 @@ TEST(StrongModeFreeVariablesNotDeclared) {
*exception));
}
}
+
+
+TEST(DestructuringPositiveTests) {
+ i::FLAG_harmony_destructuring = true;
+
+ const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
+ {"var ", " = {};"},
+ {"'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "a",
+ "{ x : y }",
+ "[a]",
+ "[a,b,c]",
+ "{ x : x, y : y }",
+ "[]",
+ "{}",
+ "[{x:x, y:y}, [a,b,c]]",
+ "[a,,b]",
+ "{42 : x}",
+ "{'hi' : x}",
arv (Not doing code reviews) 2015/04/28 16:07:22 I still want `{var: x}` to make sure we are not tr
+ NULL};
+ // clang-format on
+ static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
+ RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(DestructuringNegativeTests) {
+ i::FLAG_harmony_destructuring = true;
+ static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
+
+ { // All modes.
+ const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
+ {"var ", " = {};"},
+ {"'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "a++",
+ "++a",
+ "delete a",
+ "void a",
+ "typeof a",
+ "--a",
+ "+a",
+ "-a",
+ "~a",
+ "!a",
+ "{ x : y++ }",
+ "[a++]",
+ "(x => y)",
+ "a[i]", "a()",
+ "a.b",
+ "new a",
+ "a + a",
+ "a - a",
+ "a * a",
+ "a / a",
+ "a == a",
+ "a != a",
+ "a > a",
+ "a < a",
+ "a <<< a",
+ "a >>> a",
+ "function a() {}",
+ "a`bcd`",
+ "x => x",
+ "this",
+ "null",
+ "true",
+ "false",
+ "1",
+ "'abc'",
+ "class {}",
+ "() => x",
+ "{+2 : x}",
+ "{-2 : x}",
+ "var",
+ "[var]",
+ "{x : {y : var}}",
+ NULL};
+ // clang-format on
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+ }
+
+ { // Strict mode.
+ const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
+ {"'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "[eval]",
+ "{ a : arguments }",
+ "[public]",
+ "{ x : private }",
+ NULL};
+ // clang-format on
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+ }
+
+ { // 'yield' in generators.
+ const char* context_data[][2] = {
+ {"function*() { var ", " = {};"},
+ {"function*() { 'use strict'; let ", " = {};"},
+ {"function*() { 'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "yield",
+ "[yield]",
+ "{ x : yield }",
+ NULL};
+ // clang-format on
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+ }
+}
« src/preparser.h ('K') | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698