Skip to content

Instantly share code, notes, and snippets.

@cms
Created September 11, 2010 08:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cms/574988 to your computer and use it in GitHub Desktop.
Save cms/574988 to your computer and use it in GitHub Desktop.
BESEN bug on String index named properties
/**
* 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