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

[Generators] not correct "this" binding in v20180319 #2873

Closed
teppeis opened this issue Apr 3, 2018 · 2 comments
Closed

[Generators] not correct "this" binding in v20180319 #2873

teppeis opened this issue Apr 3, 2018 · 2 comments

Comments

@teppeis
Copy link
Contributor

teppeis commented Apr 3, 2018

Degraded in v20180319
https://kangax.github.io/compat-table/es6/#test-generators_correct_this_binding

input

// functions / generators / correct "this" binding
module.exports = function() {
  function* generator() {
    yield this.x;
    yield this.y;
  }
  var iterator = { g: generator, x: 5, y: 6 }.g();
  var item = iterator.next();
  var passed = item.value === 5 && item.done === false;
  item = iterator.next();
  passed &= item.value === 6 && item.done === false;
  item = iterator.next();
  passed &= item.value === undefined && item.done === true;
  return passed;
};

output

@MatrixFrog
Copy link
Contributor

It turns out the generator transpilation is doing things correctly but then the "fold constants" pass is producing invalid code. It didn't do this in the previous release because the generator function was brought into the object literal before "fold constants":

function *generator() {...}
{g:generator, x:5, y:6}

became

{*g() {...}, x:5, y:6}

but in the new compiler that does not happen. Will do a bisect and figure out where this changed.

@MatrixFrog MatrixFrog self-assigned this Apr 4, 2018
lauraharker pushed a commit that referenced this issue Apr 7, 2018
… if we do that then the 'this' value is wrong inside of someFunction.

(It would be safe to do this transformation if someFunction is a function literal and we've verified that it doesn't reference 'this' but for now we don't do it)

#2873

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191825381
@teppeis
Copy link
Contributor Author

teppeis commented May 11, 2018

@MatrixFrog Fixed in v20180506. Thanks!

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

No branches or pull requests

2 participants