more separation of ToInteger from ToNumber

This commit is contained in:
Josh Wolfe 2017-08-29 17:28:55 -07:00 committed by Rick Waldron
parent 0f3f22f6ab
commit 0d9ef34510
1 changed files with 42 additions and 36 deletions

View File

@ -7,59 +7,65 @@ description: |
---*/
function testCoercibleToIntegerZero(test) {
function testPrimitiveValue(value) {
test(value);
// ToPrimitive
testPrimitiveWrappers(value, "number", test);
}
testCoercibleToNumberZero(test);
// ToNumber
testPrimitiveValue(null);
testPrimitiveValue(false);
testPrimitiveValue(0);
testPrimitiveValue("0");
testCoercibleToIntegerFromInteger(0, test);
// ToInteger: NaN -> +0
testPrimitiveValue(undefined);
testPrimitiveValue(NaN);
testPrimitiveValue("");
testPrimitiveValue("foo");
testPrimitiveValue("true");
// NaN -> +0
testCoercibleToNumberNan(test);
// ToInteger: floor(abs(number))
testPrimitiveValue(0.9);
testPrimitiveValue(-0);
testPrimitiveValue(-0.9);
testPrimitiveValue("0.9");
testPrimitiveValue("-0");
testPrimitiveValue("-0.9");
// Non-primitive values that coerce to 0:
// toString() returns a string that parses to NaN.
// When toString() returns a string that parses to NaN:
test({});
test([]);
}
function testCoercibleToIntegerOne(test) {
testCoercibleToNumberOne(test);
testCoercibleToIntegerFromInteger(1, test);
// When toString() returns "1"
test([1]);
test(["1"]);
}
function testCoercibleToNumberZero(test) {
function testPrimitiveValue(value) {
test(value);
// ToPrimitive
testPrimitiveWrappers(value, "number", test);
}
testPrimitiveValue(null);
testPrimitiveValue(false);
testPrimitiveValue(0);
testPrimitiveValue("0");
}
function testCoercibleToNumberNan(test) {
function testPrimitiveValue(value) {
test(value);
// ToPrimitive
testPrimitiveWrappers(value, "number", test);
}
testPrimitiveValue(undefined);
testPrimitiveValue(NaN);
testPrimitiveValue("");
testPrimitiveValue("foo");
testPrimitiveValue("true");
}
function testCoercibleToNumberOne(test) {
function testPrimitiveValue(value) {
test(value);
// ToPrimitive
testPrimitiveWrappers(value, "number", test);
}
// ToNumber
testPrimitiveValue(true);
testPrimitiveValue(1);
testPrimitiveValue("1");
// ToInteger: floor(abs(number))
testPrimitiveValue(1.9);
testPrimitiveValue("1.9");
// Non-primitive values that coerce to 1:
// toString() returns a string that parses to 1.
test([1]);
test(["1"]);
}
function testCoercibleToIntegerFromInteger(nominalInteger, test) {