Index: test/cctest/test-parsing.cc |
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
index 24cf67b4a16fec074530d8c2a067696e8cc8ed2a..6132d4109d2bc1c966962d9154649c8dfd57bc6d 100644 |
--- a/test/cctest/test-parsing.cc |
+++ b/test/cctest/test-parsing.cc |
@@ -1386,6 +1386,7 @@ enum ParserFlag { |
kAllowHarmonySpreadCalls, |
kAllowHarmonyDestructuring, |
kAllowHarmonySpreadArrays, |
+ kAllowHarmonyNewTarget, |
kAllowStrongMode |
}; |
@@ -1419,6 +1420,7 @@ void SetParserFlags(i::ParserBase<Traits>* parser, |
flags.Contains(kAllowHarmonyDestructuring)); |
parser->set_allow_harmony_spread_arrays( |
flags.Contains(kAllowHarmonySpreadArrays)); |
+ parser->set_allow_harmony_new_target(flags.Contains(kAllowHarmonyNewTarget)); |
parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
} |
@@ -6615,3 +6617,58 @@ TEST(SpreadArrayError) { |
RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
arraysize(always_flags)); |
} |
+ |
+ |
+TEST(NewTarget) { |
+ // clang-format off |
+ const char* good_context_data[][2] = { |
+ {"function f() {", "}"}, |
+ {"'use strict'; function f() {", "}"}, |
+ {"var f = function() {", "}"}, |
+ {"'use strict'; var f = function() {", "}"}, |
+ {"({m: function() {", "}})"}, |
+ {"'use strict'; ({m: function() {", "}})"}, |
+ {"({m() {", "}})"}, |
+ {"'use strict'; ({m() {", "}})"}, |
+ {"({get x() {", "}})"}, |
+ {"'use strict'; ({get x() {", "}})"}, |
+ {"({set x(_) {", "}})"}, |
+ {"'use strict'; ({set x(_) {", "}})"}, |
+ {"class C {m() {", "}}"}, |
+ {"class C {get x() {", "}}"}, |
+ {"class C {set x(_) {", "}}"}, |
+ {NULL} |
+ }; |
+ |
+ const char* bad_context_data[][2] = { |
+ {"", ""}, |
+ {"'use strict';", ""}, |
+ {NULL} |
+ }; |
+ |
+ const char* data[] = { |
+ "new.target", |
+ "{ new.target }", |
+ "() => { new.target }", |
+ "() => new.target", |
+ "if (1) { new.target }", |
+ "if (1) {} else { new.target }", |
+ "while (0) { new.target }", |
+ "do { new.target } while (0)", |
+ NULL |
+ }; |
+ |
+ static const ParserFlag always_flags[] = { |
+ kAllowHarmonyArrowFunctions, |
+ kAllowHarmonyClasses, |
+ kAllowHarmonyNewTarget, |
+ kAllowHarmonyObjectLiterals, |
+ kAllowHarmonySloppy, |
+ }; |
+ // clang-format on |
+ |
+ RunParserSyncTest(good_context_data, data, kSuccess, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+ RunParserSyncTest(bad_context_data, data, kError, NULL, 0, always_flags, |
+ arraysize(always_flags)); |
+} |