WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED WORKSFORME
48911
Object.defineProperty doesn't create property on Global Object in the presence of a setter in the prototype chain
https://bugs.webkit.org/show_bug.cgi?id=48911
Summary
Object.defineProperty doesn't create property on Global Object in the presenc...
Kent Hansen
Reported
2010-11-03 06:26:12 PDT
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
.
Attachments
Add attachment
proposed patch, testcase, etc.
Gavin Barraclough
Comment 1
2012-03-12 14:46:52 PDT
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.
Gavin Barraclough
Comment 2
2012-03-12 18:00:31 PDT
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
.
Gavin Barraclough
Comment 3
2012-03-12 18:18:06 PDT
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
.
Gavin Barraclough
Comment 4
2012-03-12 18:22:05 PDT
Tracking the WebCore hasOwnProperty bug here:
https://bugs.webkit.org/show_bug.cgi?id=80921
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug