-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathmax2.js
36 lines (29 loc) · 1.14 KB
/
max2.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// @ts-check
function AssertNaN(value) {
if (!isNaN(value))
throw new Error("Expected NaN as value");
}
let valueOfCounter = 0;
const obj = {
valueOf: function () {
valueOfCounter++;
return 1;
}
};
AssertNaN(Math.max(NaN, obj));
AssertNaN(Math.max(NaN, NaN));
AssertNaN(Math.max(NaN, NaN, obj));
AssertNaN(Math.max(NaN, NaN, NaN));
AssertNaN(Math.min(NaN, obj));
AssertNaN(Math.min(NaN, NaN));
AssertNaN(Math.min(NaN, NaN, obj));
AssertNaN(Math.min(NaN, NaN, NaN));
const expectedCount = 4;
if (valueOfCounter != expectedCount)
throw new Error(`Expected "valueOf" to be called ${expectedCount}x; got ${valueOfCounter}`);
console.log("pass");