tc39 / proposal-private-methods

Private methods and getter/setters for ES6 classes
https://arai-a.github.io/ecma262-compare/?pr=1668
345 stars 37 forks source link

Getter-only #-name accessors should throw in strict mode #38

Closed syg closed 6 years ago

syg commented 6 years ago

I believe the intention is to align with public properties on this. Currently,

function thisDoesntThrow() {
  class C { get foo() { return 42; } }
  let c = new C;
  c.foo = "bar";
}

function thisThrows() {
  "use strict";
  class C { get foo() { return 42; } }
  let c = new C;
  c.foo = "bar";
};

The current spec doesn't have this behavior for #foo. https://tc39.github.io/proposal-private-methods/#sec-privatefieldset returns false instead of throwing, but the caller PutValue doesn't check the return boolean.

littledan commented 6 years ago

Good catch, @syg. I was hoping that returning false would make the algorithm calling this throw, but that appears to not be the case. PRs welcome.