Guest User

Untitled

a guest
Jun 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. /**
  2. * BESEN bug on String index named properties
  3. *
  4. * There are some problems accessing the named properties of String
  5. * objects that correspond to the individual characters of its
  6. * [[PrimitiveValue]].
  7. *
  8. * Tested on BESEN r117
  9. */
  10.  
  11.  
  12. // When we use a String value, it doesn't work if the Expression
  13. // of the bracket notation property accessor holds directly a
  14. // Numeric Literal:
  15.  
  16. var str = 'ab', i = 0;
  17.  
  18. // This fails:
  19. print(str[0]); // undefined
  20.  
  21. // But the following works:
  22. print(str[i]); // 'a' , OK
  23. print(str['0']); // 'a' , OK
  24. print(str[{ toString:function(){ return 0; } }]); // 'a', also OK
  25.  
  26.  
  27. // With a String object, the properties are not accessible at all:
  28. str = new String("ab");
  29.  
  30. print(str[0]); // undefined
  31. print(str[i]); // undefined
  32. print(str['0']); // undefined
  33. print(str[{ toString:function(){ return 0; } }]); // undefined
  34.  
  35. // However the own properties are there, and their descriptor looks good:
  36. print(str.hasOwnProperty('0')); // true
  37. print(JSON.stringify(Object.getOwnPropertyDescriptor(str, '0')));
  38. // {"value":"a","writable":false,"enumerable":true,"configurable":false}
  39.  
  40. print(str.hasOwnProperty('1')); // true
  41. print(JSON.stringify(Object.getOwnPropertyDescriptor(str, '1')));
  42. // {"value":"b","writable":false,"enumerable":true,"configurable":false}
  43.  
  44. // Also, the following should be taken in consideration, if we add a
  45. // property to the String.prototype object:
  46.  
  47. String.prototype['0'] = 'X';
  48.  
  49. // Even if the own property exist, and due they are not accessible
  50. // the String.prototype member is directly accessible:
  51.  
  52. print(str[0]); // "X"
  53. print(str[i]); // "X"
  54. print(str['0']); // "X"
  55. print(str[{toString:function(){ return 0;} }]); // "X"
Add Comment
Please, Sign In to add comment