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

Unified Diff: test/cctest/test-parsing.cc

Issue 1757543003: Restrict FunctionDeclarations in Statement position (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: git cl format Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/preparser.cc ('k') | test/mjsunit/harmony/sloppy-implicit-block-function.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 402e4b039aeb60510379b6f568eb96321c0657fa..ccd2ec8ca2e41d6a731848e5f335e07738f7f626 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1511,7 +1511,8 @@ enum ParserFlag {
kAllowHarmonyNewTarget,
kAllowStrongMode,
kNoLegacyConst,
- kAllowHarmonyFunctionSent
+ kAllowHarmonyFunctionSent,
+ kAllowHarmonyRestrictiveDeclarations,
};
enum ParserSyncTestResult {
@@ -1537,6 +1538,8 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
parser->set_allow_harmony_function_sent(
flags.Contains(kAllowHarmonyFunctionSent));
+ parser->set_allow_harmony_restrictive_declarations(
+ flags.Contains(kAllowHarmonyRestrictiveDeclarations));
}
@@ -8013,3 +8016,72 @@ TEST(NewTargetErrors) {
// clang-format on
RunParserSyncTest(context_data, error_data, kError);
}
+
+TEST(FunctionDeclarationError) {
+ // clang-format off
+ const char* strict_context[][2] = {
+ { "'use strict';", "" },
+ { "'use strict'; { ", "}" },
+ {"(function() { 'use strict';", "})()"},
+ {"(function() { 'use strict'; {", "} })()"},
+ { NULL, NULL }
+ };
+ const char* sloppy_context[][2] = {
+ { "", "" },
+ { "{", "}" },
+ {"(function() {", "})()"},
+ {"(function() { {", "} })()"},
+ { NULL, NULL }
+ };
+ const char* error_data[] = {
+ "try function foo() {} catch (e) {}",
+ NULL
+ };
+ const char* unrestricted_data[] = {
+ "do function foo() {} while (0);",
+ "for (;false;) function foo() {}",
+ "for (var i = 0; i < 1; i++) function f() { };",
+ "for (var x in {a: 1}) function f() { };",
+ "for (var x in {}) function f() { };",
+ "for (var x in {}) function foo() {}",
+ "for (x in {a: 1}) function f() { };",
+ "for (x in {}) function f() { };",
+ "var x; for (x in {}) function foo() {}",
+ "with ({}) function f() { };",
+ NULL
+ };
+ const char* sloppy_data[] = {
+ "if (true) function foo() {}",
+ "if (false) {} else function f() { };",
+ "label: function f() { }",
+ "label: if (true) function f() { }",
+ "label: if (true) {} else function f() { }",
+ "if (true) label: function f() {}",
+ "if (true) {} else label: function f() {}",
+ NULL
+ };
+ // clang-format on
+
+ static const ParserFlag restrictive_flags[] = {
+ kAllowHarmonyRestrictiveDeclarations};
+
+ RunParserSyncTest(strict_context, error_data, kError);
+ RunParserSyncTest(strict_context, error_data, kError, NULL, 0,
+ restrictive_flags, arraysize(restrictive_flags));
+ RunParserSyncTest(strict_context, unrestricted_data, kError);
+ RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0,
+ restrictive_flags, arraysize(restrictive_flags));
+ RunParserSyncTest(strict_context, sloppy_data, kError);
+ RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0,
+ restrictive_flags, arraysize(restrictive_flags));
+
+ RunParserSyncTest(sloppy_context, error_data, kError);
+ RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0,
+ restrictive_flags, arraysize(restrictive_flags));
+ RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess);
+ RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0,
+ restrictive_flags, arraysize(restrictive_flags));
+ RunParserSyncTest(sloppy_context, sloppy_data, kSuccess);
+ RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags,
+ arraysize(restrictive_flags));
+}
« no previous file with comments | « src/parsing/preparser.cc ('k') | test/mjsunit/harmony/sloppy-implicit-block-function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698