RESOLVED DUPLICATE of bug 96596 42801
[ES5] index setters on Array.prototype not run when index set on array instance
https://bugs.webkit.org/show_bug.cgi?id=42801
Summary [ES5] index setters on Array.prototype not run when index set on array instance
Brendan Eich
Reported 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
Attachments
Gavin Barraclough
Comment 1 2012-09-17 00:34:41 PDT
*** This bug has been marked as a duplicate of bug 96596 ***
Note You need to log in before you can comment on or make changes to this bug.