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

Side by Side Diff: src/isolate.cc

Issue 2314903004: [promises] Move PromiseResolveThenableJob to c++ (Closed)
Patch Set: 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
« no previous file with comments | « src/isolate.h ('k') | src/js/promise.js » ('j') | src/objects.h » ('J')
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 2903 matching lines...) Expand 10 before | Expand all | Expand 10 after
2914 if (promise_reject_callback_ == NULL) return; 2914 if (promise_reject_callback_ == NULL) return;
2915 Handle<JSArray> stack_trace; 2915 Handle<JSArray> stack_trace;
2916 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) { 2916 if (event == v8::kPromiseRejectWithNoHandler && value->IsJSObject()) {
2917 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value)); 2917 stack_trace = GetDetailedStackTrace(Handle<JSObject>::cast(value));
2918 } 2918 }
2919 promise_reject_callback_(v8::PromiseRejectMessage( 2919 promise_reject_callback_(v8::PromiseRejectMessage(
2920 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value), 2920 v8::Utils::PromiseToLocal(promise), event, v8::Utils::ToLocal(value),
2921 v8::Utils::StackTraceToLocal(stack_trace))); 2921 v8::Utils::StackTraceToLocal(stack_trace)));
2922 } 2922 }
2923 2923
2924 void Isolate::PromiseResolveThenableJob(Handle<PromiseContainer> container) {
2925 MaybeHandle<Object> maybe_exception;
2926 Handle<Object> resolve(container->resolve(), this);
2927 Handle<Object> reject(container->reject(), this);
2928 Handle<Object> promise(container->promise(), this);
2929 Handle<Object> thenable(container->thenable(), this);
2930 Handle<Object> then(container->then(), this);
2931 Handle<Object> argv[] = {resolve, reject};
2932 MaybeHandle<Object> result = Execution::TryCall(
2933 this, then, thenable, arraysize(argv), argv, &maybe_exception);
2934
2935 Handle<Object> reason;
2936 if (maybe_exception.ToHandle(&reason)) {
2937 Handle<Object> reason_arg[] = {reason};
2938 MaybeHandle<Object> status =
2939 Execution::Call(this, reject, factory()->undefined_value(),
2940 arraysize(reason_arg), reason_arg);
2941 }
2942 }
2924 2943
2925 void Isolate::EnqueueMicrotask(Handle<Object> microtask) { 2944 void Isolate::EnqueueMicrotask(Handle<Object> microtask) {
2926 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo()); 2945 DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo() ||
2946 microtask->IsPromiseContainer());
2927 Handle<FixedArray> queue(heap()->microtask_queue(), this); 2947 Handle<FixedArray> queue(heap()->microtask_queue(), this);
2928 int num_tasks = pending_microtask_count(); 2948 int num_tasks = pending_microtask_count();
2929 DCHECK(num_tasks <= queue->length()); 2949 DCHECK(num_tasks <= queue->length());
2930 if (num_tasks == 0) { 2950 if (num_tasks == 0) {
2931 queue = factory()->NewFixedArray(8); 2951 queue = factory()->NewFixedArray(8);
2932 heap()->set_microtask_queue(*queue); 2952 heap()->set_microtask_queue(*queue);
2933 } else if (num_tasks == queue->length()) { 2953 } else if (num_tasks == queue->length()) {
2934 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); 2954 queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks);
2935 heap()->set_microtask_queue(*queue); 2955 heap()->set_microtask_queue(*queue);
2936 } 2956 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2977 this, microtask_function, factory()->undefined_value(), 0, NULL, 2997 this, microtask_function, factory()->undefined_value(), 0, NULL,
2978 &maybe_exception); 2998 &maybe_exception);
2979 handle_scope_implementer_->LeaveMicrotaskContext(); 2999 handle_scope_implementer_->LeaveMicrotaskContext();
2980 // If execution is terminating, just bail out. 3000 // If execution is terminating, just bail out.
2981 if (result.is_null() && maybe_exception.is_null()) { 3001 if (result.is_null() && maybe_exception.is_null()) {
2982 // Clear out any remaining callbacks in the queue. 3002 // Clear out any remaining callbacks in the queue.
2983 heap()->set_microtask_queue(heap()->empty_fixed_array()); 3003 heap()->set_microtask_queue(heap()->empty_fixed_array());
2984 set_pending_microtask_count(0); 3004 set_pending_microtask_count(0);
2985 return; 3005 return;
2986 } 3006 }
2987 } else { 3007 } else if (microtask->IsCallHandlerInfo()) {
2988 Handle<CallHandlerInfo> callback_info = 3008 Handle<CallHandlerInfo> callback_info =
2989 Handle<CallHandlerInfo>::cast(microtask); 3009 Handle<CallHandlerInfo>::cast(microtask);
2990 v8::MicrotaskCallback callback = 3010 v8::MicrotaskCallback callback =
2991 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback()); 3011 v8::ToCData<v8::MicrotaskCallback>(callback_info->callback());
2992 void* data = v8::ToCData<void*>(callback_info->data()); 3012 void* data = v8::ToCData<void*>(callback_info->data());
2993 callback(data); 3013 callback(data);
3014 } else {
3015 Handle<PromiseContainer> container =
3016 Handle<PromiseContainer>::cast(microtask);
3017 PromiseResolveThenableJob(container);
2994 } 3018 }
2995 }); 3019 });
2996 } 3020 }
2997 } 3021 }
2998 3022
2999 3023
3000 void Isolate::AddMicrotasksCompletedCallback( 3024 void Isolate::AddMicrotasksCompletedCallback(
3001 MicrotasksCompletedCallback callback) { 3025 MicrotasksCompletedCallback callback) {
3002 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) { 3026 for (int i = 0; i < microtasks_completed_callbacks_.length(); i++) {
3003 if (callback == microtasks_completed_callbacks_.at(i)) return; 3027 if (callback == microtasks_completed_callbacks_.at(i)) return;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
3170 // Then check whether this scope intercepts. 3194 // Then check whether this scope intercepts.
3171 if ((flag & intercept_mask_)) { 3195 if ((flag & intercept_mask_)) {
3172 intercepted_flags_ |= flag; 3196 intercepted_flags_ |= flag;
3173 return true; 3197 return true;
3174 } 3198 }
3175 return false; 3199 return false;
3176 } 3200 }
3177 3201
3178 } // namespace internal 3202 } // namespace internal
3179 } // namespace v8 3203 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/js/promise.js » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698