Skip to content
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

Never bypass the then method #53

Closed
domenic opened this issue Oct 13, 2013 · 2 comments
Closed

Never bypass the then method #53

domenic opened this issue Oct 13, 2013 · 2 comments

Comments

@domenic
Copy link
Owner

domenic commented Oct 13, 2013

Proposal

  • Move the contents of the Then abstract operation into the Promise.prototype.then method definition.
  • Everywhere we use the Then abstract operation, replace it with a call to the respective then method.
    • Promise.all
    • Promise.race
    • Promise.prototype.then's recursive case

Observable Changes

  • This makes overriden thens govern the behavior of a promise, e.g.

    const p = new Promise(() => {});
    p.then = f => f(5);
    Promise.all([p]).then(([x]) => console.log(x)); // logs 5
  • This forces implementations to make an observable call to then instead of using internal mechanisms. I imagine this will not actually be a burden.

  • This does not impact Promise.resolve yet, i.e.

    const p = new Promise(r => r(1));
    p.then = f => f(2);
    Promise.resolve(p).then(x => console.log(x)); // still logs 1 right now

    for that, see Make Resolve operate the same on promises and thenables, using then #54.

@domenic
Copy link
Owner Author

domenic commented Oct 13, 2013

@erights would appreciate your feedback before I implement this change; assigning to you.

@ghost ghost assigned erights Oct 13, 2013
@erights
Copy link
Collaborator

erights commented Oct 14, 2013

assigning to you

accepted. Need to think about this. I will point out that

p.then = ....

fails if p is frozen. If the assignment is in strict code, it fails noisily.

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

No branches or pull requests

2 participants