LEFT | RIGHT |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 // Flags: --harmony-strings | 5 // Flags: --harmony-strings |
6 | 6 |
7 // Tests taken from: | 7 // Tests taken from: |
8 // https://github.com/mathiasbynens/String.fromCodePoint/blob/master/tests/tests
.js | 8 // https://github.com/mathiasbynens/String.fromCodePoint |
9 | 9 |
10 assertEquals(String.fromCodePoint.length, 0); | 10 assertEquals(String.fromCodePoint.length, 1); |
11 assertEquals(String.propertyIsEnumerable("fromCodePoint"), false); | 11 assertEquals(String.propertyIsEnumerable("fromCodePoint"), false); |
12 | 12 |
13 assertEquals(String.fromCodePoint(""), "\0"); | 13 assertEquals(String.fromCodePoint(""), "\0"); |
14 assertEquals(String.fromCodePoint(), ""); | 14 assertEquals(String.fromCodePoint(), ""); |
15 assertEquals(String.fromCodePoint(-0), "\0"); | 15 assertEquals(String.fromCodePoint(-0), "\0"); |
16 assertEquals(String.fromCodePoint(0), "\0"); | 16 assertEquals(String.fromCodePoint(0), "\0"); |
17 assertEquals(String.fromCodePoint(0x1D306), "\uD834\uDF06"); | 17 assertEquals(String.fromCodePoint(0x1D306), "\uD834\uDF06"); |
18 assertEquals( | 18 assertEquals( |
19 String.fromCodePoint(0x1D306, 0x61, 0x1D307), | 19 String.fromCodePoint(0x1D306, 0x61, 0x1D307), |
20 "\uD834\uDF06a\uD834\uDF07"); | 20 "\uD834\uDF06a\uD834\uDF07"); |
(...skipping 16 matching lines...) Expand all Loading... |
37 assertThrows(function() { String.fromCodePoint(/./); }, RangeError); | 37 assertThrows(function() { String.fromCodePoint(/./); }, RangeError); |
38 assertThrows(function() { String.fromCodePoint({ | 38 assertThrows(function() { String.fromCodePoint({ |
39 valueOf: function() { throw Error(); } }); | 39 valueOf: function() { throw Error(); } }); |
40 }, Error); | 40 }, Error); |
41 assertThrows(function() { String.fromCodePoint({ | 41 assertThrows(function() { String.fromCodePoint({ |
42 valueOf: function() { throw Error(); } }); | 42 valueOf: function() { throw Error(); } }); |
43 }, Error); | 43 }, Error); |
44 var tmp = 0x60; | 44 var tmp = 0x60; |
45 assertEquals(String.fromCodePoint({ | 45 assertEquals(String.fromCodePoint({ |
46 valueOf: function() { ++tmp; return tmp; } | 46 valueOf: function() { ++tmp; return tmp; } |
47 }), "a"); | 47 }), "a"); |
| 48 assertEquals(tmp, 0x61); |
48 | 49 |
49 var counter = Math.pow(2, 15) * 3 / 2; | 50 var counter = Math.pow(2, 15) * 3 / 2; |
50 var result = []; | 51 var result = []; |
51 while (--counter >= 0) { | 52 while (--counter >= 0) { |
52 result.push(0); // one code unit per symbol | 53 result.push(0); // one code unit per symbol |
53 } | 54 } |
54 String.fromCodePoint.apply(null, result); // must not throw | 55 String.fromCodePoint.apply(null, result); // must not throw |
55 | 56 |
56 var counter = Math.pow(2, 15) * 3 / 2; | 57 var counter = Math.pow(2, 15) * 3 / 2; |
57 var result = []; | 58 var result = []; |
58 while (--counter >= 0) { | 59 while (--counter >= 0) { |
59 result.push(0xFFFF + 1); // two code units per symbol | 60 result.push(0xFFFF + 1); // two code units per symbol |
60 } | 61 } |
61 String.fromCodePoint.apply(null, result); // must not throw | 62 String.fromCodePoint.apply(null, result); // must not throw |
LEFT | RIGHT |