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

Open
mysticatea opened this Issue Apr 22, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@mysticatea
Contributor

mysticatea commented Apr 22, 2018

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

This comment has been minimized.

Show comment
Hide comment
@ljharb

ljharb Apr 22, 2018

Member

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

Member

ljharb commented Apr 22, 2018

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

@mysticatea

This comment has been minimized.

Show comment
Hide comment
@mysticatea

mysticatea Apr 23, 2018

Contributor

Sounds good to me.

Contributor

mysticatea commented Apr 23, 2018

Sounds good to me.

mysticatea added a commit to mysticatea/ecma262 that referenced this issue Apr 23, 2018

@mysticatea mysticatea referenced a pull request that will close this issue Apr 23, 2018

Open

Editorial: replace obj.[[Get]](j) with Get(obj, j) #1183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment