js/src/jit-test/tests/basic/mathImul.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 var table = [
michael@0 3 [NaN, 0, 0],
michael@0 4 [Infinity, Infinity, 0],
michael@0 5 [NaN, 1000, 0],
michael@0 6
michael@0 7 [-1, -2, 2],
michael@0 8 [1, 2, 2],
michael@0 9 [-1, 2, -2],
michael@0 10 [1, -2, -2],
michael@0 11 [-0, 0, 0],
michael@0 12 [0, -0, 0],
michael@0 13 [-1, -0, 0],
michael@0 14 [1, -0, 0],
michael@0 15
michael@0 16 [0xffffffff, 1, -1],
michael@0 17
michael@0 18 [0xffffffff, 0xffffffff, 1],
michael@0 19 [0xffffffff, -0xffffffff, -1],
michael@0 20 [0xffffffff, 0xfffffffe, 2],
michael@0 21 [0xffffffff, -0xfffffffe, -2],
michael@0 22 [0x10000, 0x10000, 0],
michael@0 23
michael@0 24 [{}, {}, 0],
michael@0 25 [[], [], 0],
michael@0 26 [{}, [], 0],
michael@0 27 [[], {}, 0],
michael@0 28
michael@0 29 [{valueOf: function() { return -1; }}, 0x100000, -1048576],
michael@0 30 ["3", "-4", -12],
michael@0 31 [3.4, 6, 18]
michael@0 32 ];
michael@0 33
michael@0 34 try {
michael@0 35 Math.imul({ valueOf: function() { throw "ha ha ha"; } });
michael@0 36 assertEq(true, false, "no error thrown");
michael@0 37 } catch (e) {
michael@0 38 assertEq(e, "ha ha ha");
michael@0 39 }
michael@0 40
michael@0 41 var order = [];
michael@0 42 assertEq(Math.imul({ valueOf: function() { order.push("first"); return 0; } },
michael@0 43 { valueOf: function() { order.push("second"); return 0; } }),
michael@0 44 0);
michael@0 45 assertEq(order[0], "first");
michael@0 46 assertEq(order[1], "second");
michael@0 47
michael@0 48 var seen = [];
michael@0 49 try
michael@0 50 {
michael@0 51 Math.imul({ valueOf: function() { seen.push("one"); return 17; } },
michael@0 52 { valueOf: function() { throw "abort!"; } });
michael@0 53 assertEq(true, false, "no error thrown");
michael@0 54 }
michael@0 55 catch (e)
michael@0 56 {
michael@0 57 assertEq(e, "abort!", "should have thrown partway through, instead threw " + e);
michael@0 58 }
michael@0 59 assertEq(seen.length, 1);
michael@0 60 assertEq(seen[0], "one");
michael@0 61
michael@0 62 assertEq(Math.imul(), 0);
michael@0 63 assertEq(Math.imul(100), 0);
michael@0 64 assertEq(Math.imul(NaN, 100), 0);
michael@0 65 assertEq(Math.imul(NaN, NaN), 0);
michael@0 66 assertEq(Math.imul(5, Infinity), 0);
michael@0 67
michael@0 68 for (var i = 0; i < table.length; i++) {
michael@0 69 assertEq(Math.imul(table[i][0], table[i][1]), table[i][2]);
michael@0 70 assertEq(Math.imul(table[i][1], table[i][0]), table[i][2]);
michael@0 71 }

mercurial