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 testCoercibleToIntegerZero(test) {
function testPrimitiveValue(value) { testCoercibleToNumberZero(test);
test(value);
// ToPrimitive
testPrimitiveWrappers(value, "number", test);
}
// ToNumber testCoercibleToIntegerFromInteger(0, test);
testPrimitiveValue(null);
testPrimitiveValue(false);
testPrimitiveValue(0);
testPrimitiveValue("0");
// ToInteger: NaN -> +0 // NaN -> +0
testPrimitiveValue(undefined); testCoercibleToNumberNan(test);
testPrimitiveValue(NaN);
testPrimitiveValue("");
testPrimitiveValue("foo");
testPrimitiveValue("true");
// ToInteger: floor(abs(number)) // When toString() returns a string that parses to NaN:
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.
test({}); test({});
test([]); test([]);
} }
function testCoercibleToIntegerOne(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) { function testPrimitiveValue(value) {
test(value); test(value);
// ToPrimitive // ToPrimitive
testPrimitiveWrappers(value, "number", test); testPrimitiveWrappers(value, "number", test);
} }
// ToNumber
testPrimitiveValue(true); testPrimitiveValue(true);
testPrimitiveValue(1); testPrimitiveValue(1);
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) { function testCoercibleToIntegerFromInteger(nominalInteger, test) {