Skip to content

Instantly share code, notes, and snippets.

@medikoo
Last active August 29, 2015 13:56
Show Gist options
  • Save medikoo/9268228 to your computer and use it in GitHub Desktop.
Save medikoo/9268228 to your computer and use it in GitHub Desktop.
Terrible getter/value resolution bug that happens in Safari
// 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