Chromium Code Reviews| Index: test/cctest/test-parsing.cc |
| diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
| index bd3247e044a738947d859880a7a84ccb708bacbc..8d4ff02c55acf8c56a93f07778fa388a203fbdab 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,122 @@ 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]]", |
|
arv (Not doing code reviews)
2015/04/28 13:42:14
moar
"{var: x}",
"{42: x}",
"{+2: x}",
"{-2: x}",
Dmitry Lomov (no reviews)
2015/04/28 16:01:36
Done. {+2: x} and {-2: x} are not valid AFAIU.
arv (Not doing code reviews)
2015/04/28 16:07:22
You are right... but 42e-2 is... not needed though
|
| + "[a,,b]", |
| + 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", |
|
arv (Not doing code reviews)
2015/04/28 13:42:14
moar
// keywords
"var",
// nested
"[var]",
"{x
Dmitry Lomov (no reviews)
2015/04/28 16:01:36
Done.
|
| + "1", |
| + "'abc'", |
| + "class {}", |
| + "() => x", |
| + 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)); |
| + } |
| +} |