summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Math/20.2.2.ToNumber.js
blob: de1f4e612c3297f2e00df033ee4979794777ec28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/licenses/publicdomain/
 */

/*
 *   ECMA-262 6th Edition / Draft November 8, 2013
 *
 *   20.2.2 Function Properties of the Math Object
 */

/*
 * This custom object will allow us to check if valueOf() is called
 */

TestNumber.prototype = new Number();

function TestNumber(value) {
    this.value = value;
    this.valueOfCalled = false;
}

TestNumber.prototype = {
    valueOf: function() {
        this.valueOfCalled = true;
        return this.value;
    }
}

// Verify that each TestNumber's flag is set after calling Math func
function test(func /*, args */) {
    var args = Array.prototype.slice.call(arguments, 1);
    func.apply(null, args);

    for (var i = 0; i < args.length; ++i)
        assertEq(args[i].valueOfCalled, true);
}

// Note that we are not testing these functions' return values
// We only test whether valueOf() is called for each argument

// 1. Test Math.atan2()
var x = new TestNumber(1);
test(Math.atan2, x);

var x = new TestNumber(1);
var y = new TestNumber(2);
test(Math.atan2, y, x);

// Remove comment block once patch for bug 896264 is approved
/*
// 2. Test Math.hypot()
var x = new TestNumber(1);
test(Math.hypot, x);

var x = new TestNumber(1);
var y = new TestNumber(2);
test(Math.hypot, x, y);

var x = new TestNumber(1);
var y = new TestNumber(2);
var z = new TestNumber(3);
test(Math.hypot, x, y, z);
*/

// Remove comment block once patch for bug 808148 is approved
/*
// 3. Test Math.imul()
var x = new TestNumber(1);
test(Math.imul, x);

var x = new TestNumber(1);
var y = new TestNumber(2);
test(Math.imul, x, y);
*/

// 4. Test Math.max()
var x = new TestNumber(1);
test(Math.max, x);

var x = new TestNumber(1);
var y = new TestNumber(2);
test(Math.max, x, y);

var x = new TestNumber(1);
var y = new TestNumber(2);
var z = new TestNumber(3);
test(Math.max, x, y, z);

// 5. Test Math.min()
var x = new TestNumber(1);
test(Math.min, x);

var x = new TestNumber(1);
var y = new TestNumber(2);
test(Math.min, x, y);

var x = new TestNumber(1);
var y = new TestNumber(2);
var z = new TestNumber(3);
test(Math.min, x, y, z);

// 6. Test Math.pow()
var x = new TestNumber(1);
test(Math.pow, x);

var x = new TestNumber(1);
var y = new TestNumber(2);
test(Math.pow, x, y);

reportCompare(0, 0, "ok");