Chromium Code Reviews| 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 2244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2255 if (run_microtasks) RunMicrotasks(); | 2255 if (run_microtasks) RunMicrotasks(); |
| 2256 // Fire callbacks. Increase call depth to prevent recursive callbacks. | 2256 // Fire callbacks. Increase call depth to prevent recursive callbacks. |
| 2257 v8::Isolate::SuppressMicrotaskExecutionScope suppress( | 2257 v8::Isolate::SuppressMicrotaskExecutionScope suppress( |
| 2258 reinterpret_cast<v8::Isolate*>(this)); | 2258 reinterpret_cast<v8::Isolate*>(this)); |
| 2259 for (int i = 0; i < call_completed_callbacks_.length(); i++) { | 2259 for (int i = 0; i < call_completed_callbacks_.length(); i++) { |
| 2260 call_completed_callbacks_.at(i)(); | 2260 call_completed_callbacks_.at(i)(); |
| 2261 } | 2261 } |
| 2262 } | 2262 } |
| 2263 | 2263 |
| 2264 | 2264 |
| 2265 void Isolate::EnqueueMicrotask(Handle<JSFunction> microtask) { | 2265 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
| 2266 ASSERT(microtask->IsJSFunction() || microtask->IsCallHandlerInfo()); | |
| 2266 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 2267 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
| 2267 int num_tasks = pending_microtask_count(); | 2268 int num_tasks = pending_microtask_count(); |
| 2268 ASSERT(num_tasks <= queue->length()); | 2269 ASSERT(num_tasks <= queue->length()); |
| 2269 if (num_tasks == 0) { | 2270 if (num_tasks == 0) { |
| 2270 queue = factory()->NewFixedArray(8); | 2271 queue = factory()->NewFixedArray(8); |
| 2271 heap()->set_microtask_queue(*queue); | 2272 heap()->set_microtask_queue(*queue); |
| 2272 } else if (num_tasks == queue->length()) { | 2273 } else if (num_tasks == queue->length()) { |
| 2273 queue = FixedArray::CopySize(queue, num_tasks * 2); | 2274 queue = FixedArray::CopySize(queue, num_tasks * 2); |
| 2274 heap()->set_microtask_queue(*queue); | 2275 heap()->set_microtask_queue(*queue); |
| 2275 } | 2276 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2294 while (pending_microtask_count() > 0) { | 2295 while (pending_microtask_count() > 0) { |
| 2295 HandleScope scope(this); | 2296 HandleScope scope(this); |
| 2296 int num_tasks = pending_microtask_count(); | 2297 int num_tasks = pending_microtask_count(); |
| 2297 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 2298 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
| 2298 ASSERT(num_tasks <= queue->length()); | 2299 ASSERT(num_tasks <= queue->length()); |
| 2299 set_pending_microtask_count(0); | 2300 set_pending_microtask_count(0); |
| 2300 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2301 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
| 2301 | 2302 |
| 2302 for (int i = 0; i < num_tasks; i++) { | 2303 for (int i = 0; i < num_tasks; i++) { |
| 2303 HandleScope scope(this); | 2304 HandleScope scope(this); |
| 2304 Handle<JSFunction> microtask(JSFunction::cast(queue->get(i)), this); | 2305 Handle<Object> microtask(queue->get(i), this); |
| 2305 Handle<Object> exception; | 2306 if (microtask->IsJSFunction()) { |
| 2306 MaybeHandle<Object> result = Execution::TryCall( | 2307 Handle<JSFunction> microtask_function = |
| 2307 microtask, factory()->undefined_value(), 0, NULL, &exception); | 2308 Handle<JSFunction>::cast(microtask); |
| 2308 // If execution is terminating, just bail out. | 2309 Handle<Object> exception; |
| 2309 if (result.is_null() && | 2310 MaybeHandle<Object> result = Execution::TryCall( |
| 2310 !exception.is_null() && | 2311 microtask_function, factory()->undefined_value(), |
| 2311 *exception == heap()->termination_exception()) { | 2312 0, NULL, &exception); |
| 2312 // Clear out any remaining callbacks in the queue. | 2313 // If execution is terminating, just bail out. |
| 2313 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2314 if (result.is_null() && |
| 2314 set_pending_microtask_count(0); | 2315 !exception.is_null() && |
| 2315 return; | 2316 *exception == heap()->termination_exception()) { |
| 2317 // Clear out any remaining callbacks in the queue. | |
| 2318 heap()->set_microtask_queue(heap()->empty_fixed_array()); | |
| 2319 set_pending_microtask_count(0); | |
| 2320 return; | |
| 2321 } | |
| 2322 } else { | |
| 2323 ASSERT(microtask->IsCallHandlerInfo()); | |
|
dcarney
2014/06/02 07:22:10
no need to assert, ::cast does that
| |
| 2324 Handle<CallHandlerInfo> callback_info = | |
| 2325 Handle<CallHandlerInfo>::cast(microtask); | |
| 2326 v8::MicrotaskCallback callback = | |
| 2327 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); | |
| 2328 void* data = v8::ToCData<void*>(callback_info->data()); | |
| 2329 callback(data); | |
| 2316 } | 2330 } |
| 2317 } | 2331 } |
| 2318 } | 2332 } |
| 2319 } | 2333 } |
| 2320 | 2334 |
| 2321 | 2335 |
| 2322 } } // namespace v8::internal | 2336 } } // namespace v8::internal |
| OLD | NEW |