OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "v8.h" | 7 #include "v8.h" |
8 | 8 |
9 #include "ast.h" | 9 #include "ast.h" |
10 #include "bootstrapper.h" | 10 #include "bootstrapper.h" |
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2225 for (int i = 0; i < call_completed_callbacks_.length(); i++) { | 2225 for (int i = 0; i < call_completed_callbacks_.length(); i++) { |
2226 if (callback == call_completed_callbacks_.at(i)) { | 2226 if (callback == call_completed_callbacks_.at(i)) { |
2227 call_completed_callbacks_.Remove(i); | 2227 call_completed_callbacks_.Remove(i); |
2228 } | 2228 } |
2229 } | 2229 } |
2230 } | 2230 } |
2231 | 2231 |
2232 | 2232 |
2233 void Isolate::FireCallCompletedCallback() { | 2233 void Isolate::FireCallCompletedCallback() { |
2234 bool has_call_completed_callbacks = !call_completed_callbacks_.is_empty(); | 2234 bool has_call_completed_callbacks = !call_completed_callbacks_.is_empty(); |
2235 bool run_microtasks = autorun_microtasks() && microtask_pending(); | 2235 bool run_microtasks = autorun_microtasks() && pending_microtask_count(); |
2236 if (!has_call_completed_callbacks && !run_microtasks) return; | 2236 if (!has_call_completed_callbacks && !run_microtasks) return; |
2237 | 2237 |
2238 if (!handle_scope_implementer()->CallDepthIsZero()) return; | 2238 if (!handle_scope_implementer()->CallDepthIsZero()) return; |
2239 if (run_microtasks) RunMicrotasks(); | |
2239 // Fire callbacks. Increase call depth to prevent recursive callbacks. | 2240 // Fire callbacks. Increase call depth to prevent recursive callbacks. |
2240 handle_scope_implementer()->IncrementCallDepth(); | 2241 handle_scope_implementer()->IncrementCallDepth(); |
2241 if (run_microtasks) Execution::RunMicrotasks(this); | |
2242 for (int i = 0; i < call_completed_callbacks_.length(); i++) { | 2242 for (int i = 0; i < call_completed_callbacks_.length(); i++) { |
2243 call_completed_callbacks_.at(i)(); | 2243 call_completed_callbacks_.at(i)(); |
2244 } | 2244 } |
2245 handle_scope_implementer()->DecrementCallDepth(); | 2245 handle_scope_implementer()->DecrementCallDepth(); |
2246 } | 2246 } |
2247 | 2247 |
2248 | 2248 |
2249 void Isolate::EnqueueMicrotask(Handle<JSFunction> microtask) { | |
2250 Handle<FixedArray> queue(heap()->microtask_queue(), this); | |
2251 int num_tasks = pending_microtask_count(); | |
2252 ASSERT(num_tasks <= queue->length()); | |
2253 if (num_tasks == 0) { | |
2254 queue = factory()->NewFixedArray(1); | |
dcarney
2014/05/17 06:54:09
1 might be a little conservative here, maybe 4, 8
adamk
2014/05/19 07:47:58
Let's go with 8.
| |
2255 heap()->set_microtask_queue(*queue); | |
2256 } else if (num_tasks == queue->length()) { | |
2257 queue = FixedArray::CopySize(queue, num_tasks * 2); | |
2258 heap()->set_microtask_queue(*queue); | |
2259 } | |
2260 ASSERT(queue->get(num_tasks)->IsUndefined()); | |
2261 queue->set(num_tasks, *microtask); | |
2262 set_pending_microtask_count(num_tasks + 1); | |
2263 } | |
2264 | |
2265 | |
2249 void Isolate::RunMicrotasks() { | 2266 void Isolate::RunMicrotasks() { |
2250 if (!microtask_pending()) | |
2251 return; | |
2252 | |
2253 ASSERT(handle_scope_implementer()->CallDepthIsZero()); | 2267 ASSERT(handle_scope_implementer()->CallDepthIsZero()); |
2254 | 2268 |
2255 // Increase call depth to prevent recursive callbacks. | 2269 // Increase call depth to prevent recursive callbacks. |
2256 handle_scope_implementer()->IncrementCallDepth(); | 2270 handle_scope_implementer()->IncrementCallDepth(); |
2257 Execution::RunMicrotasks(this); | 2271 |
2272 HandleScope scope(this); | |
2273 while (pending_microtask_count() > 0) { | |
dcarney
2014/05/16 17:41:51
put handlescope here
adamk
2014/05/19 07:47:58
Done.
| |
2274 int num_tasks = pending_microtask_count(); | |
2275 Handle<FixedArray> queue(heap()->microtask_queue(), this); | |
2276 ASSERT(num_tasks <= queue->length()); | |
2277 set_pending_microtask_count(0); | |
2278 heap()->set_microtask_queue(heap()->empty_fixed_array()); | |
2279 | |
2280 for (int i = 0; i < num_tasks; i++) { | |
dcarney
2014/05/16 17:41:51
and here maybe
adamk
2014/05/19 07:47:58
Done.
| |
2281 Handle<JSFunction> microtask(JSFunction::cast(queue->get(i)), this); | |
2282 // TODO(adamk): This should ignore/clear exceptions instead of Checking. | |
2283 Execution::Call(this, microtask, factory()->undefined_value(), | |
2284 0, NULL).Check(); | |
2285 } | |
2286 } | |
2287 | |
2258 handle_scope_implementer()->DecrementCallDepth(); | 2288 handle_scope_implementer()->DecrementCallDepth(); |
2259 } | 2289 } |
2260 | 2290 |
2261 | 2291 |
2262 } } // namespace v8::internal | 2292 } } // namespace v8::internal |
OLD | NEW |