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

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

Issue 2558493003: [promises] reset callbacks once the promise is resolved (Closed)
Patch Set: Created 4 years 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 | « no previous file | no next file » | 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 debug_name = accessor->Get(array, 1); 87 debug_name = accessor->Get(array, 1);
88 } 88 }
89 } 89 }
90 Handle<PromiseReactionJobInfo> info = 90 Handle<PromiseReactionJobInfo> info =
91 isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred, 91 isolate->factory()->NewPromiseReactionJobInfo(value, tasks, deferred,
92 debug_id, debug_name, 92 debug_id, debug_name,
93 isolate->native_context()); 93 isolate->native_context());
94 isolate->EnqueueMicrotask(info); 94 isolate->EnqueueMicrotask(info);
95 } 95 }
96 96
97 void PromiseSet(Handle<JSPromise> promise, int status, Handle<Object> result) { 97 void PromiseSet(Isolate* isolate, Handle<JSPromise> promise, int status,
98 Handle<Object> result) {
98 promise->set_status(status); 99 promise->set_status(status);
99 promise->set_result(*result); 100 promise->set_result(*result);
100 // TODO(gsathya): reset reactions? 101 promise->set_deferred(isolate->heap()->undefined_value());
102 promise->set_fulfill_reactions(isolate->heap()->undefined_value());
103 promise->set_reject_reactions(isolate->heap()->undefined_value());
101 } 104 }
102 105
103 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise, 106 void PromiseFulfill(Isolate* isolate, Handle<JSPromise> promise,
104 Handle<Smi> status, Handle<Object> value) { 107 Handle<Smi> status, Handle<Object> value) {
105 // Check if there are any callbacks. 108 // Check if there are any callbacks.
106 if (!promise->deferred()->IsUndefined(isolate)) { 109 if (!promise->deferred()->IsUndefined(isolate)) {
107 Handle<Object> tasks((status->value() == kPromiseFulfilled) 110 Handle<Object> tasks((status->value() == kPromiseFulfilled)
108 ? promise->fulfill_reactions() 111 ? promise->fulfill_reactions()
109 : promise->reject_reactions(), 112 : promise->reject_reactions(),
110 isolate); 113 isolate);
111 Handle<Object> deferred(promise->deferred(), isolate); 114 Handle<Object> deferred(promise->deferred(), isolate);
112 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status); 115 EnqueuePromiseReactionJob(isolate, value, tasks, deferred, status);
113 } 116 }
114 117
115 PromiseSet(promise, status->value(), value); 118 PromiseSet(isolate, promise, status->value(), value);
116 } 119 }
117 120
118 } // namespace 121 } // namespace
119 122
120 RUNTIME_FUNCTION(Runtime_PromiseReject) { 123 RUNTIME_FUNCTION(Runtime_PromiseReject) {
121 DCHECK(args.length() == 3); 124 DCHECK(args.length() == 3);
122 HandleScope scope(isolate); 125 HandleScope scope(isolate);
123 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0); 126 CONVERT_ARG_HANDLE_CHECKED(JSPromise, promise, 0);
124 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1); 127 CONVERT_ARG_HANDLE_CHECKED(Object, reason, 1);
125 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2); 128 CONVERT_BOOLEAN_ARG_CHECKED(debug_event, 2);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 return *reject_reactions; 270 return *reject_reactions;
268 } 271 }
269 272
270 DCHECK(reject_reactions->IsFixedArray()); 273 DCHECK(reject_reactions->IsFixedArray());
271 return *isolate->factory()->NewJSArrayWithElements( 274 return *isolate->factory()->NewJSArrayWithElements(
272 Handle<FixedArray>::cast(reject_reactions)); 275 Handle<FixedArray>::cast(reject_reactions));
273 } 276 }
274 277
275 } // namespace internal 278 } // namespace internal
276 } // namespace v8 279 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698