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

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

Issue 1429653006: Remove flags for spread calls and arrays (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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/preparser.h ('k') | test/js-perf-test/JSTests.json » ('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 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 } 1491 }
1492 1492
1493 1493
1494 enum ParserFlag { 1494 enum ParserFlag {
1495 kAllowLazy, 1495 kAllowLazy,
1496 kAllowNatives, 1496 kAllowNatives,
1497 kAllowHarmonyDefaultParameters, 1497 kAllowHarmonyDefaultParameters,
1498 kAllowHarmonyRestParameters, 1498 kAllowHarmonyRestParameters,
1499 kAllowHarmonySloppy, 1499 kAllowHarmonySloppy,
1500 kAllowHarmonySloppyLet, 1500 kAllowHarmonySloppyLet,
1501 kAllowHarmonySpreadCalls,
1502 kAllowHarmonyDestructuring, 1501 kAllowHarmonyDestructuring,
1503 kAllowHarmonySpreadArrays,
1504 kAllowHarmonyNewTarget, 1502 kAllowHarmonyNewTarget,
1505 kAllowStrongMode, 1503 kAllowStrongMode,
1506 kNoLegacyConst 1504 kNoLegacyConst
1507 }; 1505 };
1508 1506
1509 1507
1510 enum ParserSyncTestResult { 1508 enum ParserSyncTestResult {
1511 kSuccessOrError, 1509 kSuccessOrError,
1512 kSuccess, 1510 kSuccess,
1513 kError 1511 kError
1514 }; 1512 };
1515 1513
1516 template <typename Traits> 1514 template <typename Traits>
1517 void SetParserFlags(i::ParserBase<Traits>* parser, 1515 void SetParserFlags(i::ParserBase<Traits>* parser,
1518 i::EnumSet<ParserFlag> flags) { 1516 i::EnumSet<ParserFlag> flags) {
1519 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1517 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1520 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1518 parser->set_allow_natives(flags.Contains(kAllowNatives));
1521 parser->set_allow_harmony_default_parameters( 1519 parser->set_allow_harmony_default_parameters(
1522 flags.Contains(kAllowHarmonyDefaultParameters)); 1520 flags.Contains(kAllowHarmonyDefaultParameters));
1523 parser->set_allow_harmony_rest_parameters( 1521 parser->set_allow_harmony_rest_parameters(
1524 flags.Contains(kAllowHarmonyRestParameters)); 1522 flags.Contains(kAllowHarmonyRestParameters));
1525 parser->set_allow_harmony_spread_calls(
1526 flags.Contains(kAllowHarmonySpreadCalls));
1527 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1523 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1528 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet)); 1524 parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
1529 parser->set_allow_harmony_destructuring( 1525 parser->set_allow_harmony_destructuring(
1530 flags.Contains(kAllowHarmonyDestructuring)); 1526 flags.Contains(kAllowHarmonyDestructuring));
1531 parser->set_allow_harmony_spread_arrays(
1532 flags.Contains(kAllowHarmonySpreadArrays));
1533 parser->set_allow_harmony_new_target(flags.Contains(kAllowHarmonyNewTarget)); 1527 parser->set_allow_harmony_new_target(flags.Contains(kAllowHarmonyNewTarget));
1534 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); 1528 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
1535 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst)); 1529 parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
1536 } 1530 }
1537 1531
1538 1532
1539 void TestParserSyncWithFlags(i::Handle<i::String> source, 1533 void TestParserSyncWithFlags(i::Handle<i::String> source,
1540 i::EnumSet<ParserFlag> flags, 1534 i::EnumSet<ParserFlag> flags,
1541 ParserSyncTestResult result) { 1535 ParserSyncTestResult result) {
1542 i::Isolate* isolate = CcTest::i_isolate(); 1536 i::Isolate* isolate = CcTest::i_isolate();
(...skipping 3808 matching lines...) Expand 10 before | Expand all | Expand 10 after
5351 {NULL, NULL}}; 5345 {NULL, NULL}};
5352 5346
5353 const char* data[] = { 5347 const char* data[] = {
5354 "...([1, 2, 3])", "...'123', ...'456'", "...new Set([1, 2, 3]), 4", 5348 "...([1, 2, 3])", "...'123', ...'456'", "...new Set([1, 2, 3]), 4",
5355 "1, ...[2, 3], 4", "...Array(...[1,2,3,4])", "...NaN", 5349 "1, ...[2, 3], 4", "...Array(...[1,2,3,4])", "...NaN",
5356 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89'", 5350 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89'",
5357 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89', 10", 5351 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89', 10",
5358 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9", 5352 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9",
5359 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9, ...[10]", NULL}; 5353 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9, ...[10]", NULL};
5360 5354
5361 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; 5355 RunParserSyncTest(context_data, data, kSuccess);
5362
5363 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
5364 arraysize(always_flags));
5365 } 5356 }
5366 5357
5367 5358
5368 TEST(SpreadCallErrors) { 5359 TEST(SpreadCallErrors) {
5369 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"}, 5360 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"},
5370 {"function fn() {} fn(", ");"}, 5361 {"function fn() {} fn(", ");"},
5371 {NULL, NULL}}; 5362 {NULL, NULL}};
5372 5363
5373 const char* data[] = {"(...[1, 2, 3])", "......[1,2,3]", NULL}; 5364 const char* data[] = {"(...[1, 2, 3])", "......[1,2,3]", NULL};
5374 5365
5375 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; 5366 RunParserSyncTest(context_data, data, kError);
5376
5377 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
5378 arraysize(always_flags));
5379 } 5367 }
5380 5368
5381 5369
5382 TEST(BadRestSpread) { 5370 TEST(BadRestSpread) {
5383 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"}, 5371 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"},
5384 {"function fn() { ", "} fn();"}, 5372 {"function fn() { ", "} fn();"},
5385 {NULL, NULL}}; 5373 {NULL, NULL}};
5386 const char* data[] = {"return ...[1,2,3];", "var ...x = [1,2,3];", 5374 const char* data[] = {"return ...[1,2,3];", "var ...x = [1,2,3];",
5387 "var [...x,] = [1,2,3];", "var [...x, y] = [1,2,3];", 5375 "var [...x,] = [1,2,3];", "var [...x, y] = [1,2,3];",
5388 "var {...x} = [1,2,3];", "var { x } = {x: ...[1,2,3]}", 5376 "var {...x} = [1,2,3];", "var { x } = {x: ...[1,2,3]}",
(...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after
6924 kError, NULL, 0, always_flags, arraysize(always_flags)); 6912 kError, NULL, 0, always_flags, arraysize(always_flags));
6925 6913
6926 RunParserSyncTest(generator_context_data, parameter_data, kError, NULL, 0, 6914 RunParserSyncTest(generator_context_data, parameter_data, kError, NULL, 0,
6927 always_flags, arraysize(always_flags)); 6915 always_flags, arraysize(always_flags));
6928 RunParserSyncTest(generator_context_data, destructuring_assignment_data, 6916 RunParserSyncTest(generator_context_data, destructuring_assignment_data,
6929 kError, NULL, 0, always_flags, arraysize(always_flags)); 6917 kError, NULL, 0, always_flags, arraysize(always_flags));
6930 } 6918 }
6931 6919
6932 6920
6933 TEST(SpreadArray) { 6921 TEST(SpreadArray) {
6934 i::FLAG_harmony_spread_arrays = true;
6935
6936 const char* context_data[][2] = { 6922 const char* context_data[][2] = {
6937 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6923 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6938 6924
6939 // clang-format off 6925 // clang-format off
6940 const char* data[] = { 6926 const char* data[] = {
6941 "[...a]", 6927 "[...a]",
6942 "[a, ...b]", 6928 "[a, ...b]",
6943 "[...a,]", 6929 "[...a,]",
6944 "[...a, ,]", 6930 "[...a, ,]",
6945 "[, ...a]", 6931 "[, ...a]",
6946 "[...a, ...b]", 6932 "[...a, ...b]",
6947 "[...a, , ...b]", 6933 "[...a, , ...b]",
6948 "[...[...a]]", 6934 "[...[...a]]",
6949 "[, ...a]", 6935 "[, ...a]",
6950 "[, , ...a]", 6936 "[, , ...a]",
6951 NULL}; 6937 NULL};
6952 // clang-format on 6938 // clang-format on
6953 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays}; 6939 RunParserSyncTest(context_data, data, kSuccess);
6954 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
6955 arraysize(always_flags));
6956 } 6940 }
6957 6941
6958 6942
6959 TEST(SpreadArrayError) { 6943 TEST(SpreadArrayError) {
6960 i::FLAG_harmony_spread_arrays = true;
6961
6962 const char* context_data[][2] = { 6944 const char* context_data[][2] = {
6963 {"'use strict';", ""}, {"", ""}, {NULL, NULL}}; 6945 {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
6964 6946
6965 // clang-format off 6947 // clang-format off
6966 const char* data[] = { 6948 const char* data[] = {
6967 "[...]", 6949 "[...]",
6968 "[a, ...]", 6950 "[a, ...]",
6969 "[..., ]", 6951 "[..., ]",
6970 "[..., ...]", 6952 "[..., ...]",
6971 "[ (...a)]", 6953 "[ (...a)]",
6972 NULL}; 6954 NULL};
6973 // clang-format on 6955 // clang-format on
6974 static const ParserFlag always_flags[] = {kAllowHarmonySpreadArrays}; 6956 RunParserSyncTest(context_data, data, kError);
6975 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
6976 arraysize(always_flags));
6977 } 6957 }
6978 6958
6979 6959
6980 TEST(NewTarget) { 6960 TEST(NewTarget) {
6981 // clang-format off 6961 // clang-format off
6982 const char* good_context_data[][2] = { 6962 const char* good_context_data[][2] = {
6983 {"function f() {", "}"}, 6963 {"function f() {", "}"},
6984 {"'use strict'; function f() {", "}"}, 6964 {"'use strict'; function f() {", "}"},
6985 {"var f = function() {", "}"}, 6965 {"var f = function() {", "}"},
6986 {"'use strict'; var f = function() {", "}"}, 6966 {"'use strict'; var f = function() {", "}"},
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
7248 NULL 7228 NULL
7249 }; 7229 };
7250 // clang-format on 7230 // clang-format on
7251 7231
7252 static const ParserFlag fail_flags[] = { 7232 static const ParserFlag fail_flags[] = {
7253 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, 7233 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst,
7254 kAllowHarmonyDestructuring}; 7234 kAllowHarmonyDestructuring};
7255 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, 7235 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags,
7256 arraysize(fail_flags)); 7236 arraysize(fail_flags));
7257 } 7237 }
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | test/js-perf-test/JSTests.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698