1 of 5

Duplicate Annex B sloppy mode function declaration in block semantics

Daniel Ehrenberg (Google)

Shu-yu Guo (Mozilla)

2 of 5

Hello

  • We’re browsers
  • We want to implement Annex B 3.3 per spec
  • But, we ran into some web compat issues :(
    • And currently ship different semantics :(((

3 of 5

Problem #1: Duplicate identical functions

  • Identical function declarations in a block
  • Likely from copy-paste-concat
    • Immediately reported error, several websites completely broken
  • Within the intersection!
    • IE11+ left out the check
  • For web compat, need to permit duplicates

{

function f() {}

function f() {}

}

4 of 5

Problem #2: Leaking a local value

  • Options
    • f = 42
      • Broke a little old code
    • f = function() {}
  • There may be other hazard cases (e.g., sloppy mode block scoped self-defining functions) to address
  • It would be nice to meet reasonable user expectations

{

f = 42

function f() {}

}

f = ?

5 of 5

Solutions

  • Allow multiple declarations
  • But how do those assignments work?
  • One solution (littledan) shipped by V8 and Edge f = 42
    • Assign based on a read of the lexical local (as in current Annex B)
  • Another solution (shu) shipped by Firefox f = function() {}
    • Assign from the last function declaration from the block
  • How to decide???
    • There are a few more subtle possibilities
    • Any ideas/opinions? Hazard cases to address?
    • We’re both fine with shu’s PR