|
1 |
|
2 assertEq("foo".charCodeAt(-123), NaN); |
|
3 assertEq("foo".charCodeAt(-0), 102); |
|
4 assertEq("foo".charCodeAt(0), 102); |
|
5 assertEq("foo".charCodeAt(2), 111); |
|
6 assertEq("foo".charCodeAt(3.4), NaN); |
|
7 assertEq("foo".charCodeAt(), 102); |
|
8 assertEq("".charCodeAt(), NaN); |
|
9 assertEq("".charCodeAt(0), NaN); |
|
10 |
|
11 /* Inferred as string.charCodeAt(int). */ |
|
12 function charCodeAt1(x) { |
|
13 return "abc".charCodeAt(x); |
|
14 } |
|
15 assertEq(charCodeAt1(-1), NaN); |
|
16 assertEq(charCodeAt1(0), 97); |
|
17 assertEq(charCodeAt1(1), 98); |
|
18 assertEq(charCodeAt1(2), 99); |
|
19 assertEq(charCodeAt1(3), NaN); |
|
20 assertEq(charCodeAt1(1234), NaN); |
|
21 |
|
22 /* Inferred as string.charCodeAt(double). */ |
|
23 function charCodeAt2(x) { |
|
24 return "abc".charCodeAt(x); |
|
25 } |
|
26 assertEq(charCodeAt2(-1.3), NaN); |
|
27 assertEq(charCodeAt2(-0), 97); |
|
28 assertEq(charCodeAt2(2), 99); |
|
29 assertEq(charCodeAt2(2.3), 99); |
|
30 assertEq(charCodeAt2(3.14), NaN); |
|
31 assertEq(charCodeAt2(NaN), 97); |
|
32 |
|
33 /* Test ropes. */ |
|
34 function charCodeAt3(s, i) { |
|
35 var s2 = "abcdef" + s + "12345"; |
|
36 return s2.charCodeAt(i); |
|
37 } |
|
38 assertEq(charCodeAt3("abcdef", 14), 51); |
|
39 assertEq(charCodeAt3("a" + "b", 1), 98); |
|
40 assertEq(charCodeAt3("abcdefg" + "hijklmnop", 10), 101); |
|
41 |
|
42 /* Other 'this'. */ |
|
43 var n = new Number(123); |
|
44 n.charCodeAt = String.prototype.charCodeAt; |
|
45 assertEq(n.charCodeAt(1), 50); |
|
46 |
|
47 |