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 4461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4472 CHECK(r7->IsNull()); | 4472 CHECK(r7->IsNull()); |
4473 Local<v8::Value> r8 = ReturnThisStrict->Call(v8_num(42), 0, NULL); | 4473 Local<v8::Value> r8 = ReturnThisStrict->Call(v8_num(42), 0, NULL); |
4474 CHECK(r8->StrictEquals(v8_num(42))); | 4474 CHECK(r8->StrictEquals(v8_num(42))); |
4475 Local<v8::Value> r9 = ReturnThisStrict->Call(v8_str("hello"), 0, NULL); | 4475 Local<v8::Value> r9 = ReturnThisStrict->Call(v8_str("hello"), 0, NULL); |
4476 CHECK(r9->StrictEquals(v8_str("hello"))); | 4476 CHECK(r9->StrictEquals(v8_str("hello"))); |
4477 Local<v8::Value> r10 = ReturnThisStrict->Call(v8::True(isolate), 0, NULL); | 4477 Local<v8::Value> r10 = ReturnThisStrict->Call(v8::True(isolate), 0, NULL); |
4478 CHECK(r10->StrictEquals(v8::True(isolate))); | 4478 CHECK(r10->StrictEquals(v8::True(isolate))); |
4479 } | 4479 } |
4480 | 4480 |
4481 | 4481 |
4482 static const char* js_code_causing_out_of_memory = | |
4483 "var a = new Array(); while(true) a.push(a);"; | |
4484 | |
4485 | |
4486 // These tests run for a long time and prevent us from running tests | |
4487 // that come after them so they cannot run in parallel. | |
4488 TEST(OutOfMemory) { | |
4489 // It's not possible to read a snapshot into a heap with different dimensions. | |
4490 if (i::Snapshot::IsEnabled()) return; | |
4491 // Set heap limits. | |
4492 static const int K = 1024; | |
4493 v8::ResourceConstraints constraints; | |
4494 constraints.set_max_young_space_size(256 * K); | |
4495 constraints.set_max_old_space_size(5 * K * K); | |
4496 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | |
4497 | |
4498 // Execute a script that causes out of memory. | |
4499 LocalContext context; | |
4500 v8::HandleScope scope(context->GetIsolate()); | |
4501 v8::V8::IgnoreOutOfMemoryException(); | |
4502 Local<Value> result = CompileRun(js_code_causing_out_of_memory); | |
4503 | |
4504 // Check for out of memory state. | |
4505 CHECK(result.IsEmpty()); | |
4506 CHECK(context->HasOutOfMemoryException()); | |
4507 } | |
4508 | |
4509 | |
4510 void ProvokeOutOfMemory(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
4511 ApiTestFuzzer::Fuzz(); | |
4512 | |
4513 LocalContext context; | |
4514 v8::HandleScope scope(context->GetIsolate()); | |
4515 Local<Value> result = CompileRun(js_code_causing_out_of_memory); | |
4516 | |
4517 // Check for out of memory state. | |
4518 CHECK(result.IsEmpty()); | |
4519 CHECK(context->HasOutOfMemoryException()); | |
4520 | |
4521 args.GetReturnValue().Set(result); | |
4522 } | |
4523 | |
4524 | |
4525 TEST(OutOfMemoryNested) { | |
4526 // It's not possible to read a snapshot into a heap with different dimensions. | |
4527 if (i::Snapshot::IsEnabled()) return; | |
4528 // Set heap limits. | |
4529 static const int K = 1024; | |
4530 v8::ResourceConstraints constraints; | |
4531 constraints.set_max_young_space_size(256 * K); | |
4532 constraints.set_max_old_space_size(5 * K * K); | |
4533 v8::Isolate* isolate = CcTest::isolate(); | |
4534 v8::SetResourceConstraints(isolate, &constraints); | |
4535 | |
4536 v8::HandleScope scope(isolate); | |
4537 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); | |
4538 templ->Set(v8_str("ProvokeOutOfMemory"), | |
4539 v8::FunctionTemplate::New(isolate, ProvokeOutOfMemory)); | |
4540 LocalContext context(0, templ); | |
4541 v8::V8::IgnoreOutOfMemoryException(); | |
4542 Local<Value> result = CompileRun( | |
4543 "var thrown = false;" | |
4544 "try {" | |
4545 " ProvokeOutOfMemory();" | |
4546 "} catch (e) {" | |
4547 " thrown = true;" | |
4548 "}"); | |
4549 // Check for out of memory state. | |
4550 CHECK(result.IsEmpty()); | |
4551 CHECK(context->HasOutOfMemoryException()); | |
4552 } | |
4553 | |
4554 | |
4555 void OOMCallback(const char* location, const char* message) { | |
4556 exit(0); | |
4557 } | |
4558 | |
4559 | |
4560 TEST(HugeConsStringOutOfMemory) { | |
4561 // It's not possible to read a snapshot into a heap with different dimensions. | |
4562 if (i::Snapshot::IsEnabled()) return; | |
4563 // Set heap limits. | |
4564 static const int K = 1024; | |
4565 v8::ResourceConstraints constraints; | |
4566 constraints.set_max_young_space_size(256 * K); | |
4567 constraints.set_max_old_space_size(4 * K * K); | |
4568 v8::SetResourceConstraints(CcTest::isolate(), &constraints); | |
4569 | |
4570 // Execute a script that causes out of memory. | |
4571 v8::V8::SetFatalErrorHandler(OOMCallback); | |
4572 | |
4573 LocalContext context; | |
4574 v8::HandleScope scope(context->GetIsolate()); | |
4575 | |
4576 // Build huge string. This should fail with out of memory exception. | |
4577 CompileRun( | |
4578 "var str = Array.prototype.join.call({length: 513}, \"A\").toUpperCase();" | |
4579 "for (var i = 0; i < 22; i++) { str = str + str; }"); | |
4580 | |
4581 CHECK(false); // Should not return. | |
4582 } | |
4583 | |
4584 | |
4585 THREADED_TEST(ConstructCall) { | 4482 THREADED_TEST(ConstructCall) { |
4586 LocalContext context; | 4483 LocalContext context; |
4587 v8::Isolate* isolate = context->GetIsolate(); | 4484 v8::Isolate* isolate = context->GetIsolate(); |
4588 v8::HandleScope scope(isolate); | 4485 v8::HandleScope scope(isolate); |
4589 CompileRun( | 4486 CompileRun( |
4590 "function Foo() {" | 4487 "function Foo() {" |
4591 " var result = [];" | 4488 " var result = [];" |
4592 " for (var i = 0; i < arguments.length; i++) {" | 4489 " for (var i = 0; i < arguments.length; i++) {" |
4593 " result.push(arguments[i]);" | 4490 " result.push(arguments[i]);" |
4594 " }" | 4491 " }" |
(...skipping 17799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22394 TEST(ThrowOnJavascriptExecution) { | 22291 TEST(ThrowOnJavascriptExecution) { |
22395 LocalContext context; | 22292 LocalContext context; |
22396 v8::Isolate* isolate = context->GetIsolate(); | 22293 v8::Isolate* isolate = context->GetIsolate(); |
22397 v8::HandleScope scope(isolate); | 22294 v8::HandleScope scope(isolate); |
22398 v8::TryCatch try_catch; | 22295 v8::TryCatch try_catch; |
22399 v8::Isolate::DisallowJavascriptExecutionScope throw_js( | 22296 v8::Isolate::DisallowJavascriptExecutionScope throw_js( |
22400 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); | 22297 isolate, v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
22401 CompileRun("1+1"); | 22298 CompileRun("1+1"); |
22402 CHECK(try_catch.HasCaught()); | 22299 CHECK(try_catch.HasCaught()); |
22403 } | 22300 } |
OLD | NEW |