From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../Number/0x-without-following-hexdigits.js | 30 ++++ js/src/tests/non262/Number/15.7.3.7-EPSILON.js | 24 +++ js/src/tests/non262/Number/15.7.4.2.js | 31 ++++ .../non262/Number/20.1.2.10-MIN_SAFE_INTEGER.js | 26 ++++ .../non262/Number/20.1.2.6-MAX_SAFE_INTEGER.js | 26 ++++ .../tests/non262/Number/20.1.3.2-toExponential.js | 47 ++++++ js/src/tests/non262/Number/20.1.3.2-toPrecision.js | 47 ++++++ js/src/tests/non262/Number/20.1.3.3-toFixed.js | 17 ++ js/src/tests/non262/Number/ToNumber.js | 26 ++++ js/src/tests/non262/Number/browser.js | 0 .../non262/Number/conversion-invalid-precision.js | 46 ++++++ js/src/tests/non262/Number/defaultvalue.js | 170 ++++++++++++++++++++ js/src/tests/non262/Number/isSafeInteger-01.js | 40 +++++ js/src/tests/non262/Number/numericSeparator.js | 10 ++ js/src/tests/non262/Number/parseFloat-01.js | 27 ++++ js/src/tests/non262/Number/parseInt-01.js | 172 +++++++++++++++++++++ .../non262/Number/parseInt-default-to-decimal.js | 30 ++++ js/src/tests/non262/Number/regress-442242-01.js | 26 ++++ js/src/tests/non262/Number/shell.js | 0 js/src/tests/non262/Number/toExponential-values.js | 118 ++++++++++++++ js/src/tests/non262/Number/toFixed-values.js | 118 ++++++++++++++ js/src/tests/non262/Number/toPrecision-values.js | 100 ++++++++++++ .../tests/non262/Number/toString-radix-handling.js | 37 +++++ js/src/tests/non262/Number/tonumber-string-hex.js | 38 +++++ 24 files changed, 1206 insertions(+) create mode 100644 js/src/tests/non262/Number/0x-without-following-hexdigits.js create mode 100644 js/src/tests/non262/Number/15.7.3.7-EPSILON.js create mode 100644 js/src/tests/non262/Number/15.7.4.2.js create mode 100644 js/src/tests/non262/Number/20.1.2.10-MIN_SAFE_INTEGER.js create mode 100644 js/src/tests/non262/Number/20.1.2.6-MAX_SAFE_INTEGER.js create mode 100644 js/src/tests/non262/Number/20.1.3.2-toExponential.js create mode 100644 js/src/tests/non262/Number/20.1.3.2-toPrecision.js create mode 100644 js/src/tests/non262/Number/20.1.3.3-toFixed.js create mode 100644 js/src/tests/non262/Number/ToNumber.js create mode 100644 js/src/tests/non262/Number/browser.js create mode 100644 js/src/tests/non262/Number/conversion-invalid-precision.js create mode 100644 js/src/tests/non262/Number/defaultvalue.js create mode 100644 js/src/tests/non262/Number/isSafeInteger-01.js create mode 100644 js/src/tests/non262/Number/numericSeparator.js create mode 100644 js/src/tests/non262/Number/parseFloat-01.js create mode 100644 js/src/tests/non262/Number/parseInt-01.js create mode 100644 js/src/tests/non262/Number/parseInt-default-to-decimal.js create mode 100644 js/src/tests/non262/Number/regress-442242-01.js create mode 100644 js/src/tests/non262/Number/shell.js create mode 100644 js/src/tests/non262/Number/toExponential-values.js create mode 100644 js/src/tests/non262/Number/toFixed-values.js create mode 100644 js/src/tests/non262/Number/toPrecision-values.js create mode 100644 js/src/tests/non262/Number/toString-radix-handling.js create mode 100644 js/src/tests/non262/Number/tonumber-string-hex.js (limited to 'js/src/tests/non262/Number') diff --git a/js/src/tests/non262/Number/0x-without-following-hexdigits.js b/js/src/tests/non262/Number/0x-without-following-hexdigits.js new file mode 100644 index 0000000000..ffb329e5c8 --- /dev/null +++ b/js/src/tests/non262/Number/0x-without-following-hexdigits.js @@ -0,0 +1,30 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 582643; +var summary = "'0x' not followed by hex digits should be a syntax error"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +try +{ + eval("0x"); + throw new Error("didn't throw parsing 0x (with no subsequent hex digits)"); +} +catch (e) +{ + assertEq(e instanceof SyntaxError, true, + "bad exception thrown: " + e); +} + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/non262/Number/15.7.3.7-EPSILON.js b/js/src/tests/non262/Number/15.7.3.7-EPSILON.js new file mode 100644 index 0000000000..55e92ef1c0 --- /dev/null +++ b/js/src/tests/non262/Number/15.7.3.7-EPSILON.js @@ -0,0 +1,24 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 885798; +var summary = "ES6 (draft May 2013) 15.7.3.7 Number.EPSILON"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// Test value +assertEq(Number.EPSILON, Math.pow(2, -52)); + +// Test property attributes +var descriptor = Object.getOwnPropertyDescriptor(Number, 'EPSILON'); +assertEq(descriptor.writable, false); +assertEq(descriptor.configurable, false); +assertEq(descriptor.enumerable, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Number/15.7.4.2.js b/js/src/tests/non262/Number/15.7.4.2.js new file mode 100644 index 0000000000..36443394cb --- /dev/null +++ b/js/src/tests/non262/Number/15.7.4.2.js @@ -0,0 +1,31 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +assertEq(raisesException(TypeError)('Number.prototype.toString.call(true)'), true); +assertEq(raisesException(TypeError)('Number.prototype.toString.call("")'), true); +assertEq(raisesException(TypeError)('Number.prototype.toString.call({})'), true); +assertEq(raisesException(TypeError)('Number.prototype.toString.call(null)'), true); +assertEq(raisesException(TypeError)('Number.prototype.toString.call([])'), true); +assertEq(raisesException(TypeError)('Number.prototype.toString.call(undefined)'), true); +assertEq(raisesException(TypeError)('Number.prototype.toString.call(new Boolean(true))'), true); + +assertEq(completesNormally('Number.prototype.toString.call(42)'), true); +assertEq(completesNormally('Number.prototype.toString.call(new Number(42))'), true); + +function testAround(middle) +{ + var range = 260; + var low = middle - range/2; + for (var i = 0; i < range; ++i) + assertEq(low + i, parseInt(String(low + i))); +} + +testAround(-Math.pow(2,32)); +testAround(-Math.pow(2,16)); +testAround(0); +testAround(+Math.pow(2,16)); +testAround(+Math.pow(2,32)); + +reportCompare(true, true); diff --git a/js/src/tests/non262/Number/20.1.2.10-MIN_SAFE_INTEGER.js b/js/src/tests/non262/Number/20.1.2.10-MIN_SAFE_INTEGER.js new file mode 100644 index 0000000000..8b96651ff2 --- /dev/null +++ b/js/src/tests/non262/Number/20.1.2.10-MIN_SAFE_INTEGER.js @@ -0,0 +1,26 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 885798; +var summary = "ES6 (draft April 2014) 20.1.2.10 Number.MIN_SAFE_INTEGER"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// Test value +assertEq(Number.MIN_SAFE_INTEGER, -(Math.pow(2, 53) - 1)); + +//Test property attributes +var descriptor = Object.getOwnPropertyDescriptor(Number, 'MIN_SAFE_INTEGER'); + +assertEq(descriptor.writable, false); +assertEq(descriptor.configurable, false); +assertEq(descriptor.enumerable, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Number/20.1.2.6-MAX_SAFE_INTEGER.js b/js/src/tests/non262/Number/20.1.2.6-MAX_SAFE_INTEGER.js new file mode 100644 index 0000000000..e3a2ddff1f --- /dev/null +++ b/js/src/tests/non262/Number/20.1.2.6-MAX_SAFE_INTEGER.js @@ -0,0 +1,26 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 885798; +var summary = "ES6 (draft April 2014) 20.1.2.6 Number.MAX_SAFE_INTEGER"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// Test value +assertEq(Number.MAX_SAFE_INTEGER, Math.pow(2, 53) - 1); + +//Test property attributes +var descriptor = Object.getOwnPropertyDescriptor(Number, 'MAX_SAFE_INTEGER'); + +assertEq(descriptor.writable, false); +assertEq(descriptor.configurable, false); +assertEq(descriptor.enumerable, false); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Number/20.1.3.2-toExponential.js b/js/src/tests/non262/Number/20.1.3.2-toExponential.js new file mode 100644 index 0000000000..f87c750df1 --- /dev/null +++ b/js/src/tests/non262/Number/20.1.3.2-toExponential.js @@ -0,0 +1,47 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 818617; +var summary = "ECMAScript 2017 Draft ECMA-262 Section 20.1.3.2: Number.prototype.toExponential"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// With NaN, fractionDigits out of range. +assertEq(Number.prototype.toExponential.call(NaN, 555), 'NaN'); + +// With NaN fractionDigits in range. +assertEq(Number.prototype.toExponential.call(NaN, 5), 'NaN'); + +// With Infinity, fractionDigits out of range. +assertEq(Number.prototype.toExponential.call(Infinity, 555), 'Infinity'); + +// With Infinity, fractionDigits in range. +assertEq(Number.prototype.toExponential.call(Infinity, 5), 'Infinity'); + +// With -Infinity, fractionDigits out of range. +assertEq(Number.prototype.toExponential.call(-Infinity, 555), '-Infinity'); + +// With -Infinity, fractionDigits in range. +assertEq(Number.prototype.toExponential.call(-Infinity, 5), '-Infinity'); + +// With NaN, function assigning a value. +let x = 10; +assertEq(Number.prototype.toExponential.call(NaN, { valueOf() { x = 20; return 1; } }), 'NaN'); +assertEq(x, 20); + +// With NaN, function throwing an exception. +assertThrows(() => Number.prototype.toExponential.call(NaN, { valueOf() { throw "hello"; } })); + +// Not a number throws TypeError +assertThrowsInstanceOf(() => Number.prototype.toExponential.call("Hello"), TypeError); + +if (typeof reportCompare === "function") { + reportCompare(true, true); +} + diff --git a/js/src/tests/non262/Number/20.1.3.2-toPrecision.js b/js/src/tests/non262/Number/20.1.3.2-toPrecision.js new file mode 100644 index 0000000000..5c98560445 --- /dev/null +++ b/js/src/tests/non262/Number/20.1.3.2-toPrecision.js @@ -0,0 +1,47 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- + +var BUGNUMBER = 818617; +var summary = "ECMAScript 2017 Draft ECMA-262 Section 20.1.3.5: Number.prototype.toPrecision"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// With NaN, fractionDigits out of range. +assertEq(Number.prototype.toPrecision.call(NaN, 555), 'NaN'); + +// With NaN, fractionDigits in range. +assertEq(Number.prototype.toPrecision.call(NaN, 5), 'NaN'); + +// With Infinity, fractionDigits out of range. +assertEq(Number.prototype.toPrecision.call(Infinity, 555), 'Infinity'); + +// With Infinity, fractionDigits in range. +assertEq(Number.prototype.toPrecision.call(Infinity, 5), 'Infinity'); + +// With -Infinity, fractionDigits out of range. +assertEq(Number.prototype.toPrecision.call(-Infinity, 555), '-Infinity'); + +// With -Infinity, fractionDigits in range. +assertEq(Number.prototype.toPrecision.call(-Infinity, 5), '-Infinity'); + +// With NaN, function assigning a value. +let x = 10; +assertEq(Number.prototype.toPrecision.call(NaN, { valueOf() { x = 20; return 1; } }), 'NaN'); +assertEq(x, 20); + +// With NaN, function throwing an exception. +assertThrows(() => Number.prototype.toPrecision.call(NaN, { valueOf() { throw "hello"; } })); + +// Not a number throws TypeError +assertThrowsInstanceOf(() => Number.prototype.toPrecision.call("Hello"), TypeError); + +if (typeof reportCompare === "function") { + reportCompare(true, true); +} + diff --git a/js/src/tests/non262/Number/20.1.3.3-toFixed.js b/js/src/tests/non262/Number/20.1.3.3-toFixed.js new file mode 100644 index 0000000000..28b57ddaa2 --- /dev/null +++ b/js/src/tests/non262/Number/20.1.3.3-toFixed.js @@ -0,0 +1,17 @@ +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +assertEq(Number.prototype.toFixed.call(-Infinity), "-Infinity"); +assertEq(Number.prototype.toFixed.call(Infinity), "Infinity"); +assertEq(Number.prototype.toFixed.call(NaN), "NaN"); + +assertThrowsInstanceOf(() => Number.prototype.toFixed.call(-Infinity, 555), RangeError); +assertThrowsInstanceOf(() => Number.prototype.toFixed.call(Infinity, 555), RangeError); +assertThrowsInstanceOf(() => Number.prototype.toFixed.call(NaN, 555), RangeError); + +assertThrowsInstanceOf(() => Number.prototype.toFixed.call("Hello"), TypeError); + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Number/ToNumber.js b/js/src/tests/non262/Number/ToNumber.js new file mode 100644 index 0000000000..5716c8a000 --- /dev/null +++ b/js/src/tests/non262/Number/ToNumber.js @@ -0,0 +1,26 @@ +/* + * Any copyright is dedicated to the Public Domain. + * https://creativecommons.org/publicdomain/zero/1.0/ + */ + +assertEq(Number("0b11"), 3); +assertEq(Number("0B11"), 3); +assertEq(Number(" 0b11 "), 3); +assertEq(Number("0b12"), NaN); +assertEq(Number("-0b11"), NaN); +assertEq(+"0b11", 3); + +assertEq(Number("0o66"), 54); +assertEq(Number("0O66"), 54); +assertEq(Number(" 0o66 "), 54); +assertEq(Number("0o88"), NaN); +assertEq(Number("-0o66"), NaN); +assertEq(+"0o66", 54); + +if(typeof getSelfHostedValue === "function"){ + assertEq(getSelfHostedValue("ToNumber")("0b11"), 3); + assertEq(getSelfHostedValue("ToNumber")("0o66"), 54); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); diff --git a/js/src/tests/non262/Number/browser.js b/js/src/tests/non262/Number/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/non262/Number/conversion-invalid-precision.js b/js/src/tests/non262/Number/conversion-invalid-precision.js new file mode 100644 index 0000000000..76c3a94d0a --- /dev/null +++ b/js/src/tests/non262/Number/conversion-invalid-precision.js @@ -0,0 +1,46 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommonn.org/licenses/publicdomain/ + */ + +var BUGNUMBER = 795745; +var summary = + "Number.prototype.to* should throw a RangeError when passed a bad precision"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +function test(method, prec) +{ + try + { + Number.prototype[method].call(0, prec); + throw "should have thrown"; + } + catch (e) + { + assertEq(e instanceof RangeError, true, + "expected RangeError for " + method + " with precision " + prec + + ", got " + e); + } +} + +test("toExponential", -32); +test("toFixed", -32); +test("toPrecision", -32); + +test("toExponential", 9999999); +test("toFixed", 9999999); +test("toPrecision", 9999999); + +test("toPrecision", 0); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete"); diff --git a/js/src/tests/non262/Number/defaultvalue.js b/js/src/tests/non262/Number/defaultvalue.js new file mode 100644 index 0000000000..15bf021629 --- /dev/null +++ b/js/src/tests/non262/Number/defaultvalue.js @@ -0,0 +1,170 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommonn.org/licenses/publicdomain/ + */ + +var BUGNUMBER = 645464; +var summary = + "[[DefaultValue]] behavior wrong for Number with overridden valueOf/toString"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + + +// equality + +var n = new Number(); +assertEq(n == 0, true); + +var n2 = new Number(); +n2.valueOf = function() { return 17; }; +assertEq(n2 == 17, true); + +var n3 = new Number(); +n3.toString = function() { return 42; }; +assertEq(n3 == 0, true); + +function testEquality() +{ + var n = new Number(); + assertEq(n == 0, true); + + var n2 = new Number(); + n2.valueOf = function() { return 17; }; + assertEq(n2 == 17, true); + + var n3 = new Number(); + n3.toString = function() { return 42; }; + assertEq(n3 == 0, true); +} +testEquality(); + + +// addition of Number to number + +var n = new Number(); +assertEq(n + 5, 5); + +var n2 = new Number(); +n2.toString = function() { return 9; }; +assertEq(n2 + 3, 3); + +var n3 = new Number(); +n3.valueOf = function() { return 17; }; +assertEq(n3 + 5, 22); + +function testNumberAddition() +{ + var n = new Number(); + assertEq(n + 5, 5); + + var n2 = new Number(); + n2.toString = function() { return 9; }; + assertEq(n2 + 3, 3); + + var n3 = new Number(); + n3.valueOf = function() { return 17; }; + assertEq(n3 + 5, 22); +} +testNumberAddition(); + + +// addition of Number to Number + +var n = new Number(); +assertEq(n + n, 0); + +var n2 = new Number(); +n2.toString = function() { return 5; }; +assertEq(n2 + n2, 0); + +var n3 = new Number(); +n3.valueOf = function() { return 8.5; }; +assertEq(n3 + n3, 17); + +function testNonNumberAddition() +{ + var n = new Number(); + assertEq(n + n, 0); + + var n2 = new Number(); + n2.toString = function() { return 5; }; + assertEq(n2 + n2, 0); + + var n3 = new Number(); + n3.valueOf = function() { return 8.5; }; + assertEq(n3 + n3, 17); +} +testNonNumberAddition(); + + +// Number as bracketed property name + +var obj = { 0: 17, 8: 42, 9: 8675309 }; + +var n = new Number(); +assertEq(obj[n], 17); + +var n2 = new Number(); +n2.valueOf = function() { return 8; } +assertEq(obj[n2], 17); + +var n3 = new Number(); +n3.toString = function() { return 9; }; +assertEq(obj[n3], 8675309); + +function testPropertyNameToNumber() +{ + var obj = { 0: 17, 8: 42, 9: 8675309 }; + + var n = new Number(); + assertEq(obj[n], 17); + + var n2 = new Number(); + n2.valueOf = function() { return 8; } + assertEq(obj[n2], 17); + + var n3 = new Number(); + n3.toString = function() { return 9; }; + assertEq(obj[n3], 8675309); +} +testPropertyNameToNumber(); + + +// Number as property name with |in| operator + +var n = new Number(); +assertEq(n in { 0: 5 }, true); + +var n2 = new Number(); +n2.toString = function() { return "baz"; }; +assertEq(n2 in { baz: 42 }, true); + +var n3 = new Number(); +n3.valueOf = function() { return "quux"; }; +assertEq(n3 in { 0: 17 }, true); + +function testInOperatorName() +{ + var n = new Number(); + assertEq(n in { 0: 5 }, true); + + var n2 = new Number(); + n2.toString = function() { return "baz"; }; + assertEq(n2 in { baz: 42 }, true); + + var n3 = new Number(); + n3.valueOf = function() { return "quux"; }; + assertEq(n3 in { 0: 17 }, true); +} +testInOperatorName(); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/non262/Number/isSafeInteger-01.js b/js/src/tests/non262/Number/isSafeInteger-01.js new file mode 100644 index 0000000000..d1a11cfe37 --- /dev/null +++ b/js/src/tests/non262/Number/isSafeInteger-01.js @@ -0,0 +1,40 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 1003764; +var summary = "ES6 (draft Draft May 22, 2014) ES6 20.1.2.5 Number.isSafeInteger(number)"; + +print(BUGNUMBER + ": " + summary); + +assertEq(Number.isSafeInteger.length, 1); + +assertEq(Number.isSafeInteger({}), false); +assertEq(Number.isSafeInteger(NaN), false); +assertEq(Number.isSafeInteger(+Infinity), false); +assertEq(Number.isSafeInteger(-Infinity), false); + +assertEq(Number.isSafeInteger(-1), true); +assertEq(Number.isSafeInteger(+0), true); +assertEq(Number.isSafeInteger(-0), true); +assertEq(Number.isSafeInteger(1), true); + +assertEq(Number.isSafeInteger(3.2), false); + +assertEq(Number.isSafeInteger(Math.pow(2, 53) - 2), true); +assertEq(Number.isSafeInteger(Math.pow(2, 53) - 1), true); +assertEq(Number.isSafeInteger(Math.pow(2, 53)), false); +assertEq(Number.isSafeInteger(Math.pow(2, 53) + 1), false); +assertEq(Number.isSafeInteger(Math.pow(2, 53) + 2), false); + +assertEq(Number.isSafeInteger(-Math.pow(2, 53) - 2), false); +assertEq(Number.isSafeInteger(-Math.pow(2, 53) - 1), false); +assertEq(Number.isSafeInteger(-Math.pow(2, 53)), false); +assertEq(Number.isSafeInteger(-Math.pow(2, 53) + 1), true); +assertEq(Number.isSafeInteger(-Math.pow(2, 53) + 2), true); + + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/non262/Number/numericSeparator.js b/js/src/tests/non262/Number/numericSeparator.js new file mode 100644 index 0000000000..46ebabc7ea --- /dev/null +++ b/js/src/tests/non262/Number/numericSeparator.js @@ -0,0 +1,10 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +assertThrowsInstanceOf(function() { eval('let a = 100_00_;'); }, SyntaxError); +assertThrowsInstanceOf(() => eval("let b = 10__;"), SyntaxError); +assertThrowsInstanceOf(() => eval("let b = 1._2;"), SyntaxError); + +if (typeof reportCompare === "function") + reportCompare(true, true); + diff --git a/js/src/tests/non262/Number/parseFloat-01.js b/js/src/tests/non262/Number/parseFloat-01.js new file mode 100644 index 0000000000..8c57e4e129 --- /dev/null +++ b/js/src/tests/non262/Number/parseFloat-01.js @@ -0,0 +1,27 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 886949; +var summary = "ES6 (draft May 2013) 15.7.3.10 Number.parseFloat(string)"; + +print(BUGNUMBER + ": " + summary); + +assertEq(Number.parseFloat("Infinity"), Infinity); +assertEq(Number.parseFloat("+Infinity"), Infinity); +assertEq(Number.parseFloat("-Infinity"), -Infinity); + +assertEq(Number.parseFloat("inf"), NaN); +assertEq(Number.parseFloat("Inf"), NaN); +assertEq(Number.parseFloat("infinity"), NaN); + +assertEq(Number.parseFloat("nan"), NaN); +assertEq(Number.parseFloat("NaN"), NaN); + +/* Number.parseFloat should be the same function object as global parseFloat. */ +assertEq(Number.parseFloat, parseFloat); + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/non262/Number/parseInt-01.js b/js/src/tests/non262/Number/parseInt-01.js new file mode 100644 index 0000000000..20bda18726 --- /dev/null +++ b/js/src/tests/non262/Number/parseInt-01.js @@ -0,0 +1,172 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 886949; +var summary = "ES6 (draft May 2013) 15.7.3.9 Number.parseInt(string, radix)"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +var str, radix; +var upvar; + +/* 1. Let inputString be ToString(string). */ + +assertEq(Number.parseInt({ toString: function() { return "17" } }, 10), 17); + +upvar = 0; +str = { get toString() { upvar++; return function() { upvar++; return "12345"; } } }; +assertEq(Number.parseInt(str, 10), 12345); +assertEq(upvar, 2); + + +/* + * 2. Let S be a newly created substring of inputString consisting of the first + * character that is not a StrWhiteSpaceChar and all characters following + * that character. (In other words, remove leading white space.) + */ + +var ws = + ["\t", "\v", "\f", " ", "\xA0", "\uFEFF", + "\u2004", "\u3000", // a few Unicode whitespaces + "\r", "\n", "\u2028", "\u2029"]; + +str = "8675309"; +for (var i = 0, sz = ws.length; i < sz; i++) +{ + assertEq(Number.parseInt(ws[i] + str, 10), 8675309); + for (var j = 0, sz = ws.length; j < sz; j++) + { + assertEq(Number.parseInt(ws[i] + ws[j] + str, 10), 8675309, + ws[i].charCodeAt(0).toString(16) + ", " + + ws[j].charCodeAt(0).toString(16)); + } +} + + +/* + * 3. Let sign be 1. + * 4. If S is not empty and the first character of S is a minus sign -, let + * sign be −1. + */ +str = "5552368"; +assertEq(Number.parseInt("-" + str, 10), -Number.parseInt(str, 10)); +assertEq(Number.parseInt(" -" + str, 10), -Number.parseInt(str, 10)); +assertEq(Number.parseInt("-", 10), NaN); +assertEq(Number.parseInt("", 10), NaN); +assertEq(Number.parseInt("-0", 10), -0); + + +/* + * 5. If S is not empty and the first character of S is a plus sign + or a + * minus sign -, then remove the first character from S. + */ +assertEq(Number.parseInt("+12345", 10), 12345); +assertEq(Number.parseInt(" +12345", 10), 12345); +assertEq(Number.parseInt("-12345", 10), -12345); +assertEq(Number.parseInt(" -12345", 10), -12345); + + +/* + * 6. Let R = ToInt32(radix). + */ + +upvar = ""; +str = + { toString: function() { if (!upvar) upvar = "string"; return "42"; } }; +radix = + { toString: function() { if (!upvar) upvar = "radix"; return "10"; } }; + +assertEq(Number.parseInt(str, radix), 42); +assertEq(upvar, "string"); + +assertEq(Number.parseInt("123", null), 123); +assertEq(Number.parseInt("123", undefined), 123); +assertEq(Number.parseInt("123", NaN), 123); +assertEq(Number.parseInt("123", -0), 123); +assertEq(Number.parseInt("10", 72057594037927950), 16); +assertEq(Number.parseInt("10", -4294967292), 4); +assertEq(Number.parseInt("0x10", 1e308), 16); +assertEq(Number.parseInt("10", 1e308), 10); +assertEq(Number.parseInt("10", { valueOf: function() { return 16; } }), 16); + + +/* + * 7. Let stripPrefix be true. + * 8. If R ≠ 0, then + * a. If R < 2 or R > 36, then return NaN. + * b. If R ≠ 16, let stripPrefix be false. + * 9. Else, R = 0 + * a. Let R = 10. + * 10. If stripPrefix is true, then + * a. If the length of S is at least 2 and the first two characters of S + * are either “0x” or “0X”, then remove the first two characters from S and + * let R = 16. + */ +var vs = ["1", "51", "917", "2343", "99963"]; +for (var i = 0, sz = vs.length; i < sz; i++) + assertEq(Number.parseInt(vs[i], 0), Number.parseInt(vs[i], 10), "bad " + vs[i]); + +assertEq(Number.parseInt("0x10"), 16); +assertEq(Number.parseInt("0x10", 0), 16); +assertEq(Number.parseInt("0x10", 16), 16); +assertEq(Number.parseInt("0x10", 8), 0); +assertEq(Number.parseInt("-0x10", 16), -16); + +assertEq(Number.parseInt("5", 1), NaN); +assertEq(Number.parseInt("5", 37), NaN); +assertEq(Number.parseInt("5", { valueOf: function() { return -1; } }), NaN); + + +/* + * 11. If S contains any character that is not a radix-R digit, then let Z be + * the substring of S consisting of all characters before the first such + * character; otherwise, let Z be S. + * 12. If Z is empty, return NaN. + */ +assertEq(Number.parseInt(""), NaN); +assertEq(Number.parseInt("ohai"), NaN); +assertEq(Number.parseInt("0xohai"), NaN); +assertEq(Number.parseInt("-ohai"), NaN); +assertEq(Number.parseInt("+ohai"), NaN); +assertEq(Number.parseInt(" ohai"), NaN); + +assertEq(Number.parseInt("0xaohai"), 10); +assertEq(Number.parseInt("hohai", 18), 17); + + +/* + * 13. Let mathInt be the mathematical integer value that is represented by Z + * in radix-R notation, using the letters A-Z and a-z for digits with + * values 10 through 35. (However, if R is 10 and Z contains more than 20 + * significant digits, every significant digit after the 20th may be + * replaced by a 0 digit, at the option of the implementation; and if R is + * not 2, 4, 8, 10, 16, or 32, then mathInt may be an implementation- + * dependent approximation to the mathematical integer value that is + * represented by Z in radix-R notation.) + * 14. Let number be the Number value for mathInt. + * 15. Return sign × number. + */ +assertEq(Number.parseInt("ohai", 36), 1142154); +assertEq(Number.parseInt("0ohai", 36), 1142154); +assertEq(Number.parseInt("00ohai", 36), 1142154); +assertEq(Number.parseInt("A", 16), 10); +assertEq(Number.parseInt("0A", 16), 10); +assertEq(Number.parseInt("00A", 16), 10); +assertEq(Number.parseInt("A", 17), 10); +assertEq(Number.parseInt("0A", 17), 10); +assertEq(Number.parseInt("00A", 17), 10); + +/* Number.parseInt should be the same function object as global parseInt. */ +assertEq(Number.parseInt, parseInt); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/non262/Number/parseInt-default-to-decimal.js b/js/src/tests/non262/Number/parseInt-default-to-decimal.js new file mode 100644 index 0000000000..7049ef661b --- /dev/null +++ b/js/src/tests/non262/Number/parseInt-default-to-decimal.js @@ -0,0 +1,30 @@ +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 886949; +var summary = "ES6 (draft May 2013) 15.7.3.9 Number.parseInt(string, radix)." + + " Verify that Number.parseInt defaults to decimal."; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +assertEq(Number.parseInt("08"), 8); +assertEq(Number.parseInt("09"), 9); +assertEq(Number.parseInt("014"), 14); + +function strictParseInt(s) { "use strict"; return Number.parseInt(s); } + +assertEq(strictParseInt("08"), 8); +assertEq(strictParseInt("09"), 9); +assertEq(strictParseInt("014"), 14); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/non262/Number/regress-442242-01.js b/js/src/tests/non262/Number/regress-442242-01.js new file mode 100644 index 0000000000..a02f9511a0 --- /dev/null +++ b/js/src/tests/non262/Number/regress-442242-01.js @@ -0,0 +1,26 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 442242; +var summary = 'Do not assert: INT_FITS_IN_JSVAL(i)'; +var actual = 'No Crash'; +var expect = 'No Crash'; + + +//----------------------------------------------------------------------------- +test(); +//----------------------------------------------------------------------------- + +function test() +{ + printBugNumber(BUGNUMBER); + printStatus (summary); + + var i = 28800000; + -i; + + reportCompare(expect, actual, summary); +} diff --git a/js/src/tests/non262/Number/shell.js b/js/src/tests/non262/Number/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/non262/Number/toExponential-values.js b/js/src/tests/non262/Number/toExponential-values.js new file mode 100644 index 0000000000..c626738461 --- /dev/null +++ b/js/src/tests/non262/Number/toExponential-values.js @@ -0,0 +1,118 @@ +let values = [ + [-0, undefined, "0e+0"], + [-0, 0, "0e+0"], + [-0, 1, "0.0e+0"], + [-0, 10, "0.0000000000e+0"], + [-0, 50, "0.00000000000000000000000000000000000000000000000000e+0"], + [-0, 100, "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+0"], + [0, undefined, "0e+0"], + [0, 0, "0e+0"], + [0, 1, "0.0e+0"], + [0, 10, "0.0000000000e+0"], + [0, 50, "0.00000000000000000000000000000000000000000000000000e+0"], + [0, 100, "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+0"], + [NaN, undefined, "NaN"], + [NaN, 0, "NaN"], + [NaN, 1, "NaN"], + [NaN, 10, "NaN"], + [NaN, 50, "NaN"], + [NaN, 100, "NaN"], + [Infinity, undefined, "Infinity"], + [Infinity, 0, "Infinity"], + [Infinity, 1, "Infinity"], + [Infinity, 10, "Infinity"], + [Infinity, 50, "Infinity"], + [Infinity, 100, "Infinity"], + [-Infinity, undefined, "-Infinity"], + [-Infinity, 0, "-Infinity"], + [-Infinity, 1, "-Infinity"], + [-Infinity, 10, "-Infinity"], + [-Infinity, 50, "-Infinity"], + [-Infinity, 100, "-Infinity"], + [3.141592653589793, undefined, "3.141592653589793e+0"], + [3.141592653589793, 0, "3e+0"], + [3.141592653589793, 1, "3.1e+0"], + [3.141592653589793, 10, "3.1415926536e+0"], + [3.141592653589793, 50, "3.14159265358979311599796346854418516159057617187500e+0"], + [3.141592653589793, 100, "3.1415926535897931159979634685441851615905761718750000000000000000000000000000000000000000000000000000e+0"], + [-1, undefined, "-1e+0"], + [-1, 0, "-1e+0"], + [-1, 1, "-1.0e+0"], + [-1, 10, "-1.0000000000e+0"], + [-1, 50, "-1.00000000000000000000000000000000000000000000000000e+0"], + [-1, 100, "-1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+0"], + [1, undefined, "1e+0"], + [1, 0, "1e+0"], + [1, 1, "1.0e+0"], + [1, 10, "1.0000000000e+0"], + [1, 50, "1.00000000000000000000000000000000000000000000000000e+0"], + [1, 100, "1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+0"], + [-123456.78, undefined, "-1.2345678e+5"], + [-123456.78, 0, "-1e+5"], + [-123456.78, 1, "-1.2e+5"], + [-123456.78, 10, "-1.2345678000e+5"], + [-123456.78, 50, "-1.23456779999999998835846781730651855468750000000000e+5"], + [-123456.78, 100, "-1.2345677999999999883584678173065185546875000000000000000000000000000000000000000000000000000000000000e+5"], + [123456.78, undefined, "1.2345678e+5"], + [123456.78, 0, "1e+5"], + [123456.78, 1, "1.2e+5"], + [123456.78, 10, "1.2345678000e+5"], + [123456.78, 50, "1.23456779999999998835846781730651855468750000000000e+5"], + [123456.78, 100, "1.2345677999999999883584678173065185546875000000000000000000000000000000000000000000000000000000000000e+5"], + [100000000000000000000, undefined, "1e+20"], + [100000000000000000000, 0, "1e+20"], + [100000000000000000000, 1, "1.0e+20"], + [100000000000000000000, 10, "1.0000000000e+20"], + [100000000000000000000, 50, "1.00000000000000000000000000000000000000000000000000e+20"], + [100000000000000000000, 100, "1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+20"], + [1e+21, undefined, "1e+21"], + [1e+21, 0, "1e+21"], + [1e+21, 1, "1.0e+21"], + [1e+21, 10, "1.0000000000e+21"], + [1e+21, 50, "1.00000000000000000000000000000000000000000000000000e+21"], + [1e+21, 100, "1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+21"], + [-100000000000000000000, undefined, "-1e+20"], + [-100000000000000000000, 0, "-1e+20"], + [-100000000000000000000, 1, "-1.0e+20"], + [-100000000000000000000, 10, "-1.0000000000e+20"], + [-100000000000000000000, 50, "-1.00000000000000000000000000000000000000000000000000e+20"], + [-100000000000000000000, 100, "-1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+20"], + [-1e+21, undefined, "-1e+21"], + [-1e+21, 0, "-1e+21"], + [-1e+21, 1, "-1.0e+21"], + [-1e+21, 10, "-1.0000000000e+21"], + [-1e+21, 50, "-1.00000000000000000000000000000000000000000000000000e+21"], + [-1e+21, 100, "-1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e+21"], + [Number.MAX_VALUE, undefined, "1.7976931348623157e+308"], + [Number.MAX_VALUE, 0, "2e+308"], + [Number.MAX_VALUE, 1, "1.8e+308"], + [Number.MAX_VALUE, 10, "1.7976931349e+308"], + [Number.MAX_VALUE, 50, "1.79769313486231570814527423731704356798070567525845e+308"], + [Number.MAX_VALUE, 100, "1.7976931348623157081452742373170435679807056752584499659891747680315726078002853876058955863276687817e+308"], + [-Number.MAX_VALUE, undefined, "-1.7976931348623157e+308"], + [-Number.MAX_VALUE, 0, "-2e+308"], + [-Number.MAX_VALUE, 1, "-1.8e+308"], + [-Number.MAX_VALUE, 10, "-1.7976931349e+308"], + [-Number.MAX_VALUE, 50, "-1.79769313486231570814527423731704356798070567525845e+308"], + [-Number.MAX_VALUE, 100, "-1.7976931348623157081452742373170435679807056752584499659891747680315726078002853876058955863276687817e+308"], + [Number.MIN_VALUE, undefined, "5e-324"], + [Number.MIN_VALUE, 0, "5e-324"], + [Number.MIN_VALUE, 1, "4.9e-324"], + [Number.MIN_VALUE, 10, "4.9406564584e-324"], + [Number.MIN_VALUE, 50, "4.94065645841246544176568792868221372365059802614325e-324"], + [Number.MIN_VALUE, 100, "4.9406564584124654417656879286822137236505980261432476442558568250067550727020875186529983636163599238e-324"], + [-Number.MIN_VALUE, undefined, "-5e-324"], + [-Number.MIN_VALUE, 0, "-5e-324"], + [-Number.MIN_VALUE, 1, "-4.9e-324"], + [-Number.MIN_VALUE, 10, "-4.9406564584e-324"], + [-Number.MIN_VALUE, 50, "-4.94065645841246544176568792868221372365059802614325e-324"], + [-Number.MIN_VALUE, 100, "-4.9406564584124654417656879286822137236505980261432476442558568250067550727020875186529983636163599238e-324"], +]; + +for (let [val, prec, expected] of values) { + assertEq(Number.prototype.toExponential.call(val, prec), expected); +} + +if (typeof reportCompare === "function") { + reportCompare(true, true); +} diff --git a/js/src/tests/non262/Number/toFixed-values.js b/js/src/tests/non262/Number/toFixed-values.js new file mode 100644 index 0000000000..9b0b193948 --- /dev/null +++ b/js/src/tests/non262/Number/toFixed-values.js @@ -0,0 +1,118 @@ +let values = [ + [-0, undefined, "0"], + [-0, 0, "0"], + [-0, 1, "0.0"], + [-0, 10, "0.0000000000"], + [-0, 50, "0.00000000000000000000000000000000000000000000000000"], + [-0, 100, "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [0, undefined, "0"], + [0, 0, "0"], + [0, 1, "0.0"], + [0, 10, "0.0000000000"], + [0, 50, "0.00000000000000000000000000000000000000000000000000"], + [0, 100, "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [NaN, undefined, "NaN"], + [NaN, 0, "NaN"], + [NaN, 1, "NaN"], + [NaN, 10, "NaN"], + [NaN, 50, "NaN"], + [NaN, 100, "NaN"], + [Infinity, undefined, "Infinity"], + [Infinity, 0, "Infinity"], + [Infinity, 1, "Infinity"], + [Infinity, 10, "Infinity"], + [Infinity, 50, "Infinity"], + [Infinity, 100, "Infinity"], + [-Infinity, undefined, "-Infinity"], + [-Infinity, 0, "-Infinity"], + [-Infinity, 1, "-Infinity"], + [-Infinity, 10, "-Infinity"], + [-Infinity, 50, "-Infinity"], + [-Infinity, 100, "-Infinity"], + [3.141592653589793, undefined, "3"], + [3.141592653589793, 0, "3"], + [3.141592653589793, 1, "3.1"], + [3.141592653589793, 10, "3.1415926536"], + [3.141592653589793, 50, "3.14159265358979311599796346854418516159057617187500"], + [3.141592653589793, 100, "3.1415926535897931159979634685441851615905761718750000000000000000000000000000000000000000000000000000"], + [-1, undefined, "-1"], + [-1, 0, "-1"], + [-1, 1, "-1.0"], + [-1, 10, "-1.0000000000"], + [-1, 50, "-1.00000000000000000000000000000000000000000000000000"], + [-1, 100, "-1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [1, undefined, "1"], + [1, 0, "1"], + [1, 1, "1.0"], + [1, 10, "1.0000000000"], + [1, 50, "1.00000000000000000000000000000000000000000000000000"], + [1, 100, "1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [-123456.78, undefined, "-123457"], + [-123456.78, 0, "-123457"], + [-123456.78, 1, "-123456.8"], + [-123456.78, 10, "-123456.7800000000"], + [-123456.78, 50, "-123456.77999999999883584678173065185546875000000000000000"], + [-123456.78, 100, "-123456.7799999999988358467817306518554687500000000000000000000000000000000000000000000000000000000000000000"], + [123456.78, undefined, "123457"], + [123456.78, 0, "123457"], + [123456.78, 1, "123456.8"], + [123456.78, 10, "123456.7800000000"], + [123456.78, 50, "123456.77999999999883584678173065185546875000000000000000"], + [123456.78, 100, "123456.7799999999988358467817306518554687500000000000000000000000000000000000000000000000000000000000000000"], + [100000000000000000000, undefined, "100000000000000000000"], + [100000000000000000000, 0, "100000000000000000000"], + [100000000000000000000, 1, "100000000000000000000.0"], + [100000000000000000000, 10, "100000000000000000000.0000000000"], + [100000000000000000000, 50, "100000000000000000000.00000000000000000000000000000000000000000000000000"], + [100000000000000000000, 100, "100000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [1e+21, undefined, "1e+21"], + [1e+21, 0, "1e+21"], + [1e+21, 1, "1e+21"], + [1e+21, 10, "1e+21"], + [1e+21, 50, "1e+21"], + [1e+21, 100, "1e+21"], + [-100000000000000000000, undefined, "-100000000000000000000"], + [-100000000000000000000, 0, "-100000000000000000000"], + [-100000000000000000000, 1, "-100000000000000000000.0"], + [-100000000000000000000, 10, "-100000000000000000000.0000000000"], + [-100000000000000000000, 50, "-100000000000000000000.00000000000000000000000000000000000000000000000000"], + [-100000000000000000000, 100, "-100000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [-1e+21, undefined, "-1e+21"], + [-1e+21, 0, "-1e+21"], + [-1e+21, 1, "-1e+21"], + [-1e+21, 10, "-1e+21"], + [-1e+21, 50, "-1e+21"], + [-1e+21, 100, "-1e+21"], + [Number.MAX_VALUE, undefined, "1.7976931348623157e+308"], + [Number.MAX_VALUE, 0, "1.7976931348623157e+308"], + [Number.MAX_VALUE, 1, "1.7976931348623157e+308"], + [Number.MAX_VALUE, 10, "1.7976931348623157e+308"], + [Number.MAX_VALUE, 50, "1.7976931348623157e+308"], + [Number.MAX_VALUE, 100, "1.7976931348623157e+308"], + [-Number.MAX_VALUE, undefined, "-1.7976931348623157e+308"], + [-Number.MAX_VALUE, 0, "-1.7976931348623157e+308"], + [-Number.MAX_VALUE, 1, "-1.7976931348623157e+308"], + [-Number.MAX_VALUE, 10, "-1.7976931348623157e+308"], + [-Number.MAX_VALUE, 50, "-1.7976931348623157e+308"], + [-Number.MAX_VALUE, 100, "-1.7976931348623157e+308"], + [Number.MIN_VALUE, undefined, "0"], + [Number.MIN_VALUE, 0, "0"], + [Number.MIN_VALUE, 1, "0.0"], + [Number.MIN_VALUE, 10, "0.0000000000"], + [Number.MIN_VALUE, 50, "0.00000000000000000000000000000000000000000000000000"], + [Number.MIN_VALUE, 100, "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [-Number.MIN_VALUE, undefined, "-0"], + [-Number.MIN_VALUE, 0, "-0"], + [-Number.MIN_VALUE, 1, "-0.0"], + [-Number.MIN_VALUE, 10, "-0.0000000000"], + [-Number.MIN_VALUE, 50, "-0.00000000000000000000000000000000000000000000000000"], + [-Number.MIN_VALUE, 100, "-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], +]; + +for (let [val, prec, expected] of values) { + assertEq(Number.prototype.toFixed.call(val, prec), expected); +} + +if (typeof reportCompare === "function") { + reportCompare(true, true); +} diff --git a/js/src/tests/non262/Number/toPrecision-values.js b/js/src/tests/non262/Number/toPrecision-values.js new file mode 100644 index 0000000000..fb59cf8597 --- /dev/null +++ b/js/src/tests/non262/Number/toPrecision-values.js @@ -0,0 +1,100 @@ +let values = [ + [-0, undefined, "0"], + [-0, 1, "0"], + [-0, 10, "0.000000000"], + [-0, 50, "0.0000000000000000000000000000000000000000000000000"], + [-0, 100, "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [0, undefined, "0"], + [0, 1, "0"], + [0, 10, "0.000000000"], + [0, 50, "0.0000000000000000000000000000000000000000000000000"], + [0, 100, "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [NaN, undefined, "NaN"], + [NaN, 1, "NaN"], + [NaN, 10, "NaN"], + [NaN, 50, "NaN"], + [NaN, 100, "NaN"], + [Infinity, undefined, "Infinity"], + [Infinity, 1, "Infinity"], + [Infinity, 10, "Infinity"], + [Infinity, 50, "Infinity"], + [Infinity, 100, "Infinity"], + [-Infinity, undefined, "-Infinity"], + [-Infinity, 1, "-Infinity"], + [-Infinity, 10, "-Infinity"], + [-Infinity, 50, "-Infinity"], + [-Infinity, 100, "-Infinity"], + [3.141592653589793, undefined, "3.141592653589793"], + [3.141592653589793, 1, "3"], + [3.141592653589793, 10, "3.141592654"], + [3.141592653589793, 50, "3.1415926535897931159979634685441851615905761718750"], + [3.141592653589793, 100, "3.141592653589793115997963468544185161590576171875000000000000000000000000000000000000000000000000000"], + [-1, undefined, "-1"], + [-1, 1, "-1"], + [-1, 10, "-1.000000000"], + [-1, 50, "-1.0000000000000000000000000000000000000000000000000"], + [-1, 100, "-1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [1, undefined, "1"], + [1, 1, "1"], + [1, 10, "1.000000000"], + [1, 50, "1.0000000000000000000000000000000000000000000000000"], + [1, 100, "1.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [-123456.78, undefined, "-123456.78"], + [-123456.78, 1, "-1e+5"], + [-123456.78, 10, "-123456.7800"], + [-123456.78, 50, "-123456.77999999999883584678173065185546875000000000"], + [-123456.78, 100, "-123456.7799999999988358467817306518554687500000000000000000000000000000000000000000000000000000000000"], + [123456.78, undefined, "123456.78"], + [123456.78, 1, "1e+5"], + [123456.78, 10, "123456.7800"], + [123456.78, 50, "123456.77999999999883584678173065185546875000000000"], + [123456.78, 100, "123456.7799999999988358467817306518554687500000000000000000000000000000000000000000000000000000000000"], + [100000000000000000000, undefined, "100000000000000000000"], + [100000000000000000000, 1, "1e+20"], + [100000000000000000000, 10, "1.000000000e+20"], + [100000000000000000000, 50, "100000000000000000000.00000000000000000000000000000"], + [100000000000000000000, 100, "100000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [1e+21, undefined, "1e+21"], + [1e+21, 1, "1e+21"], + [1e+21, 10, "1.000000000e+21"], + [1e+21, 50, "1000000000000000000000.0000000000000000000000000000"], + [1e+21, 100, "1000000000000000000000.000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [-100000000000000000000, undefined, "-100000000000000000000"], + [-100000000000000000000, 1, "-1e+20"], + [-100000000000000000000, 10, "-1.000000000e+20"], + [-100000000000000000000, 50, "-100000000000000000000.00000000000000000000000000000"], + [-100000000000000000000, 100, "-100000000000000000000.0000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [-1e+21, undefined, "-1e+21"], + [-1e+21, 1, "-1e+21"], + [-1e+21, 10, "-1.000000000e+21"], + [-1e+21, 50, "-1000000000000000000000.0000000000000000000000000000"], + [-1e+21, 100, "-1000000000000000000000.000000000000000000000000000000000000000000000000000000000000000000000000000000"], + [Number.MAX_VALUE, undefined, "1.7976931348623157e+308"], + [Number.MAX_VALUE, 1, "2e+308"], + [Number.MAX_VALUE, 10, "1.797693135e+308"], + [Number.MAX_VALUE, 50, "1.7976931348623157081452742373170435679807056752584e+308"], + [Number.MAX_VALUE, 100, "1.797693134862315708145274237317043567980705675258449965989174768031572607800285387605895586327668782e+308"], + [-Number.MAX_VALUE, undefined, "-1.7976931348623157e+308"], + [-Number.MAX_VALUE, 1, "-2e+308"], + [-Number.MAX_VALUE, 10, "-1.797693135e+308"], + [-Number.MAX_VALUE, 50, "-1.7976931348623157081452742373170435679807056752584e+308"], + [-Number.MAX_VALUE, 100, "-1.797693134862315708145274237317043567980705675258449965989174768031572607800285387605895586327668782e+308"], + [Number.MIN_VALUE, undefined, "5e-324"], + [Number.MIN_VALUE, 1, "5e-324"], + [Number.MIN_VALUE, 10, "4.940656458e-324"], + [Number.MIN_VALUE, 50, "4.9406564584124654417656879286822137236505980261432e-324"], + [Number.MIN_VALUE, 100, "4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359924e-324"], + [-Number.MIN_VALUE, undefined, "-5e-324"], + [-Number.MIN_VALUE, 1, "-5e-324"], + [-Number.MIN_VALUE, 10, "-4.940656458e-324"], + [-Number.MIN_VALUE, 50, "-4.9406564584124654417656879286822137236505980261432e-324"], + [-Number.MIN_VALUE, 100, "-4.940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359924e-324"], +]; + +for (let [val, prec, expected] of values) { + assertEq(Number.prototype.toPrecision.call(val, prec), expected); +} + +if (typeof reportCompare === "function") { + reportCompare(true, true); +} diff --git a/js/src/tests/non262/Number/toString-radix-handling.js b/js/src/tests/non262/Number/toString-radix-handling.js new file mode 100644 index 0000000000..dd91675a27 --- /dev/null +++ b/js/src/tests/non262/Number/toString-radix-handling.js @@ -0,0 +1,37 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommonn.org/licenses/publicdomain/ + */ + +var BUGNUMBER = 647385; +var summary = + "Number.prototype.toString should use ToInteger on the radix and should " + + "throw a RangeError if the radix is bad"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +function test(r) +{ + try + { + 5..toString(r); + throw "should have thrown"; + } + catch (e) + { + assertEq(e instanceof RangeError, true, "expected a RangeError, got " + e); + } +} +test(Math.pow(2, 32) + 10); +test(55); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); diff --git a/js/src/tests/non262/Number/tonumber-string-hex.js b/js/src/tests/non262/Number/tonumber-string-hex.js new file mode 100644 index 0000000000..ed1e9b9dd4 --- /dev/null +++ b/js/src/tests/non262/Number/tonumber-string-hex.js @@ -0,0 +1,38 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommonn.org/licenses/publicdomain/ + */ + +var BUGNUMBER = 872853; +var summary = 'Various tests of ToNumber(string), particularly +"0x" being NaN'; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +assertEq(+"0x", NaN); +assertEq(+"\t0x", NaN); +assertEq(+"0x\n", NaN); +assertEq(+"\n0x\t", NaN); +assertEq(+"0x0", 0); +assertEq(+"0xa", 10); +assertEq(+"0xff", 255); +assertEq(+"-0x", NaN); +assertEq(+"-0xa", NaN); +assertEq(+"-0xff", NaN); +assertEq(+"0xInfinity", NaN); +assertEq(+"+Infinity", Infinity); +assertEq(+"-Infinity", -Infinity); +assertEq(+"\t+Infinity", Infinity); +assertEq(+"-Infinity\n", -Infinity); +assertEq(+"+ Infinity", NaN); +assertEq(+"- Infinity", NaN); + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("Tests complete"); -- cgit v1.2.3