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

Side by Side 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, 9 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
« no previous file with comments | « src/parsing/preparser.cc ('k') | test/mjsunit/harmony/sloppy-implicit-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 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 kAllowLazy, 1504 kAllowLazy,
1505 kAllowNatives, 1505 kAllowNatives,
1506 kAllowHarmonyDefaultParameters, 1506 kAllowHarmonyDefaultParameters,
1507 kAllowHarmonySloppy, 1507 kAllowHarmonySloppy,
1508 kAllowHarmonySloppyLet, 1508 kAllowHarmonySloppyLet,
1509 kAllowHarmonyDestructuring, 1509 kAllowHarmonyDestructuring,
1510 kAllowHarmonyDestructuringAssignment, 1510 kAllowHarmonyDestructuringAssignment,
1511 kAllowHarmonyNewTarget, 1511 kAllowHarmonyNewTarget,
1512 kAllowStrongMode, 1512 kAllowStrongMode,
1513 kNoLegacyConst, 1513 kNoLegacyConst,
1514 kAllowHarmonyFunctionSent 1514 kAllowHarmonyFunctionSent,
1515 kAllowHarmonyRestrictiveDeclarations,
1515 }; 1516 };
1516 1517
1517 enum ParserSyncTestResult { 1518 enum ParserSyncTestResult {
1518 kSuccessOrError, 1519 kSuccessOrError,
1519 kSuccess, 1520 kSuccess,
1520 kError 1521 kError
1521 }; 1522 };
1522 1523
1523 template <typename Traits> 1524 template <typename Traits>
1524 void SetParserFlags(i::ParserBase<Traits>* parser, 1525 void SetParserFlags(i::ParserBase<Traits>* parser,
1525 i::EnumSet<ParserFlag> flags) { 1526 i::EnumSet<ParserFlag> flags) {
1526 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1527 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1527 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1528 parser->set_allow_natives(flags.Contains(kAllowNatives));
1528 parser->set_allow_harmony_default_parameters( 1529 parser->set_allow_harmony_default_parameters(
1529 flags.Contains(kAllowHarmonyDefaultParameters)); 1530 flags.Contains(kAllowHarmonyDefaultParameters));
1530 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1531 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1531 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); 1532 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
1532 parser->set_allow_harmony_destructuring_bind( 1533 parser->set_allow_harmony_destructuring_bind(
1533 flags.Contains(kAllowHarmonyDestructuring)); 1534 flags.Contains(kAllowHarmonyDestructuring));
1534 parser->set_allow_harmony_destructuring_assignment( 1535 parser->set_allow_harmony_destructuring_assignment(
1535 flags.Contains(kAllowHarmonyDestructuringAssignment)); 1536 flags.Contains(kAllowHarmonyDestructuringAssignment));
1536 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); 1537 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
1537 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); 1538 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
1538 parser->set_allow_harmony_function_sent( 1539 parser->set_allow_harmony_function_sent(
1539 flags.Contains(kAllowHarmonyFunctionSent)); 1540 flags.Contains(kAllowHarmonyFunctionSent));
1541 parser->set_allow_harmony_restrictive_declarations(
1542 flags.Contains(kAllowHarmonyRestrictiveDeclarations));
1540 } 1543 }
1541 1544
1542 1545
1543 void TestParserSyncWithFlags(i::Handle<i::String> source, 1546 void TestParserSyncWithFlags(i::Handle<i::String> source,
1544 i::EnumSet<ParserFlag> flags, 1547 i::EnumSet<ParserFlag> flags,
1545 ParserSyncTestResult result, 1548 ParserSyncTestResult result,
1546 bool is_module = false) { 1549 bool is_module = false) {
1547 i::Isolate* isolate = CcTest::i_isolate(); 1550 i::Isolate* isolate = CcTest::i_isolate();
1548 i::Factory* factory = isolate->factory(); 1551 i::Factory* factory = isolate->factory();
1549 1552
(...skipping 6456 matching lines...) Expand 10 before | Expand all | Expand 10 after
8006 { NULL, NULL } 8009 { NULL, NULL }
8007 }; 8010 };
8008 const char* error_data[] = { 8011 const char* error_data[] = {
8009 "var x = new.target", 8012 "var x = new.target",
8010 "function f() { return new.t\\u0061rget; }", 8013 "function f() { return new.t\\u0061rget; }",
8011 NULL 8014 NULL
8012 }; 8015 };
8013 // clang-format on 8016 // clang-format on
8014 RunParserSyncTest(context_data, error_data, kError); 8017 RunParserSyncTest(context_data, error_data, kError);
8015 } 8018 }
8019
8020 TEST(FunctionDeclarationError) {
8021 // clang-format off
8022 const char* strict_context[][2] = {
8023 { "'use strict';", "" },
8024 { "'use strict'; { ", "}" },
8025 {"(function() { 'use strict';", "})()"},
8026 {"(function() { 'use strict'; {", "} })()"},
8027 { NULL, NULL }
8028 };
8029 const char* sloppy_context[][2] = {
8030 { "", "" },
8031 { "{", "}" },
8032 {"(function() {", "})()"},
8033 {"(function() { {", "} })()"},
8034 { NULL, NULL }
8035 };
8036 const char* error_data[] = {
8037 "try function foo() {} catch (e) {}",
8038 NULL
8039 };
8040 const char* unrestricted_data[] = {
8041 "do function foo() {} while (0);",
8042 "for (;false;) function foo() {}",
8043 "for (var i = 0; i < 1; i++) function f() { };",
8044 "for (var x in {a: 1}) function f() { };",
8045 "for (var x in {}) function f() { };",
8046 "for (var x in {}) function foo() {}",
8047 "for (x in {a: 1}) function f() { };",
8048 "for (x in {}) function f() { };",
8049 "var x; for (x in {}) function foo() {}",
8050 "with ({}) function f() { };",
8051 NULL
8052 };
8053 const char* sloppy_data[] = {
8054 "if (true) function foo() {}",
8055 "if (false) {} else function f() { };",
8056 "label: function f() { }",
8057 "label: if (true) function f() { }",
8058 "label: if (true) {} else function f() { }",
8059 "if (true) label: function f() {}",
8060 "if (true) {} else label: function f() {}",
8061 NULL
8062 };
8063 // clang-format on
8064
8065 static const ParserFlag restrictive_flags[] = {
8066 kAllowHarmonyRestrictiveDeclarations};
8067
8068 RunParserSyncTest(strict_context, error_data, kError);
8069 RunParserSyncTest(strict_context, error_data, kError, NULL, 0,
8070 restrictive_flags, arraysize(restrictive_flags));
8071 RunParserSyncTest(strict_context, unrestricted_data, kError);
8072 RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0,
8073 restrictive_flags, arraysize(restrictive_flags));
8074 RunParserSyncTest(strict_context, sloppy_data, kError);
8075 RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0,
8076 restrictive_flags, arraysize(restrictive_flags));
8077
8078 RunParserSyncTest(sloppy_context, error_data, kError);
8079 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0,
8080 restrictive_flags, arraysize(restrictive_flags));
8081 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess);
8082 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0,
8083 restrictive_flags, arraysize(restrictive_flags));
8084 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess);
8085 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags,
8086 arraysize(restrictive_flags));
8087 }
OLDNEW
« 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