Skip to content

Correct super property access is loose mode#3536

Closed
kriszyp wants to merge 4 commits intobabel:masterfrom
kriszyp:correct-super-property-access
Closed

Correct super property access is loose mode#3536
kriszyp wants to merge 4 commits intobabel:masterfrom
kriszyp:correct-super-property-access

Conversation

@kriszyp
Copy link
Copy Markdown

@kriszyp kriszyp commented Jun 20, 2016

In loose mode super property access is wrong, accessing and changing properties on the prototype instance instead of this:
https://phabricator.babeljs.io/T7389
This fixes super property access, by using fast/loose lookups of methods on calls, but reverts to spec handling for property access/assignments, where it is necessary to call the setter/getter on the correct this instance.

EDIT @aaronang:
Fixes #4312

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jun 20, 2016

Current coverage is 88.17%

Merging #3536 into master will increase coverage by 0.06%

@@             master      #3536   diff @@
==========================================
  Files           193        193          
  Lines         10072      10203   +131   
  Methods        1553       1558     +5   
  Messages          0          0          
  Branches       2199       2287    +88   
==========================================
+ Hits           8875       8997   +122   
- Misses         1197       1206     +9   
  Partials          0          0          

Powered by Codecov. Last updated by b2390cc...f6a02d3

Copy link
Copy Markdown
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kriszyp Thank you for this PR and sorry if the review took... well... a bit too long 😅

This PR needs to be rebased and I left some comments. If you prefer, I can do it myself.


_Foo.prototype.test;
_Foo.prototype.test.whatever;
babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are in loose mode, here it would be better to use babelHelpers.get(_Foo, "test", _this).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be accessing the static test property wouldn't it? The reason for using Test.prototype is to actually simulate super property access, not just normal property access.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, you are right. I meant babelHelpers.get(_Foo.prototype, "test", _this).
Since we are in loose mode, we can assume that the user didn't modify Test's prototype, so this is true:

class Foo {}
class Test extends Foo {}

console.log(Object.getPrototypeOf(Test.prototype) === Foo.prototype);

_Foo.prototype.test;
_Foo.prototype.test.whatever;
babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this);
babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", _this).whatever;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test for super property setting?

@Andarist
Copy link
Copy Markdown
Member

Andarist commented Jan 8, 2018

Would be also great to include exec test for this.

@kriszyp
Copy link
Copy Markdown
Author

kriszyp commented Jan 9, 2018

I do appreciate you getting it to this, but yeah, after 18 months, we have already moved onto TS and this is pretty rusty in my recollection. I'll take a look at the comments though.

@Andarist
Copy link
Copy Markdown
Member

Andarist commented Jan 9, 2018

Just let us know if you want to finish this or should we take over, sorry for letting this hang for so long.

@danez
Copy link
Copy Markdown
Member

danez commented Mar 12, 2018

rebased in #7553

@danez danez closed this Mar 12, 2018
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In loose mode super setters/getters output is incorrect (T7389)

5 participants