OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "sampler.h" | 46 #include "sampler.h" |
47 #include "runtime-profiler.h" | 47 #include "runtime-profiler.h" |
48 #include "serialize.h" | 48 #include "serialize.h" |
49 #include "store-buffer.h" | 49 #include "store-buffer.h" |
50 | 50 |
51 namespace v8 { | 51 namespace v8 { |
52 namespace internal { | 52 namespace internal { |
53 | 53 |
54 V8_DECLARE_ONCE(init_once); | 54 V8_DECLARE_ONCE(init_once); |
55 | 55 |
56 List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL; | |
57 v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; | 56 v8::ArrayBuffer::Allocator* V8::array_buffer_allocator_ = NULL; |
58 v8::Platform* V8::platform_ = NULL; | 57 v8::Platform* V8::platform_ = NULL; |
59 | 58 |
60 | 59 |
61 bool V8::Initialize(Deserializer* des) { | 60 bool V8::Initialize(Deserializer* des) { |
62 InitializeOncePerProcess(); | 61 InitializeOncePerProcess(); |
63 Isolate* isolate = Isolate::UncheckedCurrent(); | 62 Isolate* isolate = Isolate::UncheckedCurrent(); |
64 if (isolate == NULL) return true; | 63 if (isolate == NULL) return true; |
65 if (isolate->IsDead()) return false; | 64 if (isolate->IsDead()) return false; |
66 if (isolate->IsInitialized()) return true; | 65 if (isolate->IsInitialized()) return true; |
(...skipping 20 matching lines...) Expand all Loading... |
87 isolate->TearDown(); | 86 isolate->TearDown(); |
88 delete isolate; | 87 delete isolate; |
89 | 88 |
90 Bootstrapper::TearDownExtensions(); | 89 Bootstrapper::TearDownExtensions(); |
91 ElementsAccessor::TearDown(); | 90 ElementsAccessor::TearDown(); |
92 LOperand::TearDownCaches(); | 91 LOperand::TearDownCaches(); |
93 ExternalReference::TearDownMathExpData(); | 92 ExternalReference::TearDownMathExpData(); |
94 RegisteredExtension::UnregisterAll(); | 93 RegisteredExtension::UnregisterAll(); |
95 Isolate::GlobalTearDown(); | 94 Isolate::GlobalTearDown(); |
96 | 95 |
97 delete call_completed_callbacks_; | |
98 call_completed_callbacks_ = NULL; | |
99 | |
100 Sampler::TearDown(); | 96 Sampler::TearDown(); |
101 Serializer::TearDown(); | 97 Serializer::TearDown(); |
102 | 98 |
103 #ifdef V8_USE_DEFAULT_PLATFORM | 99 #ifdef V8_USE_DEFAULT_PLATFORM |
104 DefaultPlatform* platform = static_cast<DefaultPlatform*>(platform_); | 100 DefaultPlatform* platform = static_cast<DefaultPlatform*>(platform_); |
105 platform_ = NULL; | 101 platform_ = NULL; |
106 delete platform; | 102 delete platform; |
107 #endif | 103 #endif |
108 } | 104 } |
109 | 105 |
110 | 106 |
111 void V8::SetReturnAddressLocationResolver( | 107 void V8::SetReturnAddressLocationResolver( |
112 ReturnAddressLocationResolver resolver) { | 108 ReturnAddressLocationResolver resolver) { |
113 StackFrame::SetReturnAddressLocationResolver(resolver); | 109 StackFrame::SetReturnAddressLocationResolver(resolver); |
114 } | 110 } |
115 | 111 |
116 | 112 |
117 void V8::AddCallCompletedCallback(CallCompletedCallback callback) { | |
118 if (call_completed_callbacks_ == NULL) { // Lazy init. | |
119 call_completed_callbacks_ = new List<CallCompletedCallback>(); | |
120 } | |
121 for (int i = 0; i < call_completed_callbacks_->length(); i++) { | |
122 if (callback == call_completed_callbacks_->at(i)) return; | |
123 } | |
124 call_completed_callbacks_->Add(callback); | |
125 } | |
126 | |
127 | |
128 void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) { | |
129 if (call_completed_callbacks_ == NULL) return; | |
130 for (int i = 0; i < call_completed_callbacks_->length(); i++) { | |
131 if (callback == call_completed_callbacks_->at(i)) { | |
132 call_completed_callbacks_->Remove(i); | |
133 } | |
134 } | |
135 } | |
136 | |
137 | |
138 void V8::FireCallCompletedCallback(Isolate* isolate) { | |
139 bool has_call_completed_callbacks = call_completed_callbacks_ != NULL; | |
140 bool run_microtasks = isolate->autorun_microtasks() && | |
141 isolate->microtask_pending(); | |
142 if (!has_call_completed_callbacks && !run_microtasks) return; | |
143 | |
144 HandleScopeImplementer* handle_scope_implementer = | |
145 isolate->handle_scope_implementer(); | |
146 if (!handle_scope_implementer->CallDepthIsZero()) return; | |
147 // Fire callbacks. Increase call depth to prevent recursive callbacks. | |
148 handle_scope_implementer->IncrementCallDepth(); | |
149 if (run_microtasks) Execution::RunMicrotasks(isolate); | |
150 if (has_call_completed_callbacks) { | |
151 for (int i = 0; i < call_completed_callbacks_->length(); i++) { | |
152 call_completed_callbacks_->at(i)(); | |
153 } | |
154 } | |
155 handle_scope_implementer->DecrementCallDepth(); | |
156 } | |
157 | |
158 | |
159 void V8::RunMicrotasks(Isolate* isolate) { | 113 void V8::RunMicrotasks(Isolate* isolate) { |
160 if (!isolate->microtask_pending()) | 114 if (!isolate->microtask_pending()) |
161 return; | 115 return; |
162 | 116 |
163 HandleScopeImplementer* handle_scope_implementer = | 117 HandleScopeImplementer* handle_scope_implementer = |
164 isolate->handle_scope_implementer(); | 118 isolate->handle_scope_implementer(); |
165 ASSERT(handle_scope_implementer->CallDepthIsZero()); | 119 ASSERT(handle_scope_implementer->CallDepthIsZero()); |
166 | 120 |
167 // Increase call depth to prevent recursive callbacks. | 121 // Increase call depth to prevent recursive callbacks. |
168 handle_scope_implementer->IncrementCallDepth(); | 122 handle_scope_implementer->IncrementCallDepth(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 platform_ = NULL; | 171 platform_ = NULL; |
218 } | 172 } |
219 | 173 |
220 | 174 |
221 v8::Platform* V8::GetCurrentPlatform() { | 175 v8::Platform* V8::GetCurrentPlatform() { |
222 ASSERT(platform_); | 176 ASSERT(platform_); |
223 return platform_; | 177 return platform_; |
224 } | 178 } |
225 | 179 |
226 } } // namespace v8::internal | 180 } } // namespace v8::internal |
OLD | NEW |