| Summary: | Promise.race(123); does not throw an error | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | 845043157 |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED INVALID | ||
| Severity: | Normal | CC: | saam, webkit-bug-importer, ysuzuki |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 15 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
It is V8's bug. https://tc39.es/ecma262/#sec-promise.race step-6 should reject the returned promise, not throwing an error. 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
spidermonkey:
1
Unhandled rejection: (new TypeError("Argument of Promise.race is not iterable", "1.js", 1))
Stack:
@1.js:1:9
jsc:
1
'Promise.race(123);' is wrong code but the output of jsc looks like it is ok.I think it may be better to throw an error or warning tell users the code is wrong.
(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. Putting a default unhandled rejection handler, which dumps log, sounds interesting idea, though it is not compatible with the existing JSC stress tests. So probably, we should add a command line flag to switch that if we add that :) Thank you for your further explication. |
Run the program: Promise.race(123).then(function(value){ console.log(value); }); Actual results: (print nothing) Expected results: In V8,it throws an typeerror:"TypeError:number 123 is not iterable (cannot read property Symbol(Symbol.iterator))". In ES6,it writes that Promise.race() needs an iterable parameter. So,I think that it may be a bug.