Last active
August 29, 2015 13:56
-
-
Save medikoo/9268228 to your computer and use it in GitHub Desktop.
Terrible getter/value resolution bug that happens in Safari
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This simplified test case unfortunately doesn't reproduce the issue | |
// nevertheless such error occurs in complex app I'm working with | |
'use strict'; | |
var Foo = function () {} | |
, resolve = function () { return {}; }; | |
Object.defineProperty(Foo.prototype, 'bar', { | |
configurable: true, | |
enumerable: false, | |
get: function () { | |
var value; | |
if (this.hasOwnProperty('bar')) { | |
if (Object.getOwnPropertyDescriptor(this, 'bar').value) { | |
// Happens in Safari [7.0.2 (9537.74.9)] | |
throw new Error("Getter called although property was defined with value!"); | |
} | |
return resolve; | |
} | |
value = resolve.call(this); | |
Object.defineProperty(this, 'bar', { | |
configurable: false, | |
enumerable: false, | |
writable: false, | |
value: value | |
}); | |
return value; | |
} | |
}); | |
var foo = new Foo(); | |
console.log(foo.bar); | |
console.log(foo.bar); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment