Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1891453005: [parser] Relex restriction on reserved words (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/parsing/parser-base.h ('K') | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1991 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 "var foo = { eval: 1 };", 2002 "var foo = { eval: 1 };",
2003 "var foo = { arguments: 1 };", 2003 "var foo = { arguments: 1 };",
2004 "var foo = { }; foo.eval = {};", 2004 "var foo = { }; foo.eval = {};",
2005 "var foo = { }; foo.arguments = {};", 2005 "var foo = { }; foo.arguments = {};",
2006 NULL 2006 NULL
2007 }; 2007 };
2008 2008
2009 RunParserSyncTest(context_data, statement_data, kSuccess); 2009 RunParserSyncTest(context_data, statement_data, kSuccess);
2010 } 2010 }
2011 2011
2012 #define FUTURE_STRICT_RESERVED_WORDS_NO_LET(V) \
2013 V(implements) \
2014 V(interface) \
2015 V(package) \
2016 V(private) \
2017 V(protected) \
2018 V(public) \
2019 V(static) \
2020 V(yield)
Dan Ehrenberg 2016/04/20 20:59:56 I believe all of these extra tests would be valid
Dan Ehrenberg 2016/04/20 21:02:31 Actually, I see you are using 'no let' for your sl
mike3 2016/04/21 19:51:20 Sure thing, I'll add tests for both cases.
2012 2021
2013 #define FUTURE_STRICT_RESERVED_WORDS(V) \ 2022 #define FUTURE_STRICT_RESERVED_WORDS(V) \
2014 V(implements) \
2015 V(interface) \
2016 V(let) \ 2023 V(let) \
2017 V(package) \ 2024 FUTURE_STRICT_RESERVED_WORDS_NO_LET(V)
2018 V(private) \ 2025
2019 V(protected) \ 2026 #define LIMITED_FUTURE_STRICT_RESERVED_WORDS_NO_LET(V) \
2020 V(public) \ 2027 V(implements) \
2021 V(static) \ 2028 V(static) \
2022 V(yield) 2029 V(yield)
2023 2030
2024
2025 #define LIMITED_FUTURE_STRICT_RESERVED_WORDS(V) \ 2031 #define LIMITED_FUTURE_STRICT_RESERVED_WORDS(V) \
2026 V(implements) \
2027 V(let) \ 2032 V(let) \
2028 V(static) \ 2033 LIMITED_FUTURE_STRICT_RESERVED_WORDS_NO_LET(V)
2029 V(yield)
2030
2031 2034
2032 #define FUTURE_STRICT_RESERVED_STATEMENTS(NAME) \ 2035 #define FUTURE_STRICT_RESERVED_STATEMENTS(NAME) \
2033 "var " #NAME ";", \ 2036 "var " #NAME ";", \
2034 "var foo, " #NAME ";", \ 2037 "var foo, " #NAME ";", \
2035 "try { } catch (" #NAME ") { }", \ 2038 "try { } catch (" #NAME ") { }", \
2036 "function " #NAME "() { }", \ 2039 "function " #NAME "() { }", \
2037 "(function " #NAME "() { })", \ 2040 "(function " #NAME "() { })", \
2038 "function foo(" #NAME ") { }", \ 2041 "function foo(" #NAME ") { }", \
2039 "function foo(bar, " #NAME ") { }", \ 2042 "function foo(bar, " #NAME ") { }", \
2040 #NAME " = 1;", \ 2043 #NAME " = 1;", \
2041 #NAME " += 1;", \ 2044 #NAME " += 1;", \
2042 "var foo = " #NAME " = 1;", \ 2045 "var foo = " #NAME " = 1;", \
2043 "++" #NAME ";", \ 2046 "++" #NAME ";", \
2044 #NAME " ++;", 2047 #NAME " ++;",
2045 2048
2049 // clang-format off
2050 #define FUTURE_STRICT_RESERVED_LET_BINDINGS(NAME) \
2051 "let " #NAME ";", \
2052 "for (let " #NAME "; false; ) {}", \
2053 "for (let " #NAME " in {}) {}", \
2054 "for (let " #NAME " of []) {}",
Dan Ehrenberg 2016/04/20 20:59:56 For completeness, you can use const for most of th
mike3 2016/04/21 19:51:20 Acknowledged.
2055 // clang-format on
2046 2056
2047 TEST(ErrorsFutureStrictReservedWords) { 2057 TEST(ErrorsFutureStrictReservedWords) {
2048 // Tests that both preparsing and parsing produce the right kind of errors for 2058 // Tests that both preparsing and parsing produce the right kind of errors for
2049 // using future strict reserved words as identifiers. Without the strict mode, 2059 // using future strict reserved words as identifiers. Without the strict mode,
2050 // it's ok to use future strict reserved words as identifiers. With the strict 2060 // it's ok to use future strict reserved words as identifiers. With the strict
2051 // mode, it isn't. 2061 // mode, it isn't.
2052 const char* context_data[][2] = { 2062 const char* context_data[][2] = {
2053 {"function test_func() {\"use strict\"; ", "}"}, 2063 {"function test_func() {\"use strict\"; ", "}"},
2054 {"() => { \"use strict\"; ", "}"}, 2064 {"() => { \"use strict\"; ", "}"},
2055 {NULL, NULL}}; 2065 {NULL, NULL}};
2056 2066
2067 // clang-format off
2057 const char* statement_data[] { 2068 const char* statement_data[] {
2058 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 2069 LIMITED_FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
2070 LIMITED_FUTURE_STRICT_RESERVED_WORDS_NO_LET(
2071 FUTURE_STRICT_RESERVED_LET_BINDINGS)
2059 NULL 2072 NULL
2060 }; 2073 };
2074 // clang-format on
2061 2075
2062 RunParserSyncTest(context_data, statement_data, kError); 2076 RunParserSyncTest(context_data, statement_data, kError);
2063 } 2077 }
2064 2078
2065
2066 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS 2079 #undef LIMITED_FUTURE_STRICT_RESERVED_WORDS
2067 2080
2068 2081
2069 TEST(NoErrorsFutureStrictReservedWords) { 2082 TEST(NoErrorsFutureStrictReservedWords) {
2070 const char* context_data[][2] = { 2083 const char* context_data[][2] = {
2071 { "", "" }, 2084 { "", "" },
2072 { "function test_func() {", "}"}, 2085 { "function test_func() {", "}"},
2073 { "() => {", "}" }, 2086 { "() => {", "}" },
2074 { NULL, NULL } 2087 { NULL, NULL }
2075 }; 2088 };
2076 2089
2090 // clang-format off
2077 const char* statement_data[] = { 2091 const char* statement_data[] = {
2078 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS) 2092 FUTURE_STRICT_RESERVED_WORDS(FUTURE_STRICT_RESERVED_STATEMENTS)
2093 FUTURE_STRICT_RESERVED_WORDS_NO_LET(FUTURE_STRICT_RESERVED_LET_BINDINGS)
2079 NULL 2094 NULL
2080 }; 2095 };
2096 // clang-format on
2081 2097
2082 RunParserSyncTest(context_data, statement_data, kSuccess); 2098 RunParserSyncTest(context_data, statement_data, kSuccess);
2083 } 2099 }
2084 2100
2085 2101
2086 TEST(ErrorsReservedWords) { 2102 TEST(ErrorsReservedWords) {
2087 // Tests that both preparsing and parsing produce the right kind of errors for 2103 // Tests that both preparsing and parsing produce the right kind of errors for
2088 // using future reserved words as identifiers. These tests don't depend on the 2104 // using future reserved words as identifiers. These tests don't depend on the
2089 // strict mode. 2105 // strict mode.
2090 const char* context_data[][2] = { 2106 const char* context_data[][2] = {
(...skipping 5132 matching lines...) Expand 10 before | Expand all | Expand 10 after
7223 // "Array() **= 10", 7239 // "Array() **= 10",
7224 NULL 7240 NULL
7225 }; 7241 };
7226 // clang-format on 7242 // clang-format on
7227 7243
7228 static const ParserFlag always_flags[] = { 7244 static const ParserFlag always_flags[] = {
7229 kAllowHarmonyExponentiationOperator}; 7245 kAllowHarmonyExponentiationOperator};
7230 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 7246 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7231 arraysize(always_flags)); 7247 arraysize(always_flags));
7232 } 7248 }
OLDNEW
« src/parsing/parser-base.h ('K') | « src/parsing/parser-base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698