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

Why do some TypedArray methods not use let Pk = ! ToString(𝔽(k)), unlike Array.prototype.indexOf? #3530

Open
yossydev opened this issue Feb 1, 2025 · 2 comments · May be fixed by #3531

Comments

@yossydev
Copy link

yossydev commented Feb 1, 2025

While reviewing the specifications of TypedArray.prototype.indexOf (ECMA-262 § 23.2.3.17) and Array.prototype.indexOf (ECMA-262 § 23.1.3.17), I noticed a difference in the way ToString(𝔽(k)) is handled.

The difference is that Array.prototype.indexOf stores the result of ToString(𝔽(k)) in a variable Pk using let Pk = ! ToString(𝔽(k)), whereas TypedArray.prototype.indexOf does not seem to follow this pattern.

Array.prototype.indexOf TypedArray.prototype.indexOf
Image Image

Is this difference intentional, or is it simply a matter of whether or not the result is assigned to a variable?

If it’s the latter, wouldn’t it be better to standardize the approach? It seems that using Pk to store the result is preferred, so I think it would be better to align with that. What do you think?

Also, this same issue applies to lastIndexOf as well.

@michaelficarra
Copy link
Member

Thank you for the well-written issue! This difference should be inconsequential. ! ToString(𝔽(k)) is infallible and unobservable, so whether it appears once or twice is exactly the same for conformance purposes. I would be willing to accept a PR that makes these steps mirror each other (in either direction) for consistency.

@yossydev
Copy link
Author

yossydev commented Feb 4, 2025

Thank you for your reply!

Thank you for the well-written issue! This difference should be inconsequential. ! ToString(𝔽(k)) is infallible and unobservable, so whether it appears once or twice is exactly the same for conformance purposes.

First of all, I’m glad to know this. As I expected.

I would be willing to accept a PR that makes these steps mirror each other (in either direction) for consistency.

Since the behavior doesn’t change, it’s not really a problem, but since it’s part of the specification, I was a bit curious about it.
Either way is fine, but I think I’d prefer to modify it so that pk is used instead of calling it multiple times!

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

Successfully merging a pull request may close this issue.

2 participants