Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

[Refactor] rewrite the spec text so that .finally observably calls .then #14

Merged
merged 1 commit into from
Jan 26, 2017

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Nov 29, 2016

This is a PR demonstrating the spec refactor that makes .finally, like .catch, observably call into .then.

Pros:

  • consistency with .catch
  • make subclassing easier in that you still only have to override .then (which might be useful in particular because the callback logic in finally is complex)
  • Less spec text

Cons:

  • adds an observable [[Get]] and [[Call]] of "then"
  • makes two new spec-created functions available to user code (which normally is only done with the new Promise executor's resolve and reject function), thus preventing them from being optimized out in implementations.

@dead-claudia
Copy link

@ljharb

  • makes two new spec-created functions available to user code (which normally is only done with the new Promise executor's resolve and reject function), thus preventing them from being optimized out in implementations.

Not if both then and finally are on an unmodified Promise.prototype, neither shadowed. At least V8 does this in TurboFan (from looking at the source) for then in particular, so I feel it is possible.

@ljharb
Copy link
Member Author

ljharb commented Dec 30, 2016

@isiahmeadows yes, this is an optimization that an implementation can certainly perform in the best case, but observability needs to be judged for the worst case, not the best case.

@ljharb ljharb mentioned this pull request Jan 19, 2017
@ljharb ljharb merged commit fd88025 into master Jan 26, 2017
@ljharb ljharb deleted the then_refactor branch January 26, 2017 20:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants