test262/implementation-contributed/javascriptcore/stress/number-is-integer-intrinsic.js
test262-automation e9a5a7f918 [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time) (#1620)
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
2018-07-03 15:59:58 -04:00

73 lines
1.5 KiB
JavaScript

function assert(b) {
if (!b)
throw new Error;
}
function onlyDouble(x) {
return Number.isInteger(x);
}
noInline(onlyDouble);
let interestingValues = [
[Infinity, false],
[-Infinity, false],
[NaN, false],
[0.0, true],
[-0.0, true],
[90071992547490009021129120, true],
[9007199254749001000, true],
[Number.MAX_SAFE_INTEGER, true],
[Number.MIN_SAFE_INTEGER, true],
[0.5, false],
[Math.PI, false],
[42, true],
[0, true],
[-10, true],
[2147483647, true],
[-2147483648, true],
[Number.MIN_VALUE, false],
[Number.MAX_VALUE, true],
[-Number.MAX_VALUE, true],
];
for (let i = 0; i < 10000; ++i) {
for (let [value, result] of interestingValues) {
assert(onlyDouble(value) === result);
}
}
interestingValues.push(
[true, false],
[false, false],
[undefined, false],
[null, false],
[{}, false],
[{valueOf() { throw new Error("Should not be called"); }}, false],
[function(){}, false],
);
function generic(x) {
return Number.isInteger(x);
}
noInline(generic);
for (let i = 0; i < 10000; ++i) {
for (let [value, result] of interestingValues) {
assert(generic(value) === result);
}
}
function onlyInts(x) {
return Number.isInteger(x);
}
noInline(onlyInts);
for (let i = 0; i < 10000; ++i) {
assert(onlyInts(i) === true);
}
for (let i = 0; i < 10000; ++i) {
for (let [value, result] of interestingValues) {
assert(onlyInts(value) === result);
}
}