]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/string-from-code-point.js
1 function shouldBe(actual
, expected
) {
2 if (actual
!== expected
)
3 throw new Error("bad value: " + String(actual
));
6 function shouldThrow(func
, message
) {
14 throw new Error("not thrown.");
15 if (String(error
) !== message
)
16 throw new Error("bad error: " + String(error
));
19 function toCodePoints(string
) {
21 for (var codePoint
of string
) {
22 result
.push(codePoint
.codePointAt(0));
27 shouldBe(String
.fromCodePoint(), "");
28 shouldBe(String
.fromCodePoint(0), "\0");
29 shouldBe(String
.fromCodePoint(0, 0), "\0\0");
39 "𠮷野家", // Contain a surrogate pair.
42 for (var test
of tests
) {
43 shouldBe(String
.fromCodePoint
.apply(String
, toCodePoints(test
)), test
);
46 function passThrough(codePoint
) {
47 var string
= String
.fromCodePoint(codePoint
);
48 shouldBe(string
.codePointAt(0), codePoint
);
52 [ 0x10FFFF, "\uDBFF\uDFFF" ],
53 [ 0x10FFFE, "\uDBFF\uDFFE" ],
55 [ 0x10000, "\uD800\uDC00" ],
56 [ 0x10001, "\uD800\uDC01" ],
62 for (var test
of numberTests
) {
63 shouldBe(String
.fromCodePoint(test
[0]), test
[1]);
66 shouldBe(String
.fromCodePoint(0xD800, 0xDC00).codePointAt(0), 0x10000);
68 // Non-character code points.
69 for (var i
= 0; i
< 17; ++i
) {
70 var plane
= 0x10000 * i
;
71 passThrough(plane
+ 0xFFFE);
72 passThrough(plane
+ 0xFFFF);
75 for (var start
= 0xFDD0; start
<= 0xFDEF; ++start
) {
93 0x100000000 + 32, // String.fromCharCode(0x100000000 + 32) produces a space, but String.fromCodePoint should throw an error.
99 for (var test
of invalidTests
) {
100 shouldThrow(function () {
101 String
.fromCodePoint(test
);
102 }, "RangeError: Arguments contain a value that is out of range of code points");
105 // toNumber causes errors.
106 shouldThrow(function () {
107 String
.fromCodePoint(Symbol
.iterator
);
108 }, "TypeError: Type error")
110 var toNumberObject
= {
112 throw new Error("valueOf is called");
116 shouldThrow(function () {
117 String
.fromCodePoint(toNumberObject
);
118 }, "Error: valueOf is called")
120 shouldThrow(function () {
121 String
.fromCodePoint(Symbol
.iterator
, toNumberObject
);
122 }, "TypeError: Type error")
124 var convertAndPassTests
= [
133 for (var test
of convertAndPassTests
) {
134 shouldBe(String
.fromCodePoint(test
[0]), test
[1]);