Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: src/v8.cc

Issue 8937003: Implement callback when script finishes running in V8 API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed comments. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/v8.h ('K') | « src/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace internal { 44 namespace internal {
45 45
46 static Mutex* init_once_mutex = OS::CreateMutex(); 46 static Mutex* init_once_mutex = OS::CreateMutex();
47 static bool init_once_called = false; 47 static bool init_once_called = false;
48 48
49 bool V8::is_running_ = false; 49 bool V8::is_running_ = false;
50 bool V8::has_been_setup_ = false; 50 bool V8::has_been_setup_ = false;
51 bool V8::has_been_disposed_ = false; 51 bool V8::has_been_disposed_ = false;
52 bool V8::has_fatal_error_ = false; 52 bool V8::has_fatal_error_ = false;
53 bool V8::use_crankshaft_ = true; 53 bool V8::use_crankshaft_ = true;
54 List<CallCompletedCallback>* V8::call_completed_callbacks_ = NULL;
54 55
55 static Mutex* entropy_mutex = OS::CreateMutex(); 56 static Mutex* entropy_mutex = OS::CreateMutex();
56 static EntropySource entropy_source; 57 static EntropySource entropy_source;
57 58
58 59
59 bool V8::Initialize(Deserializer* des) { 60 bool V8::Initialize(Deserializer* des) {
60 FlagList::EnforceFlagImplications(); 61 FlagList::EnforceFlagImplications();
61 62
62 InitializeOncePerProcess(); 63 InitializeOncePerProcess();
63 64
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 98
98 void V8::TearDown() { 99 void V8::TearDown() {
99 Isolate* isolate = Isolate::Current(); 100 Isolate* isolate = Isolate::Current();
100 ASSERT(isolate->IsDefaultIsolate()); 101 ASSERT(isolate->IsDefaultIsolate());
101 102
102 if (!has_been_setup_ || has_been_disposed_) return; 103 if (!has_been_setup_ || has_been_disposed_) return;
103 isolate->TearDown(); 104 isolate->TearDown();
104 105
105 is_running_ = false; 106 is_running_ = false;
106 has_been_disposed_ = true; 107 has_been_disposed_ = true;
108
109 delete call_completed_callbacks_;
110 call_completed_callbacks_ = NULL;
107 } 111 }
108 112
109 113
110 static void seed_random(uint32_t* state) { 114 static void seed_random(uint32_t* state) {
111 for (int i = 0; i < 2; ++i) { 115 for (int i = 0; i < 2; ++i) {
112 if (FLAG_random_seed != 0) { 116 if (FLAG_random_seed != 0) {
113 state[i] = FLAG_random_seed; 117 state[i] = FLAG_random_seed;
114 } else if (entropy_source != NULL) { 118 } else if (entropy_source != NULL) {
115 uint32_t val; 119 uint32_t val;
116 ScopedLock lock(entropy_mutex); 120 ScopedLock lock(entropy_mutex);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 bool V8::IdleNotification(int hint) { 166 bool V8::IdleNotification(int hint) {
163 // Returning true tells the caller that there is no need to call 167 // Returning true tells the caller that there is no need to call
164 // IdleNotification again. 168 // IdleNotification again.
165 if (!FLAG_use_idle_notification) return true; 169 if (!FLAG_use_idle_notification) return true;
166 170
167 // Tell the heap that it may want to adjust. 171 // Tell the heap that it may want to adjust.
168 return HEAP->IdleNotification(hint); 172 return HEAP->IdleNotification(hint);
169 } 173 }
170 174
171 175
176 void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
177 if (call_completed_callbacks_ == NULL) { // Lazy init.
178 call_completed_callbacks_ = new List<CallCompletedCallback>();
179 }
180 for (int i = 0; i < call_completed_callbacks_->length(); i++) {
181 if (callback == call_completed_callbacks_->at(i)) return;
182 }
183 call_completed_callbacks_->Add(callback);
184 }
185
186
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);
192 }
193 }
194 }
195
196
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)();
206 }
207 handle_scope_implementer->DecrementCallDepth();
208 }
209
210
172 // Use a union type to avoid type-aliasing optimizations in GCC. 211 // Use a union type to avoid type-aliasing optimizations in GCC.
173 typedef union { 212 typedef union {
174 double double_value; 213 double double_value;
175 uint64_t uint64_t_value; 214 uint64_t uint64_t_value;
176 } double_int_union; 215 } double_int_union;
177 216
178 217
179 Object* V8::FillHeapNumberWithRandom(Object* heap_number, 218 Object* V8::FillHeapNumberWithRandom(Object* heap_number,
180 Context* context) { 219 Context* context) {
181 uint64_t random_bits = Random(context); 220 uint64_t random_bits = Random(context);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 ElementsAccessor::InitializeOncePerProcess(); 261 ElementsAccessor::InitializeOncePerProcess();
223 262
224 if (FLAG_stress_compaction) { 263 if (FLAG_stress_compaction) {
225 FLAG_force_marking_deque_overflows = true; 264 FLAG_force_marking_deque_overflows = true;
226 FLAG_gc_global = true; 265 FLAG_gc_global = true;
227 FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2; 266 FLAG_max_new_space_size = (1 << (kPageSizeBits - 10)) * 2;
228 } 267 }
229 } 268 }
230 269
231 } } // namespace v8::internal 270 } } // namespace v8::internal
OLDNEW
« src/v8.h ('K') | « src/v8.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698