domenic / promises-unwrapping

The ES6 promises spec, as per September 2013 TC39 meeting
1.23k stars 94 forks source link

Bad promise constructor arguments #10

Closed domenic closed 10 years ago

domenic commented 10 years ago

Assuming #8 is implemented and Promise(x) (without new) no longer coerces, what should the following do?

  1. Promise("5")
  2. Promise(() => {})
  3. new Promise("5")

I am leaning toward "throw a TypeError" but an argument could be made for returning a new promise rejected with a TypeError instead.

domenic commented 10 years ago

@erights any thoughts on this?

annevk commented 10 years ago

Synchronously throwing here seems better as it's really just a typo.

erights commented 10 years ago

I agree with Anne. We avoid throws by using rejections to protect synchronous callers against data-dependent dynamic errors. These are just static bugs in the program, for which an early-as-possible error is good.

domenic commented 10 years ago

Sounds good, will make the change tonight.