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 2896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2907 if (promise_reject_callback_ == NULL) return; | 2907 if (promise_reject_callback_ == NULL) return; |
2908 Handle<JSArray> stack_trace; | 2908 Handle<JSArray> stack_trace; |
2909 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { | 2909 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { |
2910 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); | 2910 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); |
2911 } | 2911 } |
2912 promise_reject_callback_(v8::PromiseRejectMessage( | 2912 promise_reject_callback_(v8::PromiseRejectMessage( |
2913 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), | 2913 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), |
2914 v8::Utils::StackTraceToLocal(stack_trace))); | 2914 v8::Utils::StackTraceToLocal(stack_trace))); |
2915 } | 2915 } |
2916 | 2916 |
2917 void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container) { | |
2918 MaybeHandle<Object> maybe_exception; | |
adamk
2016/09/08 22:28:18
This should be declared right before it's used.
gsathya
2016/09/14 00:39:14
Done.
| |
2919 Handle<JSObject> promise(container->promise(), this); | |
2920 Handle<JSObject> thenable(container->thenable(), this); | |
2921 Handle<JSFunction> then(container->then(), this); | |
2922 Handle<JSFunction> resolve(container->resolve(), this); | |
2923 Handle<JSFunction> reject(container->reject(), this); | |
2924 Handle<Object> before_debug_event(container->before_debug_event(), this); | |
2925 Handle<Object> after_debug_event(container->after_debug_event(), this); | |
adamk
2016/09/08 22:28:18
I don't think you need all these handles up front,
gsathya
2016/09/14 00:39:13
Done.
| |
2926 Handle<Object> argv[] = {resolve, reject}; | |
adamk
2016/09/08 22:28:18
This can also move down to right before the call
gsathya
2016/09/14 00:39:13
Done.
| |
2927 | |
2928 if (debug()->is_active() && (*before_debug_event)->IsJSObject()) { | |
adamk
2016/09/08 22:28:17
Handles already overload operator-> so you don't n
gsathya
2016/09/14 00:39:13
Done.
| |
2929 Handle<JSObject> event_data(JSObject::cast(*before_debug_event), this); | |
adamk
2016/09/08 22:28:17
No need to create a new handle here...
gsathya
2016/09/14 00:39:13
Done.
| |
2930 debug()->OnAsyncTaskEvent(event_data); | |
adamk
2016/09/08 22:28:17
...instead use Handle<JSObject>::cast(before_debug
gsathya
2016/09/14 00:39:13
Done.
| |
2931 } | |
2932 | |
2933 MaybeHandle<Object> result = Execution::TryCall( | |
2934 this, then, thenable, arraysize(argv), argv, &maybe_exception); | |
2935 | |
2936 Handle<Object> reason; | |
2937 if (maybe_exception.ToHandle(&reason)) { | |
2938 Handle<Object> reason_arg[] = {reason}; | |
2939 MaybeHandle<Object> status = | |
2940 Execution::Call(this, reject, factory()->undefined_value(), | |
2941 arraysize(reason_arg), reason_arg); | |
2942 } | |
2943 | |
2944 if (debug()->is_active() && (*after_debug_event)->IsJSObject()) { | |
adamk
2016/09/08 22:28:17
Same applies here and below to the handling of aft
gsathya
2016/09/14 00:39:13
Done.
| |
2945 Handle<JSObject> event_data(JSObject::cast(*after_debug_event), this); | |
2946 debug()->OnAsyncTaskEvent(event_data); | |
2947 } | |
2948 } | |
2917 | 2949 |
2918 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { | 2950 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
2919 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo()); | 2951 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || |
2952 microtask->IsPromiseContainer()); | |
2920 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 2953 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
2921 int num_tasks = pending_microtask_count(); | 2954 int num_tasks = pending_microtask_count(); |
2922 DCHECK(num_tasks <= queue->length()); | 2955 DCHECK(num_tasks <= queue->length()); |
2923 if (num_tasks == 0) { | 2956 if (num_tasks == 0) { |
2924 queue = factory()->NewFixedArray(8); | 2957 queue = factory()->NewFixedArray(8); |
2925 heap()->set_microtask_queue(*queue); | 2958 heap()->set_microtask_queue(*queue); |
2926 } else if (num_tasks == queue->length()) { | 2959 } else if (num_tasks == queue->length()) { |
2927 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); | 2960 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); |
2928 heap()->set_microtask_queue(*queue); | 2961 heap()->set_microtask_queue(*queue); |
2929 } | 2962 } |
(...skipping 24 matching lines...) Expand all Loading... | |
2954 DCHECK(num_tasks <= queue->length()); | 2987 DCHECK(num_tasks <= queue->length()); |
2955 set_pending_microtask_count(0); | 2988 set_pending_microtask_count(0); |
2956 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 2989 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
2957 | 2990 |
2958 Isolate* isolate = this; | 2991 Isolate* isolate = this; |
2959 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < num_tasks, i++, { | 2992 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < num_tasks, i++, { |
2960 Handle<Object> microtask(queue->get(i), this); | 2993 Handle<Object> microtask(queue->get(i), this); |
2961 if (microtask->IsJSFunction()) { | 2994 if (microtask->IsJSFunction()) { |
2962 Handle<JSFunction> microtask_function = | 2995 Handle<JSFunction> microtask_function = |
2963 Handle<JSFunction>::cast(microtask); | 2996 Handle<JSFunction>::cast(microtask); |
2964 SaveContext save(this); | 2997 SaveContext save(this); |
adamk
2016/09/08 22:28:17
As discussed I think you might need to use most of
gsathya
2016/09/14 00:39:13
Done.
| |
2965 set_context(microtask_function->context()->native_context()); | 2998 set_context(microtask_function->context()->native_context()); |
2966 handle_scope_implementer_->EnterMicrotaskContext( | 2999 handle_scope_implementer_->EnterMicrotaskContext( |
2967 handle(microtask_function->context(), this)); | 3000 handle(microtask_function->context(), this)); |
2968 MaybeHandle<Object> maybe_exception; | 3001 MaybeHandle<Object> maybe_exception; |
2969 MaybeHandle<Object> result = Execution::TryCall( | 3002 MaybeHandle<Object> result = Execution::TryCall( |
2970 this, microtask_function, factory()->undefined_value(), 0, NULL, | 3003 this, microtask_function, factory()->undefined_value(), 0, NULL, |
2971 &maybe_exception); | 3004 &maybe_exception); |
2972 handle_scope_implementer_->LeaveMicrotaskContext(); | 3005 handle_scope_implementer_->LeaveMicrotaskContext(); |
2973 // If execution is terminating, just bail out. | 3006 // If execution is terminating, just bail out. |
2974 if (result.is_null() && maybe_exception.is_null()) { | 3007 if (result.is_null() && maybe_exception.is_null()) { |
2975 // Clear out any remaining callbacks in the queue. | 3008 // Clear out any remaining callbacks in the queue. |
2976 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 3009 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
2977 set_pending_microtask_count(0); | 3010 set_pending_microtask_count(0); |
2978 return; | 3011 return; |
2979 } | 3012 } |
2980 } else { | 3013 } else if (microtask->IsCallHandlerInfo()) { |
2981 Handle<CallHandlerInfo> callback_info = | 3014 Handle<CallHandlerInfo> callback_info = |
2982 Handle<CallHandlerInfo>::cast(microtask); | 3015 Handle<CallHandlerInfo>::cast(microtask); |
2983 v8::MicrotaskCallback callback = | 3016 v8::MicrotaskCallback callback = |
2984 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); | 3017 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); |
2985 void* data = v8::ToCData<void*>(callback_info->data()); | 3018 void* data = v8::ToCData<void*>(callback_info->data()); |
2986 callback(data); | 3019 callback(data); |
3020 } else { | |
3021 Handle<PromiseContainer> container = | |
3022 Handle<PromiseContainer>::cast(microtask); | |
3023 PromiseResolveThenableJob(container); | |
2987 } | 3024 } |
2988 }); | 3025 }); |
2989 } | 3026 } |
2990 } | 3027 } |
2991 | 3028 |
2992 | 3029 |
2993 void Isolate::AddMicrotasksCompletedCallback( | 3030 void Isolate::AddMicrotasksCompletedCallback( |
2994 MicrotasksCompletedCallback callback) { | 3031 MicrotasksCompletedCallback callback) { |
2995 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { | 3032 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { |
2996 if (callback == microtasks_completed_callbacks_.at(i)) return; | 3033 if (callback == microtasks_completed_callbacks_.at(i)) return; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3163 // Then check whether this scope intercepts. | 3200 // Then check whether this scope intercepts. |
3164 if ((flag & intercept_mask_)) { | 3201 if ((flag & intercept_mask_)) { |
3165 intercepted_flags_ |= flag; | 3202 intercepted_flags_ |= flag; |
3166 return true; | 3203 return true; |
3167 } | 3204 } |
3168 return false; | 3205 return false; |
3169 } | 3206 } |
3170 | 3207 |
3171 } // namespace internal | 3208 } // namespace internal |
3172 } // namespace v8 | 3209 } // namespace v8 |
OLD | NEW |