Bug 48911
| Summary: | Object.defineProperty doesn't create property on Global Object in the presence of a setter in the prototype chain | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Kent Hansen <kent.hansen> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED WORKSFORME | ||
| Severity: | Normal | CC: | barraclough, ggaren, oliver, sam |
| Priority: | P2 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | PC | ||
| OS: | All | ||
Kent Hansen
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
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
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
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
Tracking the WebCore hasOwnProperty bug here: https://bugs.webkit.org/show_bug.cgi?id=80921