| Index: test/cctest/test-parsing.cc
|
| diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
|
| index 675b48797952dbaf3e0afd23b933c61651ea1998..1712d5b9c30561aae4ffdd5bde0f211bc25f67cf 100644
|
| --- a/test/cctest/test-parsing.cc
|
| +++ b/test/cctest/test-parsing.cc
|
| @@ -6579,6 +6579,223 @@ 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 ", " = {});"},
|
| + {"var x, y, z; for (x of ", " = {});"},
|
| + {NULL, NULL}};
|
| +
|
| + // clang-format off
|
| + const char* data[] = {
|
| + "x",
|
| +
|
| + "{ x : y }",
|
| + "{ x : foo().y }",
|
| + "{ x : foo()[y] }",
|
| + "{ x : y.z }",
|
| + "{ x : y[z] }",
|
| + "{ x : { y } }",
|
| + "{ x : { foo: y } }",
|
| + "{ x : { foo: foo().y } }",
|
| + "{ x : { foo: foo()[y] } }",
|
| + "{ x : { foo: y.z } }",
|
| + "{ x : { foo: y[z] } }",
|
| + "{ x : [ y ] }",
|
| + "{ x : [ foo().y ] }",
|
| + "{ x : [ foo()[y] ] }",
|
| + "{ x : [ y.z ] }",
|
| + "{ x : [ y[z] ] }",
|
| +
|
| + "{ x : y = 10 }",
|
| + "{ x : foo().y = 10 }",
|
| + "{ x : foo()[y] = 10 }",
|
| + "{ x : y.z = 10 }",
|
| + "{ x : y[z] = 10 }",
|
| + "{ x : { y = 10 } = {} }",
|
| + "{ x : { foo: y = 10 } = {} }",
|
| + "{ x : { foo: foo().y = 10 } = {} }",
|
| + "{ x : { foo: foo()[y] = 10 } = {} }",
|
| + "{ x : { foo: y.z = 10 } = {} }",
|
| + "{ x : { foo: y[z] = 10 } = {} }",
|
| + "{ x : [ y = 10 ] = {} }",
|
| + "{ x : [ foo().y = 10 ] = {} }",
|
| + "{ x : [ foo()[y] = 10 ] = {} }",
|
| + "{ x : [ y.z = 10 ] = {} }",
|
| + "{ x : [ y[z] = 10 ] = {} }",
|
| +
|
| + "[ x ]",
|
| + "[ foo().x ]",
|
| + "[ foo()[x] ]",
|
| + "[ x.y ]",
|
| + "[ x[y] ]",
|
| + "[ { x } ]",
|
| + "[ { x : y } ]",
|
| + "[ { x : foo().y } ]",
|
| + "[ { x : foo()[y] } ]",
|
| + "[ { x : x.y } ]",
|
| + "[ { x : x[y] } ]",
|
| + "[ [ x ] ]",
|
| + "[ [ foo().x ] ]",
|
| + "[ [ foo()[x] ] ]",
|
| + "[ [ x.y ] ]",
|
| + "[ [ x[y] ] ]",
|
| +
|
| + "[ x = 10 ]",
|
| + "[ foo().x = 10 ]",
|
| + "[ foo()[x] = 10 ]",
|
| + "[ x.y = 10 ]",
|
| + "[ x[y] = 10 ]",
|
| + "[ { x = 10 } = {} ]",
|
| + "[ { x : y = 10 } = {} ]",
|
| + "[ { x : foo().y = 10 } = {} ]",
|
| + "[ { x : foo()[y] = 10 } = {} ]",
|
| + "[ { x : x.y = 10 } = {} ]",
|
| + "[ { x : x[y] = 10 } = {} ]",
|
| + "[ [ x = 10 ] = {} ]",
|
| + "[ [ foo().x = 10 ] = {} ]",
|
| + "[ [ foo()[x] = 10 ] = {} ]",
|
| + "[ [ x.y = 10 ] = {} ]",
|
| + "[ [ x[y] = 10 ] = {} ]",
|
| +
|
| + "{ 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 ]",
|
| + "[((x, y) => z).x]",
|
| + "{x: ((y, z) => z).x}",
|
| + "[((x, y) => z)['x']]",
|
| + "{x: ((y, z) => z)['x']}",
|
| + NULL};
|
| + // clang-format on
|
| + static const ParserFlag always_flags[] = {
|
| + kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
|
| + kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions};
|
| + 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'",
|
| + "[(x,y) => z]",
|
| + "{x: (y) => z}",
|
| + "[x, ...y, z]",
|
| + "[...x,]",
|
| + "[x, y, ...z = 1]",
|
| + "[...z = 1]",
|
| + NULL};
|
| + // clang-format on
|
| + static const ParserFlag always_flags[] = {
|
| + kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
|
| + kAllowHarmonyDestructuring, kAllowHarmonyArrowFunctions};
|
| + 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};
|
|
|