| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 static CcTest* last() { return last_; } | 80 static CcTest* last() { return last_; } |
| 81 CcTest* prev() { return prev_; } | 81 CcTest* prev() { return prev_; } |
| 82 const char* file() { return file_; } | 82 const char* file() { return file_; } |
| 83 const char* name() { return name_; } | 83 const char* name() { return name_; } |
| 84 const char* dependency() { return dependency_; } | 84 const char* dependency() { return dependency_; } |
| 85 bool enabled() { return enabled_; } | 85 bool enabled() { return enabled_; } |
| 86 static void set_default_isolate(v8::Isolate* default_isolate) { | 86 static void set_default_isolate(v8::Isolate* default_isolate) { |
| 87 default_isolate_ = default_isolate; | 87 default_isolate_ = default_isolate; |
| 88 } | 88 } |
| 89 static v8::Isolate* default_isolate() { return default_isolate_; } | 89 static v8::Isolate* default_isolate() { return default_isolate_; } |
| 90 static v8::Isolate* isolate() { return context_->GetIsolate(); } | 90 static v8::Isolate* isolate() { return context()->GetIsolate(); } |
| 91 static v8::Handle<v8::Context> env() { return context_; } | 91 static v8::Handle<v8::Context> env() { return context(); } |
| 92 | 92 |
| 93 // Helper function to initialize the VM. | 93 // Helper function to initialize the VM. |
| 94 static void InitializeVM(CcTestExtensionFlags extensions = NO_EXTENSIONS); | 94 static void InitializeVM(CcTestExtensionFlags extensions = NO_EXTENSIONS); |
| 95 | 95 |
| 96 private: | 96 private: |
| 97 static v8::Handle<v8::Context> context() { |
| 98 return *reinterpret_cast<v8::Handle<v8::Context>*>(&context_); |
| 99 } |
| 97 TestFunction* callback_; | 100 TestFunction* callback_; |
| 98 const char* file_; | 101 const char* file_; |
| 99 const char* name_; | 102 const char* name_; |
| 100 const char* dependency_; | 103 const char* dependency_; |
| 101 bool enabled_; | 104 bool enabled_; |
| 102 CcTest* prev_; | 105 CcTest* prev_; |
| 103 static CcTest* last_; | 106 static CcTest* last_; |
| 104 static v8::Isolate* default_isolate_; | 107 static v8::Isolate* default_isolate_; |
| 105 static v8::Persistent<v8::Context> context_; | 108 static v8::Persistent<v8::Context> context_; |
| 106 }; | 109 }; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 const char* name() { return name_; } | 191 const char* name() { return name_; } |
| 189 | 192 |
| 190 private: | 193 private: |
| 191 static RegisterThreadedTest* first_; | 194 static RegisterThreadedTest* first_; |
| 192 static int count_; | 195 static int count_; |
| 193 CcTest::TestFunction* callback_; | 196 CcTest::TestFunction* callback_; |
| 194 RegisterThreadedTest* prev_; | 197 RegisterThreadedTest* prev_; |
| 195 const char* name_; | 198 const char* name_; |
| 196 }; | 199 }; |
| 197 | 200 |
| 198 | 201 namespace v8 { |
| 199 // A LocalContext holds a reference to a v8::Context. | 202 // A LocalContext holds a reference to a v8::Context. |
| 200 class LocalContext { | 203 class LocalContext { |
| 201 public: | 204 public: |
| 202 LocalContext(v8::ExtensionConfiguration* extensions = 0, | 205 LocalContext(v8::ExtensionConfiguration* extensions = 0, |
| 203 v8::Handle<v8::ObjectTemplate> global_template = | 206 v8::Handle<v8::ObjectTemplate> global_template = |
| 204 v8::Handle<v8::ObjectTemplate>(), | 207 v8::Handle<v8::ObjectTemplate>(), |
| 205 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) | 208 v8::Handle<v8::Value> global_object = v8::Handle<v8::Value>()) |
| 206 : context_(v8::Context::New(extensions, global_template, global_object)) { | 209 : context_(v8::Context::New(extensions, global_template, global_object)) { |
| 207 context_->Enter(); | 210 context_->Enter(); |
| 208 // We can't do this later perhaps because of a fatal error. | 211 // We can't do this later perhaps because of a fatal error. |
| 209 isolate_ = context_->GetIsolate(); | 212 isolate_ = context_->GetIsolate(); |
| 210 } | 213 } |
| 211 | 214 |
| 212 virtual ~LocalContext() { | 215 virtual ~LocalContext() { |
| 213 context_->Exit(); | 216 context_->Exit(); |
| 214 context_.Dispose(isolate_); | 217 context_.Dispose(isolate_); |
| 215 } | 218 } |
| 216 | 219 |
| 217 v8::Context* operator->() { return *context_; } | 220 v8::Context* operator->() { return *context_; } |
| 218 v8::Context* operator*() { return *context_; } | 221 v8::Context* operator*() { return *context_; } |
| 219 bool IsReady() { return !context_.IsEmpty(); } | 222 bool IsReady() { return !context_.IsEmpty(); } |
| 220 | 223 |
| 221 v8::Local<v8::Context> local() { | 224 v8::Local<v8::Context> local() { |
| 222 return v8::Local<v8::Context>::New(context_); | 225 return v8::Local<v8::Context>::New(isolate_, context_); |
| 223 } | 226 } |
| 224 | 227 |
| 225 private: | 228 private: |
| 226 v8::Persistent<v8::Context> context_; | 229 v8::Persistent<v8::Context> context_; |
| 227 v8::Isolate* isolate_; | 230 v8::Isolate* isolate_; |
| 228 }; | 231 }; |
| 229 | 232 } |
| 233 typedef v8::LocalContext LocalContext; |
| 230 | 234 |
| 231 static inline v8::Local<v8::Value> v8_num(double x) { | 235 static inline v8::Local<v8::Value> v8_num(double x) { |
| 232 return v8::Number::New(x); | 236 return v8::Number::New(x); |
| 233 } | 237 } |
| 234 | 238 |
| 235 | 239 |
| 236 static inline v8::Local<v8::String> v8_str(const char* x) { | 240 static inline v8::Local<v8::String> v8_str(const char* x) { |
| 237 return v8::String::New(x); | 241 return v8::String::New(x); |
| 238 } | 242 } |
| 239 | 243 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { | 286 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { |
| 283 int old_linear_size = static_cast<int>(space->limit() - space->top()); | 287 int old_linear_size = static_cast<int>(space->limit() - space->top()); |
| 284 space->Free(space->top(), old_linear_size); | 288 space->Free(space->top(), old_linear_size); |
| 285 space->SetTop(space->limit(), space->limit()); | 289 space->SetTop(space->limit(), space->limit()); |
| 286 space->ResetFreeList(); | 290 space->ResetFreeList(); |
| 287 space->ClearStats(); | 291 space->ClearStats(); |
| 288 } | 292 } |
| 289 | 293 |
| 290 | 294 |
| 291 #endif // ifndef CCTEST_H_ | 295 #endif // ifndef CCTEST_H_ |
| OLD | NEW |