| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const char* name() { return name_; } | 193 const char* name() { return name_; } |
| 194 | 194 |
| 195 private: | 195 private: |
| 196 static RegisterThreadedTest* first_; | 196 static RegisterThreadedTest* first_; |
| 197 static int count_; | 197 static int count_; |
| 198 CcTest::TestFunction* callback_; | 198 CcTest::TestFunction* callback_; |
| 199 RegisterThreadedTest* prev_; | 199 RegisterThreadedTest* prev_; |
| 200 const char* name_; | 200 const char* name_; |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 namespace v8 { | |
| 204 // A LocalContext holds a reference to a v8::Context. | 203 // A LocalContext holds a reference to a v8::Context. |
| 205 class LocalContext { | 204 class LocalContext { |
| 206 public: | 205 public: |
| 207 LocalContext(v8::ExtensionConfiguration* extensions = 0, | 206 LocalContext(v8::ExtensionConfiguration* extensions = 0, |
| 208 v8::Handle<v8::ObjectTemplate> global_template = | 207 v8::Handle<v8::ObjectTemplate> global_template = |
| 209 v8::Handle<v8::ObjectTemplate>(), | 208 v8::Handle<v8::ObjectTemplate>(), |
| 210 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) { | 209 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) { |
| 211 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 210 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 212 HandleScope scope(isolate); | 211 v8::HandleScope scope(isolate); |
| 213 context_.Reset(isolate, | 212 v8::Local<v8::Context> context = v8::Context::New(isolate, |
| 214 Context::New(isolate, | 213 extensions, |
| 215 extensions, | 214 global_template, |
| 216 global_template, | 215 global_object); |
| 217 global_object)); | 216 context_.Reset(isolate, context); |
| 218 context_->Enter(); | 217 context->Enter(); |
| 219 // We can't do this later perhaps because of a fatal error. | 218 // We can't do this later perhaps because of a fatal error. |
| 220 isolate_ = context_->GetIsolate(); | 219 isolate_ = context->GetIsolate(); |
| 221 } | 220 } |
| 222 | 221 |
| 223 virtual ~LocalContext() { | 222 virtual ~LocalContext() { |
| 224 context_->Exit(); | 223 v8::HandleScope scope(isolate_); |
| 225 context_.Dispose(isolate_); | 224 v8::Local<v8::Context>::New(isolate_, context_)->Exit(); |
| 225 context_.Dispose(); |
| 226 } | 226 } |
| 227 | 227 |
| 228 v8::Context* operator->() { return *context_; } | 228 v8::Context* operator->() { |
| 229 v8::Context* operator*() { return *context_; } | 229 return *reinterpret_cast<v8::Context**>(&context_); |
| 230 } |
| 231 v8::Context* operator*() { return operator->(); } |
| 230 bool IsReady() { return !context_.IsEmpty(); } | 232 bool IsReady() { return !context_.IsEmpty(); } |
| 231 | 233 |
| 232 v8::Local<v8::Context> local() { | 234 v8::Local<v8::Context> local() { |
| 233 return v8::Local<v8::Context>::New(isolate_, context_); | 235 return v8::Local<v8::Context>::New(isolate_, context_); |
| 234 } | 236 } |
| 235 | 237 |
| 236 private: | 238 private: |
| 237 v8::Persistent<v8::Context> context_; | 239 v8::Persistent<v8::Context> context_; |
| 238 v8::Isolate* isolate_; | 240 v8::Isolate* isolate_; |
| 239 }; | 241 }; |
| 240 } | |
| 241 typedef v8::LocalContext LocalContext; | |
| 242 | 242 |
| 243 static inline v8::Local<v8::Value> v8_num(double x) { | 243 static inline v8::Local<v8::Value> v8_num(double x) { |
| 244 return v8::Number::New(x); | 244 return v8::Number::New(x); |
| 245 } | 245 } |
| 246 | 246 |
| 247 | 247 |
| 248 static inline v8::Local<v8::String> v8_str(const char* x) { | 248 static inline v8::Local<v8::String> v8_str(const char* x) { |
| 249 return v8::String::New(x); | 249 return v8::String::New(x); |
| 250 } | 250 } |
| 251 | 251 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { | 294 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { |
| 295 int old_linear_size = static_cast<int>(space->limit() - space->top()); | 295 int old_linear_size = static_cast<int>(space->limit() - space->top()); |
| 296 space->Free(space->top(), old_linear_size); | 296 space->Free(space->top(), old_linear_size); |
| 297 space->SetTop(space->limit(), space->limit()); | 297 space->SetTop(space->limit(), space->limit()); |
| 298 space->ResetFreeList(); | 298 space->ResetFreeList(); |
| 299 space->ClearStats(); | 299 space->ClearStats(); |
| 300 } | 300 } |
| 301 | 301 |
| 302 | 302 |
| 303 #endif // ifndef CCTEST_H_ | 303 #endif // ifndef CCTEST_H_ |
| OLD | NEW |