Closed
Bug 1185964
Opened 9 years ago
Closed 8 years ago
Promise.prototype.then should throw when applied to a non-promise
Categories
(Core :: DOM: Core & HTML, defect)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
People
(Reporter: claude.pache, Unassigned)
References
(Blocks 1 open bug, )
Details
When `Promise.prototype.then` is applied to a non-promise (e.g., `Promise.prototype.then.call(null)`), it must throw a TypeError. Currently, it returns a rejected promise with a TypeError as reason. Reference: Step 2 of: http://www.ecma-international.org/ecma-262/6.0/#sec-promise.prototype.then
Reporter | ||
Comment 1•9 years ago
|
||
(Dunno whether it should block Bug 856878 or Bug 885333. Arbitrarily picking the oldest of them.)
Reporter | ||
Updated•9 years ago
|
Comment 2•9 years ago
|
||
Promises are implemented in the DOM right now, not in JS yet. That'll have to change eventually, but for now you want this filed there.
Component: JavaScript: Standard Library → DOM
Comment 3•9 years ago
|
||
Actually, as long as Promises stay in the DOM this behavior won't change. Per WebIDL, all Promise-returning methods convert their exceptions to rejected promises, and Promise.prototype.then is certainly a Promise-returning method. See also bug 911216.
Depends on: 911216
Updated•8 years ago
|
Blocks: es6promises
Comment 4•8 years ago
|
||
Tested on Nightly 50.0a1 (2016-07-17) (with bug 911216 fixed), now it throws an error. > Promise.prototype.then.call(null) TypeError: Receiver of Promise.prototype.then call is not a non-null object > Promise.prototype.then.call({}) TypeError: Promise.prototype.then called on incompatible value
Reporter | ||
Comment 5•8 years ago
|
||
> Tested on Nightly 50.0a1 (2016-07-17) (with bug 911216 fixed), now it throws an error. So does it in current stable release (without bug 911216 fixed). According to my tests, the bug has been silently fixed between v44 and v45.
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → WORKSFORME
Reporter | ||
Comment 6•8 years ago
|
||
> According to my tests, the bug has been silently fixed between v44 and v45. My wild guess is that it was incidentally fixed with Bug 1170760.
Comment 7•8 years ago
|
||
Indeed. Bug 1170760 changed the return value from "Promise" to "any", so we no longer get the "convert an exception to a Promise" machinery. I actually wonder whether that's correct in all cases....
Depends on: 1170760
Resolution: WORKSFORME → FIXED
Assignee | ||
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•