OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var limit = 10000; | 5 var limit = 10000; |
6 | 6 |
7 function testStringWrapper(string) { | 7 function testStringWrapper(string) { |
8 assertEquals('a', string[0]); | 8 assertEquals('a', string[0]); |
9 assertEquals('b', string[1]); | 9 assertEquals('b', string[1]); |
10 assertEquals('c', string[2]); | 10 assertEquals('c', string[2]); |
(...skipping 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 testStringWrapper(string); | 33 testStringWrapper(string); |
34 assertEquals(limit, string[limit]); | 34 assertEquals(limit, string[limit]); |
35 | 35 |
36 for (var i = limit; i > 0; i -= 2) { | 36 for (var i = limit; i > 0; i -= 2) { |
37 delete string[i]; | 37 delete string[i]; |
38 } | 38 } |
39 testStringWrapper(string); | 39 testStringWrapper(string); |
40 assertEquals(undefined, string[limit]); | 40 assertEquals(undefined, string[limit]); |
41 })(); | 41 })(); |
| 42 |
| 43 |
| 44 (function testReconfigureStringWrapperElements() { |
| 45 var s = new String('abc'); |
| 46 // Can't reconfigure string contents. |
| 47 assertThrows(() => Object.defineProperty(s, '1', {value: "value"}), TypeError)
; |
| 48 |
| 49 // Configure a property outside the string range |
| 50 var value = 'v1'; |
| 51 Object.defineProperty(s, '3', { |
| 52 get: () => {return value}, |
| 53 configurable:true |
| 54 }); |
| 55 assertEquals('v1', s[3]); |
| 56 value = 'v2'; |
| 57 assertEquals('v2', s[3]); |
| 58 |
| 59 Object.defineProperty(s, '3', {value: 'v3', configurable: false}); |
| 60 assertEquals('v3', s[3]); |
| 61 assertThrows(() => Object.defineProperty(s, '3', {value:2}), TypeError); |
| 62 })(); |
OLD | NEW |