| 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 2246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2257 queue = FixedArray::CopySize(queue, num_tasks * 2); | 2257 queue = FixedArray::CopySize(queue, num_tasks * 2); |
| 2258 heap()->set_microtask_queue(*queue); | 2258 heap()->set_microtask_queue(*queue); |
| 2259 } | 2259 } |
| 2260 ASSERT(queue->get(num_tasks)->IsUndefined()); | 2260 ASSERT(queue->get(num_tasks)->IsUndefined()); |
| 2261 queue->set(num_tasks, *microtask); | 2261 queue->set(num_tasks, *microtask); |
| 2262 set_pending_microtask_count(num_tasks + 1); | 2262 set_pending_microtask_count(num_tasks + 1); |
| 2263 } | 2263 } |
| 2264 | 2264 |
| 2265 | 2265 |
| 2266 void Isolate::RunMicrotasks() { | 2266 void Isolate::RunMicrotasks() { |
| 2267 ASSERT(handle_scope_implementer()->CallDepthIsZero()); | 2267 // TODO(adamk): This ASSERT triggers in mjsunit tests which |
| 2268 // call the %RunMicrotasks runtime function. But it should |
| 2269 // never happen outside of tests, so it would be nice to |
| 2270 // uncomment it. |
| 2271 // |
| 2272 // ASSERT(handle_scope_implementer()->CallDepthIsZero()); |
| 2268 | 2273 |
| 2269 // Increase call depth to prevent recursive callbacks. | 2274 // Increase call depth to prevent recursive callbacks. |
| 2270 handle_scope_implementer()->IncrementCallDepth(); | 2275 handle_scope_implementer()->IncrementCallDepth(); |
| 2271 | 2276 |
| 2272 while (pending_microtask_count() > 0) { | 2277 while (pending_microtask_count() > 0) { |
| 2273 HandleScope scope(this); | 2278 HandleScope scope(this); |
| 2274 int num_tasks = pending_microtask_count(); | 2279 int num_tasks = pending_microtask_count(); |
| 2275 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 2280 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
| 2276 ASSERT(num_tasks <= queue->length()); | 2281 ASSERT(num_tasks <= queue->length()); |
| 2277 set_pending_microtask_count(0); | 2282 set_pending_microtask_count(0); |
| 2278 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2283 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
| 2279 | 2284 |
| 2280 for (int i = 0; i < num_tasks; i++) { | 2285 for (int i = 0; i < num_tasks; i++) { |
| 2281 HandleScope scope(this); | 2286 HandleScope scope(this); |
| 2282 Handle<JSFunction> microtask(JSFunction::cast(queue->get(i)), this); | 2287 Handle<JSFunction> microtask(JSFunction::cast(queue->get(i)), this); |
| 2283 // TODO(adamk): This should ignore/clear exceptions instead of Checking. | 2288 // TODO(adamk): This should ignore/clear exceptions instead of Checking. |
| 2284 Execution::Call(this, microtask, factory()->undefined_value(), | 2289 Execution::Call(this, microtask, factory()->undefined_value(), |
| 2285 0, NULL).Check(); | 2290 0, NULL).Check(); |
| 2286 } | 2291 } |
| 2287 } | 2292 } |
| 2288 | 2293 |
| 2289 handle_scope_implementer()->DecrementCallDepth(); | 2294 handle_scope_implementer()->DecrementCallDepth(); |
| 2290 } | 2295 } |
| 2291 | 2296 |
| 2292 | 2297 |
| 2293 } } // namespace v8::internal | 2298 } } // namespace v8::internal |
| OLD | NEW |