MCPcopy Index your code
hub / github.com/nodejs/node / test

Function test

deps/v8/test/mjsunit/es6/math-trunc.js:63–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61}
62
63function test() {
64 // Ensure that a negative zero coming from Math.trunc is properly handled
65 // by other operations.
66 function itrunc(x) {
67 return 1 / Math.trunc(x);
68 }
69 %PrepareFunctionForOptimization(itrunc);
70 assertEquals(Infinity, itrunc(0));
71 assertEquals(-Infinity, itrunc(-0));
72 assertEquals(Infinity, itrunc(Math.PI / 4));
73 assertEquals(-Infinity, itrunc(-Math.sqrt(2) / 2));
74 assertEquals(-Infinity, itrunc({valueOf: function() { return "-0.1"; }}));
75 %OptimizeFunctionOnNextCall(itrunc);
76
77 testTrunc(100, 100);
78 testTrunc(-199, -199);
79 testTrunc(100, 100.1);
80 testTrunc(4503599627370495.0, 4503599627370495.0);
81 testTrunc(4503599627370496.0, 4503599627370496.0);
82 testTrunc(-4503599627370495.0, -4503599627370495.0);
83 testTrunc(-4503599627370496.0, -4503599627370496.0);
84 testTrunc(9007199254740991.0, 9007199254740991.0);
85 testTrunc(-9007199254740991.0, -9007199254740991.0);
86 testTrunc(0, []);
87 testTrunc(1, [1]);
88 testTrunc(-100, [-100.1]);
89 testTrunc(-100, {toString: function() { return "-100.3"; }});
90 testTrunc(10, {toString: function() { return 10.1; }});
91 testTrunc(-1, {valueOf: function() { return -1.1; }});
92 testTrunc(-Infinity, -Infinity);
93 testTrunc(Infinity, Infinity);
94 testTrunc(-Infinity, "-Infinity");
95 testTrunc(Infinity, "Infinity");
96
97 assertTrue(isNaN(Math.trunc("abc")));
98 assertTrue(isNaN(Math.trunc({})));
99 assertTrue(isNaN(Math.trunc([1, 1])));
100}
101
102// Test in a loop to cover the custom IC and GC-related issues.
103for (var i = 0; i < 10; i++) {

Callers 11

testTruncFunction · 0.70
math-trunc.jsFile · 0.70
TestWithProxiesFunction · 0.70
TestWithObjectProxyFunction · 0.70
TestWithFunctionProxyFunction · 0.70
TestWithProxiesFunction · 0.70
RunTestFunction · 0.70
test_allFunction · 0.70
TestWithProxiesFunction · 0.70

Calls 3

testTruncFunction · 0.85
assertEqualsFunction · 0.50
assertTrueFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…