michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/licenses/publicdomain/ michael@0: */ michael@0: michael@0: /* michael@0: * ECMA-262 6th Edition / Draft November 8, 2013 michael@0: * michael@0: * 20.2.2 Function Properties of the Math Object michael@0: */ michael@0: michael@0: /* michael@0: * This custom object will allow us to check if valueOf() is called michael@0: */ michael@0: michael@0: TestNumber.prototype = new Number(); michael@0: michael@0: function TestNumber(value) { michael@0: this.value = value; michael@0: this.valueOfCalled = false; michael@0: } michael@0: michael@0: TestNumber.prototype = { michael@0: valueOf: function() { michael@0: this.valueOfCalled = true; michael@0: return this.value; michael@0: } michael@0: } michael@0: michael@0: // Verify that each TestNumber's flag is set after calling Math func michael@0: function test(func /*, args */) { michael@0: var args = Array.prototype.slice.call(arguments, 1); michael@0: func.apply(null, args); michael@0: michael@0: for (var i = 0; i < args.length; ++i) michael@0: assertEq(args[i].valueOfCalled, true); michael@0: } michael@0: michael@0: // Note that we are not testing these functions' return values michael@0: // We only test whether valueOf() is called for each argument michael@0: michael@0: // 1. Test Math.atan2() michael@0: var x = new TestNumber(1); michael@0: test(Math.atan2, x); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: test(Math.atan2, y, x); michael@0: michael@0: // Remove comment block once patch for bug 896264 is approved michael@0: /* michael@0: // 2. Test Math.hypot() michael@0: var x = new TestNumber(1); michael@0: test(Math.hypot, x); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: test(Math.hypot, x, y); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: var z = new TestNumber(3); michael@0: test(Math.hypot, x, y, z); michael@0: */ michael@0: michael@0: // Remove comment block once patch for bug 808148 is approved michael@0: /* michael@0: // 3. Test Math.imul() michael@0: var x = new TestNumber(1); michael@0: test(Math.imul, x); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: test(Math.imul, x, y); michael@0: */ michael@0: michael@0: // 4. Test Math.max() michael@0: var x = new TestNumber(1); michael@0: test(Math.max, x); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: test(Math.max, x, y); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: var z = new TestNumber(3); michael@0: test(Math.max, x, y, z); michael@0: michael@0: // 5. Test Math.min() michael@0: var x = new TestNumber(1); michael@0: test(Math.min, x); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: test(Math.min, x, y); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: var z = new TestNumber(3); michael@0: test(Math.min, x, y, z); michael@0: michael@0: // 6. Test Math.pow() michael@0: var x = new TestNumber(1); michael@0: test(Math.pow, x); michael@0: michael@0: var x = new TestNumber(1); michael@0: var y = new TestNumber(2); michael@0: test(Math.pow, x, y); michael@0: michael@0: reportCompare(0, 0, "ok"); michael@0: