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

Side by Side Diff: src/isolate.cc

Issue 1731773005: Introduce MicrotasksCompletedCallback. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: DCHECK Created 4 years, 9 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
« 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 "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 2748 matching lines...) Expand 10 before | Expand all | Expand 10 after
2759 DCHECK(queue->get(num_tasks)->IsUndefined()); 2759 DCHECK(queue->get(num_tasks)->IsUndefined());
2760 queue->set(num_tasks, *microtask); 2760 queue->set(num_tasks, *microtask);
2761 set_pending_microtask_count(num_tasks + 1); 2761 set_pending_microtask_count(num_tasks + 1);
2762 } 2762 }
2763 2763
2764 2764
2765 void Isolate::RunMicrotasks() { 2765 void Isolate::RunMicrotasks() {
2766 // Increase call depth to prevent recursive callbacks. 2766 // Increase call depth to prevent recursive callbacks.
2767 v8::Isolate::SuppressMicrotaskExecutionScope suppress( 2767 v8::Isolate::SuppressMicrotaskExecutionScope suppress(
2768 reinterpret_cast<v8::Isolate*>(this)); 2768 reinterpret_cast<v8::Isolate*>(this));
2769 RunMicrotasksInternal();
2770 FireMicrotasksCompletedCallback();
2771 }
2769 2772
2773
2774 void Isolate::RunMicrotasksInternal() {
2770 while (pending_microtask_count() > 0) { 2775 while (pending_microtask_count() > 0) {
2771 HandleScope scope(this); 2776 HandleScope scope(this);
2772 int num_tasks = pending_microtask_count(); 2777 int num_tasks = pending_microtask_count();
2773 Handle<FixedArray> queue(heap()->microtask_queue(), this); 2778 Handle<FixedArray> queue(heap()->microtask_queue(), this);
2774 DCHECK(num_tasks <= queue->length()); 2779 DCHECK(num_tasks <= queue->length());
2775 set_pending_microtask_count(0); 2780 set_pending_microtask_count(0);
2776 heap()->set_microtask_queue(heap()->empty_fixed_array()); 2781 heap()->set_microtask_queue(heap()->empty_fixed_array());
2777 2782
2778 for (int i = 0; i < num_tasks; i++) { 2783 for (int i = 0; i < num_tasks; i++) {
2779 HandleScope scope(this); 2784 HandleScope scope(this);
(...skipping 21 matching lines...) Expand all
2801 v8::MicrotaskCallback callback = 2806 v8::MicrotaskCallback callback =
2802 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); 2807 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback());
2803 void* data = v8::ToCData<void*>(callback_info->data()); 2808 void* data = v8::ToCData<void*>(callback_info->data());
2804 callback(data); 2809 callback(data);
2805 } 2810 }
2806 } 2811 }
2807 } 2812 }
2808 } 2813 }
2809 2814
2810 2815
2816 void Isolate::AddMicrotasksCompletedCallback(
2817 MicrotasksCompletedCallback callback) {
2818 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) {
2819 if (callback == microtasks_completed_callbacks_.at(i)) return;
2820 }
2821 microtasks_completed_callbacks_.Add(callback);
2822 }
2823
2824
2825 void Isolate::RemoveMicrotasksCompletedCallback(
2826 MicrotasksCompletedCallback callback) {
2827 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) {
2828 if (callback == microtasks_completed_callbacks_.at(i)) {
2829 microtasks_completed_callbacks_.Remove(i);
2830 }
2831 }
2832 }
2833
2834
2835 void Isolate::FireMicrotasksCompletedCallback() {
2836 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) {
2837 microtasks_completed_callbacks_.at(i)(reinterpret_cast<v8::Isolate*>(this));
2838 }
2839 }
2840
2841
2811 void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) { 2842 void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) {
2812 DCHECK(!use_counter_callback_); 2843 DCHECK(!use_counter_callback_);
2813 use_counter_callback_ = callback; 2844 use_counter_callback_ = callback;
2814 } 2845 }
2815 2846
2816 2847
2817 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) { 2848 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
2818 // The counter callback may cause the embedder to call into V8, which is not 2849 // The counter callback may cause the embedder to call into V8, which is not
2819 // generally possible during GC. 2850 // generally possible during GC.
2820 if (heap_.gc_state() == Heap::NOT_IN_GC) { 2851 if (heap_.gc_state() == Heap::NOT_IN_GC) {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 // Then check whether this scope intercepts. 2972 // Then check whether this scope intercepts.
2942 if ((flag & intercept_mask_)) { 2973 if ((flag & intercept_mask_)) {
2943 intercepted_flags_ |= flag; 2974 intercepted_flags_ |= flag;
2944 return true; 2975 return true;
2945 } 2976 }
2946 return false; 2977 return false;
2947 } 2978 }
2948 2979
2949 } // namespace internal 2980 } // namespace internal
2950 } // namespace v8 2981 } // namespace v8
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