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

Unified Diff: src/js/promise.js

Issue 2512103002: [async-await] Don't create resolving callbacks for throwaway promises (Closed)
Patch Set: rename to CreateInternalPromiseCapability Created 4 years, 1 month 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 | « src/js/async-await.js ('k') | 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 d7e25124708737f8c5031e8d86d0d20b31176be1..58b35bd22666351365ec6c0b84199a2b0d6d3beb 100644
--- a/src/js/promise.js
+++ b/src/js/promise.js
@@ -132,8 +132,8 @@ function PromiseHandle(value, handler, deferred) {
} %catch (exception) { // Natives syntax to mark this catch block.
try {
if (IS_UNDEFINED(deferred.reject)) {
- // Pass false for debugEvent so .then chaining does not trigger
- // redundant ExceptionEvents.
+ // Pass false for debugEvent so .then chaining or throwaway promises
+ // in async functions do not trigger redundant ExceptionEvents.
%PromiseReject(deferred.promise, exception, false);
PromiseSet(deferred.promise, kRejected, exception);
} else {
@@ -291,6 +291,17 @@ function DoRejectPromise(promise, reason) {
PromiseSet(promise, kRejected, reason);
}
+// The resultCapability.promise is only ever fulfilled internally,
+// so we don't need the closures to protect against accidentally
+// calling them multiple times.
+function CreateInternalPromiseCapability() {
+ return {
+ promise: PromiseCreate(),
+ resolve: UNDEFINED,
+ reject: UNDEFINED
+ };
+}
+
// ES#sec-newpromisecapability
// NewPromiseCapability ( C )
function NewPromiseCapability(C, debugEvent) {
@@ -381,17 +392,8 @@ function PromiseThen(onResolve, onReject) {
var constructor = SpeciesConstructor(this, GlobalPromise);
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
- };
+ resultCapability = CreateInternalPromiseCapability();
} else {
// Pass false for debugEvent so .then chaining does not trigger
// redundant ExceptionEvents.
@@ -641,7 +643,7 @@ utils.Export(function(to) {
to.PromiseThen = PromiseThen;
to.GlobalPromise = GlobalPromise;
- to.NewPromiseCapability = NewPromiseCapability;
+ to.CreateInternalPromiseCapability = CreateInternalPromiseCapability;
to.PerformPromiseThen = PerformPromiseThen;
to.ResolvePromise = ResolvePromise;
to.RejectPromise = RejectPromise;
« no previous file with comments | « src/js/async-await.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698