Index: test/cctest/test-parsing.cc |
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
index 7a35ebe469b394c52a734fd9a6b36a49ca9c61e3..249ba34ca51a22b1aaeeb581bd0c2a28ef211993 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,100 @@ TEST(ArrowFunctionASIErrors) { |
RunParserSyncTest(context_data, data, kError); |
} |
+TEST(ObjectSpreadPositiveTests) { |
+ const char* context_data[][2] = {{"'use strict'; let x = ", ""}, |
+ {"var x = ", ""}, |
+ {"x = ", ""}, |
+ {"'use strict'; const x = ", ""}, |
+ {"function f(x = ", ") {}"}, |
+ {"function f(argument1, x = ", ") {}"}, |
+ {"var f = (x = ", ") => {};"}, |
+ {"var f = (argument1, 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}", |
+ "{...1 in {}}", |
+ 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 x = ", ""}, |
+ {"x = ", ""}, |
+ {"var x = ", ""}, |
+ {"'use strict'; const x = ", ""}, |
+ {"function f(argument1, x = ", ") {}"}, |
+ {"function f(x = ", ") {}"}, |
+ {"var f = (x = ", ") => {};"}, |
+ {"var f = (argument1, x = ", ") => {};"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "{ ...var z = y}", |
+ 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(", ") {}"}, |
+ {NULL, NULL}}; |
+ |
+ // clang-format off |
+ const char* data[] = { |
+ "{ ...y }", |
+ "{ ...y } = {} ", |
adamk
2016/12/29 18:32:46
Rather than doing this here, you could cover every
gsathya
2017/01/05 22:18:36
Done.
|
+ "{ 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}", |
+ "({ ...z = {})", |
+ 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 ", " = {};"}, |