js/src/jit-test/tests/ion/getelem.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 function testValue() {
michael@0 2 function f(arr, x) {
michael@0 3 return arr[x];
michael@0 4 }
michael@0 5 var a = [1, undefined, null, Math, 2.1, ""];
michael@0 6 for (var i=0; i<50; i++) {
michael@0 7 assertEq(f(a, 0), 1);
michael@0 8 assertEq(f(a, 1), undefined);
michael@0 9 assertEq(f(a, 2), null);
michael@0 10 assertEq(f(a, 3), Math);
michael@0 11 assertEq(f(a, 4), 2.1);
michael@0 12 assertEq(f(a, 5), "");
michael@0 13 assertEq(f(a, -1), undefined);
michael@0 14 assertEq(f(a, 6), undefined);
michael@0 15 }
michael@0 16 }
michael@0 17 testValue();
michael@0 18
michael@0 19 function testOutOfBounds() {
michael@0 20 function f(arr, x) {
michael@0 21 return arr[x];
michael@0 22 }
michael@0 23 var a = [0, 1, 2, 3, 4];
michael@0 24
michael@0 25 for (var j=0; j<4; j++) {
michael@0 26 for (var i=0; i<5; i++) {
michael@0 27 assertEq(f(a, i), i);
michael@0 28 }
michael@0 29 for (var i=5; i<10; i++) {
michael@0 30 assertEq(f(a, i), undefined);
michael@0 31 }
michael@0 32 for (var i=-1; i>-10; i--) {
michael@0 33 assertEq(f(a, i), undefined);
michael@0 34 }
michael@0 35 }
michael@0 36 }
michael@0 37 testOutOfBounds();
michael@0 38
michael@0 39 function testHole() {
michael@0 40 function f(arr, x) {
michael@0 41 return arr[x];
michael@0 42 }
michael@0 43 var a = [0, , 2, ];
michael@0 44 for (var i=0; i<70; i++) {
michael@0 45 assertEq(f(a, 0), 0);
michael@0 46 assertEq(f(a, 1), undefined);
michael@0 47 assertEq(f(a, 2), 2);
michael@0 48 assertEq(f(a, 3), undefined);
michael@0 49 }
michael@0 50 }
michael@0 51 testHole();
michael@0 52
michael@0 53 function testClassGuard() {
michael@0 54 function f(arr) {
michael@0 55 return arr[2];
michael@0 56 }
michael@0 57 var a = [1, 2, 3, 4];
michael@0 58 for (var i=0; i<90; i++) {
michael@0 59 assertEq(f(a), 3);
michael@0 60 }
michael@0 61 var b = {2: 100};
michael@0 62 assertEq(f(b), 100);
michael@0 63 }
michael@0 64 testClassGuard();
michael@0 65
michael@0 66 function testGeneric1() {
michael@0 67 function f(o, i) {
michael@0 68 return o[i];
michael@0 69 }
michael@0 70 for (var i=0; i<100; i++) {
michael@0 71 assertEq(f("abc", 1), "b");
michael@0 72 assertEq(f("foo", "length"), 3);
michael@0 73 assertEq(f([], -1), undefined);
michael@0 74 assertEq(f({x: 1}, "x"), 1);
michael@0 75 }
michael@0 76 }
michael@0 77 testGeneric1();

mercurial