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 3947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3958 TEST(MethodDefinitionStrictFormalParamereters) { | 3958 TEST(MethodDefinitionStrictFormalParamereters) { |
3959 const char* context_data[][2] = {{"({method(", "){}});"}, | 3959 const char* context_data[][2] = {{"({method(", "){}});"}, |
3960 {"'use strict'; ({method(", "){}});"}, | 3960 {"'use strict'; ({method(", "){}});"}, |
3961 {"({*method(", "){}});"}, | 3961 {"({*method(", "){}});"}, |
3962 {"'use strict'; ({*method(", "){}});"}, | 3962 {"'use strict'; ({*method(", "){}});"}, |
3963 {NULL, NULL}}; | 3963 {NULL, NULL}}; |
3964 | 3964 |
3965 const char* params_data[] = { | 3965 const char* params_data[] = { |
3966 "x, x", | 3966 "x, x", |
3967 "x, y, x", | 3967 "x, y, x", |
3968 "eval", | |
3969 "arguments", | |
3970 "var", | 3968 "var", |
3971 "const", | 3969 "const", |
3972 NULL | 3970 NULL |
3973 }; | 3971 }; |
3974 | 3972 |
3975 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; | 3973 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; |
3976 RunParserSyncTest(context_data, params_data, kError, NULL, 0, | 3974 RunParserSyncTest(context_data, params_data, kError, NULL, 0, |
3977 always_flags, arraysize(always_flags)); | 3975 always_flags, arraysize(always_flags)); |
3978 } | 3976 } |
3979 | 3977 |
3980 | 3978 |
| 3979 TEST(MethodDefinitionEvalArguments) { |
| 3980 const char* strict_context_data[][2] = |
| 3981 {{"'use strict'; ({method(", "){}});"}, |
| 3982 {"'use strict'; ({*method(", "){}});"}, |
| 3983 {NULL, NULL}}; |
| 3984 const char* sloppy_context_data[][2] = |
| 3985 {{"({method(", "){}});"}, |
| 3986 {"({*method(", "){}});"}, |
| 3987 {NULL, NULL}}; |
| 3988 |
| 3989 const char* data[] = { |
| 3990 "eval", |
| 3991 "arguments", |
| 3992 NULL}; |
| 3993 |
| 3994 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; |
| 3995 |
| 3996 // Fail in strict mode |
| 3997 RunParserSyncTest(strict_context_data, data, kError, NULL, 0, always_flags, |
| 3998 arraysize(always_flags)); |
| 3999 |
| 4000 // OK in sloppy mode |
| 4001 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, |
| 4002 arraysize(always_flags)); |
| 4003 } |
| 4004 |
| 4005 |
| 4006 TEST(MethodDefinitionDuplicateEvalArguments) { |
| 4007 const char* context_data[][2] = |
| 4008 {{"'use strict'; ({method(", "){}});"}, |
| 4009 {"'use strict'; ({*method(", "){}});"}, |
| 4010 {"({method(", "){}});"}, |
| 4011 {"({*method(", "){}});"}, |
| 4012 {NULL, NULL}}; |
| 4013 |
| 4014 const char* data[] = { |
| 4015 "eval, eval", |
| 4016 "eval, a, eval", |
| 4017 "arguments, arguments", |
| 4018 "arguments, a, arguments", |
| 4019 NULL}; |
| 4020 |
| 4021 static const ParserFlag always_flags[] = {kAllowHarmonyObjectLiterals}; |
| 4022 |
| 4023 // In strict mode, the error is using "eval" or "arguments" as parameter names |
| 4024 // In sloppy mode, the error is that eval / arguments are duplicated |
| 4025 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4026 arraysize(always_flags)); |
| 4027 } |
| 4028 |
| 4029 |
3981 TEST(MethodDefinitionDuplicateProperty) { | 4030 TEST(MethodDefinitionDuplicateProperty) { |
3982 const char* context_data[][2] = {{"'use strict'; ({", "});"}, | 4031 const char* context_data[][2] = {{"'use strict'; ({", "});"}, |
3983 {NULL, NULL}}; | 4032 {NULL, NULL}}; |
3984 | 4033 |
3985 const char* params_data[] = { | 4034 const char* params_data[] = { |
3986 "x: 1, x() {}", | 4035 "x: 1, x() {}", |
3987 "x() {}, x: 1", | 4036 "x() {}, x: 1", |
3988 "x() {}, get x() {}", | 4037 "x() {}, get x() {}", |
3989 "x() {}, set x(_) {}", | 4038 "x() {}, set x(_) {}", |
3990 "x() {}, x() {}", | 4039 "x() {}, x() {}", |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4873 "a,\ta, ...args", | 4922 "a,\ta, ...args", |
4874 "a,\ra, ...args", | 4923 "a,\ra, ...args", |
4875 "a,\na, ...args", | 4924 "a,\na, ...args", |
4876 NULL}; | 4925 NULL}; |
4877 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; | 4926 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
4878 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 4927 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
4879 arraysize(always_flags)); | 4928 arraysize(always_flags)); |
4880 } | 4929 } |
4881 | 4930 |
4882 | 4931 |
| 4932 TEST(RestParametersEvalArguments) { |
| 4933 const char* strict_context_data[][2] = |
| 4934 {{"'use strict';(function(", |
| 4935 "){ return;})(1, [], /regexp/, 'str',function(){});"}, |
| 4936 {NULL, NULL}}; |
| 4937 const char* sloppy_context_data[][2] = |
| 4938 {{"(function(", |
| 4939 "){ return;})(1, [],/regexp/, 'str', function(){});"}, |
| 4940 {NULL, NULL}}; |
| 4941 |
| 4942 const char* data[] = { |
| 4943 "...eval", |
| 4944 "eval, ...args", |
| 4945 "...arguments", |
| 4946 "arguments, ...args", |
| 4947 NULL}; |
| 4948 |
| 4949 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
| 4950 |
| 4951 // Fail in strict mode |
| 4952 RunParserSyncTest(strict_context_data, data, kError, NULL, 0, always_flags, |
| 4953 arraysize(always_flags)); |
| 4954 |
| 4955 // OK in sloppy mode |
| 4956 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, |
| 4957 arraysize(always_flags)); |
| 4958 } |
| 4959 |
| 4960 |
| 4961 TEST(RestParametersDuplicateEvalArguments) { |
| 4962 const char* context_data[][2] = |
| 4963 {{"'use strict';(function(", |
| 4964 "){ return;})(1, [], /regexp/, 'str',function(){});"}, |
| 4965 {"(function(", |
| 4966 "){ return;})(1, [],/regexp/, 'str', function(){});"}, |
| 4967 {NULL, NULL}}; |
| 4968 |
| 4969 const char* data[] = { |
| 4970 "eval, ...eval", |
| 4971 "eval, eval, ...args", |
| 4972 "arguments, ...arguments", |
| 4973 "arguments, arguments, ...args", |
| 4974 NULL}; |
| 4975 |
| 4976 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; |
| 4977 |
| 4978 // In strict mode, the error is using "eval" or "arguments" as parameter names |
| 4979 // In sloppy mode, the error is that eval / arguments are duplicated |
| 4980 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 4981 arraysize(always_flags)); |
| 4982 } |
| 4983 |
| 4984 |
4883 TEST(LexicalScopingSloppyMode) { | 4985 TEST(LexicalScopingSloppyMode) { |
4884 const char* context_data[][2] = { | 4986 const char* context_data[][2] = { |
4885 {"", ""}, | 4987 {"", ""}, |
4886 {"function f() {", "}"}, | 4988 {"function f() {", "}"}, |
4887 {"{", "}"}, | 4989 {"{", "}"}, |
4888 {NULL, NULL}}; | 4990 {NULL, NULL}}; |
4889 const char* bad_data[] = { | 4991 const char* bad_data[] = { |
4890 "let x = 1;", | 4992 "let x = 1;", |
4891 "for(let x = 1;;){}", | 4993 "for(let x = 1;;){}", |
4892 "for(let x of []){}", | 4994 "for(let x of []){}", |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5310 "class C {static set arguments(_) {}}", | 5412 "class C {static set arguments(_) {}}", |
5311 | 5413 |
5312 NULL}; | 5414 NULL}; |
5313 | 5415 |
5314 static const ParserFlag always_flags[] = { | 5416 static const ParserFlag always_flags[] = { |
5315 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 5417 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, |
5316 kAllowStrongMode}; | 5418 kAllowStrongMode}; |
5317 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 5419 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
5318 always_flags, arraysize(always_flags)); | 5420 always_flags, arraysize(always_flags)); |
5319 } | 5421 } |
| 5422 |
| 5423 |
| 5424 TEST(FunctionLiteralDuplicateParameters) { |
| 5425 const char* strict_context_data[][2] = |
| 5426 {{"'use strict';(function(", "){})();"}, |
| 5427 {"(function(", ") { 'use strict'; })();"}, |
| 5428 {"'use strict'; function fn(", ") {}; fn();"}, |
| 5429 {"function fn(", ") { 'use strict'; }; fn();"}, |
| 5430 {"'use strong';(function(", "){})();"}, |
| 5431 {"(function(", ") { 'use strong'; })();"}, |
| 5432 {"'use strong'; function fn(", ") {}; fn();"}, |
| 5433 {"function fn(", ") { 'use strong'; }; fn();"}, |
| 5434 {NULL, NULL}}; |
| 5435 |
| 5436 const char* sloppy_context_data[][2] = |
| 5437 {{"(function(", "){})();"}, |
| 5438 {"(function(", ") {})();"}, |
| 5439 {"function fn(", ") {}; fn();"}, |
| 5440 {"function fn(", ") {}; fn();"}, |
| 5441 {NULL, NULL}}; |
| 5442 |
| 5443 const char* data[] = { |
| 5444 "a, a", |
| 5445 "a, a, a", |
| 5446 "b, a, a", |
| 5447 "a, b, c, c", |
| 5448 "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, w", |
| 5449 NULL}; |
| 5450 |
| 5451 static const ParserFlag always_flags[] = { kAllowStrongMode }; |
| 5452 RunParserSyncTest(strict_context_data, data, kError, NULL, 0, always_flags, |
| 5453 arraysize(always_flags)); |
| 5454 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, NULL, 0); |
| 5455 } |
OLD | NEW |