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

Disallow -0 in algorithm for checking array index #517

Merged
merged 4 commits into from
Feb 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ urlPrefix: https://tc39.github.io/ecma262/; spec: ECMA-262
text: error objects; for: ECMAScript; url: sec-error-objects
text: function object; url: function-object
text: immutable prototype exotic object; url: sec-immutable-prototype-exotic-objects
text: integer index; url: integer-index
url: sec-object-internal-methods-and-internal-slots
text: internal method
text: internal slot
Expand Down Expand Up @@ -12625,6 +12626,10 @@ internal method as follows.
applied:

1. If <a abstract-op>Type</a>(|P|) is not String, then return <emu-val>false</emu-val>.
1. If |P| is "<code>-0</code>", then return <emu-val>false</emu-val>.

Note: <a abstract-op>CanonicalNumericIndexString</a> allows "<code>-0</code>" as a special
case, even though it is not an [=integer index=] or by extension an [=array index=].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this indeed matches implementations, wouldn't it be cleaner to return false if index is -0 after the following step?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation for this in Chromium:
https://chromium.googlesource.com/v8/v8.git/+/842d424d99060375bf4a8b6fdfd2a0177e4c0477/src/api.cc#4128
https://chromium.googlesource.com/v8/v8.git/+/842d424d99060375bf4a8b6fdfd2a0177e4c0477/src/utils-inl.h#35

So no special handling of "-0" there because the code uses unsigned integers. ES uses ToNumber where negative zero is possible, so whatever this says won't be a close match.

1. Let |index| be [=!=] <a abstract-op>CanonicalNumericIndexString</a>(|P|).
1. If |index| is <emu-val>undefined</emu-val>, then return <emu-val>false</emu-val>.
1. If |index| is less than 0 or is greater than or equal to 2<sup>32</sup> − 1, then return
Expand Down