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 5957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5968 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5968 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, |
5969 arraysize(always_flags)); | 5969 arraysize(always_flags)); |
5970 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5970 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, |
5971 arraysize(always_flags)); | 5971 arraysize(always_flags)); |
5972 RunParserSyncTest(sloppy_context_data, local_strong, kError, NULL, 0, | 5972 RunParserSyncTest(sloppy_context_data, local_strong, kError, NULL, 0, |
5973 always_flags, arraysize(always_flags)); | 5973 always_flags, arraysize(always_flags)); |
5974 } | 5974 } |
5975 | 5975 |
5976 | 5976 |
5977 TEST(StrongDirectEval) { | 5977 TEST(StrongDirectEval) { |
5978 const char* context_data[][2] = {{"", ""}, {NULL}}; | 5978 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; |
| 5979 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; |
5979 | 5980 |
5980 const char* error_data[] = { | 5981 const char* error_data[] = { |
5981 "'use strong'; eval();", | 5982 "eval();", |
5982 "'use strong'; eval([]);", | 5983 "eval([]);", |
5983 "'use strong'; (eval)();", | 5984 "(eval)();", |
5984 "'use strong'; (((eval)))();", | 5985 "(((eval)))();", |
5985 "'use strong'; eval('function f() {}');", | 5986 "eval('function f() {}');", |
5986 "'use strong'; function f() {eval()}", | 5987 "function f() {eval()}", |
5987 NULL}; | 5988 NULL}; |
5988 | 5989 |
5989 const char* success_data[] = { | 5990 const char* success_data[] = { |
5990 "'use strong'; eval;", | 5991 "eval;", |
5991 "'use strong'; eval`foo`;", | 5992 "eval`foo`;", |
5992 "'use strong'; let foo = eval; foo();", | 5993 "let foo = eval; foo();", |
5993 "'use strong'; (1, eval)();", | 5994 "(1, eval)();", |
5994 NULL}; | 5995 NULL}; |
5995 | 5996 |
5996 static const ParserFlag always_flags[] = { | 5997 static const ParserFlag always_flags[] = { |
5997 kAllowStrongMode | 5998 kAllowStrongMode |
5998 }; | 5999 }; |
5999 | 6000 |
6000 RunParserSyncTest(context_data, error_data, kError, NULL, 0, | 6001 RunParserSyncTest(sloppy_context_data, error_data, kSuccess, NULL, 0, |
6001 always_flags, arraysize(always_flags)); | 6002 always_flags, arraysize(always_flags)); |
6002 RunParserSyncTest(context_data, success_data, kSuccess, NULL, 0, | 6003 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, |
| 6004 always_flags, arraysize(always_flags)); |
| 6005 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0, |
6003 always_flags, arraysize(always_flags)); | 6006 always_flags, arraysize(always_flags)); |
6004 } | 6007 } |
6005 | 6008 |
| 6009 |
| 6010 TEST(StrongSwitchTerminators) { |
| 6011 const char* sloppy_context_data[][2] = { |
| 6012 {"function f() { for(;;) { switch(1) {", "};}}"}, |
| 6013 {NULL, NULL} |
| 6014 }; |
| 6015 const char* strong_context_data[][2] = { |
| 6016 {"function f() { 'use strong'; for(;;) { switch(1) {", "};}}"}, |
| 6017 {NULL, NULL} |
| 6018 }; |
| 6019 |
| 6020 const char* data_success[] = { |
| 6021 "", |
| 6022 "case 1:", |
| 6023 "case 1: case 2:", |
| 6024 "case 1: break;", |
| 6025 "default: throw new TypeError();", |
| 6026 "case 1: break; case 2: return; default:", |
| 6027 "case 1: case 2: break; case 3: continue; case 4: default:", |
| 6028 "case 1: case 2: {{return;}} case 3: default:", |
| 6029 "case 1: case 2: case 3: default: {1+1;{continue;}}", |
| 6030 "case 1: case 2: {1+1;{1+1;{continue;}}} case 3: default:", |
| 6031 NULL}; |
| 6032 |
| 6033 const char* data_error[] = { |
| 6034 "case 1: 1+1; case 2:", |
| 6035 "case 1: foo: break foo; case 2: break;", |
| 6036 "case 1: continue; case 2: foo: break foo;", |
| 6037 "case 1: foo:return;", |
| 6038 "case 1: foo:{ continue;}", |
| 6039 "case 1: break; default: foo:{ throw new TypeError() }", |
| 6040 "case 1: case 2: { foo:{ { break;} } } default: break;", |
| 6041 NULL}; |
| 6042 |
| 6043 static const ParserFlag always_flags[] = { |
| 6044 kAllowStrongMode |
| 6045 }; |
| 6046 RunParserSyncTest(strong_context_data, data_success, kSuccess, NULL, 0, |
| 6047 always_flags, arraysize(always_flags)); |
| 6048 RunParserSyncTest(sloppy_context_data, data_error, kSuccess, NULL, 0, |
| 6049 always_flags, arraysize(always_flags)); |
| 6050 RunParserSyncTest(strong_context_data, data_error, kError, NULL, 0, |
| 6051 always_flags, arraysize(always_flags)); |
| 6052 } |
| 6053 |
6006 | 6054 |
6007 TEST(ArrowFunctionASIErrors) { | 6055 TEST(ArrowFunctionASIErrors) { |
6008 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, | 6056 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, |
6009 {NULL, NULL}}; | 6057 {NULL, NULL}}; |
6010 | 6058 |
6011 const char* data[] = { | 6059 const char* data[] = { |
6012 "(a\n=> a)(1)", | 6060 "(a\n=> a)(1)", |
6013 "(a/*\n*/=> a)(1)", | 6061 "(a/*\n*/=> a)(1)", |
6014 "((a)\n=> a)(1)", | 6062 "((a)\n=> a)(1)", |
6015 "((a)/*\n*/=> a)(1)", | 6063 "((a)/*\n*/=> a)(1)", |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6163 v8::Script::Compile(v8_str(script3)); | 6211 v8::Script::Compile(v8_str(script3)); |
6164 CHECK(try_catch2.HasCaught()); | 6212 CHECK(try_catch2.HasCaught()); |
6165 v8::String::Utf8Value exception(try_catch2.Exception()); | 6213 v8::String::Utf8Value exception(try_catch2.Exception()); |
6166 CHECK_EQ(0, | 6214 CHECK_EQ(0, |
6167 strcmp( | 6215 strcmp( |
6168 "ReferenceError: In strong mode, using an undeclared global " | 6216 "ReferenceError: In strong mode, using an undeclared global " |
6169 "variable 'not_there3' is not allowed", | 6217 "variable 'not_there3' is not allowed", |
6170 *exception)); | 6218 *exception)); |
6171 } | 6219 } |
6172 } | 6220 } |
OLD | NEW |