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 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 static const int K = 1024; | 1202 static const int K = 1024; |
1203 v8::ResourceConstraints constraints; | 1203 v8::ResourceConstraints constraints; |
1204 constraints.set_max_young_space_size(256 * K); | 1204 constraints.set_max_young_space_size(256 * K); |
1205 constraints.set_max_old_space_size(4 * K * K); | 1205 constraints.set_max_old_space_size(4 * K * K); |
1206 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | 1206 v8::SetResourceConstraints(CcTest::isolate(), &constraints); |
1207 | 1207 |
1208 // String s is made of 2^17 = 131072 'c' characters and a is an array | 1208 // String s is made of 2^17 = 131072 'c' characters and a is an array |
1209 // starting with 'bad', followed by 2^14 times the string s. That means the | 1209 // starting with 'bad', followed by 2^14 times the string s. That means the |
1210 // total length of the concatenated strings is 2^31 + 3. So on 32bit systems | 1210 // total length of the concatenated strings is 2^31 + 3. So on 32bit systems |
1211 // summing the lengths of the strings (as Smis) overflows and wraps. | 1211 // summing the lengths of the strings (as Smis) overflows and wraps. |
1212 LocalContext context; | 1212 static const char* join_causing_out_of_memory = |
1213 v8::HandleScope scope(CcTest::isolate()); | |
1214 v8::TryCatch try_catch; | |
1215 CHECK(CompileRun( | |
1216 "var two_14 = Math.pow(2, 14);" | 1213 "var two_14 = Math.pow(2, 14);" |
1217 "var two_17 = Math.pow(2, 17);" | 1214 "var two_17 = Math.pow(2, 17);" |
1218 "var s = Array(two_17 + 1).join('c');" | 1215 "var s = Array(two_17 + 1).join('c');" |
1219 "var a = ['bad'];" | 1216 "var a = ['bad'];" |
1220 "for (var i = 1; i <= two_14; i++) a.push(s);" | 1217 "for (var i = 1; i <= two_14; i++) a.push(s);" |
1221 "a.join("");").IsEmpty()); | 1218 "a.join("");"; |
1222 CHECK(try_catch.HasCaught()); | 1219 |
| 1220 v8::HandleScope scope(CcTest::isolate()); |
| 1221 LocalContext context; |
| 1222 v8::V8::IgnoreOutOfMemoryException(); |
| 1223 v8::Local<v8::Script> script = v8::Script::Compile( |
| 1224 v8::String::NewFromUtf8(CcTest::isolate(), join_causing_out_of_memory)); |
| 1225 v8::Local<v8::Value> result = script->Run(); |
| 1226 |
| 1227 // Check for out of memory state. |
| 1228 CHECK(result.IsEmpty()); |
| 1229 CHECK(context->HasOutOfMemoryException()); |
1223 } | 1230 } |
1224 | 1231 |
1225 | 1232 |
1226 static void CheckException(const char* source) { | 1233 static void CheckException(const char* source) { |
1227 // An empty handle is returned upon exception. | 1234 // An empty handle is returned upon exception. |
1228 CHECK(CompileRun(source).IsEmpty()); | 1235 CHECK(CompileRun(source).IsEmpty()); |
1229 } | 1236 } |
1230 | 1237 |
1231 | 1238 |
1232 TEST(RobustSubStringStub) { | 1239 TEST(RobustSubStringStub) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 CheckCanonicalEquivalence(c, test); | 1369 CheckCanonicalEquivalence(c, test); |
1363 continue; | 1370 continue; |
1364 } | 1371 } |
1365 if (upper != c && lower != c) { | 1372 if (upper != c && lower != c) { |
1366 CheckCanonicalEquivalence(c, test); | 1373 CheckCanonicalEquivalence(c, test); |
1367 continue; | 1374 continue; |
1368 } | 1375 } |
1369 CHECK_EQ(Min(upper, lower), test); | 1376 CHECK_EQ(Min(upper, lower), test); |
1370 } | 1377 } |
1371 } | 1378 } |
OLD | NEW |