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
3 // found in the LICENSE file.
6 // https://github.com/mathiasbynens/String.fromCodePoint
8 assertEquals(String.fromCodePoint.length, 1);
9 assertEquals(String.propertyIsEnumerable("fromCodePoint"), false);
11 assertEquals(String.fromCodePoint(""), "\0");
12 assertEquals(String.fromCodePoint(), "");
13 assertEquals(String.fromCodePoint(-0), "\0");
14 assertEquals(String.fromCodePoint(0), "\0");
15 assertEquals(String.fromCodePoint(0x1D306), "\uD834\uDF06");
17 String.fromCodePoint(0x1D306, 0x61, 0x1D307),
18 "\uD834\uDF06a\uD834\uDF07");
19 assertEquals(String.fromCodePoint(0x61, 0x62, 0x1D307), "ab\uD834\uDF07");
20 assertEquals(String.fromCodePoint(false), "\0");
21 assertEquals(String.fromCodePoint(null), "\0");
23 assertThrows(function() { String.fromCodePoint("_"); }, RangeError);
24 assertThrows(function() { String.fromCodePoint("+Infinity"); }, RangeError);
25 assertThrows(function() { String.fromCodePoint("-Infinity"); }, RangeError);
26 assertThrows(function() { String.fromCodePoint(-1); }, RangeError);
27 assertThrows(function() { String.fromCodePoint(0x10FFFF + 1); }, RangeError);
28 assertThrows(function() { String.fromCodePoint(3.14); }, RangeError);
29 assertThrows(function() { String.fromCodePoint(3e-2); }, RangeError);
30 assertThrows(function() { String.fromCodePoint(-Infinity); }, RangeError);
31 assertThrows(function() { String.fromCodePoint(+Infinity); }, RangeError);
32 assertThrows(function() { String.fromCodePoint(NaN); }, RangeError);
33 assertThrows(function() { String.fromCodePoint(undefined); }, RangeError);
34 assertThrows(function() { String.fromCodePoint({}); }, RangeError);
35 assertThrows(function() { String.fromCodePoint(/./); }, RangeError);
36 assertThrows(function() { String.fromCodePoint({
37 valueOf: function() { throw Error(); } });
39 assertThrows(function() { String.fromCodePoint({
40 valueOf: function() { throw Error(); } });
43 assertEquals(String.fromCodePoint({
44 valueOf: function() { ++tmp; return tmp; }
46 assertEquals(tmp, 0x61);
48 var counter = Math.pow(2, 15) * 3 / 2;
50 while (--counter >= 0) {
51 result.push(0); // one code unit per symbol
53 String.fromCodePoint.apply(null, result); // must not throw
55 var counter = Math.pow(2, 15) * 3 / 2;
57 while (--counter >= 0) {
58 result.push(0xFFFF + 1); // two code units per symbol
60 String.fromCodePoint.apply(null, result); // must not throw