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 5787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5798 RunParserSyncTest(sloppy_context_data, let_declarations, kError, NULL, 0, | 5798 RunParserSyncTest(sloppy_context_data, let_declarations, kError, NULL, 0, |
5799 always_flags, arraysize(always_flags)); | 5799 always_flags, arraysize(always_flags)); |
5800 } | 5800 } |
5801 | 5801 |
5802 | 5802 |
5803 TEST(StrongEmptySubStatements) { | 5803 TEST(StrongEmptySubStatements) { |
5804 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; | 5804 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; |
5805 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; | 5805 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; |
5806 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; | 5806 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; |
5807 | 5807 |
5808 const char* data[] = { | 5808 const char* data_error[] = { |
5809 "if (1);", | 5809 "if (1);", |
5810 "if (1) {} else;", | 5810 "if (1) {} else;", |
5811 "while (1);", | 5811 "while (1);", |
5812 "do; while (1);", | 5812 "do; while (1);", |
5813 "for (;;);", | 5813 "for (;;);", |
5814 "for (x in []);", | 5814 "for (x in []);", |
5815 "for (x of []);", | 5815 "for (x of []);", |
5816 "for (const x = 0;;);", | 5816 "for (const x = 0;;);", |
5817 "for (const x in []);", | 5817 "for (const x in []);", |
5818 "for (const x of []);", | 5818 "for (const x of []);", |
5819 NULL}; | 5819 NULL}; |
5820 | 5820 |
| 5821 const char* data_success[] = { |
| 5822 "if (1) {} else {}", |
| 5823 "switch(1) {}", |
| 5824 "1+1;;", |
| 5825 "1+1; ;", |
| 5826 NULL}; |
| 5827 |
5821 static const ParserFlag always_flags[] = { | 5828 static const ParserFlag always_flags[] = { |
5822 kAllowStrongMode, | 5829 kAllowStrongMode, |
5823 }; | 5830 }; |
5824 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, | 5831 RunParserSyncTest(sloppy_context_data, data_error, kSuccess, NULL, 0, |
5825 arraysize(always_flags)); | 5832 always_flags, arraysize(always_flags)); |
5826 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5833 RunParserSyncTest(strict_context_data, data_error, kSuccess, NULL, 0, |
5827 arraysize(always_flags)); | 5834 always_flags, arraysize(always_flags)); |
5828 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5835 RunParserSyncTest(strong_context_data, data_error, kError, NULL, 0, |
5829 arraysize(always_flags)); | 5836 always_flags, arraysize(always_flags)); |
| 5837 RunParserSyncTest(strong_context_data, data_success, kSuccess, NULL, 0, |
| 5838 always_flags, arraysize(always_flags)); |
5830 } | 5839 } |
5831 | 5840 |
5832 | 5841 |
5833 TEST(StrongForIn) { | 5842 TEST(StrongForIn) { |
5834 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; | 5843 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; |
5835 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; | 5844 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; |
5836 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; | 5845 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; |
5837 | 5846 |
5838 const char* data[] = { | 5847 const char* data[] = { |
5839 "for (x in []) {}", | 5848 "for (x in []) {}", |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5968 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5977 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, |
5969 arraysize(always_flags)); | 5978 arraysize(always_flags)); |
5970 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5979 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, |
5971 arraysize(always_flags)); | 5980 arraysize(always_flags)); |
5972 RunParserSyncTest(sloppy_context_data, local_strong, kError, NULL, 0, | 5981 RunParserSyncTest(sloppy_context_data, local_strong, kError, NULL, 0, |
5973 always_flags, arraysize(always_flags)); | 5982 always_flags, arraysize(always_flags)); |
5974 } | 5983 } |
5975 | 5984 |
5976 | 5985 |
5977 TEST(StrongDirectEval) { | 5986 TEST(StrongDirectEval) { |
5978 const char* context_data[][2] = {{"", ""}, {NULL}}; | 5987 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; |
| 5988 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; |
5979 | 5989 |
5980 const char* error_data[] = { | 5990 const char* error_data[] = { |
5981 "'use strong'; eval();", | 5991 "eval();", |
5982 "'use strong'; eval([]);", | 5992 "eval([]);", |
5983 "'use strong'; (eval)();", | 5993 "(eval)();", |
5984 "'use strong'; (((eval)))();", | 5994 "(((eval)))();", |
5985 "'use strong'; eval('function f() {}');", | 5995 "eval('function f() {}');", |
5986 "'use strong'; function f() {eval()}", | 5996 "function f() {eval()}", |
5987 NULL}; | 5997 NULL}; |
5988 | 5998 |
5989 const char* success_data[] = { | 5999 const char* success_data[] = { |
5990 "'use strong'; eval;", | 6000 "eval;", |
5991 "'use strong'; eval`foo`;", | 6001 "eval`foo`;", |
5992 "'use strong'; let foo = eval; foo();", | 6002 "let foo = eval; foo();", |
5993 "'use strong'; (1, eval)();", | 6003 "(1, eval)();", |
5994 NULL}; | 6004 NULL}; |
5995 | 6005 |
5996 static const ParserFlag always_flags[] = { | 6006 static const ParserFlag always_flags[] = { |
5997 kAllowStrongMode | 6007 kAllowStrongMode |
5998 }; | 6008 }; |
5999 | 6009 |
6000 RunParserSyncTest(context_data, error_data, kError, NULL, 0, | 6010 RunParserSyncTest(sloppy_context_data, error_data, kSuccess, NULL, 0, |
6001 always_flags, arraysize(always_flags)); | 6011 always_flags, arraysize(always_flags)); |
6002 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, | 6012 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, |
| 6013 always_flags, arraysize(always_flags)); |
| 6014 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0, |
6003 always_flags, arraysize(always_flags)); | 6015 always_flags, arraysize(always_flags)); |
6004 } | 6016 } |
6005 | 6017 |
| 6018 |
| 6019 TEST(StrongSwitchFallthrough) { |
| 6020 const char* sloppy_context_data[][2] = { |
| 6021 {"function f() { foo:for(;;) { switch(1) {", "};}}"}, |
| 6022 {NULL, NULL} |
| 6023 }; |
| 6024 const char* strong_context_data[][2] = { |
| 6025 {"function f() { 'use strong'; foo:for(;;) { switch(1) {", "};}}"}, |
| 6026 {NULL, NULL} |
| 6027 }; |
| 6028 |
| 6029 const char* data_success[] = { |
| 6030 "", |
| 6031 "case 1:", |
| 6032 "case 1: case 2:", |
| 6033 "case 1: break;", |
| 6034 "default: throw new TypeError();", |
| 6035 "case 1: case 2: null", |
| 6036 "case 1: case 2: default: 1+1", |
| 6037 "case 1: break; case 2: return; default:", |
| 6038 "case 1: break foo; case 2: return; default:", |
| 6039 "case 1: case 2: break; case 3: continue; case 4: default:", |
| 6040 "case 1: case 2: break; case 3: continue foo; case 4: default:", |
| 6041 "case 1: case 2: {{return;}} case 3: default:", |
| 6042 "case 1: case 2: case 3: default: {1+1;{continue;}}", |
| 6043 "case 1: case 2: {1+1;{1+1;{continue;}}} case 3: default:", |
| 6044 "case 1: if (1) break; else continue; case 2: case 3: default:", |
| 6045 "case 1: case 2: if (1) {{break;}} else break; case 3: default:", |
| 6046 "case 1: if (1) break; else {if (1) break; else break;} case 2: default:", |
| 6047 "case 1: if (1) {if (1) break; else break;} else break; case 2: default:", |
| 6048 NULL}; |
| 6049 |
| 6050 const char* data_error[] = { |
| 6051 "case 1: case 2: (function(){return}); default:", |
| 6052 "case 1: 1+1; case 2:", |
| 6053 "case 1: bar: break bar; case 2: break;", |
| 6054 "case 1: bar:return; case 2:", |
| 6055 "case 1: bar:{ continue;} case 2:", |
| 6056 "case 1: break; case 2: bar:{ throw new TypeError() } default:", |
| 6057 "case 1: case 2: { bar:{ { break;} } } default: break;", |
| 6058 "case 1: if (1) break; else {}; case 2: default:", |
| 6059 "case 1: case 2: if (1) break; default:", |
| 6060 "case 1: case 2: if (1) break; else 0; default:", |
| 6061 "case 1: case 2: if (1) 0; else break; default:", |
| 6062 "case 1: case 2: case 3: if (1) {} default:", |
| 6063 "case 1: bar:if (1) break; else continue; case 2: case 3: default:", |
| 6064 NULL}; |
| 6065 |
| 6066 static const ParserFlag always_flags[] = { |
| 6067 kAllowStrongMode |
| 6068 }; |
| 6069 RunParserSyncTest(strong_context_data, data_success, kSuccess, NULL, 0, |
| 6070 always_flags, arraysize(always_flags)); |
| 6071 RunParserSyncTest(sloppy_context_data, data_error, kSuccess, NULL, 0, |
| 6072 always_flags, arraysize(always_flags)); |
| 6073 RunParserSyncTest(strong_context_data, data_error, kError, NULL, 0, |
| 6074 always_flags, arraysize(always_flags)); |
| 6075 } |
| 6076 |
6006 | 6077 |
6007 TEST(ArrowFunctionASIErrors) { | 6078 TEST(ArrowFunctionASIErrors) { |
6008 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, | 6079 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, |
6009 {NULL, NULL}}; | 6080 {NULL, NULL}}; |
6010 | 6081 |
6011 const char* data[] = { | 6082 const char* data[] = { |
6012 "(a\n=> a)(1)", | 6083 "(a\n=> a)(1)", |
6013 "(a/*\n*/=> a)(1)", | 6084 "(a/*\n*/=> a)(1)", |
6014 "((a)\n=> a)(1)", | 6085 "((a)\n=> a)(1)", |
6015 "((a)/*\n*/=> a)(1)", | 6086 "((a)/*\n*/=> a)(1)", |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6163 v8::Script::Compile(v8_str(script3)); | 6234 v8::Script::Compile(v8_str(script3)); |
6164 CHECK(try_catch2.HasCaught()); | 6235 CHECK(try_catch2.HasCaught()); |
6165 v8::String::Utf8Value exception(try_catch2.Exception()); | 6236 v8::String::Utf8Value exception(try_catch2.Exception()); |
6166 CHECK_EQ(0, | 6237 CHECK_EQ(0, |
6167 strcmp( | 6238 strcmp( |
6168 "ReferenceError: In strong mode, using an undeclared global " | 6239 "ReferenceError: In strong mode, using an undeclared global " |
6169 "variable 'not_there3' is not allowed", | 6240 "variable 'not_there3' is not allowed", |
6170 *exception)); | 6241 *exception)); |
6171 } | 6242 } |
6172 } | 6243 } |
OLD | NEW |