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

Make handling of object indices more in line with the spec #1392

Merged
merged 3 commits into from
Oct 31, 2023

Conversation

gbrail
Copy link
Collaborator

@gbrail gbrail commented Oct 6, 2023

  • In more cases, treat out-of-range numeric indices as strings
  • For typed arrays, correctly implement index semantics

This addresses many (but maybe not all) of the issues identified in #1389

* In more cases, treat out-of-range numeric indices as strings
* For typed arrays, correctly implement index semantics
@p-bakker p-bakker linked an issue Oct 19, 2023 that may be closed by this pull request
@p-bakker
Copy link
Collaborator

Looks like this PR fixes Object.keys(x) and JSON.stringify(x) testcases, but not the JSON.parse(...) test:

js> JSON.parse('{"D": true, "-1": true, "A": true}', console.log);
INFO -1 true
INFO D true
INFO A true
INFO {}

@p-bakker
Copy link
Collaborator

Think JSON.parse does it wrong, because it calls Scriptruntime.indexFromString directly from JsonParser.readObject, instead of ScriptRuntime.toStringIdOrIndex()/getIndexObject()

@p-bakker
Copy link
Collaborator

Or its just that ScriptRuntime.indexFromString("-1") returns an odd value, namely 4294967295 instead of -1

@p-bakker
Copy link
Collaborator

Nice! All tests in the compat table under (ES)6 > Misc > 'own property order' (except for the ones based on Reflect) now pass!

Amazed that this doesn't unbreak some Test262 tests, but it is what it is

So, LGTM!

@gbrail gbrail merged commit f085d50 into mozilla:master Oct 31, 2023
3 checks passed
@gbrail gbrail deleted the fix-indices branch October 31, 2023 22:42
@rbri
Copy link
Collaborator

rbri commented Nov 5, 2023

@gbrail sorry for being late at this party but while comparing your patch with my one i found one difference

org.mozilla.javascript.ScriptRuntime.getIndexObject(double)

/**
 * If d is exact int value, return its value wrapped as Integer and othewise return d converted
 * to String.
 */
static Object getIndexObject(double d) {
    int i = (int) d;
    if (i == d) {
        if (i < 0) {
            return Integer.toString(i);
        }
        return Integer.valueOf(i);
    }
    return toString(d);
}

I have added the i<0 check to this method but you not. Is this missing or have you checked that this is not needed?

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 this pull request may close these issues.

ES2015 Object own keys order issues
3 participants