super.prop assignment can silently overwrite non-writable properties

Jason Orendorff jason.orendorff at gmail.com
Mon Apr 20 16:38:01 UTC 2015


We're implementing `super` in Firefox, and ran across this surprising behavior:

    class X {
        constructor() {
            Object.defineProperty(this, "prop", {
                configurable: true,
                writable: false,
                value: 1});
        }
        f() {
            super.prop = 2;  // overwrites non-writable property!
        }
    }

    var x = new X();
    x.f();
    assertEq(x.prop, 2);  // passes

In the spec, 9.1.9 step 4.d.i. is where `super.prop = 2` ends up, with
O=X.prototype.

Options:

1. Do nothing. Allow overwriting. It's a little weird, but this code
is pretty weird.

2. (post-ES6 of course) Add more "code" in 4.d.i. to perform a
[[GetOwnProperty]] and check.

-j


More information about the es-discuss mailing list