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

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

Issue 1808373003: Implement ES2015 labelled function declaration restrictions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« src/parsing/parser.cc ('K') | « src/parsing/preparser.cc ('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 7252 matching lines...) Expand 10 before | Expand all | Expand 10 after
7263 {"(function() { 'use strict'; {", "} })()"}, 7263 {"(function() { 'use strict'; {", "} })()"},
7264 { NULL, NULL } 7264 { NULL, NULL }
7265 }; 7265 };
7266 const char* sloppy_context[][2] = { 7266 const char* sloppy_context[][2] = {
7267 { "", "" }, 7267 { "", "" },
7268 { "{", "}" }, 7268 { "{", "}" },
7269 {"(function() {", "})()"}, 7269 {"(function() {", "})()"},
7270 {"(function() { {", "} })()"}, 7270 {"(function() { {", "} })()"},
7271 { NULL, NULL } 7271 { NULL, NULL }
7272 }; 7272 };
7273 // Invalid in all contexts
7273 const char* error_data[] = { 7274 const char* error_data[] = {
7274 "try function foo() {} catch (e) {}", 7275 "try function foo() {} catch (e) {}",
7275 NULL 7276 NULL
7276 }; 7277 };
7278 // Valid in sloppy mode only, and only when the
7279 // --harmony-restrictive-declarations flag is off
7277 const char* unrestricted_data[] = { 7280 const char* unrestricted_data[] = {
7278 "do function foo() {} while (0);", 7281 "do function foo() {} while (0);",
7279 "for (;false;) function foo() {}", 7282 "for (;false;) function foo() {}",
7280 "for (var i = 0; i < 1; i++) function f() { };", 7283 "for (var i = 0; i < 1; i++) function f() { };",
7281 "for (var x in {a: 1}) function f() { };", 7284 "for (var x in {a: 1}) function f() { };",
7282 "for (var x in {}) function f() { };", 7285 "for (var x in {}) function f() { };",
7283 "for (var x in {}) function foo() {}", 7286 "for (var x in {}) function foo() {}",
7284 "for (x in {a: 1}) function f() { };", 7287 "for (x in {a: 1}) function f() { };",
7285 "for (x in {}) function f() { };", 7288 "for (x in {}) function f() { };",
7286 "var x; for (x in {}) function foo() {}", 7289 "var x; for (x in {}) function foo() {}",
7287 "with ({}) function f() { };", 7290 "with ({}) function f() { };",
7291 "do label: function foo() {} while (0);",
7292 "for (;false;) label: function foo() {}",
7293 "for (var i = 0; i < 1; i++) label: function f() { };",
7294 "for (var x in {a: 1}) label: function f() { };",
7295 "for (var x in {}) label: function f() { };",
7296 "for (var x in {}) label: function foo() {}",
7297 "for (x in {a: 1}) label: function f() { };",
7298 "for (x in {}) label: function f() { };",
7299 "var x; for (x in {}) label: function foo() {}",
7300 "with ({}) label: function f() { };",
7301 "if (true) label: function f() {}",
7302 "if (true) {} else label: function f() {}",
7288 NULL 7303 NULL
7289 }; 7304 };
7305 // Valid only in sloppy mode, with or without
7306 // --harmony-restrictive-declarations
7290 const char* sloppy_data[] = { 7307 const char* sloppy_data[] = {
7291 "if (true) function foo() {}", 7308 "if (true) function foo() {}",
7292 "if (false) {} else function f() { };", 7309 "if (false) {} else function f() { };",
7293 "label: function f() { }", 7310 "label: function f() { }",
7294 "label: if (true) function f() { }", 7311 "label: if (true) function f() { }",
7295 "label: if (true) {} else function f() { }", 7312 "label: if (true) {} else function f() { }",
7296 "if (true) label: function f() {}",
7297 "if (true) {} else label: function f() {}",
7298 NULL 7313 NULL
7299 }; 7314 };
7300 // clang-format on 7315 // clang-format on
7301 7316
7302 static const ParserFlag restrictive_flags[] = { 7317 static const ParserFlag restrictive_flags[] = {
7303 kAllowHarmonyRestrictiveDeclarations}; 7318 kAllowHarmonyRestrictiveDeclarations};
7304 7319
7320 // Nothing parses in strict mode without a SyntaxError
7305 RunParserSyncTest(strict_context, error_data, kError); 7321 RunParserSyncTest(strict_context, error_data, kError);
7306 RunParserSyncTest(strict_context, error_data, kError, NULL, 0, 7322 RunParserSyncTest(strict_context, error_data, kError, NULL, 0,
7307 restrictive_flags, arraysize(restrictive_flags)); 7323 restrictive_flags, arraysize(restrictive_flags));
7308 RunParserSyncTest(strict_context, unrestricted_data, kError); 7324 RunParserSyncTest(strict_context, unrestricted_data, kError);
7309 RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0, 7325 RunParserSyncTest(strict_context, unrestricted_data, kError, NULL, 0,
7310 restrictive_flags, arraysize(restrictive_flags)); 7326 restrictive_flags, arraysize(restrictive_flags));
7311 RunParserSyncTest(strict_context, sloppy_data, kError); 7327 RunParserSyncTest(strict_context, sloppy_data, kError);
7312 RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0, 7328 RunParserSyncTest(strict_context, sloppy_data, kError, NULL, 0,
7313 restrictive_flags, arraysize(restrictive_flags)); 7329 restrictive_flags, arraysize(restrictive_flags));
7314 7330
7331 // In sloppy mode, some things are successful, depending on the flag
7315 RunParserSyncTest(sloppy_context, error_data, kError); 7332 RunParserSyncTest(sloppy_context, error_data, kError);
7316 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0, 7333 RunParserSyncTest(sloppy_context, error_data, kError, NULL, 0,
7317 restrictive_flags, arraysize(restrictive_flags)); 7334 restrictive_flags, arraysize(restrictive_flags));
7318 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess); 7335 RunParserSyncTest(sloppy_context, unrestricted_data, kSuccess);
7319 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0, 7336 RunParserSyncTest(sloppy_context, unrestricted_data, kError, NULL, 0,
7320 restrictive_flags, arraysize(restrictive_flags)); 7337 restrictive_flags, arraysize(restrictive_flags));
7321 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess); 7338 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess);
7322 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags, 7339 RunParserSyncTest(sloppy_context, sloppy_data, kSuccess, restrictive_flags,
7323 arraysize(restrictive_flags)); 7340 arraysize(restrictive_flags));
7324 } 7341 }
OLDNEW
« src/parsing/parser.cc ('K') | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698