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

Wonky evaluation order for SuperProperty #1175

Closed
jridgewell opened this issue Apr 18, 2018 · 8 comments
Closed

Wonky evaluation order for SuperProperty #1175

jridgewell opened this issue Apr 18, 2018 · 8 comments
Labels
has consensus This has committee consensus. normative change Affects behavior required to correctly evaluate some ECMAScript source text web reality

Comments

@jridgewell
Copy link
Member

jridgewell commented Apr 18, 2018

Per the spec:

SuperProperty: super [ Expression ]
  1. Let propertyNameReference be the result of evaluating Expression.
  2. Let propertyNameValue be ? GetValue(propertyNameReference).
  3. Let propertyKey be ? ToPropertyKey(propertyNameValue).
  ...
  5. Return ? MakeSuperPropertyReference(propertyKey, strict).

Runtime Semantics: MakeSuperPropertyReference(propertyKey, strict)
  1. Let env be GetThisEnvironment( ).
  ...
  3. Let actualThis be ? env.GetThisBinding().
  ...

This differs from regular MemberExpression:

MemberExpression: MemberExpression [ Expression ]
  1. Let baseReference be the result of evaluating MemberExpression.
  ...
  3. Let propertyNameReference be the result of evaluating Expression.

The fact that we evaluate the the inner [ Expression ] before evaluating the super feels wrong. I realize super.property isn't really a MemberExpression, but it looks just like it. This is observable with super[super(), "prop"], allowing me to initialize the this binding (GetThisEnvironment ().BindThisValue(...)) even after I've referenced it.

Can we move the env.GetThisBinding() into SuperProperty's RS: Evaluation?

As for real-world implementations of super[super(), "prop"]:

Implemntation Throws?
Chrome Yes
Firefox No
Safari Yes
Edge 🤷‍♂️ No
Babel No, but I'm about to change it...
@ljharb ljharb added normative change Affects behavior required to correctly evaluate some ECMAScript source text question needs data This PR needs more information; such as web compatibility data, “web reality” (what all engines do)… web reality labels Apr 18, 2018
@ljharb
Copy link
Member

ljharb commented Apr 18, 2018

It’d be good to know what edge does here.

@jridgewell
Copy link
Member Author

I'll try downloading an IE VM. In the meantime, try https://output.jsbin.com/miderik/1/quiet if you already have one.

@jridgewell
Copy link
Member Author

Whoo, SauceLabs to the rescue. Edge 16 doesn't throw.

@ljharb
Copy link
Member

ljharb commented Apr 18, 2018

In that case, it's 50/50, so it could go either way for web compat.

How might this change impact future proposals, like decorators or private class methods?

@allenwb
Copy link
Member

allenwb commented Apr 18, 2018

I agree, resolving this first would be more consistent with normal left-to-right evaluation order. Since this is only observable in a constructor using unlikely code pattern I don't think there will be any problem with changing it.

@bakkot
Copy link
Contributor

bakkot commented Apr 18, 2018

This is kind of an interesting question. On the one hand, it's inconsistent with member access. On the other, the current behavior is strictly more useful, albeit only in extremely weird cases.

Because of those competing values I don't personally care much either way, though I'd lean towards prioritizing the first (i.e., changing the spec to throw for super[super()]).

@gsathya
Copy link
Member

gsathya commented May 23, 2018

As others point out, it does seem very inconsistent to have this[super()] throw, but not super[super()]. +1 for changing the spec to throw.

@allenwb
Copy link
Member

allenwb commented May 23, 2018

+1

@ljharb ljharb added has consensus This has committee consensus. and removed needs data This PR needs more information; such as web compatibility data, “web reality” (what all engines do)… question labels May 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has consensus This has committee consensus. normative change Affects behavior required to correctly evaluate some ECMAScript source text web reality
Projects
None yet
Development

No branches or pull requests

5 participants