47
47
static bool init_once_called = false;
49
49
bool V8::is_running_ = false;
50
bool V8::has_been_setup_ = false;
50
bool V8::has_been_set_up_ = false;
51
51
bool V8::has_been_disposed_ = false;
52
52
bool V8::has_fatal_error_ = false;
53
53
bool V8::use_crankshaft_ = true;
54
List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL;
55
56
static Mutex* entropy_mutex = OS::CreateMutex();
56
57
static EntropySource entropy_source;
59
60
bool V8::Initialize(Deserializer* des) {
60
// Setting --harmony implies all other harmony flags.
61
// TODO(rossberg): Is there a better place to put this?
63
FLAG_harmony_typeof = true;
64
FLAG_harmony_scoping = true;
65
FLAG_harmony_proxies = true;
66
FLAG_harmony_collections = true;
61
FlagList::EnforceFlagImplications();
69
63
InitializeOncePerProcess();
106
100
Isolate* isolate = Isolate::Current();
107
101
ASSERT(isolate->IsDefaultIsolate());
109
if (!has_been_setup_ || has_been_disposed_) return;
103
if (!has_been_set_up_ || has_been_disposed_) return;
110
104
isolate->TearDown();
112
106
is_running_ = false;
113
107
has_been_disposed_ = true;
109
delete call_completed_callbacks_;
110
call_completed_callbacks_ = NULL;
169
bool V8::IdleNotification() {
166
bool V8::IdleNotification(int hint) {
170
167
// Returning true tells the caller that there is no need to call
171
168
// IdleNotification again.
172
169
if (!FLAG_use_idle_notification) return true;
174
171
// Tell the heap that it may want to adjust.
175
return HEAP->IdleNotification();
172
return HEAP->IdleNotification(hint);
176
void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
177
if (call_completed_callbacks_ == NULL) { // Lazy init.
178
call_completed_callbacks_ = new List<CallCompletedCallback>();
180
for (int i = 0; i < call_completed_callbacks_->length(); i++) {
181
if (callback == call_completed_callbacks_->at(i)) return;
183
call_completed_callbacks_->Add(callback);
187
void V8::RemoveCallCompletedCallback(CallCompletedCallback callback) {
188
if (call_completed_callbacks_ == NULL) return;
189
for (int i = 0; i < call_completed_callbacks_->length(); i++) {
190
if (callback == call_completed_callbacks_->at(i)) {
191
call_completed_callbacks_->Remove(i);
197
void V8::FireCallCompletedCallback(Isolate* isolate) {
198
if (call_completed_callbacks_ == NULL) return;
199
HandleScopeImplementer* handle_scope_implementer =
200
isolate->handle_scope_implementer();
201
if (!handle_scope_implementer->CallDepthIsZero()) return;
202
// Fire callbacks. Increase call depth to prevent recursive callbacks.
203
handle_scope_implementer->IncrementCallDepth();
204
for (int i = 0; i < call_completed_callbacks_->length(); i++) {
205
call_completed_callbacks_->at(i)();
207
handle_scope_implementer->DecrementCallDepth();