Skip to content

Wonky evaluation order for SuperProperty #1175

Closed
@jridgewell

Description

@jridgewell

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    has consensusThis has committee consensus.normative changeAffects behavior required to correctly evaluate some ECMAScript source textweb reality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions