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

Side by Side Diff: src/js/promise.js

Issue 2403163002: [promises] update comment about deferred reactions symbol state (Closed)
Patch Set: fmt Created 4 years, 2 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/heap-symbols.h ('k') | 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 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 (function(global, utils, extrasUtils) { 5 (function(global, utils, extrasUtils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var InternalArray = utils.InternalArray; 14 var InternalArray = utils.InternalArray;
15 var promiseAsyncStackIDSymbol = 15 var promiseAsyncStackIDSymbol =
16 utils.ImportNow("promise_async_stack_id_symbol"); 16 utils.ImportNow("promise_async_stack_id_symbol");
17 var promiseHandledBySymbol = 17 var promiseHandledBySymbol =
18 utils.ImportNow("promise_handled_by_symbol"); 18 utils.ImportNow("promise_handled_by_symbol");
19 var promiseForwardingHandlerSymbol = 19 var promiseForwardingHandlerSymbol =
20 utils.ImportNow("promise_forwarding_handler_symbol"); 20 utils.ImportNow("promise_forwarding_handler_symbol");
21 var promiseHasHandlerSymbol = 21 var promiseHasHandlerSymbol =
22 utils.ImportNow("promise_has_handler_symbol"); 22 utils.ImportNow("promise_has_handler_symbol");
23 var promiseRejectReactionsSymbol = 23 var promiseRejectReactionsSymbol =
24 utils.ImportNow("promise_reject_reactions_symbol"); 24 utils.ImportNow("promise_reject_reactions_symbol");
25 var promiseFulfillReactionsSymbol = 25 var promiseFulfillReactionsSymbol =
26 utils.ImportNow("promise_fulfill_reactions_symbol"); 26 utils.ImportNow("promise_fulfill_reactions_symbol");
27 var promiseDeferredReactionsSymbol = 27 var promiseDeferredReactionSymbol =
28 utils.ImportNow("promise_deferred_reactions_symbol"); 28 utils.ImportNow("promise_deferred_reaction_symbol");
29 var promiseHandledHintSymbol = 29 var promiseHandledHintSymbol =
30 utils.ImportNow("promise_handled_hint_symbol"); 30 utils.ImportNow("promise_handled_hint_symbol");
31 var promiseRawSymbol = utils.ImportNow("promise_raw_symbol"); 31 var promiseRawSymbol = utils.ImportNow("promise_raw_symbol");
32 var promiseStateSymbol = utils.ImportNow("promise_state_symbol"); 32 var promiseStateSymbol = utils.ImportNow("promise_state_symbol");
33 var promiseResultSymbol = utils.ImportNow("promise_result_symbol"); 33 var promiseResultSymbol = utils.ImportNow("promise_result_symbol");
34 var SpeciesConstructor; 34 var SpeciesConstructor;
35 var speciesSymbol = utils.ImportNow("species_symbol"); 35 var speciesSymbol = utils.ImportNow("species_symbol");
36 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 36 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
37 var ObjectHasOwnProperty; 37 var ObjectHasOwnProperty;
38 38
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 // 1) UNDEFINED -- This is the zero state where there is no callback 121 // 1) UNDEFINED -- This is the zero state where there is no callback
122 // registered. When we see this state, we directly attach the callbacks to 122 // registered. When we see this state, we directly attach the callbacks to
123 // the symbol. 123 // the symbol.
124 // 2) !IS_ARRAY -- There is a single callback directly attached to the 124 // 2) !IS_ARRAY -- There is a single callback directly attached to the
125 // symbols. We need to create a new array to store additional callbacks. 125 // symbols. We need to create a new array to store additional callbacks.
126 // 3) IS_ARRAY -- There are multiple callbacks already registered, 126 // 3) IS_ARRAY -- There are multiple callbacks already registered,
127 // therefore we can just push the new callback to the existing array. 127 // therefore we can just push the new callback to the existing array.
128 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, UNDEFINED); 128 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, UNDEFINED);
129 SET_PRIVATE(promise, promiseRejectReactionsSymbol, UNDEFINED); 129 SET_PRIVATE(promise, promiseRejectReactionsSymbol, UNDEFINED);
130 130
131 // There are 2 possible states for this symbol -- 131 // This symbol is used only when one deferred needs to be attached. When more
132 // 1) UNDEFINED -- This is the zero state, no deferred object is 132 // than one deferred need to be attached the promise, we attach them directly
133 // attached to this symbol. When we want to add a new deferred we 133 // to the promiseFulfillReactionsSymbol and promiseRejectReactionsSymbol and
134 // directly attach it to this symbol. 134 // reset this back to UNDEFINED.
135 // 2) symbol with attached deferred object -- New deferred objects 135 SET_PRIVATE(promise, promiseDeferredReactionSymbol, UNDEFINED);
136 // are not attached to this symbol, but instead they are directly
137 // attached to the resolve, reject callback arrays. At this point,
138 // the deferred symbol's state is stale, and the deferreds should be
139 // read from the reject, resolve callbacks.
140 SET_PRIVATE(promise, promiseDeferredReactionsSymbol, UNDEFINED);
141 136
142 return promise; 137 return promise;
143 } 138 }
144 139
145 function PromiseCreateAndSet(status, value) { 140 function PromiseCreateAndSet(status, value) {
146 var promise = new GlobalPromise(promiseRawSymbol); 141 var promise = new GlobalPromise(promiseRawSymbol);
147 // If debug is active, notify about the newly created promise first. 142 // If debug is active, notify about the newly created promise first.
148 if (DEBUG_IS_ACTIVE) PromiseSet(promise, kPending, UNDEFINED); 143 if (DEBUG_IS_ACTIVE) PromiseSet(promise, kPending, UNDEFINED);
149 return PromiseSet(promise, status, value); 144 return PromiseSet(promise, status, value);
150 } 145 }
151 146
152 function PromiseInit(promise) { 147 function PromiseInit(promise) {
153 return PromiseSet(promise, kPending, UNDEFINED); 148 return PromiseSet(promise, kPending, UNDEFINED);
154 } 149 }
155 150
156 function FulfillPromise(promise, status, value, promiseQueue) { 151 function FulfillPromise(promise, status, value, promiseQueue) {
157 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) { 152 if (GET_PRIVATE(promise, promiseStateSymbol) === kPending) {
158 var tasks = GET_PRIVATE(promise, promiseQueue); 153 var tasks = GET_PRIVATE(promise, promiseQueue);
159 if (!IS_UNDEFINED(tasks)) { 154 if (!IS_UNDEFINED(tasks)) {
160 var deferreds = GET_PRIVATE(promise, promiseDeferredReactionsSymbol); 155 var deferred = GET_PRIVATE(promise, promiseDeferredReactionSymbol);
161 PromiseEnqueue(value, tasks, deferreds, status); 156 PromiseEnqueue(value, tasks, deferred, status);
162 } 157 }
163 PromiseSet(promise, status, value); 158 PromiseSet(promise, status, value);
164 } 159 }
165 } 160 }
166 161
167 function PromiseHandle(value, handler, deferred) { 162 function PromiseHandle(value, handler, deferred) {
168 var debug_is_active = DEBUG_IS_ACTIVE; 163 var debug_is_active = DEBUG_IS_ACTIVE;
169 try { 164 try {
170 if (debug_is_active) %DebugPushPromise(deferred.promise); 165 if (debug_is_active) %DebugPushPromise(deferred.promise);
171 var result = handler(value); 166 var result = handler(value);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 222 }
228 } 223 }
229 } 224 }
230 225
231 function PromiseAttachCallbacks(promise, deferred, onResolve, onReject) { 226 function PromiseAttachCallbacks(promise, deferred, onResolve, onReject) {
232 var maybeResolveCallbacks = 227 var maybeResolveCallbacks =
233 GET_PRIVATE(promise, promiseFulfillReactionsSymbol); 228 GET_PRIVATE(promise, promiseFulfillReactionsSymbol);
234 if (IS_UNDEFINED(maybeResolveCallbacks)) { 229 if (IS_UNDEFINED(maybeResolveCallbacks)) {
235 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, onResolve); 230 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, onResolve);
236 SET_PRIVATE(promise, promiseRejectReactionsSymbol, onReject); 231 SET_PRIVATE(promise, promiseRejectReactionsSymbol, onReject);
237 SET_PRIVATE(promise, promiseDeferredReactionsSymbol, deferred); 232 SET_PRIVATE(promise, promiseDeferredReactionSymbol, deferred);
238 } else if (!IS_ARRAY(maybeResolveCallbacks)) { 233 } else if (!IS_ARRAY(maybeResolveCallbacks)) {
239 var resolveCallbacks = new InternalArray(); 234 var resolveCallbacks = new InternalArray();
240 var rejectCallbacks = new InternalArray(); 235 var rejectCallbacks = new InternalArray();
241 var existingDeferred = GET_PRIVATE(promise, promiseDeferredReactionsSymbol); 236 var existingDeferred = GET_PRIVATE(promise, promiseDeferredReactionSymbol);
242 237
243 resolveCallbacks.push( 238 resolveCallbacks.push(
244 maybeResolveCallbacks, existingDeferred, onResolve, deferred); 239 maybeResolveCallbacks, existingDeferred, onResolve, deferred);
245 rejectCallbacks.push(GET_PRIVATE(promise, promiseRejectReactionsSymbol), 240 rejectCallbacks.push(GET_PRIVATE(promise, promiseRejectReactionsSymbol),
246 existingDeferred, 241 existingDeferred,
247 onReject, 242 onReject,
248 deferred); 243 deferred);
249 244
250 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, resolveCallbacks); 245 SET_PRIVATE(promise, promiseFulfillReactionsSymbol, resolveCallbacks);
251 SET_PRIVATE(promise, promiseRejectReactionsSymbol, rejectCallbacks); 246 SET_PRIVATE(promise, promiseRejectReactionsSymbol, rejectCallbacks);
252 SET_PRIVATE(promise, promiseDeferredReactionsSymbol, UNDEFINED); 247 SET_PRIVATE(promise, promiseDeferredReactionSymbol, UNDEFINED);
253 } else { 248 } else {
254 maybeResolveCallbacks.push(onResolve, deferred); 249 maybeResolveCallbacks.push(onResolve, deferred);
255 GET_PRIVATE(promise, promiseRejectReactionsSymbol).push(onReject, deferred); 250 GET_PRIVATE(promise, promiseRejectReactionsSymbol).push(onReject, deferred);
256 } 251 }
257 } 252 }
258 253
259 function PromiseIdResolveHandler(x) { return x; } 254 function PromiseIdResolveHandler(x) { return x; }
260 function PromiseIdRejectHandler(r) { %_ReThrow(r); } 255 function PromiseIdRejectHandler(r) { %_ReThrow(r); }
261 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true); 256 SET_PRIVATE(PromiseIdRejectHandler, promiseForwardingHandlerSymbol, true);
262 257
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 // within async/await), then recurse on the outer Promise. 634 // within async/await), then recurse on the outer Promise.
640 // In this case, the dependency is one possible way that the Promise 635 // In this case, the dependency is one possible way that the Promise
641 // could be resolved, so it does not subsume the other following cases. 636 // could be resolved, so it does not subsume the other following cases.
642 var outerPromise = GET_PRIVATE(promise, promiseHandledBySymbol); 637 var outerPromise = GET_PRIVATE(promise, promiseHandledBySymbol);
643 if (outerPromise && 638 if (outerPromise &&
644 PromiseHasUserDefinedRejectHandlerRecursive(outerPromise)) { 639 PromiseHasUserDefinedRejectHandlerRecursive(outerPromise)) {
645 return true; 640 return true;
646 } 641 }
647 642
648 var queue = GET_PRIVATE(promise, promiseRejectReactionsSymbol); 643 var queue = GET_PRIVATE(promise, promiseRejectReactionsSymbol);
649 var deferreds = GET_PRIVATE(promise, promiseDeferredReactionsSymbol); 644 var deferred = GET_PRIVATE(promise, promiseDeferredReactionSymbol);
650 645
651 if (IS_UNDEFINED(queue)) return false; 646 if (IS_UNDEFINED(queue)) return false;
652 647
653 if (!IS_ARRAY(queue)) { 648 if (!IS_ARRAY(queue)) {
654 return PromiseHasUserDefinedRejectHandlerCheck(queue, deferreds); 649 return PromiseHasUserDefinedRejectHandlerCheck(queue, deferred);
655 } 650 }
656 651
657 for (var i = 0; i < queue.length; i += 2) { 652 for (var i = 0; i < queue.length; i += 2) {
658 if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], queue[i + 1])) { 653 if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], queue[i + 1])) {
659 return true; 654 return true;
660 } 655 }
661 } 656 }
662 return false; 657 return false;
663 } 658 }
664 659
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 to.PromiseNextMicrotaskID = PromiseNextMicrotaskID; 717 to.PromiseNextMicrotaskID = PromiseNextMicrotaskID;
723 718
724 to.GlobalPromise = GlobalPromise; 719 to.GlobalPromise = GlobalPromise;
725 to.NewPromiseCapability = NewPromiseCapability; 720 to.NewPromiseCapability = NewPromiseCapability;
726 to.PerformPromiseThen = PerformPromiseThen; 721 to.PerformPromiseThen = PerformPromiseThen;
727 to.ResolvePromise = ResolvePromise; 722 to.ResolvePromise = ResolvePromise;
728 to.RejectPromise = RejectPromise; 723 to.RejectPromise = RejectPromise;
729 }); 724 });
730 725
731 }) 726 })
OLDNEW
« no previous file with comments | « src/heap-symbols.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698