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

obj.[[Get]](j) in Array.prototype.sort section lacks the 2nd argument #1180

Closed
mysticatea opened this issue Apr 22, 2018 · 2 comments · Fixed by #1183 or sthagen/tc39-ecma262#13
Closed

Comments

@mysticatea
Copy link
Contributor

In https://tc39.github.io/ecma262/#sec-array.prototype.sort section, the following sentence exists:

Here the notation old[j] is used to refer to the hypothetical result of calling obj.[[Get]](j) before this function is executed, and the notation new[j] to refer to the hypothetical result of calling obj.[[Get]](j) after this function has been executed.

Now, obj.[[Get]](j) in the sentence doesn't have the 2nd argument receiver, so I guess that this in accessor properties are undefined in sorting. For example:

const impl = Symbol()
class MyArrayLike {
    constructor() {
        this[impl] = [1, 2]
    }

    get 0() { return this[impl][0] } // this `this` is undefined in sorting.
    set 0(value) { this[impl][0] = value }
    get 1() { return this[impl][1] }
    set 1(value) { this[impl][1] = value }
    get length() { return 2 }
}

const xs = new MyArrayLike()
Array.prototype.sort.call(xs)

However, those thiss are not undefined in real world.
I'm suspecting that we should fix those obj.[[Get]](j) to obj.[[Get]](j, obj).

@ljharb
Copy link
Member

ljharb commented Apr 22, 2018

What about replacing it with Get(obj, j)?

@mysticatea
Copy link
Contributor Author

Sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants