google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.18k stars 580 forks source link

Assigning an arrow function to a member of a derived class assigns this instead #1989

Closed phistuck closed 8 years ago

phistuck commented 8 years ago

Test case -

class Bar {
}

class Foo extends Bar
{
    constructor()
    {
        super();
        this.callback = evt =>
        {
            this.baz = 1;
        };
        setTimeout(this.callback);
    }
}
new Foo();

Throws an exception, because this.callback is actually this which results in setTimeout("[object Object]") instead of the actual function.

arv commented 8 years ago

Fixed by #1988

phistuck commented 8 years ago

Thank you! When will the REPL page be updated, then? https://google.github.io/traceur-compiler/demo/repl.html#class%20Bar%20%7B%0A%7D%0A%0Aclass%20Foo%20extends%20Bar%0A%7B%0A%20%20%20%20constructor()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20super()%3B%0A%20%20%20%20%20%20%20%20this.callback%20%3D%20evt%20%3D%3E%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20this.baz%20%3D%201%3B%0A%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20setTimeout(this.callback)%3B%0A%20%20%20%20%7D%0A%7D%0Anew%20Foo()%3B

arv commented 8 years ago

I'll try to get a new version pushed soonish

@johnjbarton FYI

phistuck commented 8 years ago

Great! Thank you. :)

johnjbarton commented 8 years ago

Unfortunately Feature Tests Symbol Object.js: fails for me on master.

On Mon, Oct 12, 2015 at 9:04 AM, PhistucK notifications@github.com wrote:

Great! Thank you. :)

— Reply to this email directly or view it on GitHub https://github.com/google/traceur-compiler/issues/1989#issuecomment-147447228 .

johnjbarton commented 8 years ago

The test fails because object[s] is enumerable and the loop at the bottom of the file uses 'in'. https://github.com/google/traceur-compiler/blob/master/test/feature/Symbol/Object.js#L28

Probably something to do with "native" Symbols.

arv commented 8 years ago

@johnjbarton Which version of node/chrome?

johnjbarton commented 8 years ago

node -v v0.10.38

arv commented 8 years ago

I was using node 4.1.1. Lets just disable the test for now.

johnjbarton commented 8 years ago

@phistuck please try again, I updated the server and your case works.

phistuck commented 8 years ago

Great, it works. :)