Skip to content

Commit 0ecab0e

Browse files
committed
implement strictly equal for bigint
1 parent f9b712a commit 0ecab0e

File tree

4 files changed

+111
-1
lines changed

4 files changed

+111
-1
lines changed

lib/Runtime/Language/JavascriptOperators.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,14 @@ using namespace Js;
937937
return FEqualDbl(dblLeft, dblRight);
938938
}
939939
return FALSE;
940+
941+
case TypeIds_BigInt:
942+
switch (rightType)
943+
{
944+
case TypeIds_BigInt:
945+
return JavascriptBigInt::Equals(aLeft, aRight);
946+
}
947+
return FALSE;
940948
case TypeIds_Boolean:
941949
switch (rightType)
942950
{

lib/Runtime/Library/JavascriptBigInt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ namespace Js
405405

406406
bool JavascriptBigInt::Equals(Var aLeft, Var aRight)
407407
{
408-
AssertMsg(VarIs<JavascriptBigInt>(aLeft) && VarIs<JavascriptBigInt>(aRight), "BigInt Equals");
409408
JavascriptBigInt *leftBigInt = VarTo<JavascriptBigInt>(aLeft);
410409
JavascriptBigInt *rightBigInt = VarTo<JavascriptBigInt>(aRight);
411410

test/BigInt/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,10 @@
4848
<compile-flags>-args summary -endargs -ESBigInt</compile-flags>
4949
</default>
5050
</test>
51+
<test>
52+
<default>
53+
<files>strictly_equal.js</files>
54+
<compile-flags>-args summary -endargs -ESBigInt</compile-flags>
55+
</default>
56+
</test>
5157
</regress-exe>

test/BigInt/strictly_equal.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
7+
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
8+
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
9+
}
10+
11+
var tests = [
12+
{
13+
name: "With different types on right side",
14+
body: function () {
15+
assert.isFalse(1n === false);
16+
assert.isFalse(1n === 1);
17+
assert.isFalse(1n === "1");
18+
assert.isFalse(1n === "1.0");
19+
assert.isFalse(1n === 1.0);
20+
assert.isFalse(1n === {a: 1});
21+
assert.isFalse(1n === null);
22+
assert.isFalse(1n === undefined);
23+
assert.isFalse(1n === []);
24+
assert.isFalse(1n === Symbol());
25+
}
26+
},
27+
{
28+
name: "With different types on left side",
29+
body: function () {
30+
assert.isFalse(true === 1n);
31+
assert.isFalse(1 === 1n);
32+
assert.isFalse("1" === 1n);
33+
assert.isFalse("1.0" === 1n);
34+
assert.isFalse(1.0 === 1n);
35+
assert.isFalse({a: 1} === 1n);
36+
assert.isFalse(null === 1n);
37+
assert.isFalse(undefined === 1n);
38+
assert.isFalse([] === 1n);
39+
assert.isFalse(Symbol() === 1n);
40+
}
41+
},
42+
{
43+
name: "With same type BigInt",
44+
body: function () {
45+
assert.isTrue(0n === -0n);
46+
assert.isTrue(1n === 1n);
47+
assert.isTrue(1n === BigInt(1n));
48+
assert.isTrue(BigInt(2n) === BigInt(2n));
49+
assert.isTrue(BigInt(3n) === 3n);
50+
assert.isTrue(1n === 2n-1n);
51+
var x = 2n;
52+
var y = 2n;
53+
assert.isTrue(x === y);
54+
assert.isTrue(--x === 1n);
55+
assert.isTrue(y === 2n);
56+
assert.isFalse(x === y);
57+
}
58+
},
59+
{
60+
name: "Cross scope",
61+
body: function () {
62+
var y = 1n;
63+
var f = () => {
64+
return y;
65+
};
66+
var g = () => {
67+
return 1n;
68+
};
69+
var x = 1n;
70+
assert.isTrue(x === f());
71+
assert.isTrue(x === g());
72+
var o = {a: 1n};
73+
assert.isTrue(x == o.a);
74+
}
75+
},
76+
{
77+
name: "Marshal",
78+
body: function () {
79+
let child_global = WScript.LoadScript('var val = 5n;', 'samethread');
80+
assert.isTrue(5n === child_global.val);
81+
}
82+
},
83+
{
84+
name: "Module",
85+
body: function () {
86+
WScript.RegisterModuleSource("exporter.js", "export var val = 5n;");
87+
WScript.RegisterModuleSource("importer.js",
88+
`
89+
import { val } from 'exporter.js';
90+
assert.isTrue(5n === val);
91+
`);
92+
WScript.LoadScriptFile("importer.js", "module");
93+
}
94+
},
95+
];
96+
97+
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 commit comments

Comments
 (0)