Skip to content

Commit 8bb9dd3

Browse files
committed
fix bug with -NaN and +NaN in sets
1 parent 0fd7555 commit 8bb9dd3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/Runtime/Language/JavascriptConversion.inl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,10 @@ namespace Js {
303303
if (typeId == TypeIds_Number)
304304
{
305305
double numberValue = JavascriptNumber::GetValue(value);
306+
// NaN and -NaN do not canonicalize to the same value, but they are equal, so only allow +NaN
306307
return JavascriptNumber::IsNan(numberValue)
307308
? JavascriptNumber::IsNegative(numberValue)
308-
? JavascriptNumber::ToVar(JavascriptNumber::NegativeNaN)
309+
? nullptr
309310
: JavascriptNumber::ToVar(JavascriptNumber::NaN)
310311
: value;
311312
}

test/es6/set_functionality.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,15 @@ var tests = [
742742
assert.isTrue(set.has(value), "1.0 should be equal to the value 1 and set has it");
743743
}
744744
},
745+
{
746+
name: "-NaN and +NaN in set should not assert (github #6063)",
747+
body: function() {
748+
let set = new Set([+NaN, -NaN, "asdf"]);
749+
assert.isTrue(set.has(-NaN));
750+
assert.isTrue(set.has(NaN));
751+
assert.isTrue(set.has("asdf"));
752+
}
753+
},
745754
];
746755

747756
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)