OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if (v8::Locker::IsActive()) { | 98 if (v8::Locker::IsActive()) { |
99 v8::Locker locker(isolate_); | 99 v8::Locker locker(isolate_); |
100 EmptyMessageQueues(isolate_); | 100 EmptyMessageQueues(isolate_); |
101 } else { | 101 } else { |
102 EmptyMessageQueues(isolate_); | 102 EmptyMessageQueues(isolate_); |
103 } | 103 } |
104 isolate_->Exit(); | 104 isolate_->Exit(); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
| 108 i::Heap* CcTest::heap() { return i_isolate()->heap(); } |
| 109 |
| 110 v8::base::RandomNumberGenerator* CcTest::random_number_generator() { |
| 111 return InitIsolateOnce()->random_number_generator(); |
| 112 } |
| 113 |
| 114 v8::Local<v8::Object> CcTest::global() { |
| 115 return isolate()->GetCurrentContext()->Global(); |
| 116 } |
| 117 |
| 118 void CcTest::InitializeVM() { |
| 119 CHECK(!v8::base::NoBarrier_Load(&isolate_used_)); |
| 120 CHECK(!initialize_called_); |
| 121 initialize_called_ = true; |
| 122 v8::HandleScope handle_scope(CcTest::isolate()); |
| 123 v8::Context::New(CcTest::isolate())->Enter(); |
| 124 } |
| 125 |
| 126 void CcTest::TearDown() { |
| 127 if (isolate_ != NULL) isolate_->Dispose(); |
| 128 } |
108 | 129 |
109 v8::Local<v8::Context> CcTest::NewContext(CcTestExtensionFlags extensions, | 130 v8::Local<v8::Context> CcTest::NewContext(CcTestExtensionFlags extensions, |
110 v8::Isolate* isolate) { | 131 v8::Isolate* isolate) { |
111 const char* extension_names[kMaxExtensions]; | 132 const char* extension_names[kMaxExtensions]; |
112 int extension_count = 0; | 133 int extension_count = 0; |
113 #define CHECK_EXTENSION_FLAG(Name, Id) \ | 134 #define CHECK_EXTENSION_FLAG(Name, Id) \ |
114 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id; | 135 if (extensions.Contains(Name##_ID)) extension_names[extension_count++] = Id; |
115 EXTENSION_LIST(CHECK_EXTENSION_FLAG) | 136 EXTENSION_LIST(CHECK_EXTENSION_FLAG) |
116 #undef CHECK_EXTENSION_FLAG | 137 #undef CHECK_EXTENSION_FLAG |
117 v8::ExtensionConfiguration config(extension_count, extension_names); | 138 v8::ExtensionConfiguration config(extension_count, extension_names); |
118 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); | 139 v8::Local<v8::Context> context = v8::Context::New(isolate, &config); |
119 CHECK(!context.IsEmpty()); | 140 CHECK(!context.IsEmpty()); |
120 return context; | 141 return context; |
121 } | 142 } |
122 | 143 |
123 | 144 |
124 void CcTest::DisableAutomaticDispose() { | 145 void CcTest::DisableAutomaticDispose() { |
125 CHECK_EQ(kUnintialized, initialization_state_); | 146 CHECK_EQ(kUnintialized, initialization_state_); |
126 disable_automatic_dispose_ = true; | 147 disable_automatic_dispose_ = true; |
127 } | 148 } |
128 | 149 |
| 150 LocalContext::~LocalContext() { |
| 151 v8::HandleScope scope(isolate_); |
| 152 v8::Local<v8::Context>::New(isolate_, context_)->Exit(); |
| 153 context_.Reset(); |
| 154 } |
| 155 |
| 156 void LocalContext::Initialize(v8::Isolate* isolate, |
| 157 v8::ExtensionConfiguration* extensions, |
| 158 v8::Local<v8::ObjectTemplate> global_template, |
| 159 v8::Local<v8::Value> global_object) { |
| 160 v8::HandleScope scope(isolate); |
| 161 v8::Local<v8::Context> context = |
| 162 v8::Context::New(isolate, extensions, global_template, global_object); |
| 163 context_.Reset(isolate, context); |
| 164 context->Enter(); |
| 165 // We can't do this later perhaps because of a fatal error. |
| 166 isolate_ = isolate; |
| 167 } |
| 168 |
| 169 // This indirection is needed because HandleScopes cannot be heap-allocated, and |
| 170 // we don't want any unnecessary #includes in cctest.h. |
| 171 class InitializedHandleScopeImpl { |
| 172 public: |
| 173 explicit InitializedHandleScopeImpl(i::Isolate* isolate) |
| 174 : handle_scope_(isolate) {} |
| 175 |
| 176 private: |
| 177 i::HandleScope handle_scope_; |
| 178 }; |
| 179 |
| 180 InitializedHandleScope::InitializedHandleScope() |
| 181 : main_isolate_(CcTest::InitIsolateOnce()), |
| 182 initialized_handle_scope_impl_( |
| 183 new InitializedHandleScopeImpl(main_isolate_)) {} |
| 184 |
| 185 InitializedHandleScope::~InitializedHandleScope() {} |
| 186 |
| 187 HandleAndZoneScope::HandleAndZoneScope() |
| 188 : main_zone_(new i::Zone(&allocator_)) {} |
| 189 |
| 190 HandleAndZoneScope::~HandleAndZoneScope() {} |
129 | 191 |
130 static void PrintTestList(CcTest* current) { | 192 static void PrintTestList(CcTest* current) { |
131 if (current == NULL) return; | 193 if (current == NULL) return; |
132 PrintTestList(current->prev()); | 194 PrintTestList(current->prev()); |
133 printf("%s/%s\n", current->file(), current->name()); | 195 printf("%s/%s\n", current->file(), current->name()); |
134 } | 196 } |
135 | 197 |
136 | 198 |
137 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | 199 class CcTestArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
138 virtual void* Allocate(size_t length) { | 200 virtual void* Allocate(size_t length) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 CcTest::TearDown(); | 315 CcTest::TearDown(); |
254 // TODO(svenpanne) See comment above. | 316 // TODO(svenpanne) See comment above. |
255 // if (!disable_automatic_dispose_) v8::V8::Dispose(); | 317 // if (!disable_automatic_dispose_) v8::V8::Dispose(); |
256 v8::V8::ShutdownPlatform(); | 318 v8::V8::ShutdownPlatform(); |
257 delete platform; | 319 delete platform; |
258 return 0; | 320 return 0; |
259 } | 321 } |
260 | 322 |
261 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; | 323 RegisterThreadedTest *RegisterThreadedTest::first_ = NULL; |
262 int RegisterThreadedTest::count_ = 0; | 324 int RegisterThreadedTest::count_ = 0; |
OLD | NEW |