| 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 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2008 "var foo = { eval: 1 };", | 2008 "var foo = { eval: 1 };", |
| 2009 "var foo = { arguments: 1 };", | 2009 "var foo = { arguments: 1 };", |
| 2010 "var foo = { }; foo.eval = {};", | 2010 "var foo = { }; foo.eval = {};", |
| 2011 "var foo = { }; foo.arguments = {};", | 2011 "var foo = { }; foo.arguments = {};", |
| 2012 NULL | 2012 NULL |
| 2013 }; | 2013 }; |
| 2014 | 2014 |
| 2015 RunParserSyncTest(context_data, statement_data, kSuccess); | 2015 RunParserSyncTest(context_data, statement_data, kSuccess); |
| 2016 } | 2016 } |
| 2017 | 2017 |
| 2018 #define FUTURE_STRICT_RESERVED_WORDS_NO_LET(V) \ |
| 2019 V(implements) \ |
| 2020 V(interface) \ |
| 2021 V(package) \ |
| 2022 V(private) \ |
| 2023 V(protected) \ |
| 2024 V(public) \ |
| 2025 V(static) \ |
| 2026 V(yield) |
| 2018 | 2027 |
| 2019 #define FUTURE_STRICT_RESERVED_WORDS(V) \ | 2028 #define FUTURE_STRICT_RESERVED_WORDS(V) \ |
| 2020 V(implements) \ | |
| 2021 V(interface) \ | |
| 2022 V(let) \ | 2029 V(let) \ |
| 2023 V(package) \ | 2030 FUTURE_STRICT_RESERVED_WORDS_NO_LET(V) |
| 2024 V(private) \ | 2031 |
| 2025 V(protected) \ | 2032 #define LIMITED_FUTURE_STRICT_RESERVED_WORDS_NO_LET(V) \ |
| 2026 V(public) \ | 2033 V(implements) \ |
| 2027 V(static) \ | 2034 V(static) \ |
| 2028 V(yield) | 2035 V(yield) |
| 2029 | 2036 |
| 2030 | |
| 2031 #define LIMITED_FUTURE_STRICT_RESERVED_WORDS(V) \ | 2037 #define LIMITED_FUTURE_STRICT_RESERVED_WORDS(V) \ |
| 2032 V(implements) \ | |
| 2033 V(let) \ | 2038 V(let) \ |
| 2034 V(static) \ | 2039 LIMITED_FUTURE_STRICT_RESERVED_WORDS_NO_LET(V) |
| 2035 V(yield) | |
| 2036 | |
| 2037 | 2040 |
| 2038 #define FUTURE_STRICT_RESERVED_STATEMENTS(NAME) \ | 2041 #define FUTURE_STRICT_RESERVED_STATEMENTS(NAME) \ |
| 2039 "var " #NAME ";", \ | 2042 "var " #NAME ";", \ |
| 2040 "var foo, " #NAME ";", \ | 2043 "var foo, " #NAME ";", \ |
| 2041 "try { } catch (" #NAME ") { }", \ | 2044 "try { } catch (" #NAME ") { }", \ |
| 2042 "function " #NAME "() { }", \ | 2045 "function " #NAME "() { }", \ |
| 2043 "(function " #NAME "() { })", \ | 2046 "(function " #NAME "() { })", \ |
| 2044 "function foo(" #NAME ") { }", \ | 2047 "function foo(" #NAME ") { }", \ |
| 2045 "function foo(bar, " #NAME ") { }", \ | 2048 "function foo(bar, " #NAME ") { }", \ |
| 2046 #NAME " = 1;", \ | 2049 #NAME " = 1;", \ |
| 2047 #NAME " += 1;", \ | 2050 #NAME " += 1;", \ |
| 2048 "var foo = " #NAME " = 1;", \ | 2051 "var foo = " #NAME " = 1;", \ |
| 2049 "++" #NAME ";", \ | 2052 "++" #NAME ";", \ |
| 2050 #NAME " ++;", | 2053 #NAME " ++;", |
| 2051 | 2054 |
| 2055 // clang-format off |
| 2056 #define FUTURE_STRICT_RESERVED_LEX_BINDINGS(NAME) \ |
| 2057 "let " #NAME ";", \ |
| 2058 "for (let " #NAME "; false; ) {}", \ |
| 2059 "for (let " #NAME " in {}) {}", \ |
| 2060 "for (let " #NAME " of []) {}", \ |
| 2061 "const " #NAME " = null;", \ |
| 2062 "for (const " #NAME " = null; false; ) {}", \ |
| 2063 "for (const " #NAME " in {}) {}", \ |
| 2064 "for (const " #NAME " of []) {}", |
| 2065 // clang-format on |
| 2052 | 2066 |
| 2053 TEST(ErrorsFutureStrictReservedWords) { | 2067 TEST(ErrorsFutureStrictReservedWords) { |
| 2054 // Tests that both preparsing and parsing produce the right kind of errors for | 2068 // Tests that both preparsing and parsing produce the right kind of errors for |
| 2055 // using future strict reserved words as identifiers. Without the strict mode, | 2069 // using future strict reserved words as identifiers. Without the strict mode, |
| 2056 // it's ok to use future strict reserved words as identifiers. With the strict | 2070 // it's ok to use future strict reserved words as identifiers. With the strict |
| 2057 // mode, it isn't. | 2071 // mode, it isn't. |
| 2058 const char* context_data[][2] = { | 2072 const char* strict_contexts[][2] = { |
| 2059 {"function test_func() {\"use strict\"; ", "}"}, | 2073 {"function test_func() {\"use strict\"; ", "}"}, |
| 2060 {"() => { \"use strict\"; ", "}"}, | 2074 {"() => { \"use strict\"; ", "}"}, |
| 2061 {NULL, NULL}}; | 2075 {NULL, NULL}}; |
| 2062 | 2076 |
| 2077 // clang-format off |
| 2063 const char* statement_data[] { | 2078 const char* statement_data[] { |
| 2064 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) | 2079 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) |
| 2080 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_LEX_BINDINGS) |
| 2065 NULL | 2081 NULL |
| 2066 }; | 2082 }; |
| 2083 // clang-format on |
| 2067 | 2084 |
| 2068 RunParserSyncTest(context_data, statement_data, kError); | 2085 RunParserSyncTest(strict_contexts, statement_data, kError); |
| 2086 |
| 2087 // From ES2015, 13.3.1.1 Static Semantics: Early Errors: |
| 2088 // |
| 2089 // > LexicalDeclaration : LetOrConst BindingList ; |
| 2090 // > |
| 2091 // > - It is a Syntax Error if the BoundNames of BindingList contains "let". |
| 2092 const char* non_strict_contexts[][2] = {{"", ""}, |
| 2093 {"function test_func() {", "}"}, |
| 2094 {"() => {", "}"}, |
| 2095 {NULL, NULL}}; |
| 2096 const char* invalid_statements[] = {FUTURE_STRICT_RESERVED_LEX_BINDINGS("let") |
| 2097 NULL}; |
| 2098 |
| 2099 RunParserSyncTest(non_strict_contexts, invalid_statements, kError); |
| 2069 } | 2100 } |
| 2070 | 2101 |
| 2071 | |
| 2072 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS | 2102 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS |
| 2073 | 2103 |
| 2074 | 2104 |
| 2075 TEST(NoErrorsFutureStrictReservedWords) { | 2105 TEST(NoErrorsFutureStrictReservedWords) { |
| 2076 const char* context_data[][2] = { | 2106 const char* context_data[][2] = { |
| 2077 { "", "" }, | 2107 { "", "" }, |
| 2078 { "function test_func() {", "}"}, | 2108 { "function test_func() {", "}"}, |
| 2079 { "() => {", "}" }, | 2109 { "() => {", "}" }, |
| 2080 { NULL, NULL } | 2110 { NULL, NULL } |
| 2081 }; | 2111 }; |
| 2082 | 2112 |
| 2113 // clang-format off |
| 2083 const char* statement_data[] = { | 2114 const char* statement_data[] = { |
| 2084 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) | 2115 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) |
| 2116 FUTURE_STRICT_RESERVED_WORDS_NO_LET(FUTURE_STRICT_RESERVED_LEX_BINDINGS) |
| 2085 NULL | 2117 NULL |
| 2086 }; | 2118 }; |
| 2119 // clang-format on |
| 2087 | 2120 |
| 2088 RunParserSyncTest(context_data, statement_data, kSuccess); | 2121 RunParserSyncTest(context_data, statement_data, kSuccess); |
| 2089 } | 2122 } |
| 2090 | 2123 |
| 2091 | 2124 |
| 2092 TEST(ErrorsReservedWords) { | 2125 TEST(ErrorsReservedWords) { |
| 2093 // Tests that both preparsing and parsing produce the right kind of errors for | 2126 // Tests that both preparsing and parsing produce the right kind of errors for |
| 2094 // using future reserved words as identifiers. These tests don't depend on the | 2127 // using future reserved words as identifiers. These tests don't depend on the |
| 2095 // strict mode. | 2128 // strict mode. |
| 2096 const char* context_data[][2] = { | 2129 const char* context_data[][2] = { |
| (...skipping 5594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7691 "for (const x = 0 in {});", | 7724 "for (const x = 0 in {});", |
| 7692 "for (let x = 0 in {});", | 7725 "for (let x = 0 in {});", |
| 7693 NULL | 7726 NULL |
| 7694 }; | 7727 }; |
| 7695 // clang-format on | 7728 // clang-format on |
| 7696 | 7729 |
| 7697 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; | 7730 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; |
| 7698 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, | 7731 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, |
| 7699 arraysize(always_flags)); | 7732 arraysize(always_flags)); |
| 7700 } | 7733 } |
| OLD | NEW |