js/src/jit-test/tests/jaeger/inline/stringCharCodeAt.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/jaeger/inline/stringCharCodeAt.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,47 @@
     1.4 +
     1.5 +assertEq("foo".charCodeAt(-123), NaN);
     1.6 +assertEq("foo".charCodeAt(-0), 102);
     1.7 +assertEq("foo".charCodeAt(0), 102);
     1.8 +assertEq("foo".charCodeAt(2), 111);
     1.9 +assertEq("foo".charCodeAt(3.4), NaN);
    1.10 +assertEq("foo".charCodeAt(), 102);
    1.11 +assertEq("".charCodeAt(), NaN);
    1.12 +assertEq("".charCodeAt(0), NaN);
    1.13 +
    1.14 +/* Inferred as string.charCodeAt(int). */
    1.15 +function charCodeAt1(x) {
    1.16 +    return "abc".charCodeAt(x);
    1.17 +}
    1.18 +assertEq(charCodeAt1(-1), NaN);
    1.19 +assertEq(charCodeAt1(0), 97);
    1.20 +assertEq(charCodeAt1(1), 98);
    1.21 +assertEq(charCodeAt1(2), 99);
    1.22 +assertEq(charCodeAt1(3), NaN);
    1.23 +assertEq(charCodeAt1(1234), NaN);
    1.24 +
    1.25 +/* Inferred as string.charCodeAt(double). */
    1.26 +function charCodeAt2(x) {
    1.27 +    return "abc".charCodeAt(x);
    1.28 +}
    1.29 +assertEq(charCodeAt2(-1.3), NaN);
    1.30 +assertEq(charCodeAt2(-0), 97);
    1.31 +assertEq(charCodeAt2(2), 99);
    1.32 +assertEq(charCodeAt2(2.3), 99);
    1.33 +assertEq(charCodeAt2(3.14), NaN);
    1.34 +assertEq(charCodeAt2(NaN), 97);
    1.35 +
    1.36 +/* Test ropes. */
    1.37 +function charCodeAt3(s, i) {
    1.38 +    var s2 = "abcdef" + s + "12345";
    1.39 +    return s2.charCodeAt(i);
    1.40 +}
    1.41 +assertEq(charCodeAt3("abcdef", 14), 51);
    1.42 +assertEq(charCodeAt3("a" + "b", 1), 98);
    1.43 +assertEq(charCodeAt3("abcdefg" + "hijklmnop", 10), 101);
    1.44 +
    1.45 +/* Other 'this'. */
    1.46 +var n = new Number(123);
    1.47 +n.charCodeAt = String.prototype.charCodeAt;
    1.48 +assertEq(n.charCodeAt(1), 50);
    1.49 +
    1.50 +

mercurial