Giter Site home page Giter Site logo

Comments (6)

domenic avatar domenic commented on July 24, 2024

Nope, this is working as intended. You should never be able to fulfill with a thenable; that's why resolving with a thenable triggers its then function.

from test262.

domenic avatar domenic commented on July 24, 2024

An analogous situation: if you remove [Symbol.iterator] from Array.prototype, then passing an array in to Promise.all will not work as you expect.

from test262.

smikes avatar smikes commented on July 24, 2024

Although I see your point, I believe this behavior will be surprising to many -- similar to Promise.race([]) returning a never-fulfilled promise; it makes sense, but it isn't expected.

In particular, the difference between deleting Symbol.iterator and adding Array.prototype.then is that deleting Symbol.iterator is obviously bad, and will visibly break lots of syntax; while adding a 'then' to a object prototype will only affect Promise.all.

Psychology plays into this as well. It's easier to understand that removing something causes damage than adding something seemingly innocuous which happens to have a magic name.

Consider:

var p1 = Promise.resolve(1);
var p2 = Promise.resolve(2);
var logger = console.log.bind(console);

Promise.all([p1, p2]).then(logger); // outputs [1, 2]

Array.prototype.then = function (a, b) { a('foo'); }

Promise.all([p1, p2]).then(logger); // outputs foo

Or how about this:

Object.prototype.then = function (a, b) { a('baz'); }

Promise.resolve({}).then(logger);  // outputs baz

I think that's pretty surprising. Especially if the definition of then comes from loading a library or some other code.

This behavior is visible in Chrome 38.0.2125.104 m

from test262.

smikes avatar smikes commented on July 24, 2024

i thought of two more:

O.p.then = function (a, b) { b(new SyntaxError("illegal character")); }

O.p.then = function () {} // all promises fulfilled with an object will pend forever

And another:

O.p.then = function (a) { console.log(JSON.stringify(this)); a(this); } // log all promise fulfillment args

from test262.

domenic avatar domenic commented on July 24, 2024

Shrug. This is just how promises work. then has essentially become a reserved property name.

from test262.

smikes avatar smikes commented on July 24, 2024

OK. I will add tests to cover this behavior.

from test262.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.