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

Side by Side Diff: src/runtime/runtime-promise.cc

Issue 2487053002: [promises] Remove one runtime call to create_resolving_functions (Closed)
Patch Set: add dcheck Created 4 years, 1 month 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/runtime/runtime.h ('k') | src/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.h"
6 6
7 #include "src/debug/debug.h" 7 #include "src/debug/debug.h"
8 #include "src/elements.h" 8 #include "src/elements.h"
9 #include "src/promise-utils.h"
9 10
10 namespace v8 { 11 namespace v8 {
11 namespace internal { 12 namespace internal {
12 13
13 namespace { 14 namespace {
14 15
15 void PromiseRejectEvent(Isolate* isolate, Handle<JSReceiver> promise, 16 void PromiseRejectEvent(Isolate* isolate, Handle<JSReceiver> promise,
16 Handle<Object> rejected_promise, Handle<Object> value, 17 Handle<Object> rejected_promise, Handle<Object> value,
17 bool debug_event) { 18 bool debug_event) {
18 if (isolate->debug()->is_active() && debug_event) { 19 if (isolate->debug()->is_active() && debug_event) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); 133 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
133 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1); 134 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 1);
134 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2); 135 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 2);
135 CONVERT_ARG_HANDLE_CHECKED(Object, status, 3); 136 CONVERT_ARG_HANDLE_CHECKED(Object, status, 3);
136 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); 137 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status);
137 return isolate->heap()->undefined_value(); 138 return isolate->heap()->undefined_value();
138 } 139 }
139 140
140 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { 141 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) {
141 HandleScope scope(isolate); 142 HandleScope scope(isolate);
142 DCHECK(args.length() == 4); 143 DCHECK(args.length() == 3);
143 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 0); 144 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
144 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 1); 145 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1);
145 CONVERT_ARG_HANDLE_CHECKED(JSFunction, resolve, 2); 146 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2);
146 CONVERT_ARG_HANDLE_CHECKED(JSFunction, reject, 3); 147
147 Handle<Object> debug_id; 148 // TODO(gsathya): Add fast path for native promises with unmodified
148 Handle<Object> debug_name; 149 // PromiseThen (which don't need these resolving functions, but
150 // instead can just call resolve/reject directly).
151 Handle<JSFunction> resolve, reject;
152 PromiseUtils::CreateResolvingFunctions(
153 isolate, promise, isolate->factory()->false_value(), &resolve, &reject);
154
155 Handle<Object> debug_id, debug_name;
149 if (isolate->debug()->is_active()) { 156 if (isolate->debug()->is_active()) {
150 debug_id = 157 debug_id =
151 handle(Smi::FromInt(isolate->GetNextDebugMicrotaskId()), isolate); 158 handle(Smi::FromInt(isolate->GetNextDebugMicrotaskId()), isolate);
152 debug_name = isolate->factory()->PromiseResolveThenableJob_string(); 159 debug_name = isolate->factory()->PromiseResolveThenableJob_string();
153 isolate->debug()->OnAsyncTaskEvent(isolate->factory()->enqueue_string(), 160 isolate->debug()->OnAsyncTaskEvent(isolate->factory()->enqueue_string(),
154 debug_id, 161 debug_id,
155 Handle<String>::cast(debug_name)); 162 Handle<String>::cast(debug_name));
156 } else { 163 } else {
157 debug_id = isolate->factory()->undefined_value(); 164 debug_id = isolate->factory()->undefined_value();
158 debug_name = isolate->factory()->undefined_value(); 165 debug_name = isolate->factory()->undefined_value();
159 } 166 }
167
160 Handle<PromiseResolveThenableJobInfo> info = 168 Handle<PromiseResolveThenableJobInfo> info =
161 isolate->factory()->NewPromiseResolveThenableJobInfo( 169 isolate->factory()->NewPromiseResolveThenableJobInfo(
162 resolution, then, resolve, reject, debug_id, debug_name); 170 resolution, then, resolve, reject, debug_id, debug_name,
171 isolate->native_context());
163 isolate->EnqueueMicrotask(info); 172 isolate->EnqueueMicrotask(info);
173
164 return isolate->heap()->undefined_value(); 174 return isolate->heap()->undefined_value();
165 } 175 }
166 176
167 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) { 177 RUNTIME_FUNCTION(Runtime_EnqueueMicrotask) {
168 HandleScope scope(isolate); 178 HandleScope scope(isolate);
169 DCHECK(args.length() == 1); 179 DCHECK(args.length() == 1);
170 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0); 180 CONVERT_ARG_HANDLE_CHECKED(JSFunction, microtask, 0);
171 isolate->EnqueueMicrotask(microtask); 181 isolate->EnqueueMicrotask(microtask);
172 return isolate->heap()->undefined_value(); 182 return isolate->heap()->undefined_value();
173 } 183 }
174 184
175 RUNTIME_FUNCTION(Runtime_RunMicrotasks) { 185 RUNTIME_FUNCTION(Runtime_RunMicrotasks) {
176 HandleScope scope(isolate); 186 HandleScope scope(isolate);
177 DCHECK(args.length() == 0); 187 DCHECK(args.length() == 0);
178 isolate->RunMicrotasks(); 188 isolate->RunMicrotasks();
179 return isolate->heap()->undefined_value(); 189 return isolate->heap()->undefined_value();
180 } 190 }
181 191
182 } // namespace internal 192 } // namespace internal
183 } // namespace v8 193 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698