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 2941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2952 if (promise_reject_callback_ == NULL) return; | 2952 if (promise_reject_callback_ == NULL) return; |
2953 Handle<JSArray> stack_trace; | 2953 Handle<JSArray> stack_trace; |
2954 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { | 2954 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { |
2955 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); | 2955 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); |
2956 } | 2956 } |
2957 promise_reject_callback_(v8::PromiseRejectMessage( | 2957 promise_reject_callback_(v8::PromiseRejectMessage( |
2958 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), | 2958 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), |
2959 v8::Utils::StackTraceToLocal(stack_trace))); | 2959 v8::Utils::StackTraceToLocal(stack_trace))); |
2960 } | 2960 } |
2961 | 2961 |
2962 void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container) { | |
2963 Handle<JSFunction> then(container->then(), this); | |
2964 SaveContext save(this); | |
2965 set_context(then->context()->native_context()); | |
2966 handle_scope_implementer_->EnterMicrotaskContext( | |
2967 handle(then->context(), this)); | |
2968 | |
2969 Handle<Object> before_debug_event(container->before_debug_event(), this); | |
2970 if (debug()->is_active() && before_debug_event->IsJSObject()) { | |
2971 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(before_debug_event)); | |
2972 } | |
2973 | |
2974 MaybeHandle<Object> maybe_exception; | |
2975 Handle<JSReceiver> thenable(container->thenable(), this); | |
2976 Handle<JSFunction> resolve(container->resolve(), this); | |
2977 Handle<JSFunction> reject(container->reject(), this); | |
2978 Handle<Object> argv[] = {resolve, reject}; | |
2979 MaybeHandle<Object> result = Execution::TryCall( | |
2980 this, then, thenable, arraysize(argv), argv, &maybe_exception); | |
2981 | |
2982 Handle<Object> reason; | |
2983 if (maybe_exception.ToHandle(&reason)) { | |
2984 Handle<Object> reason_arg[] = {reason}; | |
2985 MaybeHandle<Object> status = | |
adamk
2016/09/19 21:42:35
No need to assign this anymore, now that TryCall s
| |
2986 Execution::TryCall(this, reject, factory()->undefined_value(), | |
2987 arraysize(reason_arg), reason_arg); | |
2988 } | |
2989 | |
2990 Handle<Object> after_debug_event(container->after_debug_event(), this); | |
2991 if (debug()->is_active() && after_debug_event->IsJSObject()) { | |
2992 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_debug_event)); | |
2993 } | |
2994 | |
2995 handle_scope_implementer_->LeaveMicrotaskContext(); | |
2996 } | |
2962 | 2997 |
2963 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { | 2998 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { |
2964 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo()); | 2999 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() || |
3000 microtask->IsPromiseContainer()); | |
2965 Handle<FixedArray> queue(heap()->microtask_queue(), this); | 3001 Handle<FixedArray> queue(heap()->microtask_queue(), this); |
2966 int num_tasks = pending_microtask_count(); | 3002 int num_tasks = pending_microtask_count(); |
2967 DCHECK(num_tasks <= queue->length()); | 3003 DCHECK(num_tasks <= queue->length()); |
2968 if (num_tasks == 0) { | 3004 if (num_tasks == 0) { |
2969 queue = factory()->NewFixedArray(8); | 3005 queue = factory()->NewFixedArray(8); |
2970 heap()->set_microtask_queue(*queue); | 3006 heap()->set_microtask_queue(*queue); |
2971 } else if (num_tasks == queue->length()) { | 3007 } else if (num_tasks == queue->length()) { |
2972 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); | 3008 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); |
2973 heap()->set_microtask_queue(*queue); | 3009 heap()->set_microtask_queue(*queue); |
2974 } | 3010 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3009 SaveContext save(this); | 3045 SaveContext save(this); |
3010 set_context(microtask_function->context()->native_context()); | 3046 set_context(microtask_function->context()->native_context()); |
3011 handle_scope_implementer_->EnterMicrotaskContext( | 3047 handle_scope_implementer_->EnterMicrotaskContext( |
3012 handle(microtask_function->context(), this)); | 3048 handle(microtask_function->context(), this)); |
3013 MaybeHandle<Object> maybe_exception; | 3049 MaybeHandle<Object> maybe_exception; |
3014 MaybeHandle<Object> result = Execution::TryCall( | 3050 MaybeHandle<Object> result = Execution::TryCall( |
3015 this, microtask_function, factory()->undefined_value(), 0, NULL, | 3051 this, microtask_function, factory()->undefined_value(), 0, NULL, |
3016 &maybe_exception); | 3052 &maybe_exception); |
3017 handle_scope_implementer_->LeaveMicrotaskContext(); | 3053 handle_scope_implementer_->LeaveMicrotaskContext(); |
3018 // If execution is terminating, just bail out. | 3054 // If execution is terminating, just bail out. |
3019 if (result.is_null() && maybe_exception.is_null()) { | 3055 if (result.is_null() && maybe_exception.is_null()) { |
adamk
2016/09/19 21:42:35
It worries me a little bit that we're now missing
| |
3020 // Clear out any remaining callbacks in the queue. | 3056 // Clear out any remaining callbacks in the queue. |
3021 heap()->set_microtask_queue(heap()->empty_fixed_array()); | 3057 heap()->set_microtask_queue(heap()->empty_fixed_array()); |
3022 set_pending_microtask_count(0); | 3058 set_pending_microtask_count(0); |
3023 return; | 3059 return; |
3024 } | 3060 } |
3025 } else { | 3061 } else if (microtask->IsCallHandlerInfo()) { |
3026 Handle<CallHandlerInfo> callback_info = | 3062 Handle<CallHandlerInfo> callback_info = |
3027 Handle<CallHandlerInfo>::cast(microtask); | 3063 Handle<CallHandlerInfo>::cast(microtask); |
3028 v8::MicrotaskCallback callback = | 3064 v8::MicrotaskCallback callback = |
3029 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); | 3065 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); |
3030 void* data = v8::ToCData<void*>(callback_info->data()); | 3066 void* data = v8::ToCData<void*>(callback_info->data()); |
3031 callback(data); | 3067 callback(data); |
3068 } else { | |
3069 PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask)); | |
3032 } | 3070 } |
3033 }); | 3071 }); |
3034 } | 3072 } |
3035 } | 3073 } |
3036 | 3074 |
3037 | 3075 |
3038 void Isolate::AddMicrotasksCompletedCallback( | 3076 void Isolate::AddMicrotasksCompletedCallback( |
3039 MicrotasksCompletedCallback callback) { | 3077 MicrotasksCompletedCallback callback) { |
3040 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { | 3078 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { |
3041 if (callback == microtasks_completed_callbacks_.at(i)) return; | 3079 if (callback == microtasks_completed_callbacks_.at(i)) return; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3208 // Then check whether this scope intercepts. | 3246 // Then check whether this scope intercepts. |
3209 if ((flag & intercept_mask_)) { | 3247 if ((flag & intercept_mask_)) { |
3210 intercepted_flags_ |= flag; | 3248 intercepted_flags_ |= flag; |
3211 return true; | 3249 return true; |
3212 } | 3250 } |
3213 return false; | 3251 return false; |
3214 } | 3252 } |
3215 | 3253 |
3216 } // namespace internal | 3254 } // namespace internal |
3217 } // namespace v8 | 3255 } // namespace v8 |
OLD | NEW |