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 "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/ast.h" | 9 #include "src/ast.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 2274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 queue = FixedArray::CopySize(queue, num_tasks * 2); | 2285 queue = FixedArray::CopySize(queue, num_tasks * 2); |
2286 heap()->set_microtask_queue(*queue); | 2286 heap()->set_microtask_queue(*queue); |
2287 } | 2287 } |
2288 ASSERT(queue->get(num_tasks)->IsUndefined()); | 2288 ASSERT(queue->get(num_tasks)->IsUndefined()); |
2289 queue->set(num_tasks, *microtask); | 2289 queue->set(num_tasks, *microtask); |
2290 set_pending_microtask_count(num_tasks + 1); | 2290 set_pending_microtask_count(num_tasks + 1); |
2291 } | 2291 } |
2292 | 2292 |
2293 | 2293 |
2294 void Isolate::RunMicrotasks() { | 2294 void Isolate::RunMicrotasks() { |
2295 // TODO(adamk): This ASSERT triggers in mjsunit tests which | 2295 // In some mjsunit tests %RunMicrotasks is called explicitly, violating |
2296 // call the %RunMicrotasks runtime function. But it should | 2296 // this assertion. Therefore we also check for --allow-natives-syntax. |
2297 // never happen outside of tests, so it would be nice to | 2297 ASSERT(FLAG_allow_natives_syntax || |
2298 // uncomment it. | 2298 handle_scope_implementer()->CallDepthIsZero()); |
2299 // | |
2300 // ASSERT(handle_scope_implementer()->CallDepthIsZero()); | |
2301 | 2299 |
2302 // Increase call depth to prevent recursive callbacks. | 2300 // Increase call depth to prevent recursive callbacks. |
2303 v8::Isolate::SuppressMicrotaskExecutionScope suppress( | 2301 v8::Isolate::SuppressMicrotaskExecutionScope suppress( |
2304 reinterpret_cast<v8::Isolate*>(this)); | 2302 reinterpret_cast<v8::Isolate*>(this)); |
2305 | 2303 |
2306 while (pending_microtask_count() > 0) { | 2304 while (pending_microtask_count() > 0) { |
2307 HandleScope scope(this); | 2305 HandleScope scope(this); |
2308 int num_tasks = pending_microtask_count(); | 2306 int num_tasks = pending_microtask_count(); |
2309 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 2307 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
2310 ASSERT(num_tasks <= queue->length()); | 2308 ASSERT(num_tasks <= queue->length()); |
2311 set_pending_microtask_count(0); | 2309 set_pending_microtask_count(0); |
2312 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2310 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
2313 | 2311 |
2314 for (int i = 0; i < num_tasks; i++) { | 2312 for (int i = 0; i < num_tasks; i++) { |
2315 HandleScope scope(this); | 2313 HandleScope scope(this); |
2316 Handle<Object> microtask(queue->get(i), this); | 2314 Handle<Object> microtask(queue->get(i), this); |
2317 if (microtask->IsJSFunction()) { | 2315 if (microtask->IsJSFunction()) { |
2318 Handle<JSFunction> microtask_function = | 2316 Handle<JSFunction> microtask_function = |
2319 Handle<JSFunction>::cast(microtask); | 2317 Handle<JSFunction>::cast(microtask); |
| 2318 SaveContext save(this); |
| 2319 set_context(microtask_function->context()->native_context()); |
2320 Handle<Object> exception; | 2320 Handle<Object> exception; |
2321 MaybeHandle<Object> result = Execution::TryCall( | 2321 MaybeHandle<Object> result = Execution::TryCall( |
2322 microtask_function, factory()->undefined_value(), | 2322 microtask_function, factory()->undefined_value(), |
2323 0, NULL, &exception); | 2323 0, NULL, &exception); |
2324 // If execution is terminating, just bail out. | 2324 // If execution is terminating, just bail out. |
2325 if (result.is_null() && | 2325 if (result.is_null() && |
2326 !exception.is_null() && | 2326 !exception.is_null() && |
2327 *exception == heap()->termination_exception()) { | 2327 *exception == heap()->termination_exception()) { |
2328 // Clear out any remaining callbacks in the queue. | 2328 // Clear out any remaining callbacks in the queue. |
2329 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2329 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
(...skipping 19 matching lines...) Expand all Loading... |
2349 // The simulator uses a separate JS stack. | 2349 // The simulator uses a separate JS stack. |
2350 Address jssp_address = Simulator::current(isolate_)->get_sp(); | 2350 Address jssp_address = Simulator::current(isolate_)->get_sp(); |
2351 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); | 2351 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); |
2352 if (jssp < stack_guard->real_jslimit()) return true; | 2352 if (jssp < stack_guard->real_jslimit()) return true; |
2353 #endif // USE_SIMULATOR | 2353 #endif // USE_SIMULATOR |
2354 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); | 2354 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); |
2355 } | 2355 } |
2356 | 2356 |
2357 | 2357 |
2358 } } // namespace v8::internal | 2358 } } // namespace v8::internal |
OLD | NEW |