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

Unified Diff: src/js/promise.js

Issue 2396763002: [promises] dont create resolving closures in PromiseThen (Closed)
Patch Set: Add todo 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 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 793d60fb0a7fa29f5f828da7dee849d5d42dabb1..b47472aa07f88e6d3638f08cd6085f2033c6bab2 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -169,9 +169,21 @@ function PromiseHandle(value, handler, deferred) {
try {
if (debug_is_active) %DebugPushPromise(deferred.promise);
var result = handler(value);
- deferred.resolve(result);
+ if (IS_UNDEFINED(deferred.resolve)) {
+ ResolvePromise(deferred.promise, result);
+ } else {
+ deferred.resolve(result);
+ }
} %catch (exception) { // Natives syntax to mark this catch block.
- try { deferred.reject(exception); } catch (e) { }
+ try {
+ if (IS_UNDEFINED(deferred.reject)) {
+ // Pass false for debugEvent so .then chaining does not trigger
+ // redundant ExceptionEvents.
+ RejectPromise(deferred.promise, exception, false);
+ } else {
+ deferred.reject(exception);
+ }
+ } catch (e) { }
} finally {
if (debug_is_active) %DebugPopPromise();
}
@@ -452,9 +464,23 @@ function PromiseThen(onResolve, onReject) {
}
var constructor = SpeciesConstructor(this, GlobalPromise);
- // Pass false for debugEvent so .then chaining does not trigger
- // redundant ExceptionEvents.
- var resultCapability = NewPromiseCapability(constructor, false);
+ var resultCapability;
+
+ // The resultCapability.promise is only ever fulfilled internally,
+ // so we don't need the closures to protect against accidentally
+ // calling them multiple times.
+ if (constructor === GlobalPromise) {
+ // TODO(gsathya): Combine this into NewPromiseCapability.
+ resultCapability = {
+ promise: PromiseCreate(),
+ resolve: UNDEFINED,
+ reject: UNDEFINED
+ };
+ } else {
+ // Pass false for debugEvent so .then chaining does not trigger
+ // redundant ExceptionEvents.
+ resultCapability = NewPromiseCapability(constructor, false);
+ }
return PerformPromiseThen(this, onResolve, onReject, resultCapability);
}
« 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