Status: New
Owner: ----
New issue 242 by kripkensteinr: getters/setters (__defineGetter__,
__defineSetter__) fail if property name is "0"
http://code.google.com/p/v8/issues/detail?id=242
V8 supports __defineGetter__ and __defineSetter__ perfectly for properties
with normal string names, like "test". However, if a getter/setter is
defined for a property with the name "0" (etc.) then things don't work. For
comparison, this does work in SpiderMonkey (Firefox).
Code and elaboration:
First, just to remind us that properties with the name "0" work ok (without
getters/setters):
var simple = { "0": "Hello" };
assert( simple["0"] === "Hello" );
assert( simple[0] === "Hello" );
And with a property with a name like "test", getters/setters work ok also:
var complicated = { value: 0 };
complicated.__defineGetter__("test", function() { return this.value; });
complicated.__defineSetter__("test", function(_value) { this.value =
_value + 100; });
assert( complicated.test !== undefined );
assert( complicated.test === 0 );
complicated.test = 721;
eval(assert( complicated.test === 821 );
complicated.test = 0;
eval(assert( complicated.test === 100 );
assert( complicated["test"] !== undefined );
assert( complicated["test"] === 100 );
complicated["test"] = 721;
assert( complicated["test"] === 821 );
complicated["test"] = 0;
assert( complicated["test"] === 100 );
But, with a property name of "0", things do not work:
complicated.__defineGetter__("0", function() { return this.value; });
// Returns undefined
complicated.__defineSetter__("0", function(_value) { this.value =
_value + 100; }); // Returns undefined
assert( complicated["0"] !== undefined ); // Fails
assert( complicated["0"] === 100 ); // Fails, etc.
complicated["0"] = 721;
assert( complicated["0"] === 821 );
complicated["0"] = 0;
assert( complicated["0"] === 100 );
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---