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 static const char* join_causing_out_of_memory = | 1212 v8::HandleScope scope(CcTest::isolate()); |
| 1213 LocalContext context; |
| 1214 v8::TryCatch try_catch; |
| 1215 CHECK(CompileRun( |
1213 "var two_14 = Math.pow(2, 14);" | 1216 "var two_14 = Math.pow(2, 14);" |
1214 "var two_17 = Math.pow(2, 17);" | 1217 "var two_17 = Math.pow(2, 17);" |
1215 "var s = Array(two_17 + 1).join('c');" | 1218 "var s = Array(two_17 + 1).join('c');" |
1216 "var a = ['bad'];" | 1219 "var a = ['bad'];" |
1217 "for (var i = 1; i <= two_14; i++) a.push(s);" | 1220 "for (var i = 1; i <= two_14; i++) a.push(s);" |
1218 "a.join("");"; | 1221 "a.join("");").IsEmpty()); |
1219 | 1222 CHECK(try_catch.HasCaught()); |
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()); | |
1230 } | 1223 } |
1231 | 1224 |
1232 | 1225 |
1233 static void CheckException(const char* source) { | 1226 static void CheckException(const char* source) { |
1234 // An empty handle is returned upon exception. | 1227 // An empty handle is returned upon exception. |
1235 CHECK(CompileRun(source).IsEmpty()); | 1228 CHECK(CompileRun(source).IsEmpty()); |
1236 } | 1229 } |
1237 | 1230 |
1238 | 1231 |
1239 TEST(RobustSubStringStub) { | 1232 TEST(RobustSubStringStub) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 CheckCanonicalEquivalence(c, test); | 1362 CheckCanonicalEquivalence(c, test); |
1370 continue; | 1363 continue; |
1371 } | 1364 } |
1372 if (upper != c && lower != c) { | 1365 if (upper != c && lower != c) { |
1373 CheckCanonicalEquivalence(c, test); | 1366 CheckCanonicalEquivalence(c, test); |
1374 continue; | 1367 continue; |
1375 } | 1368 } |
1376 CHECK_EQ(Min(upper, lower), test); | 1369 CHECK_EQ(Min(upper, lower), test); |
1377 } | 1370 } |
1378 } | 1371 } |
OLD | NEW |