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