slightlyoff / Promises

DOM Promises IDL/polyfill
Apache License 2.0
154 stars 28 forks source link

Throwing non-errors #2

Closed domenic closed 11 years ago

domenic commented 11 years ago

It seems from the IDL that resolvers are not going to allow rejecting with non-Errors. OK. But what about this sentence?

If the callback throws, resolve the returned future with an Error

What if the callback throws a non-Error? E.g.

future.then(undefined, function () {
    throw 5;
});

or worse,

future.then(undefined, function () {
    throw undefined;
});

?

slightlyoff commented 11 years ago

It's a good point. What do you think it should do?

domenic commented 11 years ago

The rejection reason (error, I think it's called now?) should be 5 or undefined.

jakearchibald commented 11 years ago

+1, any thrown value should be passed to the rejection call back (as it is in _onResolution)

slightlyoff commented 11 years ago

Changing the text to indicate that this is how it works. Thanks for spotting it!

slightlyoff commented 11 years ago

Fixed: https://github.com/slightlyoff/DOMFuture/commit/534379985228bed952609f9b9b991f07f59f7f26#L0R185