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 14463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14474 // result has the 'x' property. | 14474 // result has the 'x' property. |
14475 context1->Enter(); | 14475 context1->Enter(); |
14476 context1->Global()->Set(v8_str("other"), context0->Global()); | 14476 context1->Global()->Set(v8_str("other"), context0->Global()); |
14477 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); | 14477 Local<Value> value = CompileRun("var instance = new other.C(); instance.x"); |
14478 CHECK(value->IsInt32()); | 14478 CHECK(value->IsInt32()); |
14479 CHECK_EQ(42, value->Int32Value()); | 14479 CHECK_EQ(42, value->Int32Value()); |
14480 context1->Exit(); | 14480 context1->Exit(); |
14481 } | 14481 } |
14482 | 14482 |
14483 | 14483 |
14484 class ApplyInterruptTest { | |
14485 public: | |
14486 ApplyInterruptTest() : block_(0) {} | |
14487 ~ApplyInterruptTest() {} | |
14488 void RunTest() { | |
14489 gc_count_ = 0; | |
14490 gc_during_apply_ = 0; | |
14491 apply_success_ = false; | |
14492 gc_success_ = false; | |
14493 GCThread gc_thread(this); | |
14494 gc_thread.Start(); | |
14495 v8::Isolate* isolate = CcTest::isolate(); | |
14496 v8::Locker::StartPreemption(isolate, 1); | |
14497 | |
14498 LongRunningApply(); | |
14499 { | |
14500 v8::Unlocker unlock(isolate); | |
14501 gc_thread.Join(); | |
14502 } | |
14503 v8::Locker::StopPreemption(isolate); | |
14504 CHECK(apply_success_); | |
14505 CHECK(gc_success_); | |
14506 } | |
14507 | |
14508 private: | |
14509 // Number of garbage collections required. | |
14510 static const int kRequiredGCs = 2; | |
14511 | |
14512 class GCThread : public i::Thread { | |
14513 public: | |
14514 explicit GCThread(ApplyInterruptTest* test) | |
14515 : Thread("GCThread"), test_(test) {} | |
14516 virtual void Run() { | |
14517 test_->CollectGarbage(); | |
14518 } | |
14519 private: | |
14520 ApplyInterruptTest* test_; | |
14521 }; | |
14522 | |
14523 void CollectGarbage() { | |
14524 block_.Wait(); | |
14525 while (gc_during_apply_ < kRequiredGCs) { | |
14526 { | |
14527 v8::Locker lock(CcTest::isolate()); | |
14528 v8::Isolate::Scope isolate_scope(CcTest::isolate()); | |
14529 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); | |
14530 gc_count_++; | |
14531 } | |
14532 i::OS::Sleep(1); | |
14533 } | |
14534 gc_success_ = true; | |
14535 } | |
14536 | |
14537 void LongRunningApply() { | |
14538 block_.Signal(); | |
14539 int rounds = 0; | |
14540 while (gc_during_apply_ < kRequiredGCs) { | |
14541 int gc_before = gc_count_; | |
14542 { | |
14543 const char* c_source = | |
14544 "function do_very_little(bar) {" | |
14545 " this.foo = bar;" | |
14546 "}" | |
14547 "for (var i = 0; i < 100000; i++) {" | |
14548 " do_very_little.apply(this, ['bar']);" | |
14549 "}"; | |
14550 Local<String> source = String::New(c_source); | |
14551 Local<Script> script = Script::Compile(source); | |
14552 Local<Value> result = script->Run(); | |
14553 // Check that no exception was thrown. | |
14554 CHECK(!result.IsEmpty()); | |
14555 } | |
14556 int gc_after = gc_count_; | |
14557 gc_during_apply_ += gc_after - gc_before; | |
14558 rounds++; | |
14559 } | |
14560 apply_success_ = true; | |
14561 } | |
14562 | |
14563 i::Semaphore block_; | |
14564 int gc_count_; | |
14565 int gc_during_apply_; | |
14566 bool apply_success_; | |
14567 bool gc_success_; | |
14568 }; | |
14569 | |
14570 | |
14571 // Test that nothing bad happens if we get a preemption just when we were | |
14572 // about to do an apply(). | |
14573 TEST(ApplyInterruption) { | |
14574 v8::Locker lock(CcTest::isolate()); | |
14575 v8::V8::Initialize(); | |
14576 v8::HandleScope scope(CcTest::isolate()); | |
14577 Local<Context> local_env; | |
14578 { | |
14579 LocalContext env; | |
14580 local_env = env.local(); | |
14581 } | |
14582 | |
14583 // Local context should still be live. | |
14584 CHECK(!local_env.IsEmpty()); | |
14585 local_env->Enter(); | |
14586 | |
14587 // Should complete without problems. | |
14588 ApplyInterruptTest().RunTest(); | |
14589 | |
14590 local_env->Exit(); | |
14591 } | |
14592 | |
14593 | |
14594 // Verify that we can clone an object | 14484 // Verify that we can clone an object |
14595 TEST(ObjectClone) { | 14485 TEST(ObjectClone) { |
14596 LocalContext env; | 14486 LocalContext env; |
14597 v8::HandleScope scope(env->GetIsolate()); | 14487 v8::HandleScope scope(env->GetIsolate()); |
14598 | 14488 |
14599 const char* sample = | 14489 const char* sample = |
14600 "var rv = {};" \ | 14490 "var rv = {};" \ |
14601 "rv.alpha = 'hello';" \ | 14491 "rv.alpha = 'hello';" \ |
14602 "rv.beta = 123;" \ | 14492 "rv.beta = 123;" \ |
14603 "rv;"; | 14493 "rv;"; |
(...skipping 6200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20804 } | 20694 } |
20805 for (int i = 0; i < runs; i++) { | 20695 for (int i = 0; i < runs; i++) { |
20806 Local<String> expected; | 20696 Local<String> expected; |
20807 if (i != 0) { | 20697 if (i != 0) { |
20808 CHECK_EQ(v8_str("escape value"), values[i]); | 20698 CHECK_EQ(v8_str("escape value"), values[i]); |
20809 } else { | 20699 } else { |
20810 CHECK(values[i].IsEmpty()); | 20700 CHECK(values[i].IsEmpty()); |
20811 } | 20701 } |
20812 } | 20702 } |
20813 } | 20703 } |
OLD | NEW |