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

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

Issue 2590563003: [promises] Remove deferred object (Closed)
Patch Set: rebase 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/runtime/runtime.h ('k') | test/cctest/test-code-stub-assembler.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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 HandleScope scope(isolate); 53 HandleScope scope(isolate);
54 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 54 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
55 // At this point, no revocation has been issued before 55 // At this point, no revocation has been issued before
56 CHECK(!promise->has_handler()); 56 CHECK(!promise->has_handler());
57 isolate->ReportPromiseReject(promise, Handle<Object>(), 57 isolate->ReportPromiseReject(promise, Handle<Object>(),
58 v8::kPromiseHandlerAddedAfterReject); 58 v8::kPromiseHandlerAddedAfterReject);
59 return isolate->heap()->undefined_value(); 59 return isolate->heap()->undefined_value();
60 } 60 }
61 61
62 namespace { 62 namespace {
63 void EnqueuePromiseReactionJob(Isolate* isolate, Handle<JSPromise> promise, 63 void EnqueuePromiseReactionJob(Isolate* isolate,
64 Handle<Object> value, Handle<Object> tasks, 64 Handle<PromiseReactionJobInfo> info,
65 Handle<Object> deferred, Handle<Object> status) { 65 Handle<Object> status) {
66 Handle<Object> debug_id = isolate->factory()->undefined_value();
67 Handle<Object> debug_name = isolate->factory()->undefined_value();
68 if (isolate->debug()->is_active()) { 66 if (isolate->debug()->is_active()) {
69 MaybeHandle<Object> maybe_result; 67 MaybeHandle<Object> maybe_result;
70 Handle<Object> deferred_obj(deferred); 68 Handle<Object> deferred_obj(info->deferred_promise(), isolate);
71 69
72 if (deferred->IsFixedArray()) { 70 if (info->deferred_promise()->IsFixedArray()) {
73 deferred_obj = isolate->factory()->undefined_value(); 71 deferred_obj = isolate->factory()->undefined_value();
74 } 72 }
75 73
76 Handle<Object> argv[] = {deferred_obj, status}; 74 Handle<Object> argv[] = {deferred_obj, status};
77 maybe_result = Execution::TryCall( 75 maybe_result = Execution::TryCall(
78 isolate, isolate->promise_debug_get_info(), 76 isolate, isolate->promise_debug_get_info(),
79 isolate->factory()->undefined_value(), arraysize(argv), argv); 77 isolate->factory()->undefined_value(), arraysize(argv), argv);
80 78
81 Handle<Object> result; 79 Handle<Object> result;
82 if ((maybe_result).ToHandle(&result)) { 80 if ((maybe_result).ToHandle(&result)) {
83 CHECK(result->IsJSArray()); 81 CHECK(result->IsJSArray());
84 Handle<JSArray> array = Handle<JSArray>::cast(result); 82 Handle<JSArray> array = Handle<JSArray>::cast(result);
85 ElementsAccessor* accessor = array->GetElementsAccessor(); 83 ElementsAccessor* accessor = array->GetElementsAccessor();
86 DCHECK(accessor->HasElement(array, 0)); 84 DCHECK(accessor->HasElement(array, 0));
87 DCHECK(accessor->HasElement(array, 1)); 85 DCHECK(accessor->HasElement(array, 1));
88 debug_id = accessor->Get(array, 0); 86 info->set_debug_id(*accessor->Get(array, 0));
89 debug_name = accessor->Get(array, 1); 87 info->set_debug_name(*accessor->Get(array, 1));
90 } 88 }
91 } 89 }
92 Handle<PromiseReactionJobInfo> info =
93 isolate->factory()->NewPromiseReactionJobInfo(
94 promise, value, tasks, deferred, debug_id, debug_name,
95 isolate->native_context());
96 isolate->EnqueueMicrotask(info); 90 isolate->EnqueueMicrotask(info);
97 } 91 }
98 92
99 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status, 93 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status,
100 Handle<Object> result) { 94 Handle<Object> result) {
101 promise->set_status(status); 95 promise->set_status(status);
102 promise->set_result(*result); 96 promise->set_result(*result);
103 promise->set_deferred(isolate->heap()->undefined_value()); 97 promise->set_deferred_promise(isolate->heap()->undefined_value());
98 promise->set_deferred_on_resolve(isolate->heap()->undefined_value());
99 promise->set_deferred_on_reject(isolate->heap()->undefined_value());
104 promise->set_fulfill_reactions(isolate->heap()->undefined_value()); 100 promise->set_fulfill_reactions(isolate->heap()->undefined_value());
105 promise->set_reject_reactions(isolate->heap()->undefined_value()); 101 promise->set_reject_reactions(isolate->heap()->undefined_value());
106 } 102 }
107 103
108 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, 104 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise,
109 Handle<Smi> status, Handle<Object> value) { 105 Handle<Smi> status, Handle<Object> value) {
110 // Check if there are any callbacks. 106 // Check if there are any callbacks.
111 if (!promise->deferred()->IsUndefined(isolate)) { 107 if (!promise->deferred_promise()->IsUndefined(isolate)) {
112 Handle<Object> tasks((status->value() == v8::Promise::kFulfilled) 108 Handle<Object> tasks((status->value() == v8::Promise::kFulfilled)
113 ? promise->fulfill_reactions() 109 ? promise->fulfill_reactions()
114 : promise->reject_reactions(), 110 : promise->reject_reactions(),
115 isolate); 111 isolate);
116 Handle<Object> deferred(promise->deferred(), isolate); 112 Handle<PromiseReactionJobInfo> info =
117 EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status); 113 isolate->factory()->NewPromiseReactionJobInfo(
114 promise, value, tasks, handle(promise->deferred_promise(), isolate),
115 handle(promise->deferred_on_resolve(), isolate),
116 handle(promise->deferred_on_reject(), isolate),
117 isolate->native_context());
118 EnqueuePromiseReactionJob(isolate, info, status);
118 } 119 }
119 120
120 PromiseSet(isolate, promise, status->value(), value); 121 PromiseSet(isolate, promise, status->value(), value);
121 } 122 }
122 123
123 } // namespace 124 } // namespace
124 125
125 RUNTIME_FUNCTION(Runtime_PromiseReject) { 126 RUNTIME_FUNCTION(Runtime_PromiseReject) {
126 DCHECK(args.length() == 3); 127 DCHECK(args.length() == 3);
127 HandleScope scope(isolate); 128 HandleScope scope(isolate);
(...skipping 13 matching lines...) Expand all
141 HandleScope scope(isolate); 142 HandleScope scope(isolate);
142 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 143 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
143 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1); 144 CONVERT_ARG_HANDLE_CHECKED(Smi, status, 1);
144 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 145 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
145 PromiseFulfill(isolate, promise, status, value); 146 PromiseFulfill(isolate, promise, status, value);
146 return isolate->heap()->undefined_value(); 147 return isolate->heap()->undefined_value();
147 } 148 }
148 149
149 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) { 150 RUNTIME_FUNCTION(Runtime_EnqueuePromiseReactionJob) {
150 HandleScope scope(isolate); 151 HandleScope scope(isolate);
151 DCHECK(args.length() == 5); 152 DCHECK(args.length() == 2);
152 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 153 CONVERT_ARG_HANDLE_CHECKED(PromiseReactionJobInfo, info, 0);
153 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); 154 CONVERT_ARG_HANDLE_CHECKED(Object, status, 1);
154 CONVERT_ARG_HANDLE_CHECKED(Object, tasks, 2); 155 EnqueuePromiseReactionJob(isolate, info, status);
155 CONVERT_ARG_HANDLE_CHECKED(Object, deferred, 3);
156 CONVERT_ARG_HANDLE_CHECKED(Object, status, 4);
157 EnqueuePromiseReactionJob(isolate, promise, value, tasks, deferred, status);
158 return isolate->heap()->undefined_value(); 156 return isolate->heap()->undefined_value();
159 } 157 }
160 158
161 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) { 159 RUNTIME_FUNCTION(Runtime_EnqueuePromiseResolveThenableJob) {
162 HandleScope scope(isolate); 160 HandleScope scope(isolate);
163 DCHECK(args.length() == 3); 161 DCHECK(args.length() == 3);
164 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); 162 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0);
165 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1); 163 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, resolution, 1);
166 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2); 164 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, then, 2);
167 165
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 DCHECK(args.length() == 1); 236 DCHECK(args.length() == 1);
239 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 237 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
240 return promise->result(); 238 return promise->result();
241 } 239 }
242 240
243 RUNTIME_FUNCTION(Runtime_PromiseDeferred) { 241 RUNTIME_FUNCTION(Runtime_PromiseDeferred) {
244 HandleScope scope(isolate); 242 HandleScope scope(isolate);
245 DCHECK(args.length() == 1); 243 DCHECK(args.length() == 1);
246 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 244 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
247 245
248 Handle<Object> deferred(promise->deferred(), isolate); 246 Handle<Object> deferred(promise->deferred_promise(), isolate);
249 if (deferred->IsUndefined(isolate)) { 247 if (deferred->IsUndefined(isolate)) {
250 return isolate->heap()->undefined_value(); 248 return isolate->heap()->undefined_value();
251 } 249 }
252 250
253 if (deferred->IsJSObject()) { 251 if (deferred->IsJSObject()) {
254 return *deferred; 252 return *deferred;
255 } 253 }
256 254
257 DCHECK(deferred->IsFixedArray()); 255 DCHECK(deferred->IsFixedArray());
258 return *isolate->factory()->NewJSArrayWithElements( 256 return *isolate->factory()->NewJSArrayWithElements(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 HandleScope scope(isolate); 325 HandleScope scope(isolate);
328 DCHECK_EQ(1, args.length()); 326 DCHECK_EQ(1, args.length());
329 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 327 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
330 isolate->RunPromiseHook(PromiseHookType::kAfter, promise, 328 isolate->RunPromiseHook(PromiseHookType::kAfter, promise,
331 isolate->factory()->undefined_value()); 329 isolate->factory()->undefined_value());
332 return isolate->heap()->undefined_value(); 330 return isolate->heap()->undefined_value();
333 } 331 }
334 332
335 } // namespace internal 333 } // namespace internal
336 } // namespace v8 334 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | test/cctest/test-code-stub-assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698