Index: test/cctest/test-parsing.cc |
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
index 24cf67b4a16fec074530d8c2a067696e8cc8ed2a..157572050e1f7465299d64b9f9d56d71b895e12d 100644 |
--- a/test/cctest/test-parsing.cc |
+++ b/test/cctest/test-parsing.cc |
@@ -6544,6 +6544,144 @@ TEST(DestructuringNegativeTests) { |
} |
+TEST(DestructuringAssignmentPositiveTests) { |
+ i::FLAG_harmony_destructuring = true; |
+ i::FLAG_harmony_computed_property_names = true; |
+ |
+ const char* context_data[][2] = { |
+ {"'use strict'; let x, y, z; (", " = {});"}, |
+ {"var x, y, z; (", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
+ {"var x, y, z; for (x in ", " = {});"}, |
arv (Not doing code reviews)
2015/06/05 18:45:26
This was not what I had in mind. Here is an exampl
caitp (gmail)
2015/06/05 19:00:20
They're both valid, but we may be reporting an err
|
+ {"var x, y, z; for (x of ", " = {});"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "x", |
+ "{ x : y }", |
+ "{ x : y = 1 }", |
+ "{ x }", |
+ "{ x, y, z }", |
+ "{ x = 1, y: z, z: y }", |
+ "{x = 42, y = 15}", |
+ "[x]", |
+ "[x = 1]", |
+ "[x,y,z]", |
+ "[x, y = 42, z]", |
+ "{ x : x, y : y }", |
+ "{ x : x = 1, y : y }", |
+ "{ x : x, y : y = 42 }", |
+ "[]", |
+ "{}", |
+ "[{x:x, y:y}, [,x,z,]]", |
+ "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]", |
+ "[x,,y]", |
+ "[(x),,(y)]", |
+ "[(x)]", |
+ "{42 : x}", |
+ "{42 : x = 42}", |
+ "{42e-2 : x}", |
+ "{42e-2 : x = 42}", |
+ "{'hi' : x}", |
+ "{'hi' : x = 42}", |
+ "{var: x}", |
+ "{var: x = 42}", |
+ "{var: (x) = 42}", |
+ "{[x] : z}", |
+ "{[1+1] : z}", |
+ "{[1+1] : (z)}", |
+ "{[foo()] : z}", |
+ "{[foo()] : (z)}", |
+ "{[foo()] : foo().bar}", |
+ "{[foo()] : foo()['bar']}", |
+ "{[foo()] : this.bar}", |
+ "{[foo()] : this['bar']}", |
+ "{[foo()] : 'foo'.bar}", |
+ "{[foo()] : 'foo'['bar']}", |
+ "[...x]", |
+ "[x,y,...z]", |
+ "[x,,...z]", |
+ "{ x: y } = z", |
+ "[x, y] = z", |
+ "{ x: y } = { z }", |
+ "[x, y] = { z }", |
+ "{ x: y } = [ z ]", |
+ "[x, y] = [ z ]", |
+ NULL}; |
+ // clang-format on |
+ static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals, |
+ kAllowHarmonyComputedPropertyNames, |
+ kAllowHarmonyDestructuring}; |
+ RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |
+ |
+ |
+TEST(DestructuringAssignmentNegativeTests) { |
+ i::FLAG_harmony_destructuring = true; |
+ i::FLAG_harmony_computed_property_names = true; |
+ |
+ const char* context_data[][2] = { |
+ {"'use strict'; let x, y, z; (", " = {});"}, |
+ {"var x, y, z; (", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x in ", " = {});"}, |
+ {"'use strict'; let x, y, z; for (x of ", " = {});"}, |
+ {"var x, y, z; for (x in ", " = {});"}, |
+ {"var x, y, z; for (x of ", " = {});"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "{ x : ++y }", |
+ "{ x : y * 2 }", |
+ "{ ...x }", |
+ "{ get x() {} }", |
+ "{ set x() {} }", |
+ "{ x: y() }", |
+ "{ this }", |
+ "{ x: this }", |
+ "{ x: this = 1 }", |
+ "{ super }", |
+ "{ x: super }", |
+ "{ x: super = 1 }", |
+ "{ new.target }", |
+ "{ x: new.target }", |
+ "{ x: new.target = 1 }", |
+ "[x--]", |
+ "[--x = 1]", |
+ "[x()]", |
+ "[this]", |
+ "[this = 1]", |
+ "[new.target]", |
+ "[new.target = 1]", |
+ "[super]", |
+ "[super = 1]", |
+ "[function f() {}]", |
+ "[50]", |
+ "[(50)]", |
+ "[(function() {})]", |
+ "[(foo())]", |
+ "{ x: 50 }", |
+ "{ x: (50) }", |
+ "['str']", |
+ "{ x: 'str' }", |
+ "{ x: ('str') }", |
+ "{ x: (foo()) }", |
+ "{ x: (function() {}) }", |
+ "{ x: y } = 'str'", |
+ "[x, y] = 'str'", |
+ NULL}; |
+ // clang-format on |
+ static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals, |
+ kAllowHarmonyComputedPropertyNames, |
+ kAllowHarmonyDestructuring}; |
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |
+ |
+ |
TEST(DestructuringDisallowPatternsInForVarIn) { |
i::FLAG_harmony_destructuring = true; |
static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring}; |