OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 i::DeleteArray(arg); | 1493 i::DeleteArray(arg); |
1494 } else { | 1494 } else { |
1495 CHECK_EQ(0, arg_count); | 1495 CHECK_EQ(0, arg_count); |
1496 arg_object = isolate->factory()->undefined_value(); | 1496 arg_object = isolate->factory()->undefined_value(); |
1497 } | 1497 } |
1498 | 1498 |
1499 data.Dispose(); | 1499 data.Dispose(); |
1500 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); | 1500 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); |
1501 } | 1501 } |
1502 | 1502 |
1503 | |
1504 enum ParserFlag { | 1503 enum ParserFlag { |
1505 kAllowLazy, | 1504 kAllowLazy, |
1506 kAllowNatives, | 1505 kAllowNatives, |
1507 kAllowHarmonyDefaultParameters, | 1506 kAllowHarmonyDefaultParameters, |
1508 kAllowHarmonySloppy, | 1507 kAllowHarmonySloppy, |
1509 kAllowHarmonySloppyLet, | 1508 kAllowHarmonySloppyLet, |
1510 kAllowHarmonyDestructuring, | 1509 kAllowHarmonyDestructuring, |
1511 kAllowHarmonyDestructuringAssignment, | 1510 kAllowHarmonyDestructuringAssignment, |
1512 kAllowHarmonyNewTarget, | 1511 kAllowHarmonyNewTarget, |
1513 kAllowStrongMode, | 1512 kAllowStrongMode, |
1514 kNoLegacyConst | 1513 kNoLegacyConst, |
| 1514 kAllowHarmonyFunctionSent |
1515 }; | 1515 }; |
1516 | 1516 |
1517 | |
1518 enum ParserSyncTestResult { | 1517 enum ParserSyncTestResult { |
1519 kSuccessOrError, | 1518 kSuccessOrError, |
1520 kSuccess, | 1519 kSuccess, |
1521 kError | 1520 kError |
1522 }; | 1521 }; |
1523 | 1522 |
1524 template <typename Traits> | 1523 template <typename Traits> |
1525 void SetParserFlags(i::ParserBase<Traits>* parser, | 1524 void SetParserFlags(i::ParserBase<Traits>* parser, |
1526 i::EnumSet<ParserFlag> flags) { | 1525 i::EnumSet<ParserFlag> flags) { |
1527 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1526 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1528 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1527 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1529 parser->set_allow_harmony_default_parameters( | 1528 parser->set_allow_harmony_default_parameters( |
1530 flags.Contains(kAllowHarmonyDefaultParameters)); | 1529 flags.Contains(kAllowHarmonyDefaultParameters)); |
1531 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1530 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1532 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); | 1531 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); |
1533 parser->set_allow_harmony_destructuring_bind( | 1532 parser->set_allow_harmony_destructuring_bind( |
1534 flags.Contains(kAllowHarmonyDestructuring)); | 1533 flags.Contains(kAllowHarmonyDestructuring)); |
1535 parser->set_allow_harmony_destructuring_assignment( | 1534 parser->set_allow_harmony_destructuring_assignment( |
1536 flags.Contains(kAllowHarmonyDestructuringAssignment)); | 1535 flags.Contains(kAllowHarmonyDestructuringAssignment)); |
1537 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); | 1536 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
1538 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); | 1537 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); |
| 1538 parser->set_allow_harmony_function_sent( |
| 1539 flags.Contains(kAllowHarmonyFunctionSent)); |
1539 } | 1540 } |
1540 | 1541 |
1541 | 1542 |
1542 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1543 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1543 i::EnumSet<ParserFlag> flags, | 1544 i::EnumSet<ParserFlag> flags, |
1544 ParserSyncTestResult result, | 1545 ParserSyncTestResult result, |
1545 bool is_module = false) { | 1546 bool is_module = false) { |
1546 i::Isolate* isolate = CcTest::i_isolate(); | 1547 i::Isolate* isolate = CcTest::i_isolate(); |
1547 i::Factory* factory = isolate->factory(); | 1548 i::Factory* factory = isolate->factory(); |
1548 | 1549 |
(...skipping 6466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8015 { "", "" }, | 8016 { "", "" }, |
8016 { NULL, NULL } | 8017 { NULL, NULL } |
8017 }; | 8018 }; |
8018 const char* error_data[] = { | 8019 const char* error_data[] = { |
8019 "var x = function.sent", | 8020 "var x = function.sent", |
8020 "function* g() { yield function.s\\u0065nt; }", | 8021 "function* g() { yield function.s\\u0065nt; }", |
8021 NULL | 8022 NULL |
8022 }; | 8023 }; |
8023 // clang-format on | 8024 // clang-format on |
8024 | 8025 |
8025 bool old_flag = i::FLAG_harmony_function_sent; | 8026 static const ParserFlag always_flags[] = {kAllowHarmonyFunctionSent}; |
8026 i::FLAG_harmony_function_sent = true; | 8027 RunParserSyncTest(context_data, error_data, kError, always_flags, |
8027 RunParserSyncTest(context_data, error_data, kError); | 8028 arraysize(always_flags)); |
8028 i::FLAG_harmony_function_sent = old_flag; | |
8029 } | 8029 } |
8030 | 8030 |
8031 TEST(NewTargetErrors) { | 8031 TEST(NewTargetErrors) { |
8032 // clang-format off | 8032 // clang-format off |
8033 const char* context_data[][2] = { | 8033 const char* context_data[][2] = { |
8034 { "'use strict'", "" }, | 8034 { "'use strict'", "" }, |
8035 { "", "" }, | 8035 { "", "" }, |
8036 { NULL, NULL } | 8036 { NULL, NULL } |
8037 }; | 8037 }; |
8038 const char* error_data[] = { | 8038 const char* error_data[] = { |
8039 "var x = new.target", | 8039 "var x = new.target", |
8040 "function f() { return new.t\\u0061rget; }", | 8040 "function f() { return new.t\\u0061rget; }", |
8041 NULL | 8041 NULL |
8042 }; | 8042 }; |
8043 // clang-format on | 8043 // clang-format on |
8044 RunParserSyncTest(context_data, error_data, kError); | 8044 RunParserSyncTest(context_data, error_data, kError); |
8045 } | 8045 } |
OLD | NEW |