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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 assertEq("foo".charAt(-123), "");
michael@0 3 assertEq("foo".charAt(-1), "");
michael@0 4 assertEq("foo".charAt(0), "f");
michael@0 5 assertEq("foo".charAt(1), "o");
michael@0 6 assertEq("foo".charAt(2), "o");
michael@0 7 assertEq("foo".charAt(3.4), "");
michael@0 8 assertEq("foo".charAt(), "f");
michael@0 9 assertEq("".charAt(), "");
michael@0 10 assertEq("".charAt(0), "");
michael@0 11 assertEq("abc\u9123".charAt(3), "\u9123"); // char without unit string
michael@0 12
michael@0 13 /* Inferred as string.charAt(int). */
michael@0 14 function charAt1(x) {
michael@0 15 return "abc".charAt(x);
michael@0 16 }
michael@0 17 assertEq(charAt1(-1), "");
michael@0 18 assertEq(charAt1(0), "a");
michael@0 19 assertEq(charAt1(1), "b");
michael@0 20 assertEq(charAt1(2), "c");
michael@0 21 assertEq(charAt1(3), "");
michael@0 22 assertEq(charAt1(1234), "");
michael@0 23
michael@0 24 /* Inferred as string.charAt(double). */
michael@0 25 function charAt2(x) {
michael@0 26 return "abc".charAt(x);
michael@0 27 }
michael@0 28 assertEq(charAt2(-1.3), "");
michael@0 29 assertEq(charAt2(-0), "a");
michael@0 30 assertEq(charAt2(2), "c");
michael@0 31 assertEq(charAt2(2.3), "c");
michael@0 32 assertEq(charAt2(3.14), "");
michael@0 33 assertEq(charAt2(NaN), "a");
michael@0 34
michael@0 35 /* Test ropes. */
michael@0 36 function charAt3(s, i) {
michael@0 37 var s2 = "abcdef" + s + "12345";
michael@0 38 return s2.charAt(i);
michael@0 39 }
michael@0 40 assertEq(charAt3("abcdef", 14), "3");
michael@0 41 assertEq(charAt3("a" + "b", 1), "b");
michael@0 42 assertEq(charAt3("abcdefg" + "hijklmnop", 10), "e");
michael@0 43
michael@0 44 /* Other 'this'. */
michael@0 45 var arr = [1, 2];
michael@0 46 arr.charAt = String.prototype.charAt;
michael@0 47 assertEq(arr.charAt(1), ",");
michael@0 48
michael@0 49

mercurial