Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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"
Add Comment
Please, Sign In to add comment