Chromium Code Reviews| Index: test/cctest/test-parsing.cc |
| diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
| index 7a35ebe469b394c52a734fd9a6b36a49ca9c61e3..72b409804fc2c2a3605a5a445e539fdbc10b8ede 100644 |
| --- a/test/cctest/test-parsing.cc |
| +++ b/test/cctest/test-parsing.cc |
| @@ -1268,7 +1268,6 @@ const char* ReadString(unsigned* start) { |
| return result; |
| } |
| - |
| enum ParserFlag { |
| kAllowLazy, |
| kAllowNatives, |
| @@ -1277,6 +1276,7 @@ enum ParserFlag { |
| kAllowHarmonyRestrictiveGenerators, |
| kAllowHarmonyTrailingCommas, |
| kAllowHarmonyClassFields, |
| + kAllowHarmonyObjectSpread, |
| }; |
| enum ParserSyncTestResult { |
| @@ -1293,6 +1293,7 @@ void SetGlobalFlags(i::EnumSet<ParserFlag> flags) { |
| flags.Contains(kAllowHarmonyRestrictiveGenerators); |
| i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas); |
| i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields); |
| + i::FLAG_harmony_object_spread = flags.Contains(kAllowHarmonyObjectSpread); |
| } |
| void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { |
| @@ -1307,6 +1308,8 @@ void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) { |
| flags.Contains(kAllowHarmonyTrailingCommas)); |
| parser->set_allow_harmony_class_fields( |
| flags.Contains(kAllowHarmonyClassFields)); |
| + parser->set_allow_harmony_object_spread( |
| + flags.Contains(kAllowHarmonyObjectSpread)); |
| } |
| void TestParserSyncWithFlags(i::Handle<i::String> source, |
| @@ -6564,6 +6567,98 @@ TEST(ArrowFunctionASIErrors) { |
| RunParserSyncTest(context_data, data, kError); |
| } |
| +TEST(ObjectSpreadPositiveTests) { |
| + const char* context_data[][2] = { |
| + {"'use strict'; let y = { a: 1}; let x = ", ""}, |
|
adamk
2016/12/29 00:48:45
Generally the context data is about different sort
gsathya
2016/12/29 06:40:56
Done.
adamk
2016/12/29 18:32:45
Sorry if I wasn't clear, but I don't think you nee
gsathya
2017/01/05 22:18:35
Done.
|
| + {"var y = { a: 1}, x = ", ""}, |
| + {"var y = { a: 1}; var x = ", ""}, |
| + {"'use strict'; const y = { a: 1}; const x = ", ""}, |
| + {"function f(y = { a: 1}, x = ", ") {}"}, |
| + {"var y = { a: 1 }; function f(x = ", ") {}"}, |
| + {"var y = { a: 1 }; var f = (x = ", ") => {};"}, |
| + {"var f = (y = { a: 1 }, x = ", ") => {};"}, |
| + {NULL, NULL}}; |
| + |
| + // clang-format off |
| + const char* data[] = { |
| + "{ ...y }", |
| + "{ a: 1, ...y }", |
| + "{ b: 1, ...y }", |
| + "{ y, ...y}", |
| + "{ ...z = y}", |
| + "{ ...y, y }", |
| + "{ ...y, ...y}", |
| + "{ a: 1, ...y, b: 1}", |
| + "{ ...y, b: 1}", |
| + "{ ...1}", |
| + "{ ...null}", |
| + "{ ...undefined}", |
| + "{ ...unknown}", |
| + NULL}; |
| + |
| + static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; |
| + RunParserSyncTest(context_data, data, kSuccess, NULL, 0, flags, |
| + arraysize(flags)); |
| +} |
| + |
| +TEST(ObjectSpreadNegativeTests) { |
| + { |
| + const char* context_data[][2] = { |
| + {"'use strict'; let y = { a: 1}; let x = ", ""}, |
|
adamk
2016/12/29 00:48:45
Same comment on context data here.
gsathya
2016/12/29 06:40:56
Done.
adamk
2016/12/29 18:32:45
Same here
gsathya
2017/01/05 22:18:35
Done.
|
| + {"var y = { a: 1}, x = ", ""}, |
| + {"var y = { a: 1}; var x = ", ""}, |
| + {"'use strict'; const y = { a: 1}; const x = ", ""}, |
| + {"function f(y = { a: 1}, x = ", ") {}"}, |
| + {"var y = { a: 1 }; function f(x = ", ") {}"}, |
| + {"var y = { a: 1 }; var f = (x = ", ") => {};"}, |
| + {"var f = (y = { a: 1 }, x = ", ") => {};"}, |
| + {NULL, NULL}}; |
| + |
| + // clang-format off |
| + const char* data[] = { |
| + "{ ...var z = y}", |
|
adamk
2016/12/29 00:48:45
I agree that negative tests are kinda tricky for t
gsathya
2016/12/29 06:40:56
Done.
adamk
2016/12/29 18:32:45
? I don't see any additional tests here.
|
| + NULL}; |
| + |
| + static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; |
| + RunParserSyncTest(context_data, data, kError, NULL, 0, flags, |
| + arraysize(flags)); |
| + } |
| + |
| + // Destructuring tests |
| + { |
| + const char* context_data[][2] = { |
| + {"var ", " = {};"}, |
| + {"'use strict'; const ", " = {};"}, |
| + {"function f(", ") {}"}, |
| + {"function f(argument1, ", ") {}"}, |
| + {"var f = (", ") => {};"}, |
| + {"var f = (argument1,", ") => {};"}, |
| + {"try {} catch(", ") {}"}, |
|
adamk
2016/12/29 00:48:45
Need to add an assignment context.
|
| + {NULL, NULL}}; |
| + |
| + // clang-format off |
| + const char* data[] = { |
| + "{ ...y }", |
| + "{ a: 1, ...y }", |
| + "{ b: 1, ...y }", |
| + "{ y, ...y}", |
| + "{ ...z = y}", |
| + "{ ...y, y }", |
| + "{ ...y, ...y}", |
| + "{ a: 1, ...y, b: 1}", |
| + "{ ...y, b: 1}", |
| + "{ ...1}", |
| + "{ ...null}", |
| + "{ ...undefined}", |
| + "{ ...unknown}", |
| + "{ ...var z = y}", |
| + NULL}; |
| + |
| + static const ParserFlag flags[] = {kAllowHarmonyObjectSpread}; |
| + RunParserSyncTest(context_data, data, kError, NULL, 0, flags, |
| + arraysize(flags)); |
| + } |
| +} |
| TEST(DestructuringPositiveTests) { |
| const char* context_data[][2] = {{"'use strict'; let ", " = {};"}, |