[Webkit-unassigned] [Bug 241088] Promise.race(123); does not throw an error

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jun 7 06:46:52 PDT 2022


https://bugs.webkit.org/show_bug.cgi?id=241088

--- Comment #4 from Yusuke Suzuki <ysuzuki at apple.com> ---
(In reply to 845043157 from comment #3)
> When I run the follow program:
> 1.js:
> Promise.race(123);
> print(1);
> 
> V8:
> 1
> 1.js:1: TypeError: number 123 is not iterable (cannot read property
> Symbol(Symbol.iterator))
> Promise.race(123);
>         ^
> TypeError: number 123 is not iterable (cannot read property
> Symbol(Symbol.iterator))
>     at Function.race (<anonymous>)
>     at 1.js:1:9

This V8's behavior is not aligned to the spec (spec requires rejecting the resulted promise, not throwing an error).

> 
> spidermonkey:
> 1
> Unhandled rejection: (new TypeError("Argument of Promise.race is not
> iterable", "1.js", 1))
> Stack:
>   @1.js:1:9

SpiderMonkey shell dumps Unhandled rejection too.
In JSC, you can get it via,

setUnhandledRejectionCallback(function (error) {
    // When unhandled rejection happens, this callback is called.
});

> 
> jsc:
> 1
> 
> 'Promise.race(123);' is wrong code but the output of jsc looks like it is
> ok.

You can catch the rejected promise via,

Promise.race(123).catch(function (error) {
    // Here, you will get an error in JSC / SpiderMonkey.
});



I think it may be better to throw an error or warning tell users the code
> is wrong.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20220607/39c7cf81/attachment.htm>


More information about the webkit-unassigned mailing list