Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw on non-Symbols #9

Closed
Tracked by #11
michaelficarra opened this issue Jan 23, 2023 · 12 comments
Closed
Tracked by #11

throw on non-Symbols #9

michaelficarra opened this issue Jan 23, 2023 · 12 comments

Comments

@michaelficarra
Copy link
Member

I don't think these predicates should produce a Boolean result for non-Symbols. Receiving a false implies that we could answer the question but the question is, in fact, unanswerable.

@ljharb
Copy link
Member

ljharb commented Jan 23, 2023

Predicate functions don't typically throw on any input - if it's not a symbol, then logically it's not a well-known symbol - how is the question unanswerable?

@ljharb
Copy link
Member

ljharb commented Jan 23, 2023

Some existing precedent is Array.isArray, which never throws for any input.

(If we went with prototype methods, or accessors, then I would definitely expect throwing if the receiver isn't a symbol)

@michaelficarra
Copy link
Member Author

Ah, I was thinking of the question "is this Symbol well-known", not "is this a Symbol that is well-known" (probably because the name is just isWellKnown instead of isWellKnownSymbol). You're right that the former question is probably more expected of a prototype method. This is fine, then. Personally, I would probably rename it to isWellKnownSymbol to make the implication stronger.

@ljharb
Copy link
Member

ljharb commented Jan 25, 2023

It already is named that imo, since it’s on “Symbol” - its common use will have the words “Symbol is well known”, which would make that name redundant. We can certainly discuss it in plenary tho.

@michaelficarra
Copy link
Member Author

The "Symbol is well-known" reading is exactly why I thought it should throw for non-Symbols.

I think the difference here is whether the "is" is followed by a noun or an adjective. Array.isArray is fine. Array.isEmpty would need to throw on non-Arrays. However, Array.isEmptyArray could just return false for non-Arrays.

@ljharb
Copy link
Member

ljharb commented Jan 25, 2023

I see your logic, but i don’t agree with it; a predicate should never throw. I’d expect Array.isEmpty to have an implied “is array” as well.

It could return undefined instead of false in these cases, though, since that’s falsy.

@ljharb
Copy link
Member

ljharb commented Feb 1, 2023

The proposal achieved stage 2 today. Are you content with returning false for non-symbols, or is this a strongly held opinion?

@michaelficarra
Copy link
Member Author

I think this is something I'd like to hear opinions on from the broader committee.

@ljharb
Copy link
Member

ljharb commented Feb 1, 2023

Gotcha, then I should have asked that today. I'll see if I can squeeze in an overflow item.

@michaelficarra
Copy link
Member Author

@ljharb You can try sharing the thread on Matrix first or something.

@ljharb
Copy link
Member

ljharb commented Feb 1, 2023

good call, i'll do both!

@ljharb
Copy link
Member

ljharb commented May 15, 2023

Rough consensus in plenary today was to keep them non-throwing, but to rename them to Symbol.isWellKnownSymbol and Symbol.isRegisteredSymbol.

@ljharb ljharb closed this as completed in e1900e8 May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants