Created
September 11, 2010 08:27
-
-
Save cms/574988 to your computer and use it in GitHub Desktop.
BESEN bug on String index named properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* BESEN bug on String index named properties | |
* | |
* There are some problems accessing the named properties of String | |
* objects that correspond to the individual characters of its | |
* [[PrimitiveValue]]. | |
* | |
* Tested on BESEN r117 | |
*/ | |
// When we use a String value, it doesn't work if the Expression | |
// of the bracket notation property accessor holds directly a | |
// Numeric Literal: | |
var str = 'ab', i = 0; | |
// This fails: | |
print(str[0]); // undefined | |
// But the following works: | |
print(str[i]); // 'a' , OK | |
print(str['0']); // 'a' , OK | |
print(str[{ toString:function(){ return 0; } }]); // 'a', also OK | |
// With a String object, the properties are not accessible at all: | |
str = new String("ab"); | |
print(str[0]); // undefined | |
print(str[i]); // undefined | |
print(str['0']); // undefined | |
print(str[{ toString:function(){ return 0; } }]); // undefined | |
// However the own properties are there, and their descriptor looks good: | |
print(str.hasOwnProperty('0')); // true | |
print(JSON.stringify(Object.getOwnPropertyDescriptor(str, '0'))); | |
// {"value":"a","writable":false,"enumerable":true,"configurable":false} | |
print(str.hasOwnProperty('1')); // true | |
print(JSON.stringify(Object.getOwnPropertyDescriptor(str, '1'))); | |
// {"value":"b","writable":false,"enumerable":true,"configurable":false} | |
// Also, the following should be taken in consideration, if we add a | |
// property to the String.prototype object: | |
String.prototype['0'] = 'X'; | |
// Even if the own property exist, and due they are not accessible | |
// the String.prototype member is directly accessible: | |
print(str[0]); // "X" | |
print(str[i]); // "X" | |
print(str['0']); // "X" | |
print(str[{toString:function(){ return 0;} }]); // "X" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment