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

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

Issue 2478883002: Remove always-true --harmony-restrictive-declarations flag (Closed)
Patch Set: Formatting Created 4 years, 1 month 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
« no previous file with comments | « src/parsing/parser-base.h ('k') | test/mjsunit/es6/sloppy-restrictive-block-function.js » ('j') | 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 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 } 1284 }
1285 1285
1286 data.Dispose(); 1286 data.Dispose();
1287 return i::MessageTemplate::FormatMessage(isolate, message, arg_object); 1287 return i::MessageTemplate::FormatMessage(isolate, message, arg_object);
1288 } 1288 }
1289 1289
1290 enum ParserFlag { 1290 enum ParserFlag {
1291 kAllowLazy, 1291 kAllowLazy,
1292 kAllowNatives, 1292 kAllowNatives,
1293 kAllowHarmonyFunctionSent, 1293 kAllowHarmonyFunctionSent,
1294 kAllowHarmonyRestrictiveDeclarations,
1295 kAllowHarmonyAsyncAwait, 1294 kAllowHarmonyAsyncAwait,
1296 kAllowHarmonyRestrictiveGenerators, 1295 kAllowHarmonyRestrictiveGenerators,
1297 kAllowHarmonyTrailingCommas, 1296 kAllowHarmonyTrailingCommas,
1298 kAllowHarmonyClassFields, 1297 kAllowHarmonyClassFields,
1299 }; 1298 };
1300 1299
1301 enum ParserSyncTestResult { 1300 enum ParserSyncTestResult {
1302 kSuccessOrError, 1301 kSuccessOrError,
1303 kSuccess, 1302 kSuccess,
1304 kError 1303 kError
1305 }; 1304 };
1306 1305
1307 template <typename Traits> 1306 template <typename Traits>
1308 void SetParserFlags(i::ParserBase<Traits>* parser, 1307 void SetParserFlags(i::ParserBase<Traits>* parser,
1309 i::EnumSet<ParserFlag> flags) { 1308 i::EnumSet<ParserFlag> flags) {
1310 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1309 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1311 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1310 parser->set_allow_natives(flags.Contains(kAllowNatives));
1312 parser->set_allow_harmony_function_sent( 1311 parser->set_allow_harmony_function_sent(
1313 flags.Contains(kAllowHarmonyFunctionSent)); 1312 flags.Contains(kAllowHarmonyFunctionSent));
1314 parser->set_allow_harmony_restrictive_declarations(
1315 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1316 parser->set_allow_harmony_async_await( 1313 parser->set_allow_harmony_async_await(
1317 flags.Contains(kAllowHarmonyAsyncAwait)); 1314 flags.Contains(kAllowHarmonyAsyncAwait));
1318 parser->set_allow_harmony_restrictive_generators( 1315 parser->set_allow_harmony_restrictive_generators(
1319 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1316 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1320 parser->set_allow_harmony_trailing_commas( 1317 parser->set_allow_harmony_trailing_commas(
1321 flags.Contains(kAllowHarmonyTrailingCommas)); 1318 flags.Contains(kAllowHarmonyTrailingCommas));
1322 parser->set_allow_harmony_class_fields( 1319 parser->set_allow_harmony_class_fields(
1323 flags.Contains(kAllowHarmonyClassFields)); 1320 flags.Contains(kAllowHarmonyClassFields));
1324 } 1321 }
1325 1322
(...skipping 6312 matching lines...) Expand 10 before | Expand all | Expand 10 after
7638 const char* sloppy_context[][2] = { 7635 const char* sloppy_context[][2] = {
7639 { "", "" }, 7636 { "", "" },
7640 { "{", "}" }, 7637 { "{", "}" },
7641 {"(function() {", "})()"}, 7638 {"(function() {", "})()"},
7642 {"(function() { {", "} })()"}, 7639 {"(function() { {", "} })()"},
7643 { NULL, NULL } 7640 { NULL, NULL }
7644 }; 7641 };
7645 // Invalid in all contexts 7642 // Invalid in all contexts
7646 const char* error_data[] = { 7643 const char* error_data[] = {
7647 "try function foo() {} catch (e) {}", 7644 "try function foo() {} catch (e) {}",
7648 NULL
7649 };
7650 // Valid in sloppy mode only, and only when the
7651 // --harmony-restrictive-declarations flag is off
7652 const char* unrestricted_data[] = {
7653 "do function foo() {} while (0);", 7645 "do function foo() {} while (0);",
7654 "for (;false;) function foo() {}", 7646 "for (;false;) function foo() {}",
7655 "for (var i = 0; i < 1; i++) function f() { };", 7647 "for (var i = 0; i < 1; i++) function f() { };",
7656 "for (var x in {a: 1}) function f() { };", 7648 "for (var x in {a: 1}) function f() { };",
7657 "for (var x in {}) function f() { };", 7649 "for (var x in {}) function f() { };",
7658 "for (var x in {}) function foo() {}", 7650 "for (var x in {}) function foo() {}",
7659 "for (x in {a: 1}) function f() { };", 7651 "for (x in {a: 1}) function f() { };",
7660 "for (x in {}) function f() { };", 7652 "for (x in {}) function f() { };",
7661 "var x; for (x in {}) function foo() {}", 7653 "var x; for (x in {}) function foo() {}",
7662 "with ({}) function f() { };", 7654 "with ({}) function f() { };",
(...skipping 11 matching lines...) Expand all
7674 "if (true) {} else label: function f() {}", 7666 "if (true) {} else label: function f() {}",
7675 "if (true) function* f() { }", 7667 "if (true) function* f() { }",
7676 "label: function* f() { }", 7668 "label: function* f() { }",
7677 // TODO(littledan, v8:4806): Ban duplicate generator declarations in 7669 // TODO(littledan, v8:4806): Ban duplicate generator declarations in
7678 // a block, maybe by tracking whether a Variable is a generator declaration 7670 // a block, maybe by tracking whether a Variable is a generator declaration
7679 // "{ function* f() {} function* f() {} }", 7671 // "{ function* f() {} function* f() {} }",
7680 // "{ function f() {} function* f() {} }", 7672 // "{ function f() {} function* f() {} }",
7681 // "{ function* f() {} function f() {} }", 7673 // "{ function* f() {} function f() {} }",
7682 NULL 7674 NULL
7683 }; 7675 };
7684 // Valid only in sloppy mode, with or without 7676 // Valid only in sloppy mode.
7685 // --harmony-restrictive-declarations
7686 const char* sloppy_data[] = { 7677 const char* sloppy_data[] = {
7687 "if (true) function foo() {}", 7678 "if (true) function foo() {}",
7688 "if (false) {} else function f() { };", 7679 "if (false) {} else function f() { };",
7689 "label: function f() { }", 7680 "label: function f() { }",
7690 "label: if (true) function f() { }", 7681 "label: if (true) function f() { }",
7691 "label: if (true) {} else function f() { }", 7682 "label: if (true) {} else function f() { }",
7692 NULL 7683 NULL
7693 }; 7684 };
7694 // clang-format on 7685 // clang-format on
7695 7686
7696 static const ParserFlag restrictive_flags[] = {
7697 kAllowHarmonyRestrictiveDeclarations};
7698
7699 // Nothing parses in strict mode without a SyntaxError 7687 // Nothing parses in strict mode without a SyntaxError
7700 RunParserSyncTest(strict_context, error_data, kError); 7688 RunParserSyncTest(strict_context, error_data, kError);
7701 RunParserSyncTest(strict_context, error_data, kError, NULL, 0,
7702 restrictive_flags, arraysize(restrictive_flags));
7703 RunParserSyncTest(strict_context, unrestricted_data, kError);
7704 RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0,
7705 restrictive_flags, arraysize(restrictive_flags));
7706 RunParserSyncTest(strict_context, sloppy_data, kError); 7689 RunParserSyncTest(strict_context, sloppy_data, kError);
7707 RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0,
7708 restrictive_flags, arraysize(restrictive_flags));
7709 7690
7710 // In sloppy mode, some things are successful, depending on the flag 7691 // In sloppy mode, sloppy_data is successful
7711 RunParserSyncTest(sloppy_context, error_data, kError); 7692 RunParserSyncTest(sloppy_context, error_data, kError);
7712 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0,
7713 restrictive_flags, arraysize(restrictive_flags));
7714 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess);
7715 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0,
7716 restrictive_flags, arraysize(restrictive_flags));
7717 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); 7693 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess);
7718 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags,
7719 arraysize(restrictive_flags));
7720 } 7694 }
7721 7695
7722 TEST(ExponentiationOperator) { 7696 TEST(ExponentiationOperator) {
7723 // clang-format off 7697 // clang-format off
7724 const char* context_data[][2] = { 7698 const char* context_data[][2] = {
7725 { "var O = { p: 1 }, x = 10; ; if (", ") { foo(); }" }, 7699 { "var O = { p: 1 }, x = 10; ; if (", ") { foo(); }" },
7726 { "var O = { p: 1 }, x = 10; ; (", ")" }, 7700 { "var O = { p: 1 }, x = 10; ; (", ")" },
7727 { "var O = { p: 1 }, x = 10; foo(", ")" }, 7701 { "var O = { p: 1 }, x = 10; foo(", ")" },
7728 { NULL, NULL } 7702 { NULL, NULL }
7729 }; 7703 };
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
8340 const char* data[] = { 8314 const char* data[] = {
8341 "const arguments = 1", 8315 "const arguments = 1",
8342 "let arguments", 8316 "let arguments",
8343 "var arguments", 8317 "var arguments",
8344 NULL 8318 NULL
8345 }; 8319 };
8346 // clang-format on 8320 // clang-format on
8347 RunParserSyncTest(context_data, data, kSuccess); 8321 RunParserSyncTest(context_data, data, kSuccess);
8348 } 8322 }
8349 } 8323 }
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | test/mjsunit/es6/sloppy-restrictive-block-function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698