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

Unified Diff: src/js/promise.js

Issue 2396763002: [promises] dont create resolving closures in PromiseThen (Closed)
Patch Set: fix broken revert 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..44d748a54d235ddac84931b7c0386778322d724d 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -169,9 +169,13 @@ function PromiseHandle(value, handler, deferred) {
try {
if (debug_is_active) %DebugPushPromise(deferred.promise);
var result = handler(value);
- deferred.resolve(result);
+ if (deferred.resolve) { deferred.resolve(result); }
adamk 2016/10/05 22:12:00 And an explicit IS_UNDEFINED() check for these, ju
gsathya 2016/10/05 22:47:40 Done.
+ else { ResolvePromise(deferred.promise, result); }
adamk 2016/10/05 22:12:00 Please reformat this and the below into the usual
gsathya 2016/10/05 22:47:40 Done.
} %catch (exception) { // Natives syntax to mark this catch block.
- try { deferred.reject(exception); } catch (e) { }
+ try {
+ if (deferred.reject) { deferred.reject(exception); }
+ else { RejectPromise(deferred.promise, exception, false); }
adamk 2016/10/05 22:12:00 This needs a comment for why false is the third ar
gsathya 2016/10/05 22:47:40 Done.
+ } catch (e) { }
} finally {
if (debug_is_active) %DebugPopPromise();
}
@@ -452,9 +456,18 @@ 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;
+ if (constructor === GlobalPromise) {
+ resultCapability = {
adamk 2016/10/05 22:12:00 Please add a comment here explaining this special
gsathya 2016/10/05 22:47:40 Done.
+ promise: PromiseCreate(),
+ resolve: false,
+ reject: false
adamk 2016/10/05 22:12:00 How about UNDEFINED for these falses...
gsathya 2016/10/05 22:47:40 Done.
+ };
+ } 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