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

Side by Side Diff: src/isolate.cc

Issue 620673005: Introduce HasPendingMicrotasks API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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
« no previous file with comments | « src/isolate.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 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/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
(...skipping 2295 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 // Increase call depth to prevent recursive callbacks. 2306 // Increase call depth to prevent recursive callbacks.
2307 v8::Isolate::SuppressMicrotaskExecutionScope suppress( 2307 v8::Isolate::SuppressMicrotaskExecutionScope suppress(
2308 reinterpret_cast<v8::Isolate*>(this)); 2308 reinterpret_cast<v8::Isolate*>(this));
2309 2309
2310 while (pending_microtask_count() > 0) { 2310 while (pending_microtask_count() > 0) {
2311 HandleScope scope(this); 2311 HandleScope scope(this);
2312 int num_tasks = pending_microtask_count(); 2312 int num_tasks = pending_microtask_count();
2313 Handle<FixedArray> queue(heap()->microtask_queue(), this); 2313 Handle<FixedArray> queue(heap()->microtask_queue(), this);
2314 DCHECK(num_tasks <= queue->length()); 2314 DCHECK(num_tasks <= queue->length());
2315 set_pending_microtask_count(0); 2315 set_pending_microtask_count(0);
2316 set_running_microtask_count(num_tasks);
2316 heap()->set_microtask_queue(heap()->empty_fixed_array()); 2317 heap()->set_microtask_queue(heap()->empty_fixed_array());
2317 2318
2318 for (int i = 0; i < num_tasks; i++) { 2319 for (int i = 0; i < num_tasks; i++) {
2320 set_running_microtask_count(num_tasks - i - 1);
2319 HandleScope scope(this); 2321 HandleScope scope(this);
2320 Handle<Object> microtask(queue->get(i), this); 2322 Handle<Object> microtask(queue->get(i), this);
2321 if (microtask->IsJSFunction()) { 2323 if (microtask->IsJSFunction()) {
2322 Handle<JSFunction> microtask_function = 2324 Handle<JSFunction> microtask_function =
2323 Handle<JSFunction>::cast(microtask); 2325 Handle<JSFunction>::cast(microtask);
2324 SaveContext save(this); 2326 SaveContext save(this);
2325 set_context(microtask_function->context()->native_context()); 2327 set_context(microtask_function->context()->native_context());
2326 MaybeHandle<Object> maybe_exception; 2328 MaybeHandle<Object> maybe_exception;
2327 MaybeHandle<Object> result = 2329 MaybeHandle<Object> result =
2328 Execution::TryCall(microtask_function, factory()->undefined_value(), 2330 Execution::TryCall(microtask_function, factory()->undefined_value(),
2329 0, NULL, &maybe_exception); 2331 0, NULL, &maybe_exception);
2330 // If execution is terminating, just bail out. 2332 // If execution is terminating, just bail out.
2331 Handle<Object> exception; 2333 Handle<Object> exception;
2332 if (result.is_null() && maybe_exception.is_null()) { 2334 if (result.is_null() && maybe_exception.is_null()) {
2333 // Clear out any remaining callbacks in the queue. 2335 // Clear out any remaining callbacks in the queue.
2334 heap()->set_microtask_queue(heap()->empty_fixed_array()); 2336 heap()->set_microtask_queue(heap()->empty_fixed_array());
2335 set_pending_microtask_count(0); 2337 set_pending_microtask_count(0);
2338 set_running_microtask_count(0);
2336 return; 2339 return;
2337 } 2340 }
2338 } else { 2341 } else {
2339 Handle<CallHandlerInfo> callback_info = 2342 Handle<CallHandlerInfo> callback_info =
2340 Handle<CallHandlerInfo>::cast(microtask); 2343 Handle<CallHandlerInfo>::cast(microtask);
2341 v8::MicrotaskCallback callback = 2344 v8::MicrotaskCallback callback =
2342 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); 2345 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback());
2343 void* data = v8::ToCData<void*>(callback_info->data()); 2346 void* data = v8::ToCData<void*>(callback_info->data());
2344 callback(data); 2347 callback(data);
2345 } 2348 }
2346 } 2349 }
2347 } 2350 }
2348 } 2351 }
2349 2352
2350 2353
2354 bool Isolate::HasMoreMicrotasksToRun() const {
2355 return pending_microtask_count() || running_microtask_count();
2356 }
2357
2358
2351 void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) { 2359 void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) {
2352 DCHECK(!use_counter_callback_); 2360 DCHECK(!use_counter_callback_);
2353 use_counter_callback_ = callback; 2361 use_counter_callback_ = callback;
2354 } 2362 }
2355 2363
2356 2364
2357 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) { 2365 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
2358 if (use_counter_callback_) { 2366 if (use_counter_callback_) {
2359 use_counter_callback_(reinterpret_cast<v8::Isolate*>(this), feature); 2367 use_counter_callback_(reinterpret_cast<v8::Isolate*>(this), feature);
2360 } 2368 }
(...skipping 25 matching lines...) Expand all
2386 if (prev_ && prev_->Intercept(flag)) return true; 2394 if (prev_ && prev_->Intercept(flag)) return true;
2387 // Then check whether this scope intercepts. 2395 // Then check whether this scope intercepts.
2388 if ((flag & intercept_mask_)) { 2396 if ((flag & intercept_mask_)) {
2389 intercepted_flags_ |= flag; 2397 intercepted_flags_ |= flag;
2390 return true; 2398 return true;
2391 } 2399 }
2392 return false; 2400 return false;
2393 } 2401 }
2394 2402
2395 } } // namespace v8::internal 2403 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698