1 of 7

Refactoring�Function Name Inference:

�For "consensus awaiting tests"

Author: André Bargull

Presenter: Daniel Ehrenberg

January 2019 TC39

2 of 7

Class name availability in static fields

  • Class name is set after static initializers run!

class C {� static foo = this.name;�}�print(C.name === "C");�print(C.foo === "");

3 of 7

Problem: Class names and a @frozen decorator

  • Decorators run before name is added, so it's already frozen!

function frozen(desc) {� desc.elements.push({� kind: "hook",� finish: Object.freeze� });�}��@frozen�class B { } // TypeError!

4 of 7

Problem: FNI over decorated fields

  • Unclear how to permit function name inference to work on decorated field initializers

const id = desc => desc;

class D {� @id fn = () => {};�}

const d = new D;�d.fn.name // ""

5 of 7

Opportunity: Enumeration order web reality

$ eshost -e "Reflect.ownKeys(class C { static method() { } })"

#### V8

length,prototype,method,name

#### JSC

length,name,prototype,method

#### ChakraCore

prototype,name,method,length

#### SpiderMonkey

prototype,method,length,name

6 of 7

anba's solution: NamedEvaluation

https://github.com/tc39/ecma262/pull/1372

  • Trick: FNI names precede the thing they are naming
  • NamedEvaluation abstract op passes name into evaluation
  • Class name assignment moves to ClassDefinitionEvaluation
  • Observable change: enumeration order of class properties
  • Shipping in Chrome 72

7 of 7

Consensus, awaiting tests?