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 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 kAllowLazy, | 1373 kAllowLazy, |
1374 kAllowNatives, | 1374 kAllowNatives, |
1375 kAllowHarmonyModules, | 1375 kAllowHarmonyModules, |
1376 kAllowHarmonyArrowFunctions, | 1376 kAllowHarmonyArrowFunctions, |
1377 kAllowHarmonyClasses, | 1377 kAllowHarmonyClasses, |
1378 kAllowHarmonyObjectLiterals, | 1378 kAllowHarmonyObjectLiterals, |
1379 kAllowHarmonyRestParameters, | 1379 kAllowHarmonyRestParameters, |
1380 kAllowHarmonySloppy, | 1380 kAllowHarmonySloppy, |
1381 kAllowHarmonyUnicode, | 1381 kAllowHarmonyUnicode, |
1382 kAllowHarmonyComputedPropertyNames, | 1382 kAllowHarmonyComputedPropertyNames, |
1383 kAllowStrongMode | 1383 kAllowStrongMode, |
| 1384 kAllowHarmonySpreadCalls |
1384 }; | 1385 }; |
1385 | 1386 |
1386 | 1387 |
1387 enum ParserSyncTestResult { | 1388 enum ParserSyncTestResult { |
1388 kSuccessOrError, | 1389 kSuccessOrError, |
1389 kSuccess, | 1390 kSuccess, |
1390 kError | 1391 kError |
1391 }; | 1392 }; |
1392 | 1393 |
1393 template <typename Traits> | 1394 template <typename Traits> |
1394 void SetParserFlags(i::ParserBase<Traits>* parser, | 1395 void SetParserFlags(i::ParserBase<Traits>* parser, |
1395 i::EnumSet<ParserFlag> flags) { | 1396 i::EnumSet<ParserFlag> flags) { |
1396 parser->set_allow_lazy(flags.Contains(kAllowLazy)); | 1397 parser->set_allow_lazy(flags.Contains(kAllowLazy)); |
1397 parser->set_allow_natives(flags.Contains(kAllowNatives)); | 1398 parser->set_allow_natives(flags.Contains(kAllowNatives)); |
1398 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); | 1399 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); |
1399 parser->set_allow_harmony_object_literals( | 1400 parser->set_allow_harmony_object_literals( |
1400 flags.Contains(kAllowHarmonyObjectLiterals)); | 1401 flags.Contains(kAllowHarmonyObjectLiterals)); |
1401 parser->set_allow_harmony_arrow_functions( | 1402 parser->set_allow_harmony_arrow_functions( |
1402 flags.Contains(kAllowHarmonyArrowFunctions)); | 1403 flags.Contains(kAllowHarmonyArrowFunctions)); |
1403 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); | 1404 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); |
1404 parser->set_allow_harmony_rest_params( | 1405 parser->set_allow_harmony_rest_params( |
1405 flags.Contains(kAllowHarmonyRestParameters)); | 1406 flags.Contains(kAllowHarmonyRestParameters)); |
| 1407 parser->set_allow_harmony_spreadcalls( |
| 1408 flags.Contains(kAllowHarmonySpreadCalls)); |
1406 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); | 1409 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); |
1407 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); | 1410 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode)); |
1408 parser->set_allow_harmony_computed_property_names( | 1411 parser->set_allow_harmony_computed_property_names( |
1409 flags.Contains(kAllowHarmonyComputedPropertyNames)); | 1412 flags.Contains(kAllowHarmonyComputedPropertyNames)); |
1410 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); | 1413 parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode)); |
1411 } | 1414 } |
1412 | 1415 |
1413 | 1416 |
1414 void TestParserSyncWithFlags(i::Handle<i::String> source, | 1417 void TestParserSyncWithFlags(i::Handle<i::String> source, |
1415 i::EnumSet<ParserFlag> flags, | 1418 i::EnumSet<ParserFlag> flags, |
(...skipping 3681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5097 | 5100 |
5098 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; | 5101 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
5099 | 5102 |
5100 // In strict mode, the error is using "eval" or "arguments" as parameter names | 5103 // In strict mode, the error is using "eval" or "arguments" as parameter names |
5101 // In sloppy mode, the error is that eval / arguments are duplicated | 5104 // In sloppy mode, the error is that eval / arguments are duplicated |
5102 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 5105 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
5103 arraysize(always_flags)); | 5106 arraysize(always_flags)); |
5104 } | 5107 } |
5105 | 5108 |
5106 | 5109 |
| 5110 TEST(SpreadCall) { |
| 5111 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"}, |
| 5112 {"function fn() {} fn(", ");"}, |
| 5113 {NULL, NULL}}; |
| 5114 |
| 5115 const char* data[] = { |
| 5116 "...([1, 2, 3])", "...'123', ...'456'", "...new Set([1, 2, 3]), 4", |
| 5117 "1, ...[2, 3], 4", "...Array(...[1,2,3,4])", "...NaN", |
| 5118 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89'", |
| 5119 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89', 10", |
| 5120 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9", |
| 5121 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9, ...[10]", NULL}; |
| 5122 |
| 5123 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; |
| 5124 |
| 5125 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 5126 arraysize(always_flags)); |
| 5127 } |
| 5128 |
| 5129 |
| 5130 TEST(SpreadCallErrors) { |
| 5131 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"}, |
| 5132 {"function fn() {} fn(", ");"}, |
| 5133 {NULL, NULL}}; |
| 5134 |
| 5135 const char* data[] = {"(...[1, 2, 3])", "......[1,2,3]", NULL}; |
| 5136 |
| 5137 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; |
| 5138 |
| 5139 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 5140 arraysize(always_flags)); |
| 5141 } |
| 5142 |
| 5143 |
| 5144 TEST(BadRestSpread) { |
| 5145 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"}, |
| 5146 {"function fn() { ", "} fn();"}, |
| 5147 {NULL, NULL}}; |
| 5148 const char* data[] = {"return ...[1,2,3];", "var ...x = [1,2,3];", |
| 5149 "var [...x,] = [1,2,3];", "var [...x, y] = [1,2,3];", |
| 5150 "var {...x} = [1,2,3];", "var { x } = {x: ...[1,2,3]}", |
| 5151 NULL}; |
| 5152 RunParserSyncTest(context_data, data, kError, NULL, 0, NULL, 0); |
| 5153 } |
| 5154 |
| 5155 |
5107 TEST(LexicalScopingSloppyMode) { | 5156 TEST(LexicalScopingSloppyMode) { |
5108 const char* context_data[][2] = { | 5157 const char* context_data[][2] = { |
5109 {"", ""}, | 5158 {"", ""}, |
5110 {"function f() {", "}"}, | 5159 {"function f() {", "}"}, |
5111 {"{", "}"}, | 5160 {"{", "}"}, |
5112 {NULL, NULL}}; | 5161 {NULL, NULL}}; |
5113 const char* bad_data[] = { | 5162 const char* bad_data[] = { |
5114 "let x = 1;", | 5163 "let x = 1;", |
5115 "for(let x = 1;;){}", | 5164 "for(let x = 1;;){}", |
5116 "for(let x of []){}", | 5165 "for(let x of []){}", |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5950 v8::Script::Compile(v8_str(script3)); | 5999 v8::Script::Compile(v8_str(script3)); |
5951 CHECK(try_catch2.HasCaught()); | 6000 CHECK(try_catch2.HasCaught()); |
5952 v8::String::Utf8Value exception(try_catch2.Exception()); | 6001 v8::String::Utf8Value exception(try_catch2.Exception()); |
5953 CHECK_EQ(0, | 6002 CHECK_EQ(0, |
5954 strcmp( | 6003 strcmp( |
5955 "ReferenceError: In strong mode, using an undeclared global " | 6004 "ReferenceError: In strong mode, using an undeclared global " |
5956 "variable 'not_there3' is not allowed", | 6005 "variable 'not_there3' is not allowed", |
5957 *exception)); | 6006 *exception)); |
5958 } | 6007 } |
5959 } | 6008 } |
OLD | NEW |