This Gist is a test to see what happens when you freeze an object's prototype via Object.freeze
.
I created it because, after I upgraded my NodeJS installation to version 0.10.2 (I previously had v0.8.18), the Pipette library stopped working with this error:
Fatal error: Cannot assign to read only property 'onClose' of #<State>
TypeError: Cannot assign to read only property 'onClose' of #<State>
at new State (node_modules/pipette/lib/sink.js:81:16)
The problem is that the library freezes the prototypes of various objects, but the objects want to override some of the properties they inherit from their prototypes which is prevented because the prototype is frozen:
function State(emitter, source) {
// This line causes the error
this.onClose = this.onClose.bind(this);
}
State.prototype.onClose = function onClose(info) {
...
}
Object.freeze(State);
Object.freeze(State.prototype);
I'd have thought that would be ok, because the instance is not itself frozen.
So, this gist is a minimal test case to see what happens in the above example in various browsers and in NodeJS.
Just execute the fiddle.js file under node:
node fiddle.js
To run in a browser, this Gist can be run as a JSFiddle:
http://jsfiddle.net/gh/gist/library/pure/5283131/
At time of writing, results are:
Only tests 5 and 6 fail.
All tests fail except test 4, the one that uses Object.defineProperty().