Bug 42801 - [ES5] index setters on Array.prototype not run when index set on array instance
Summary: [ES5] index setters on Array.prototype not run when index set on array instance
Status: RESOLVED DUPLICATE of bug 96596
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-21 18:56 PDT by Brendan Eich
Modified: 2012-09-17 00:34 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brendan Eich 2010-07-21 18:56:02 PDT
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
Comment 1 Gavin Barraclough 2012-09-17 00:34:41 PDT

*** This bug has been marked as a duplicate of bug 96596 ***