1 of 6

Module Namespace Objects:

Various Oddities

Adam Klein

TC39

November 2016

2 of 6

Overview

  • Module Namespace Objects are Exotic
    • Overrides nearly all operations
    • Mostly immutable (from the outside)
  • Also "exotic" in a couple other ways
    • null [[Prototype]] handling
    • Special @@iterator behavior

3 of 6

@@iterator: issues

  • Utilizes CreateListIterator spec machinery, appears to be designed for spec-internal use
    • Each returned iterator object has its own "next" method, and no [[Prototype]]
    • next method does brand-checking on its receiver
  • The @@iterator function object itself is mutable
    • Matches up poorly with rest of Module Namespace Object design

4 of 6

@@iterator: solutions

Either:

Remove @@iterator. Functionality is redundant with Object.keys()

Or:

Make @@iterator more like other iterators, and freeze the function

5 of 6

@@toStringTag

Current state: [[Configurable]] is true, but [[Set]] and [[DefineOwnProperty]] fail

Proposal: [[Configurable]] should be false

6 of 6

[[SetPrototypeOf]]

Current state: Always returns false, even if argument is null

Proposal: Match other spec behavior, returning true if argument is null