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

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

Issue 938443002: [es6] implement spread calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove --harmony-spread flag Created 5 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
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 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 kAllowNatives, 1374 kAllowNatives,
1375 kAllowHarmonyModules, 1375 kAllowHarmonyModules,
1376 kAllowHarmonyNumericLiterals, 1376 kAllowHarmonyNumericLiterals,
1377 kAllowHarmonyArrowFunctions, 1377 kAllowHarmonyArrowFunctions,
1378 kAllowHarmonyClasses, 1378 kAllowHarmonyClasses,
1379 kAllowHarmonyObjectLiterals, 1379 kAllowHarmonyObjectLiterals,
1380 kAllowHarmonyRestParameters, 1380 kAllowHarmonyRestParameters,
1381 kAllowHarmonySloppy, 1381 kAllowHarmonySloppy,
1382 kAllowHarmonyUnicode, 1382 kAllowHarmonyUnicode,
1383 kAllowHarmonyComputedPropertyNames, 1383 kAllowHarmonyComputedPropertyNames,
1384 kAllowStrongMode 1384 kAllowStrongMode,
1385 kAllowHarmonySpreadCalls
1385 }; 1386 };
1386 1387
1387 1388
1388 enum ParserSyncTestResult { 1389 enum ParserSyncTestResult {
1389 kSuccessOrError, 1390 kSuccessOrError,
1390 kSuccess, 1391 kSuccess,
1391 kError 1392 kError
1392 }; 1393 };
1393 1394
1394 template <typename Traits> 1395 template <typename Traits>
1395 void SetParserFlags(i::ParserBase<Traits>* parser, 1396 void SetParserFlags(i::ParserBase<Traits>* parser,
1396 i::EnumSet<ParserFlag> flags) { 1397 i::EnumSet<ParserFlag> flags) {
1397 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1398 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1398 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1399 parser->set_allow_natives(flags.Contains(kAllowNatives));
1399 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); 1400 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
1400 parser->set_allow_harmony_numeric_literals( 1401 parser->set_allow_harmony_numeric_literals(
1401 flags.Contains(kAllowHarmonyNumericLiterals)); 1402 flags.Contains(kAllowHarmonyNumericLiterals));
1402 parser->set_allow_harmony_object_literals( 1403 parser->set_allow_harmony_object_literals(
1403 flags.Contains(kAllowHarmonyObjectLiterals)); 1404 flags.Contains(kAllowHarmonyObjectLiterals));
1404 parser->set_allow_harmony_arrow_functions( 1405 parser->set_allow_harmony_arrow_functions(
1405 flags.Contains(kAllowHarmonyArrowFunctions)); 1406 flags.Contains(kAllowHarmonyArrowFunctions));
1406 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); 1407 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses));
1407 parser->set_allow_harmony_rest_params( 1408 parser->set_allow_harmony_rest_params(
1408 flags.Contains(kAllowHarmonyRestParameters)); 1409 flags.Contains(kAllowHarmonyRestParameters));
1410 parser->set_allow_harmony_spreadcalls(
1411 flags.Contains(kAllowHarmonySpreadCalls));
1409 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1412 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1410 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); 1413 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
1411 parser->set_allow_harmony_computed_property_names( 1414 parser->set_allow_harmony_computed_property_names(
1412 flags.Contains(kAllowHarmonyComputedPropertyNames)); 1415 flags.Contains(kAllowHarmonyComputedPropertyNames));
1413 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); 1416 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
1414 } 1417 }
1415 1418
1416 1419
1417 void TestParserSyncWithFlags(i::Handle<i::String> source, 1420 void TestParserSyncWithFlags(i::Handle<i::String> source,
1418 i::EnumSet<ParserFlag> flags, 1421 i::EnumSet<ParserFlag> flags,
(...skipping 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after
4928 4931
4929 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; 4932 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters};
4930 4933
4931 // In strict mode, the error is using "eval" or "arguments" as parameter names 4934 // In strict mode, the error is using "eval" or "arguments" as parameter names
4932 // In sloppy mode, the error is that eval / arguments are duplicated 4935 // In sloppy mode, the error is that eval / arguments are duplicated
4933 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 4936 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
4934 arraysize(always_flags)); 4937 arraysize(always_flags));
4935 } 4938 }
4936 4939
4937 4940
4941 TEST(SpreadCall) {
4942 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"},
4943 {"function fn() {} fn(", ");"},
4944 {NULL, NULL}};
4945
4946 const char* data[] = {
4947 "...([1, 2, 3])",
4948 "...'123', ...'456'",
4949 "...new Set([1, 2, 3]), 4",
4950 "1, ...[2, 3], 4",
4951 "...Array(...[1,2,3,4])",
4952 "...NaN",
4953 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89'",
4954 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89', 10",
4955 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9",
4956 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9, ...[10]",
4957 NULL};
4958
4959 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls};
4960
4961 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
4962 arraysize(always_flags));
4963 }
4964
4965
4966 TEST(SpreadCallErrors) {
4967 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"},
4968 {"function fn() {} fn(", ");"},
4969 {NULL, NULL}};
4970
4971 const char* data[] = {
4972 "(...[1, 2, 3])",
4973 "......[1,2,3]",
4974 NULL};
4975
4976 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls};
4977
4978 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
4979 arraysize(always_flags));
4980 }
4981
4982
4983 TEST(BadRestSpread) {
4984 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"},
4985 {"function fn() { ", "} fn();" },
4986 {NULL, NULL}};
4987 const char* data[] = {
4988 "return ...[1,2,3];",
4989 "var ...x = [1,2,3];",
4990 "var [...x,] = [1,2,3];",
4991 "var [...x, y] = [1,2,3];",
4992 "var {...x} = [1,2,3];",
4993 "var { x } = {x: ...[1,2,3]}",
4994 NULL};
4995 RunParserSyncTest(context_data, data, kError, NULL, 0, NULL, 0);
4996 }
4997
4998
4938 TEST(LexicalScopingSloppyMode) { 4999 TEST(LexicalScopingSloppyMode) {
4939 const char* context_data[][2] = { 5000 const char* context_data[][2] = {
4940 {"", ""}, 5001 {"", ""},
4941 {"function f() {", "}"}, 5002 {"function f() {", "}"},
4942 {"{", "}"}, 5003 {"{", "}"},
4943 {NULL, NULL}}; 5004 {NULL, NULL}};
4944 const char* bad_data[] = { 5005 const char* bad_data[] = {
4945 "let x = 1;", 5006 "let x = 1;",
4946 "for(let x = 1;;){}", 5007 "for(let x = 1;;){}",
4947 "for(let x of []){}", 5008 "for(let x of []){}",
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
5631 "(a/*\n*/=> a)(1)", 5692 "(a/*\n*/=> a)(1)",
5632 "((a)\n=> a)(1)", 5693 "((a)\n=> a)(1)",
5633 "((a)/*\n*/=> a)(1)", 5694 "((a)/*\n*/=> a)(1)",
5634 "((a, b)\n=> a + b)(1, 2)", 5695 "((a, b)\n=> a + b)(1, 2)",
5635 "((a, b)/*\n*/=> a + b)(1, 2)", 5696 "((a, b)/*\n*/=> a + b)(1, 2)",
5636 NULL}; 5697 NULL};
5637 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 5698 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
5638 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 5699 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
5639 arraysize(always_flags)); 5700 arraysize(always_flags));
5640 } 5701 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698