Bug 182509 - Error messages for apis that expect iterables are inconsistent
Summary: Error messages for apis that expect iterables are inconsistent
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 11
Hardware: All All
: P2 Enhancement
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-02-05 14:11 PST by Michael Hayes
Modified: 2018-02-05 15:08 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Hayes 2018-02-05 14:11:38 PST
`new Set(123)` and `for(const x of 123);` both throw errors because they expect iterables, but the errors they throw are very different and not very informative. 

In the spec these errors are generated when step if https://tc39.github.io/ecma262/#sec-set-iterable is run on a value that does not have an iterator property.
Currently firefox generates error messages that look like: `TypeError: 123 is not iterable` for both of the above cases, which is very intuitive and actionable.

Chrome handles the for-of case the same way, but generates an `undefined is not a function` error for the Set case.  I have filed an issue to make this behavior consistent (https://bugs.chromium.org/p/chromium/issues/detail?id=809214).

In Safari the Set constructor example generates a TypeError with no message, and the for-of loop generates an `undefined is not a function` error.

Ideally the behavior for these 2 examples would be consistent.