Bug 42801
| Summary: | [ES5] index setters on Array.prototype not run when index set on array instance | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Brendan Eich <brendan> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED DUPLICATE | ||
| Severity: | Normal | CC: | barraclough, jwalden+bwo, oliver |
| Priority: | P2 | ||
| Version: | 528+ (Nightly build) | ||
| Hardware: | All | ||
| OS: | All | ||
Brendan Eich
From a SpiderMonkey shell:
js> Array.prototype.__defineSetter__("foo", function() { print("Foo!"); });
js> Array.prototype.__defineSetter__(0, function() { print("Zero!"); });
js> var a = Array();
js> a.foo = 0;
Foo!
js> a[0] = 0;
Zero!
In a JSC shell:
> Array.prototype.__defineSetter__("foo", function() { print("Foo!"); });
undefined
> Array.prototype.__defineSetter__(0, function() { print("Zero!"); });
undefined
> var a = Array();
undefined
> a.foo = 0;
Foo!
0
> a[0] = 0;
0
V8 matches JSC. The __defineSetter__ stuff predates ES5, but ES5 codifies what Mozilla promulgated for __defineSetter__:
8.12.5 [[Put]] ( P, V, Throw )
. . .
1. If the result of calling the [[CanPut]] internal method of O with argument P is false, then
a. If Throw is true, then throw a TypeError exception.
b. Else return.
2. Let ownDesc be the result of calling the [[GetOwnProperty]] internal method of O with argument P.
3. If IsDataDescriptor(ownDesc) is true, then
a. Let valueDesc be the Property Descriptor {[[Value]]: V}.
b. Call the [[DefineOwnProperty]] internal method of O passing P, valueDesc, and Throw as arguments.
c. Return.
4. Let desc be the result of calling the [[GetProperty]] internal method of O with argument P. This may be either an own or inherited accessor property descriptor or an inherited data property descriptor.5. If IsAccessorDescriptor(desc) is true, then
a. Let setter be desc.[[Set]] which cannot be undefined.
b. Call the [[Call]] internal method of setter providing O as the this value and providing V as the sole argument.
5. If IsAccessorDescriptor(desc) is true, then
a. Let setter be desc.[[Set]] which cannot be undefined.
b. Call the [[Call]] internal method of setter providing O as the this value and providing V as the sole argument.
6. Else, create a named data property named P on object O as follows
a. Let newDesc be the Property Descriptor {[[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true}.
b. Call the [[DefineOwnProperty]] internal method of O passing P, newDesc, and Throw as arguments.
7. Return.
/be
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Gavin Barraclough
*** This bug has been marked as a duplicate of bug 96596 ***