New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec factoring: allow PerformPromiseThen with no capability #694

Closed
domenic opened this Issue Sep 16, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@domenic
Member

domenic commented Sep 16, 2016

PerformPromiseThen is used often to run some spec code after a promise settles. However, often what's being done is not a promise transform, but instead just some reaction to the promise. So you don't need the promise-returning behavior that Promise.prototype.then does.

Examples of this are in #692 and in the cancelable promises proposal at two locations: https://tc39.github.io/proposal-cancelable-promises/#sec-canceltoken.race and https://tc39.github.io/proposal-cancelable-promises/#sec-promise.withcanceltoken. In general we've been signaling this by creating a new "throwawayCapability" to pass in. As @littledan pointed out in #692, this is error prone since you need to make sure to mark the throwawayCapability.[[Promise]] as handled.

The ideal solution, in my opinion, would be to make the capability argument to PerformPromiseThen optional. In more detail:

  • Change the definition of the [[Capability]] field of PromiseReaction records to allow undefined
  • In PerformPromiseThen, mark resultCapability as optional, and add a line saying that if it's not provided, it gets set to undefined. (I think that's how we handle optional args to abstract ops...)
  • In PromiseReactionJob, before "If handlerResult is an abrupt completion", add an "Assert: if promiseCapability is undefined, handlerResult is not an abrupt completion." (I.e., specs using PerformPromiseThen must never throw an error in their fulfill/reject handlers.) Then, if promiseCapability is undefined, return NormalCompletion(undefined) instead of doing the rest of the steps.
@gibson042

This comment has been minimized.

Contributor

gibson042 commented Sep 17, 2016

Isn't this problem exposed in the external Promise.prototype.then interface? Reacting without creating a new promise is also a common need for user code, and I'd hate to see a spec fix that isn't surfaced.

@domenic

This comment has been minimized.

Member

domenic commented Sep 17, 2016

That sounds like a new feature request; the proper procedure for those is outlined in https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#feature-requests

ljharb added a commit to ljharb/ecma262 that referenced this issue Mar 21, 2018

ljharb added a commit to ljharb/ecma262 that referenced this issue Mar 21, 2018

ljharb added a commit to ljharb/ecma262 that referenced this issue Apr 17, 2018

ljharb added a commit to ljharb/ecma262 that referenced this issue Apr 20, 2018

ljharb added a commit to ljharb/ecma262 that referenced this issue Jun 4, 2018

ljharb added a commit to ljharb/ecma262 that referenced this issue Jul 11, 2018

ljharb added a commit to ljharb/ecma262 that referenced this issue Aug 9, 2018

ljharb added a commit to ljharb/ecma262 that referenced this issue Aug 9, 2018

@ljharb ljharb closed this in #1146 Aug 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment