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

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

Issue 2633443002: [promisehook] Pass deferred promise to Before/After callback (Closed)
Patch Set: Remove adaptor Created 3 years, 11 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/objects-printer.cc ('k') | test/cctest/test-api.cc » ('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 #include "src/runtime/runtime-utils.h" 4 #include "src/runtime/runtime-utils.h"
5 5
6 #include "src/debug/debug.h" 6 #include "src/debug/debug.h"
7 #include "src/elements.h" 7 #include "src/elements.h"
8 #include "src/promise-utils.h" 8 #include "src/promise-utils.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 // id can be Undefined or Smi. 104 // id can be Undefined or Smi.
105 if (!id->IsSmi()) { 105 if (!id->IsSmi()) {
106 return false; 106 return false;
107 } 107 }
108 108
109 *debug_id = Handle<Smi>::cast(id)->value(); 109 *debug_id = Handle<Smi>::cast(id)->value();
110 return true; 110 return true;
111 } 111 }
112 112
113 void SetDebugInfo(Isolate* isolate, Handle<PromiseReactionJobInfo> info, 113 void SetDebugInfo(Isolate* isolate, Handle<JSPromise> promise,
114 int status) { 114 Handle<PromiseReactionJobInfo> info, int status) {
115 int id; 115 int id;
116 PromiseDebugActionName name; 116 PromiseDebugActionName name;
117 117
118 if (GetDebugIdForAsyncFunction(isolate, info, &id)) { 118 if (GetDebugIdForAsyncFunction(isolate, info, &id)) {
119 name = kDebugAsyncFunction; 119 name = kDebugAsyncFunction;
120 } else { 120 } else {
121 id = isolate->debug()->NextAsyncTaskId(handle(info->promise(), isolate)); 121 id = isolate->debug()->NextAsyncTaskId(promise);
122 DCHECK(status != v8::Promise::kPending); 122 DCHECK(status != v8::Promise::kPending);
123 name = status == v8::Promise::kFulfilled ? kDebugPromiseResolve 123 name = status == v8::Promise::kFulfilled ? kDebugPromiseResolve
124 : kDebugPromiseReject; 124 : kDebugPromiseReject;
125 } 125 }
126 126
127 info->set_debug_id(id); 127 info->set_debug_id(id);
128 info->set_debug_name(name); 128 info->set_debug_name(name);
129 } 129 }
130 130
131 void EnqueuePromiseReactionJob(Isolate* isolate, 131 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise,
132 Handle<PromiseReactionJobInfo> info, 132 Handle<PromiseReactionJobInfo> info,
133 int status) { 133 int status) {
134 if (isolate->debug()->is_active()) { 134 if (isolate->debug()->is_active()) {
135 SetDebugInfo(isolate, info, status); 135 SetDebugInfo(isolate, promise, info, status);
136 } 136 }
137 137
138 isolate->EnqueueMicrotask(info); 138 isolate->EnqueueMicrotask(info);
139 } 139 }
140 140
141 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, 141 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status,
142 Handle<Object> result) { 142 Handle<Object> result) {
143 promise->set_status(status); 143 promise->set_status(status);
144 promise->set_result(*result); 144 promise->set_result(*result);
145 promise->set_deferred_promise(isolate->heap()->undefined_value()); 145 promise->set_deferred_promise(isolate->heap()->undefined_value());
(...skipping 13 matching lines...) Expand all
159 : kDebugPromiseReject); 159 : kDebugPromiseReject);
160 } 160 }
161 // Check if there are any callbacks. 161 // Check if there are any callbacks.
162 if (!promise->deferred_promise()->IsUndefined(isolate)) { 162 if (!promise->deferred_promise()->IsUndefined(isolate)) {
163 Handle<Object> tasks((status == v8::Promise::kFulfilled) 163 Handle<Object> tasks((status == v8::Promise::kFulfilled)
164 ? promise->fulfill_reactions() 164 ? promise->fulfill_reactions()
165 : promise->reject_reactions(), 165 : promise->reject_reactions(),
166 isolate); 166 isolate);
167 Handle<PromiseReactionJobInfo> info = 167 Handle<PromiseReactionJobInfo> info =
168 isolate->factory()->NewPromiseReactionJobInfo( 168 isolate->factory()->NewPromiseReactionJobInfo(
169 promise, value, tasks, handle(promise->deferred_promise(), isolate), 169 value, tasks, handle(promise->deferred_promise(), isolate),
170 handle(promise->deferred_on_resolve(), isolate), 170 handle(promise->deferred_on_resolve(), isolate),
171 handle(promise->deferred_on_reject(), isolate), 171 handle(promise->deferred_on_reject(), isolate),
172 isolate->native_context()); 172 isolate->native_context());
173 EnqueuePromiseReactionJob(isolate, info, status); 173 EnqueuePromiseReactionJob(isolate, promise, info, status);
174 } 174 }
175 175
176 PromiseSet(isolate, promise, status, value); 176 PromiseSet(isolate, promise, status, value);
177 } 177 }
178 178
179 } // namespace 179 } // namespace
180 180
181 RUNTIME_FUNCTION(Runtime_PromiseReject) { 181 RUNTIME_FUNCTION(Runtime_PromiseReject) {
182 DCHECK_EQ(3, args.length()); 182 DCHECK_EQ(3, args.length());
183 HandleScope scope(isolate); 183 HandleScope scope(isolate);
184 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 184 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
185 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1); 185 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1);
186 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); 186 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2);
187 187
188 PromiseRejectEvent(isolate, promise, promise, reason, debug_event); 188 PromiseRejectEvent(isolate, promise, promise, reason, debug_event);
189 PromiseFulfill(isolate, promise, v8::Promise::kRejected, reason); 189 PromiseFulfill(isolate, promise, v8::Promise::kRejected, reason);
190 190
191 return isolate->heap()->undefined_value(); 191 return isolate->heap()->undefined_value();
192 } 192 }
193 193
194 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { 194 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) {
195 HandleScope scope(isolate); 195 HandleScope scope(isolate);
196 DCHECK_EQ(2, args.length()); 196 DCHECK_EQ(3, args.length());
197 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 0); 197 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
198 CONVERT_SMI_ARG_CHECKED(status, 1); 198 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 1);
199 EnqueuePromiseReactionJob(isolate, info, status); 199 CONVERT_SMI_ARG_CHECKED(status, 2);
200 EnqueuePromiseReactionJob(isolate, promise, info, status);
200 return isolate->heap()->undefined_value(); 201 return isolate->heap()->undefined_value();
201 } 202 }
202 203
203 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { 204 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) {
204 HandleScope scope(isolate); 205 HandleScope scope(isolate);
205 DCHECK(args.length() == 1); 206 DCHECK(args.length() == 1);
206 CONVERT_ARG_HANDLE_CHECKED(PromiseResolveThenableJobInfo, info, 0); 207 CONVERT_ARG_HANDLE_CHECKED(PromiseResolveThenableJobInfo, info, 0);
207 isolate->EnqueueMicrotask(info); 208 isolate->EnqueueMicrotask(info);
208 return isolate->heap()->undefined_value(); 209 return isolate->heap()->undefined_value();
209 } 210 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 HandleScope scope(isolate); 288 HandleScope scope(isolate);
288 DCHECK_EQ(1, args.length()); 289 DCHECK_EQ(1, args.length());
289 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 290 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
290 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, 291 isolate->RunPromiseHook(PromiseHookType::kAfter, promise,
291 isolate->factory()->undefined_value()); 292 isolate->factory()->undefined_value());
292 return isolate->heap()->undefined_value(); 293 return isolate->heap()->undefined_value();
293 } 294 }
294 295
295 } // namespace internal 296 } // namespace internal
296 } // namespace v8 297 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698