[[Set]] and inherited readonly data properties

Jason Orendorff jason.orendorff at gmail.com
Wed Mar 26 11:24:47 PDT 2014

    "use strict";
    function Pony() {}
    Pony.prototype.toString = function () { return "Pony"; };

The last line here throws a TypeError in ES5 and ES6.*  Can we change
it? To me, it stands to reason that you should be able to freeze
Object.prototype and not break your other code, as long as that code
doesn't actually try to modify Object.prototype.

This bit some Mozilla hackers in <http://bugzil.la/980752>.

Compatibility: Changing from throwing to not-throwing is usually ok.
In addition, I don't think Chrome implements this TypeError. So
presumably the web can't be depending on the exception.

Patch: Step 5.a of [[Set]] could be changed like from:
    a. If ownDesc.[[Writable]] is false, return false.
    a. If ownDesc.[[Writable]] is false and O and Receiver are the
same object, return false.


*Why I think it throws:


Pony.prototype.[[Set]] reaches step 4.c. and tail-calls
Object.prototype.[[Set]], which reaches step 5.a. and returns false.

The TypeError is thrown from step 6.d. of PutValue:

which is called from step 1.f. from AssignmentExpression Evaluation:

More information about the es-discuss mailing list