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

Side by Side Diff: src/isolate.cc

Issue 2314903004: [promises] Move PromiseResolveThenableJob to c++ (Closed)
Patch Set: reorder Created 4 years, 3 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
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 2896 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Handle<JSFunction> then(container->then(), this);
2919 SaveContext save(this);
2920 set_context(then->context()->native_context());
2921 handle_scope_implementer_->EnterMicrotaskContext(
2922 handle(then->context(), this));
2923
2924 Handle<Object> before_debug_event(container->before_debug_event(), this);
2925 if (debug()->is_active() && before_debug_event->IsJSObject()) {
2926 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(before_debug_event));
2927 }
2928
2929 MaybeHandle<Object> maybe_exception;
2930 Handle<JSObject> promise(container->promise(), this);
adamk 2016/09/14 22:52:51 This doesn't seem to be used at all. Why is it pas
2931 Handle<JSObject> thenable(container->thenable(), this);
2932 Handle<JSFunction> resolve(container->resolve(), this);
2933 Handle<JSFunction> reject(container->reject(), this);
2934 Handle<Object> argv[] = {resolve, reject};
2935 MaybeHandle<Object> result = Execution::TryCall(
2936 this, then, thenable, arraysize(argv), argv, &maybe_exception);
2937
2938 Handle<Object> reason;
2939 if (maybe_exception.ToHandle(&reason)) {
2940 Handle<Object> reason_arg[] = {reason};
2941 MaybeHandle<Object> status =
2942 Execution::Call(this, reject, factory()->undefined_value(),
adamk 2016/09/14 22:52:51 What happens if the reject handler throws?
2943 arraysize(reason_arg), reason_arg);
2944 }
2945
2946 Handle<Object> after_debug_event(container->after_debug_event(), this);
2947 if (debug()->is_active() && after_debug_event->IsJSObject()) {
2948 debug()->OnAsyncTaskEvent(Handle<JSObject>::cast(after_debug_event));
2949 }
2950
2951 handle_scope_implementer_->LeaveMicrotaskContext();
2952 }
2917 2953
2918 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { 2954 void Isolate::EnqueueMicrotask(Handle<Object> microtask) {
2919 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo()); 2955 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() ||
2956 microtask->IsPromiseContainer());
2920 Handle<FixedArray> queue(heap()->microtask_queue(), this); 2957 Handle<FixedArray> queue(heap()->microtask_queue(), this);
2921 int num_tasks = pending_microtask_count(); 2958 int num_tasks = pending_microtask_count();
2922 DCHECK(num_tasks <= queue->length()); 2959 DCHECK(num_tasks <= queue->length());
2923 if (num_tasks == 0) { 2960 if (num_tasks == 0) {
2924 queue = factory()->NewFixedArray(8); 2961 queue = factory()->NewFixedArray(8);
2925 heap()->set_microtask_queue(*queue); 2962 heap()->set_microtask_queue(*queue);
2926 } else if (num_tasks == queue->length()) { 2963 } else if (num_tasks == queue->length()) {
2927 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); 2964 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks);
2928 heap()->set_microtask_queue(*queue); 2965 heap()->set_microtask_queue(*queue);
2929 } 2966 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 this, microtask_function, factory()->undefined_value(), 0, NULL, 3007 this, microtask_function, factory()->undefined_value(), 0, NULL,
2971 &maybe_exception); 3008 &maybe_exception);
2972 handle_scope_implementer_->LeaveMicrotaskContext(); 3009 handle_scope_implementer_->LeaveMicrotaskContext();
2973 // If execution is terminating, just bail out. 3010 // If execution is terminating, just bail out.
2974 if (result.is_null() && maybe_exception.is_null()) { 3011 if (result.is_null() && maybe_exception.is_null()) {
2975 // Clear out any remaining callbacks in the queue. 3012 // Clear out any remaining callbacks in the queue.
2976 heap()->set_microtask_queue(heap()->empty_fixed_array()); 3013 heap()->set_microtask_queue(heap()->empty_fixed_array());
2977 set_pending_microtask_count(0); 3014 set_pending_microtask_count(0);
2978 return; 3015 return;
2979 } 3016 }
2980 } else { 3017 } else if (microtask->IsCallHandlerInfo()) {
2981 Handle<CallHandlerInfo> callback_info = 3018 Handle<CallHandlerInfo> callback_info =
2982 Handle<CallHandlerInfo>::cast(microtask); 3019 Handle<CallHandlerInfo>::cast(microtask);
2983 v8::MicrotaskCallback callback = 3020 v8::MicrotaskCallback callback =
2984 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); 3021 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback());
2985 void* data = v8::ToCData<void*>(callback_info->data()); 3022 void* data = v8::ToCData<void*>(callback_info->data());
2986 callback(data); 3023 callback(data);
3024 } else {
3025 PromiseResolveThenableJob(Handle<PromiseContainer>::cast(microtask));
2987 } 3026 }
2988 }); 3027 });
2989 } 3028 }
2990 } 3029 }
2991 3030
2992 3031
2993 void Isolate::AddMicrotasksCompletedCallback( 3032 void Isolate::AddMicrotasksCompletedCallback(
2994 MicrotasksCompletedCallback callback) { 3033 MicrotasksCompletedCallback callback) {
2995 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { 3034 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) {
2996 if (callback == microtasks_completed_callbacks_.at(i)) return; 3035 if (callback == microtasks_completed_callbacks_.at(i)) return;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3163 // Then check whether this scope intercepts. 3202 // Then check whether this scope intercepts.
3164 if ((flag & intercept_mask_)) { 3203 if ((flag & intercept_mask_)) {
3165 intercepted_flags_ |= flag; 3204 intercepted_flags_ |= flag;
3166 return true; 3205 return true;
3167 } 3206 }
3168 return false; 3207 return false;
3169 } 3208 }
3170 3209
3171 } // namespace internal 3210 } // namespace internal
3172 } // namespace v8 3211 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/js/promise.js » ('j') | src/runtime/runtime-internal.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698