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 "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 2765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2776 | 2776 |
2777 void Isolate::RunMicrotasksInternal() { | 2777 void Isolate::RunMicrotasksInternal() { |
2778 while (pending_microtask_count() > 0) { | 2778 while (pending_microtask_count() > 0) { |
2779 HandleScope scope(this); | 2779 HandleScope scope(this); |
2780 int num_tasks = pending_microtask_count(); | 2780 int num_tasks = pending_microtask_count(); |
2781 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 2781 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
2782 DCHECK(num_tasks <= queue->length()); | 2782 DCHECK(num_tasks <= queue->length()); |
2783 set_pending_microtask_count(0); | 2783 set_pending_microtask_count(0); |
2784 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2784 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
2785 | 2785 |
2786 for (int i = 0; i < num_tasks; i++) { | 2786 Isolate* isolate = this; |
2787 HandleScope scope(this); | 2787 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < num_tasks, i++, { |
2788 Handle<Object> microtask(queue->get(i), this); | 2788 Handle<Object> microtask(queue->get(i), this); |
2789 if (microtask->IsJSFunction()) { | 2789 if (microtask->IsJSFunction()) { |
2790 Handle<JSFunction> microtask_function = | 2790 Handle<JSFunction> microtask_function = |
2791 Handle<JSFunction>::cast(microtask); | 2791 Handle<JSFunction>::cast(microtask); |
2792 SaveContext save(this); | 2792 SaveContext save(this); |
2793 set_context(microtask_function->context()->native_context()); | 2793 set_context(microtask_function->context()->native_context()); |
2794 MaybeHandle<Object> maybe_exception; | 2794 MaybeHandle<Object> maybe_exception; |
2795 MaybeHandle<Object> result = Execution::TryCall( | 2795 MaybeHandle<Object> result = Execution::TryCall( |
2796 this, microtask_function, factory()->undefined_value(), 0, NULL, | 2796 this, microtask_function, factory()->undefined_value(), 0, NULL, |
2797 &maybe_exception); | 2797 &maybe_exception); |
2798 // If execution is terminating, just bail out. | 2798 // If execution is terminating, just bail out. |
2799 Handle<Object> exception; | 2799 Handle<Object> exception; |
2800 if (result.is_null() && maybe_exception.is_null()) { | 2800 if (result.is_null() && maybe_exception.is_null()) { |
2801 // Clear out any remaining callbacks in the queue. | 2801 // Clear out any remaining callbacks in the queue. |
2802 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2802 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
2803 set_pending_microtask_count(0); | 2803 set_pending_microtask_count(0); |
2804 return; | 2804 return; |
2805 } | 2805 } |
2806 } else { | 2806 } else { |
2807 Handle<CallHandlerInfo> callback_info = | 2807 Handle<CallHandlerInfo> callback_info = |
2808 Handle<CallHandlerInfo>::cast(microtask); | 2808 Handle<CallHandlerInfo>::cast(microtask); |
2809 v8::MicrotaskCallback callback = | 2809 v8::MicrotaskCallback callback = |
2810 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); | 2810 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); |
2811 void* data = v8::ToCData<void*>(callback_info->data()); | 2811 void* data = v8::ToCData<void*>(callback_info->data()); |
2812 callback(data); | 2812 callback(data); |
2813 } | 2813 } |
2814 } | 2814 }); |
2815 } | 2815 } |
2816 } | 2816 } |
2817 | 2817 |
2818 | 2818 |
2819 void Isolate::AddMicrotasksCompletedCallback( | 2819 void Isolate::AddMicrotasksCompletedCallback( |
2820 MicrotasksCompletedCallback callback) { | 2820 MicrotasksCompletedCallback callback) { |
2821 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { | 2821 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { |
2822 if (callback == microtasks_completed_callbacks_.at(i)) return; | 2822 if (callback == microtasks_completed_callbacks_.at(i)) return; |
2823 } | 2823 } |
2824 microtasks_completed_callbacks_.Add(callback); | 2824 microtasks_completed_callbacks_.Add(callback); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2975 // Then check whether this scope intercepts. | 2975 // Then check whether this scope intercepts. |
2976 if ((flag & intercept_mask_)) { | 2976 if ((flag & intercept_mask_)) { |
2977 intercepted_flags_ |= flag; | 2977 intercepted_flags_ |= flag; |
2978 return true; | 2978 return true; |
2979 } | 2979 } |
2980 return false; | 2980 return false; |
2981 } | 2981 } |
2982 | 2982 |
2983 } // namespace internal | 2983 } // namespace internal |
2984 } // namespace v8 | 2984 } // namespace v8 |
OLD | NEW |