Chromium Code Reviews| 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() { for(;;) { switch(1) {", "};}}"}, | |
| 6022 {NULL, NULL} | |
| 6023 }; | |
| 6024 const char* strong_context_data[][2] = { | |
| 6025 {"function f() { 'use strong'; 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: case 2: break; case 3: continue; case 4: default:", | |
| 6039 "case 1: case 2: {{return;}} case 3: default:", | |
| 6040 "case 1: case 2: case 3: default: {1+1;{continue;}}", | |
| 6041 "case 1: case 2: {1+1;{1+1;{continue;}}} case 3: default:", | |
| 6042 "case 1: if (1) break; else continue; case 2: case 3: default:", | |
| 6043 "case 1: case 2: if (1) {{break;}} else break; case 3: default:", | |
| 6044 NULL}; | |
|
rossberg
2015/04/16 12:01:16
Can you add cases with break/continue to label, e.
conradw
2015/04/16 12:34:20
Done.
| |
| 6045 | |
| 6046 const char* data_error[] = { | |
| 6047 "case 1: case 2: (function(){return}); default:", | |
| 6048 "case 1: 1+1; case 2:", | |
| 6049 "case 1: foo: break foo; case 2: break;", | |
| 6050 "case 1: foo:return; case 2:", | |
| 6051 "case 1: foo:{ continue;} case 2:", | |
| 6052 "case 1: break; case 2: foo:{ throw new TypeError() } default:", | |
| 6053 "case 1: case 2: { foo:{ { break;} } } default: break;", | |
| 6054 "case 1: if (1) break; else {}; case 2: default:", | |
| 6055 "case 1: case 2: if (1) break; default:", | |
|
rossberg
2015/04/16 12:01:16
Also add
if (1) break else 0
if (1) 0 else br
conradw
2015/04/16 12:34:20
Done.
| |
| 6056 "case 1: case 2: case 3: if (1) {} default:", | |
| 6057 "case 1: foo:if (1) break; else continue; case 2: case 3: default:", | |
| 6058 NULL}; | |
| 6059 | |
| 6060 static const ParserFlag always_flags[] = { | |
| 6061 kAllowStrongMode | |
| 6062 }; | |
| 6063 RunParserSyncTest(strong_context_data, data_success, kSuccess, NULL, 0, | |
| 6064 always_flags, arraysize(always_flags)); | |
| 6065 RunParserSyncTest(sloppy_context_data, data_error, kSuccess, NULL, 0, | |
| 6066 always_flags, arraysize(always_flags)); | |
| 6067 RunParserSyncTest(strong_context_data, data_error, kError, NULL, 0, | |
| 6068 always_flags, arraysize(always_flags)); | |
| 6069 } | |
| 6070 | |
| 6006 | 6071 |
| 6007 TEST(ArrowFunctionASIErrors) { | 6072 TEST(ArrowFunctionASIErrors) { |
| 6008 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, | 6073 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, |
| 6009 {NULL, NULL}}; | 6074 {NULL, NULL}}; |
| 6010 | 6075 |
| 6011 const char* data[] = { | 6076 const char* data[] = { |
| 6012 "(a\n=> a)(1)", | 6077 "(a\n=> a)(1)", |
| 6013 "(a/*\n*/=> a)(1)", | 6078 "(a/*\n*/=> a)(1)", |
| 6014 "((a)\n=> a)(1)", | 6079 "((a)\n=> a)(1)", |
| 6015 "((a)/*\n*/=> a)(1)", | 6080 "((a)/*\n*/=> a)(1)", |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6163 v8::Script::Compile(v8_str(script3)); | 6228 v8::Script::Compile(v8_str(script3)); |
| 6164 CHECK(try_catch2.HasCaught()); | 6229 CHECK(try_catch2.HasCaught()); |
| 6165 v8::String::Utf8Value exception(try_catch2.Exception()); | 6230 v8::String::Utf8Value exception(try_catch2.Exception()); |
| 6166 CHECK_EQ(0, | 6231 CHECK_EQ(0, |
| 6167 strcmp( | 6232 strcmp( |
| 6168 "ReferenceError: In strong mode, using an undeclared global " | 6233 "ReferenceError: In strong mode, using an undeclared global " |
| 6169 "variable 'not_there3' is not allowed", | 6234 "variable 'not_there3' is not allowed", |
| 6170 *exception)); | 6235 *exception)); |
| 6171 } | 6236 } |
| 6172 } | 6237 } |
| OLD | NEW |