| 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 3526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4942 | 4945 |
| 4943 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; | 4946 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
| 4944 | 4947 |
| 4945 // In strict mode, the error is using "eval" or "arguments" as parameter names | 4948 // In strict mode, the error is using "eval" or "arguments" as parameter names |
| 4946 // In sloppy mode, the error is that eval / arguments are duplicated | 4949 // In sloppy mode, the error is that eval / arguments are duplicated |
| 4947 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 4950 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4948 arraysize(always_flags)); | 4951 arraysize(always_flags)); |
| 4949 } | 4952 } |
| 4950 | 4953 |
| 4951 | 4954 |
| 4955 TEST(SpreadCall) { |
| 4956 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"}, |
| 4957 {"function fn() {} fn(", ");"}, |
| 4958 {NULL, NULL}}; |
| 4959 |
| 4960 const char* data[] = { |
| 4961 "...([1, 2, 3])", |
| 4962 "...'123', ...'456'", |
| 4963 "...new Set([1, 2, 3]), 4", |
| 4964 "1, ...[2, 3], 4", |
| 4965 "...Array(...[1,2,3,4])", |
| 4966 "...NaN", |
| 4967 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89'", |
| 4968 "0, 1, ...[2, 3, 4], 5, 6, 7, ...'89', 10", |
| 4969 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9", |
| 4970 "...[0, 1, 2], 3, 4, 5, 6, ...'7', 8, 9, ...[10]", |
| 4971 NULL}; |
| 4972 |
| 4973 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; |
| 4974 |
| 4975 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| 4976 arraysize(always_flags)); |
| 4977 } |
| 4978 |
| 4979 |
| 4980 TEST(SpreadCallErrors) { |
| 4981 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"}, |
| 4982 {"function fn() {} fn(", ");"}, |
| 4983 {NULL, NULL}}; |
| 4984 |
| 4985 const char* data[] = { |
| 4986 "(...[1, 2, 3])", |
| 4987 "......[1,2,3]", |
| 4988 NULL}; |
| 4989 |
| 4990 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls}; |
| 4991 |
| 4992 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4993 arraysize(always_flags)); |
| 4994 } |
| 4995 |
| 4996 |
| 4997 TEST(BadRestSpread) { |
| 4998 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"}, |
| 4999 {"function fn() { ", "} fn();" }, |
| 5000 {NULL, NULL}}; |
| 5001 const char* data[] = { |
| 5002 "return ...[1,2,3];", |
| 5003 "var ...x = [1,2,3];", |
| 5004 "var [...x,] = [1,2,3];", |
| 5005 "var [...x, y] = [1,2,3];", |
| 5006 "var {...x} = [1,2,3];", |
| 5007 "var { x } = {x: ...[1,2,3]}", |
| 5008 NULL}; |
| 5009 RunParserSyncTest(context_data, data, kError, NULL, 0, NULL, 0); |
| 5010 } |
| 5011 |
| 5012 |
| 4952 TEST(LexicalScopingSloppyMode) { | 5013 TEST(LexicalScopingSloppyMode) { |
| 4953 const char* context_data[][2] = { | 5014 const char* context_data[][2] = { |
| 4954 {"", ""}, | 5015 {"", ""}, |
| 4955 {"function f() {", "}"}, | 5016 {"function f() {", "}"}, |
| 4956 {"{", "}"}, | 5017 {"{", "}"}, |
| 4957 {NULL, NULL}}; | 5018 {NULL, NULL}}; |
| 4958 const char* bad_data[] = { | 5019 const char* bad_data[] = { |
| 4959 "let x = 1;", | 5020 "let x = 1;", |
| 4960 "for(let x = 1;;){}", | 5021 "for(let x = 1;;){}", |
| 4961 "for(let x of []){}", | 5022 "for(let x of []){}", |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5795 v8::Script::Compile(v8_str(script3)); | 5856 v8::Script::Compile(v8_str(script3)); |
| 5796 CHECK(try_catch2.HasCaught()); | 5857 CHECK(try_catch2.HasCaught()); |
| 5797 v8::String::Utf8Value exception(try_catch2.Exception()); | 5858 v8::String::Utf8Value exception(try_catch2.Exception()); |
| 5798 CHECK_EQ(0, | 5859 CHECK_EQ(0, |
| 5799 strcmp( | 5860 strcmp( |
| 5800 "ReferenceError: In strong mode, using an undeclared global " | 5861 "ReferenceError: In strong mode, using an undeclared global " |
| 5801 "variable 'not_there3' is not allowed", | 5862 "variable 'not_there3' is not allowed", |
| 5802 *exception)); | 5863 *exception)); |
| 5803 } | 5864 } |
| 5804 } | 5865 } |
| OLD | NEW |