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 12 matching lines...) Expand all Loading... |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef CCTEST_H_ | 28 #ifndef CCTEST_H_ |
29 #define CCTEST_H_ | 29 #define CCTEST_H_ |
30 | 30 |
31 #include "src/v8.h" | 31 #include "src/v8.h" |
32 | 32 |
| 33 #include "src/isolate-inl.h" |
| 34 |
33 #ifndef TEST | 35 #ifndef TEST |
34 #define TEST(Name) \ | 36 #define TEST(Name) \ |
35 static void Test##Name(); \ | 37 static void Test##Name(); \ |
36 CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, true); \ | 38 CcTest register_test_##Name(Test##Name, __FILE__, #Name, NULL, true, true); \ |
37 static void Test##Name() | 39 static void Test##Name() |
38 #endif | 40 #endif |
39 | 41 |
40 #ifndef UNINITIALIZED_TEST | 42 #ifndef UNINITIALIZED_TEST |
41 #define UNINITIALIZED_TEST(Name) \ | 43 #define UNINITIALIZED_TEST(Name) \ |
42 static void Test##Name(); \ | 44 static void Test##Name(); \ |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const char* name() { return name_; } | 107 const char* name() { return name_; } |
106 const char* dependency() { return dependency_; } | 108 const char* dependency() { return dependency_; } |
107 bool enabled() { return enabled_; } | 109 bool enabled() { return enabled_; } |
108 | 110 |
109 static v8::Isolate* isolate() { | 111 static v8::Isolate* isolate() { |
110 CHECK(isolate_ != NULL); | 112 CHECK(isolate_ != NULL); |
111 isolate_used_ = true; | 113 isolate_used_ = true; |
112 return isolate_; | 114 return isolate_; |
113 } | 115 } |
114 | 116 |
| 117 static i::Isolate* InitIsolateOnce() { |
| 118 if (!initialize_called_) InitializeVM(); |
| 119 return i_isolate(); |
| 120 } |
| 121 |
115 static i::Isolate* i_isolate() { | 122 static i::Isolate* i_isolate() { |
116 return reinterpret_cast<i::Isolate*>(isolate()); | 123 return reinterpret_cast<i::Isolate*>(isolate()); |
117 } | 124 } |
118 | 125 |
119 static i::Heap* heap() { | 126 static i::Heap* heap() { |
120 return i_isolate()->heap(); | 127 return i_isolate()->heap(); |
121 } | 128 } |
122 | 129 |
123 static TestHeap* test_heap() { | 130 static TestHeap* test_heap() { |
124 return reinterpret_cast<TestHeap*>(i_isolate()->heap()); | 131 return reinterpret_cast<TestHeap*>(i_isolate()->heap()); |
125 } | 132 } |
126 | 133 |
| 134 static v8::base::RandomNumberGenerator* random_number_generator() { |
| 135 return InitIsolateOnce()->random_number_generator(); |
| 136 } |
| 137 |
127 static v8::Local<v8::Object> global() { | 138 static v8::Local<v8::Object> global() { |
128 return isolate()->GetCurrentContext()->Global(); | 139 return isolate()->GetCurrentContext()->Global(); |
129 } | 140 } |
130 | 141 |
131 // TODO(dcarney): Remove. | 142 // TODO(dcarney): Remove. |
132 // This must be called first in a test. | 143 // This must be called first in a test. |
133 static void InitializeVM() { | 144 static void InitializeVM() { |
134 CHECK(!isolate_used_); | 145 CHECK(!isolate_used_); |
135 CHECK(!initialize_called_); | 146 CHECK(!initialize_called_); |
136 initialize_called_ = true; | 147 initialize_called_ = true; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 i::Isolate::Current()->heap()->CollectAllAvailableGarbage(); | 510 i::Isolate::Current()->heap()->CollectAllAvailableGarbage(); |
500 CHECK_EQ(0, heap_profiler_->heap_object_map()->FindUntrackedObjects()); | 511 CHECK_EQ(0, heap_profiler_->heap_object_map()->FindUntrackedObjects()); |
501 heap_profiler_->StopHeapObjectsTracking(); | 512 heap_profiler_->StopHeapObjectsTracking(); |
502 } | 513 } |
503 | 514 |
504 private: | 515 private: |
505 i::HeapProfiler* heap_profiler_; | 516 i::HeapProfiler* heap_profiler_; |
506 }; | 517 }; |
507 | 518 |
508 | 519 |
| 520 class InitializedHandleScope { |
| 521 public: |
| 522 InitializedHandleScope() |
| 523 : main_isolate_(CcTest::InitIsolateOnce()), |
| 524 handle_scope_(main_isolate_) {} |
| 525 |
| 526 // Prefixing the below with main_ reduces a lot of naming clashes. |
| 527 i::Isolate* main_isolate() { return main_isolate_; } |
| 528 |
| 529 private: |
| 530 i::Isolate* main_isolate_; |
| 531 i::HandleScope handle_scope_; |
| 532 }; |
| 533 |
| 534 |
| 535 class HandleAndZoneScope : public InitializedHandleScope { |
| 536 public: |
| 537 HandleAndZoneScope() : main_zone_(main_isolate()) {} |
| 538 |
| 539 // Prefixing the below with main_ reduces a lot of naming clashes. |
| 540 i::Zone* main_zone() { return &main_zone_; } |
| 541 |
| 542 private: |
| 543 i::Zone main_zone_; |
| 544 }; |
| 545 |
509 #endif // ifndef CCTEST_H_ | 546 #endif // ifndef CCTEST_H_ |
OLD | NEW |