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)

defect
Not set
normal

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
(Dunno whether it should block Bug 856878 or Bug 885333. Arbitrarily picking the oldest of them.)
Blocks: es6, 856878
Blocks: 885333
No longer blocks: 856878
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
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
No longer blocks: es6
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
> 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
> 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.
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
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.