For normal objects, this works as expected: o = {}; o.__proto__ = {}; o.__proto__.__defineGetter__("foo", function() { return this._x; }); o.__proto__.__defineSetter__("foo", function(v) { this._x = v; }); o.foo = 123; o.hasOwnProperty("foo"); // false Object.defineProperty(o, "foo", { value : 456 }); o.hasOwnProperty("foo"); // true i.e. even if there's a getter for a property named "foo" in the prototype chain, Object.defineProperty creates a new property on the object itself. This is in accordance with the ES5 spec, so all is good. However, if instead you do this on the Global Object (this=global): this.__proto__ = {}; this.__proto__.__defineGetter__("foo", function() { return this._x; }); this.__proto__.__defineSetter__("foo", function(v) { this._x = v; }); this.foo = 123; this.hasOwnProperty("foo"); // false Object.defineProperty(this, "foo", { value : 456 }); this.hasOwnProperty("foo"); // still false the property will _not_ be created on the Global Object, but will instead call the setter in the prototype. This is because JSGlobalObject::putWithAttributes() calls JSObject::put(), as discussed in https://bugs.webkit.org/show_bug.cgi?id=38636.
This works for me in ToT, was likely fixed in r106783. Will land a regression test for this. Please reopen if you're still repro'ing any issues in ToT. Cheers, G.
Gah, the test case still fails. It works since in JSC, but fails in WebCore. Object.defineProperty works fine, it's actually hasOwnProperty that fails, because JSDOMWindow::getOwnPropertySlot erroneously searches the prototype chain, which it shouldn't be doing for an 'own' access. This is likely related to the sadness that is bug#49739.
Okay, the hasOwnProperty thing is really a separate issue, and defineProperty now works, so to get these tests in I've changed them to use getOwnPropertyDescriptor (which does work correctly in WebCore's global object). I'll file a new bug to track the problems with hasOwnProperty. Layout tests landed in r110521.
Tracking the WebCore hasOwnProperty bug here: https://bugs.webkit.org/show_bug.cgi?id=80921