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 6907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6918 "for (let x of []) {}", | 6918 "for (let x of []) {}", |
6919 NULL | 6919 NULL |
6920 }; | 6920 }; |
6921 // clang-format on | 6921 // clang-format on |
6922 | 6922 |
6923 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, | 6923 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, |
6924 kAllowHarmonySloppyLet}; | 6924 kAllowHarmonySloppyLet}; |
6925 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, | 6925 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
6926 arraysize(always_flags)); | 6926 arraysize(always_flags)); |
6927 } | 6927 } |
| 6928 |
| 6929 |
| 6930 TEST(LanguageModeDirectivesNonSimpleParameterListErrors) { |
| 6931 // TC39 deemed "use strict" directives to be an error when occurring in the |
| 6932 // body of a function with non-simple parameter list, on 29/7/2015. |
| 6933 // https://goo.gl/ueA7Ln |
| 6934 // |
| 6935 // In V8, this also applies to "use strong " directives. |
| 6936 const char* context_data[][2] = { |
| 6937 {"function f(", ") { 'use strict'; }"}, |
| 6938 {"function f(", ") { 'use strong'; }"}, |
| 6939 {"function* g(", ") { 'use strict'; }"}, |
| 6940 {"function* g(", ") { 'use strong'; }"}, |
| 6941 {"class c { foo(", ") { 'use strict' }"}, |
| 6942 {"class c { foo(", ") { 'use strong' }"}, |
| 6943 {"var a = (", ") => { 'use strict'; }"}, |
| 6944 {"var a = (", ") => { 'use strong'; }"}, |
| 6945 {"var o = { m(", ") { 'use strict'; }"}, |
| 6946 {"var o = { m(", ") { 'use strong'; }"}, |
| 6947 {"var o = { *gm(", ") { 'use strict'; }"}, |
| 6948 {"var o = { *gm(", ") { 'use strong'; }"}, |
| 6949 {"var c = { m(", ") { 'use strict'; }"}, |
| 6950 {"var c = { m(", ") { 'use strong'; }"}, |
| 6951 {"var c = { *gm(", ") { 'use strict'; }"}, |
| 6952 {"var c = { *gm(", ") { 'use strong'; }"}, |
| 6953 |
| 6954 {"'use strict'; function f(", ") { 'use strict'; }"}, |
| 6955 {"'use strict'; function f(", ") { 'use strong'; }"}, |
| 6956 {"'use strict'; function* g(", ") { 'use strict'; }"}, |
| 6957 {"'use strict'; function* g(", ") { 'use strong'; }"}, |
| 6958 {"'use strict'; class c { foo(", ") { 'use strict' }"}, |
| 6959 {"'use strict'; class c { foo(", ") { 'use strong' }"}, |
| 6960 {"'use strict'; var a = (", ") => { 'use strict'; }"}, |
| 6961 {"'use strict'; var a = (", ") => { 'use strong'; }"}, |
| 6962 {"'use strict'; var o = { m(", ") { 'use strict'; }"}, |
| 6963 {"'use strict'; var o = { m(", ") { 'use strong'; }"}, |
| 6964 {"'use strict'; var o = { *gm(", ") { 'use strict'; }"}, |
| 6965 {"'use strict'; var o = { *gm(", ") { 'use strong'; }"}, |
| 6966 {"'use strict'; var c = { m(", ") { 'use strict'; }"}, |
| 6967 {"'use strict'; var c = { m(", ") { 'use strong'; }"}, |
| 6968 {"'use strict'; var c = { *gm(", ") { 'use strict'; }"}, |
| 6969 {"'use strict'; var c = { *gm(", ") { 'use strong'; }"}, |
| 6970 |
| 6971 {"'use strong'; function f(", ") { 'use strict'; }"}, |
| 6972 {"'use strong'; function f(", ") { 'use strong'; }"}, |
| 6973 {"'use strong'; function* g(", ") { 'use strict'; }"}, |
| 6974 {"'use strong'; function* g(", ") { 'use strong'; }"}, |
| 6975 {"'use strong'; class c { foo(", ") { 'use strict' }"}, |
| 6976 {"'use strong'; class c { foo(", ") { 'use strong' }"}, |
| 6977 {"'use strong'; var a = (", ") => { 'use strict'; }"}, |
| 6978 {"'use strong'; var a = (", ") => { 'use strong'; }"}, |
| 6979 {"'use strong'; var o = { m(", ") { 'use strict'; }"}, |
| 6980 {"'use strong'; var o = { m(", ") { 'use strong'; }"}, |
| 6981 {"'use strong'; var o = { *gm(", ") { 'use strict'; }"}, |
| 6982 {"'use strong'; var o = { *gm(", ") { 'use strong'; }"}, |
| 6983 {"'use strong'; var c = { m(", ") { 'use strict'; }"}, |
| 6984 {"'use strong'; var c = { m(", ") { 'use strong'; }"}, |
| 6985 {"'use strong'; var c = { *gm(", ") { 'use strict'; }"}, |
| 6986 {"'use strong'; var c = { *gm(", ") { 'use strong'; }"}, |
| 6987 |
| 6988 {NULL, NULL}}; |
| 6989 |
| 6990 const char* data[] = { |
| 6991 // TODO(@caitp): support formal parameter initializers |
| 6992 "{}", |
| 6993 "[]", |
| 6994 "[{}]", |
| 6995 "{a}", |
| 6996 "a, {b}", |
| 6997 "a, b, {c, d, e}", |
| 6998 "initializer = true", |
| 6999 "a, b, c = 1", |
| 7000 "...args", |
| 7001 "a, b, ...rest", |
| 7002 "[a, b, ...rest]", |
| 7003 "{ bindingPattern = {} }", |
| 7004 "{ initializedBindingPattern } = { initializedBindingPattern: true }", |
| 7005 NULL}; |
| 7006 |
| 7007 static const ParserFlag always_flags[] = { |
| 7008 kAllowHarmonyArrowFunctions, kAllowHarmonyDefaultParameters, |
| 7009 kAllowHarmonyDestructuring, kAllowHarmonyRestParameters, |
| 7010 kAllowHarmonySloppy, kAllowStrongMode |
| 7011 }; |
| 7012 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 7013 arraysize(always_flags)); |
| 7014 } |
OLD | NEW |