| OLD | NEW |
| 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 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 kAllowHarmonyModules, | 1381 kAllowHarmonyModules, |
| 1382 kAllowHarmonyNumericLiterals, | 1382 kAllowHarmonyNumericLiterals, |
| 1383 kAllowHarmonyArrowFunctions, | 1383 kAllowHarmonyArrowFunctions, |
| 1384 kAllowHarmonyClasses, | 1384 kAllowHarmonyClasses, |
| 1385 kAllowHarmonyObjectLiterals, | 1385 kAllowHarmonyObjectLiterals, |
| 1386 kAllowHarmonyRestParameters, | 1386 kAllowHarmonyRestParameters, |
| 1387 kAllowHarmonyTemplates, | 1387 kAllowHarmonyTemplates, |
| 1388 kAllowHarmonySloppy, | 1388 kAllowHarmonySloppy, |
| 1389 kAllowHarmonyUnicode, | 1389 kAllowHarmonyUnicode, |
| 1390 kAllowHarmonyComputedPropertyNames, | 1390 kAllowHarmonyComputedPropertyNames, |
| 1391 kAllowStrongMode | 1391 kAllowStrongMode, |
| 1392 kAllowHarmonySpreadCalls |
| 1392 }; | 1393 }; |
| 1393 | 1394 |
| 1394 | 1395 |
| 1395 enum ParserSyncTestResult { | 1396 enum ParserSyncTestResult { |
| 1396 kSuccessOrError, | 1397 kSuccessOrError, |
| 1397 kSuccess, | 1398 kSuccess, |
| 1398 kError | 1399 kError |
| 1399 }; | 1400 }; |
| 1400 | 1401 |
| 1401 template <typename Traits> | 1402 template <typename Traits> |
| 1402 void SetParserFlags(i::ParserBase<Traits>* parser, | 1403 void SetParserFlags(i::ParserBase<Traits>* parser, |
| 1403 i::EnumSet<ParserFlag> flags) { | 1404 i::EnumSet<ParserFlag> flags) { |
| 1404 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1405 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
| 1405 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1406 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
| 1406 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); | 1407 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); |
| 1407 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); | 1408 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); |
| 1408 parser->set_allow_harmony_numeric_literals( | 1409 parser->set_allow_harmony_numeric_literals( |
| 1409 flags.Contains(kAllowHarmonyNumericLiterals)); | 1410 flags.Contains(kAllowHarmonyNumericLiterals)); |
| 1410 parser->set_allow_harmony_object_literals( | 1411 parser->set_allow_harmony_object_literals( |
| 1411 flags.Contains(kAllowHarmonyObjectLiterals)); | 1412 flags.Contains(kAllowHarmonyObjectLiterals)); |
| 1412 parser->set_allow_harmony_arrow_functions( | 1413 parser->set_allow_harmony_arrow_functions( |
| 1413 flags.Contains(kAllowHarmonyArrowFunctions)); | 1414 flags.Contains(kAllowHarmonyArrowFunctions)); |
| 1414 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); | 1415 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); |
| 1415 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); | 1416 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); |
| 1416 parser->set_allow_harmony_rest_params( | 1417 parser->set_allow_harmony_rest_params( |
| 1417 flags.Contains(kAllowHarmonyRestParameters)); | 1418 flags.Contains(kAllowHarmonyRestParameters)); |
| 1419 parser->set_allow_harmony_spreadcalls( |
| 1420 flags.Contains(kAllowHarmonySpreadCalls)); |
| 1418 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1421 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
| 1419 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | 1422 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
| 1420 parser->set_allow_harmony_computed_property_names( | 1423 parser->set_allow_harmony_computed_property_names( |
| 1421 flags.Contains(kAllowHarmonyComputedPropertyNames)); | 1424 flags.Contains(kAllowHarmonyComputedPropertyNames)); |
| 1422 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); | 1425 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
| 1423 } | 1426 } |
| 1424 | 1427 |
| 1425 | 1428 |
| 1426 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1429 void TestParserSyncWithFlags(i::Handle<i::String> source, |
| 1427 i::EnumSet<ParserFlag> flags, | 1430 i::EnumSet<ParserFlag> flags, |
| (...skipping 3493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4921 | 4924 |
| 4922 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; | 4925 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
| 4923 | 4926 |
| 4924 // In strict mode, the error is using "eval" or "arguments" as parameter names | 4927 // In strict mode, the error is using "eval" or "arguments" as parameter names |
| 4925 // In sloppy mode, the error is that eval / arguments are duplicated | 4928 // In sloppy mode, the error is that eval / arguments are duplicated |
| 4926 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 4929 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4927 arraysize(always_flags)); | 4930 arraysize(always_flags)); |
| 4928 } | 4931 } |
| 4929 | 4932 |
| 4930 | 4933 |
| 4934 TEST(SpreadCall) { |
| 4935 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"}, |
| 4936 {"function fn() {} fn(", ");"}, |
| 4937 {NULL, NULL}}; |
| 4938 |
| 4939 const char* data[] = { |
| 4940 "...([1, 2, 3])", |
| 4941 "...'123', ...'456'", |
| 4942 "...new Set([1, 2, 3]), 4", |
| 4943 "1, ...[2, 3], 4", |
| 4944 "...Array(...[1,2,3,4])", |
| 4945 "...NaN", |
| 4946 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89'", |
| 4947 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89', 10", |
| 4948 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9", |
| 4949 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9, ...[10]", |
| 4950 NULL}; |
| 4951 |
| 4952 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; |
| 4953 |
| 4954 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4955 arraysize(always_flags)); |
| 4956 } |
| 4957 |
| 4958 |
| 4959 TEST(SpreadCallErrors) { |
| 4960 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"}, |
| 4961 {"function fn() {} fn(", ");"}, |
| 4962 {NULL, NULL}}; |
| 4963 |
| 4964 const char* data[] = { |
| 4965 "(...[1, 2, 3])", |
| 4966 "......[1,2,3]", |
| 4967 NULL}; |
| 4968 |
| 4969 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; |
| 4970 |
| 4971 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4972 arraysize(always_flags)); |
| 4973 } |
| 4974 |
| 4975 |
| 4976 TEST(BadRestSpread) { |
| 4977 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"}, |
| 4978 {"function fn() { ", "} fn();" }, |
| 4979 {NULL, NULL}}; |
| 4980 const char* data[] = { |
| 4981 "return ...[1,2,3];", |
| 4982 "var ...x = [1,2,3];", |
| 4983 "var [...x,] = [1,2,3];", |
| 4984 "var [...x, y] = [1,2,3];", |
| 4985 "var {...x} = [1,2,3];", |
| 4986 "var { x } = {x: ...[1,2,3]}", |
| 4987 NULL}; |
| 4988 RunParserSyncTest(context_data, data, kError, NULL, 0, NULL, 0); |
| 4989 } |
| 4990 |
| 4991 |
| 4931 TEST(LexicalScopingSloppyMode) { | 4992 TEST(LexicalScopingSloppyMode) { |
| 4932 const char* context_data[][2] = { | 4993 const char* context_data[][2] = { |
| 4933 {"", ""}, | 4994 {"", ""}, |
| 4934 {"function f() {", "}"}, | 4995 {"function f() {", "}"}, |
| 4935 {"{", "}"}, | 4996 {"{", "}"}, |
| 4936 {NULL, NULL}}; | 4997 {NULL, NULL}}; |
| 4937 const char* bad_data[] = { | 4998 const char* bad_data[] = { |
| 4938 "let x = 1;", | 4999 "let x = 1;", |
| 4939 "for(let x = 1;;){}", | 5000 "for(let x = 1;;){}", |
| 4940 "for(let x of []){}", | 5001 "for(let x of []){}", |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5504 static const ParserFlag always_flags[] = { | 5565 static const ParserFlag always_flags[] = { |
| 5505 kAllowStrongMode, kAllowHarmonyScoping | 5566 kAllowStrongMode, kAllowHarmonyScoping |
| 5506 }; | 5567 }; |
| 5507 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, | 5568 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, |
| 5508 arraysize(always_flags)); | 5569 arraysize(always_flags)); |
| 5509 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5570 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, |
| 5510 arraysize(always_flags)); | 5571 arraysize(always_flags)); |
| 5511 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5572 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, |
| 5512 arraysize(always_flags)); | 5573 arraysize(always_flags)); |
| 5513 } | 5574 } |
| OLD | NEW |