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

Unified Diff: src/js/promise.js

Issue 2018913004: Promises: Remove additional array for storing deferred objects (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Merge calls to array.push Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/promise.js
diff --git a/src/js/promise.js b/src/js/promise.js
index fcb0826f8405c1839ec1f3cafda887b18de9294b..9c335a2b9d19a42cc48ba205ace220e47a58ec53 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -115,7 +115,18 @@ function PromiseSet(promise, status, value) {
// therefore we can just push the new callback to the existing array.
SET_PRIVATE(promise, promiseFulfillReactionsSymbol, UNDEFINED);
SET_PRIVATE(promise, promiseRejectReactionsSymbol, UNDEFINED);
+
+ // There are 2 possible states for this symbol --
+ // 1) UNDEFINED -- This is the zero state, no deferred object is
+ // attached to this symbol. When we want to add a new deferred we
+ // directly attach it to this symbol.
+ // 2) symbol with attached deferred object -- New deferred objects
+ // are not attached to this symbol, but instead they are directly
+ // attached to the resolve, reject callback arrays. At this point,
+ // the deferred symbol's state is stale, and the deferreds should be
+ // read from the reject, resolve callbacks.
SET_PRIVATE(promise, promiseDeferredReactionsSymbol, UNDEFINED);
+
return promise;
}
@@ -163,8 +174,8 @@ function PromiseEnqueue(value, tasks, deferreds, status) {
%DebugAsyncTaskEvent({ type: "willHandle", id: id, name: name });
}
if (IS_ARRAY(tasks)) {
- for (var i = 0; i < tasks.length; i += 1) {
- PromiseHandle(value, tasks[i], deferreds[i]);
+ for (var i = 0; i < tasks.length; i += 2) {
+ PromiseHandle(value, tasks[i], tasks[i + 1]);
}
} else {
PromiseHandle(value, tasks, deferreds);
@@ -190,23 +201,20 @@ function PromiseAttachCallbacks(promise, deferred, onResolve, onReject) {
} else if (!IS_ARRAY(maybeResolveCallbacks)) {
var resolveCallbacks = new InternalArray();
var rejectCallbacks = new InternalArray();
- var deferreds = new InternalArray();
-
- resolveCallbacks.push(maybeResolveCallbacks);
- rejectCallbacks.push(GET_PRIVATE(promise, promiseRejectReactionsSymbol));
- deferreds.push(GET_PRIVATE(promise, promiseDeferredReactionsSymbol));
+ var existingDeferred = GET_PRIVATE(promise, promiseDeferredReactionsSymbol);
- resolveCallbacks.push(onResolve);
- rejectCallbacks.push(onReject);
- deferreds.push(deferred);
+ resolveCallbacks.push(
+ maybeResolveCallbacks, existingDeferred, onResolve, deferred);
+ rejectCallbacks.push(GET_PRIVATE(promise, promiseRejectReactionsSymbol),
+ existingDeferred,
+ onReject,
+ deferred);
SET_PRIVATE(promise, promiseFulfillReactionsSymbol, resolveCallbacks);
SET_PRIVATE(promise, promiseRejectReactionsSymbol, rejectCallbacks);
- SET_PRIVATE(promise, promiseDeferredReactionsSymbol, deferreds);
} else {
- maybeResolveCallbacks.push(onResolve);
- GET_PRIVATE(promise, promiseRejectReactionsSymbol).push(onReject);
- GET_PRIVATE(promise, promiseDeferredReactionsSymbol).push(deferred);
+ maybeResolveCallbacks.push(onResolve, deferred);
+ GET_PRIVATE(promise, promiseRejectReactionsSymbol).push(onReject, deferred);
}
}
@@ -512,8 +520,8 @@ function PromiseHasUserDefinedRejectHandlerRecursive(promise) {
if (!IS_ARRAY(queue)) {
return PromiseHasUserDefinedRejectHandlerCheck(queue, deferreds);
} else {
- for (var i = 0; i < queue.length; i += 1) {
- if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], deferreds[i])) {
+ for (var i = 0; i < queue.length; i += 2) {
+ if (PromiseHasUserDefinedRejectHandlerCheck(queue[i], queue[i + 1])) {
return true;
}
}
« 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