Comments (6)
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.
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.
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.
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.
Shrug. This is just how promises work. then
has essentially become a reserved property name.
from test262.
OK. I will add tests to cover this behavior.
from test262.
Related Issues (20)
- Guidance on writing testing plans and where to include them in the process HOT 1
- Tests for `-->` in the first line should not have `raw` flag. HOT 2
- test/harness/testTypedArray{,-conversions}.js not updated for Float16Array
- Ideas for additional coverage for base64
- Add test case for `Object.groupBy` / `Map.groupBy` with strings? HOT 3
- `Function.prototype.toString` for a built-in function with a name that is invalid as an identifier HOT 4
- Decorators Testing Plan
- Mapping between Test262 and web-features HOT 10
- Remove non-existend "AsyncArrowFunction" constructor
- Please sync the test to intl-duration-format/pull PR181 HOT 1
- Math.sumPrecise testing plan HOT 3
- nanoseconds: Number.MAX_VALUE in precision-exact-mathematical-values HOT 4
- Question: NPM Registry HOT 4
- `new Iterator()` should throw `TypeError`? HOT 2
- Add more tests for `v` flag
- Various ECMA links 404 HOT 2
- Testing plan for JSON-parse-with-source HOT 1
- Create testing plan for the Deferring Module Evaluation proposal. HOT 2
- Create testing plan for the Joint Iteration proposal. HOT 1
- Automatically add a results table for CI runs on pull requests HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from test262.