Chromium Code Reviews| Index: test/cctest/test-lockers.cc |
| diff --git a/test/cctest/test-lockers.cc b/test/cctest/test-lockers.cc |
| index a54390bf4e92a6cd133aa22cdd67581e2b7113a5..7fb3c030a85e2ea457577f0f8d028256afa32807 100644 |
| --- a/test/cctest/test-lockers.cc |
| +++ b/test/cctest/test-lockers.cc |
| @@ -33,6 +33,7 @@ |
| #include "isolate.h" |
| #include "compilation-cache.h" |
| #include "execution.h" |
| +#include "smart-pointers.h" |
| #include "snapshot.h" |
| #include "platform.h" |
| #include "utils.h" |
| @@ -58,11 +59,10 @@ using ::v8::V8; |
| // Migrating an isolate |
| class KangarooThread : public v8::internal::Thread { |
| public: |
| - KangarooThread(v8::Isolate* isolate, |
| - v8::Handle<v8::Context> context) |
| + KangarooThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) |
| : Thread("KangarooThread"), |
| - isolate_(isolate), context_(context) { |
| - } |
| + isolate_(isolate), |
| + context_(isolate, context) {} |
| void Run() { |
| { |
| @@ -95,19 +95,19 @@ class KangarooThread : public v8::internal::Thread { |
| // Migrates an isolate from one thread to another |
| TEST(KangarooIsolates) { |
| v8::Isolate* isolate = v8::Isolate::New(); |
| - Persistent<v8::Context> context; |
| + v8::internal::SmartPointer<KangarooThread> thread1; |
| { |
| v8::Locker locker(isolate); |
| v8::Isolate::Scope isolate_scope(isolate); |
| v8::HandleScope handle_scope(isolate); |
| - context = v8::Context::New(); |
| + v8::Local<v8::Context> context = v8::Context::New(isolate); |
| v8::Context::Scope context_scope(context); |
| CHECK_EQ(isolate, v8::internal::Isolate::Current()); |
| CompileRun("function getValue() { return 30; }"); |
| + thread1.Reset(new KangarooThread(isolate, context)); |
| } |
| - KangarooThread thread1(isolate, context); |
| - thread1.Start(); |
| - thread1.Join(); |
| + thread1->Start(); |
| + thread1->Join(); |
| } |
| static void CalcFibAndCheck() { |
| @@ -342,7 +342,7 @@ class LockIsolateAndCalculateFibSharedContextThread : public JoinableThread { |
| v8::Isolate* isolate, v8::Handle<v8::Context> context) |
| : JoinableThread("LockIsolateAndCalculateFibThread"), |
| isolate_(isolate), |
| - context_(context) { |
| + context_(isolate, context) { |
| } |
| virtual void Run() { |
| @@ -368,15 +368,15 @@ class LockerUnlockerThread : public JoinableThread { |
| v8::Locker lock(isolate_); |
| v8::Isolate::Scope isolate_scope(isolate_); |
| v8::HandleScope handle_scope(isolate_); |
| - v8::Handle<v8::Context> context = v8::Context::New(); |
| + v8::Local<v8::Context> context = v8::Context::New(isolate_); |
| { |
| v8::Context::Scope context_scope(context); |
| CalcFibAndCheck(); |
| } |
| { |
| + LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); |
| isolate_->Exit(); |
| v8::Unlocker unlocker(isolate_); |
| - LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); |
| thread.Start(); |
| thread.Join(); |
| } |
| @@ -418,7 +418,7 @@ class LockTwiceAndUnlockThread : public JoinableThread { |
| v8::Locker lock(isolate_); |
| v8::Isolate::Scope isolate_scope(isolate_); |
| v8::HandleScope handle_scope(isolate_); |
| - v8::Handle<v8::Context> context = v8::Context::New(); |
| + v8::Local<v8::Context> context = v8::Context::New(isolate_); |
| { |
| v8::Context::Scope context_scope(context); |
| CalcFibAndCheck(); |
| @@ -426,9 +426,9 @@ class LockTwiceAndUnlockThread : public JoinableThread { |
| { |
| v8::Locker second_lock(isolate_); |
| { |
| + LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); |
| isolate_->Exit(); |
| v8::Unlocker unlocker(isolate_); |
| - LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context); |
| thread.Start(); |
| thread.Join(); |
| } |
| @@ -497,16 +497,24 @@ class LockAndUnlockDifferentIsolatesThread : public JoinableThread { |
| } |
| } |
| { |
| + v8::internal::SmartPointer<LockIsolateAndCalculateFibSharedContextThread> |
| + thread; |
|
dcarney
2013/04/24 13:13:38
spacing
jochen (gone - plz use gerrit)
2013/04/24 13:15:16
that's the way the google c++ style wants it (sinc
Sven Panne
2013/04/24 13:40:39
Perhaps we can resolve this dispute by using i::Sm
|
| + { |
| + CHECK(v8::Locker::IsLocked(isolate1_)); |
| + v8::Isolate::Scope isolate_scope(isolate1_); |
| + v8::HandleScope handle_scope(isolate1_); |
| + thread.Reset(new LockIsolateAndCalculateFibSharedContextThread( |
| + isolate1_, v8::Local<v8::Context>::New(isolate1_, context1))); |
| + } |
| v8::Unlocker unlock1(isolate1_); |
| CHECK(!v8::Locker::IsLocked(isolate1_)); |
| CHECK(v8::Locker::IsLocked(isolate2_)); |
| v8::Isolate::Scope isolate_scope(isolate2_); |
| v8::HandleScope handle_scope(isolate2_); |
| v8::Context::Scope context_scope(context2); |
| - LockIsolateAndCalculateFibSharedContextThread thread(isolate1_, context1); |
| - thread.Start(); |
| + thread->Start(); |
| CalcFibAndCheck(); |
| - thread.Join(); |
| + thread->Join(); |
| } |
| } |
| @@ -528,10 +536,10 @@ TEST(LockAndUnlockDifferentIsolates) { |
| class LockUnlockLockThread : public JoinableThread { |
| public: |
| - LockUnlockLockThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) |
| + LockUnlockLockThread(v8::Isolate* isolate, v8::Local<v8::Context> context) |
| : JoinableThread("LockUnlockLockThread"), |
| isolate_(isolate), |
| - context_(context) { |
| + context_(isolate, context) { |
| } |
| virtual void Run() { |
| @@ -574,15 +582,16 @@ TEST(LockUnlockLockMultithreaded) { |
| #endif |
| v8::Isolate* isolate = v8::Isolate::New(); |
| Persistent<v8::Context> context; |
| + i::List<JoinableThread*> threads(kNThreads); |
| { |
| v8::Locker locker_(isolate); |
| v8::Isolate::Scope isolate_scope(isolate); |
| v8::HandleScope handle_scope(isolate); |
| context = v8::Context::New(); |
| - } |
| - i::List<JoinableThread*> threads(kNThreads); |
| - for (int i = 0; i < kNThreads; i++) { |
| - threads.Add(new LockUnlockLockThread(isolate, context)); |
| + for (int i = 0; i < kNThreads; i++) { |
| + threads.Add(new LockUnlockLockThread( |
| + isolate, v8::Local<v8::Context>::New(isolate, context))); |
| + } |
| } |
| StartJoinAndDeleteThreads(threads); |
| isolate->Dispose(); |
| @@ -590,10 +599,9 @@ TEST(LockUnlockLockMultithreaded) { |
| class LockUnlockLockDefaultIsolateThread : public JoinableThread { |
| public: |
| - explicit LockUnlockLockDefaultIsolateThread(v8::Handle<v8::Context> context) |
| - : JoinableThread("LockUnlockLockDefaultIsolateThread"), |
| - context_(context) { |
| - } |
| + explicit LockUnlockLockDefaultIsolateThread(v8::Local<v8::Context> context) |
| + : JoinableThread("LockUnlockLockDefaultIsolateThread"), |
| + context_(CcTest::default_isolate(), context) {} |
| virtual void Run() { |
| v8::Locker lock1(CcTest::default_isolate()); |
| @@ -625,14 +633,15 @@ TEST(LockUnlockLockDefaultIsolateMultithreaded) { |
| const int kNThreads = 100; |
| #endif |
| Persistent<v8::Context> context; |
| + i::List<JoinableThread*> threads(kNThreads); |
| { |
| v8::Locker locker_(CcTest::default_isolate()); |
| v8::HandleScope handle_scope(CcTest::default_isolate()); |
| context = v8::Context::New(); |
| - } |
| - i::List<JoinableThread*> threads(kNThreads); |
| - for (int i = 0; i < kNThreads; i++) { |
| - threads.Add(new LockUnlockLockDefaultIsolateThread(context)); |
| + for (int i = 0; i < kNThreads; i++) { |
| + threads.Add(new LockUnlockLockDefaultIsolateThread( |
| + v8::Local<v8::Context>::New(CcTest::default_isolate(), context))); |
| + } |
| } |
| StartJoinAndDeleteThreads(threads); |
| } |