Permalink
Browse files

implement strictly equal for bigint

  • Loading branch information...
duongnhn committed Nov 3, 2018
1 parent f9b712a commit 0ecab0ef72396a1753feab30070a433599c75001
@@ -937,6 +937,14 @@ using namespace Js;
return FEqualDbl(dblLeft, dblRight);
}
return FALSE;
case TypeIds_BigInt:
switch (rightType)
{
case TypeIds_BigInt:
return JavascriptBigInt::Equals(aLeft, aRight);
}
return FALSE;
case TypeIds_Boolean:
switch (rightType)
{
@@ -405,7 +405,6 @@ namespace Js
bool JavascriptBigInt::Equals(Var aLeft, Var aRight)
{
AssertMsg(VarIs<JavascriptBigInt>(aLeft) && VarIs<JavascriptBigInt>(aRight), "BigInt Equals");
JavascriptBigInt *leftBigInt = VarTo<JavascriptBigInt>(aLeft);
JavascriptBigInt *rightBigInt = VarTo<JavascriptBigInt>(aRight);
@@ -48,4 +48,10 @@
<compile-flags>-args summary -endargs -ESBigInt</compile-flags>
</default>
</test>
<test>
<default>
<files>strictly_equal.js</files>
<compile-flags>-args summary -endargs -ESBigInt</compile-flags>
</default>
</test>
</regress-exe>
@@ -0,0 +1,97 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
if (this.WScript && this.WScript.LoadScriptFile) { // Check for running in ch
this.WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
}
var tests = [
{
name: "With different types on right side",
body: function () {
assert.isFalse(1n === false);
assert.isFalse(1n === 1);
assert.isFalse(1n === "1");
assert.isFalse(1n === "1.0");
assert.isFalse(1n === 1.0);
assert.isFalse(1n === {a: 1});
assert.isFalse(1n === null);
assert.isFalse(1n === undefined);
assert.isFalse(1n === []);
assert.isFalse(1n === Symbol());
}
},
{
name: "With different types on left side",
body: function () {
assert.isFalse(true === 1n);
assert.isFalse(1 === 1n);
assert.isFalse("1" === 1n);
assert.isFalse("1.0" === 1n);
assert.isFalse(1.0 === 1n);
assert.isFalse({a: 1} === 1n);
assert.isFalse(null === 1n);
assert.isFalse(undefined === 1n);
assert.isFalse([] === 1n);
assert.isFalse(Symbol() === 1n);
}
},
{
name: "With same type BigInt",
body: function () {
assert.isTrue(0n === -0n);
assert.isTrue(1n === 1n);
assert.isTrue(1n === BigInt(1n));
assert.isTrue(BigInt(2n) === BigInt(2n));
assert.isTrue(BigInt(3n) === 3n);
assert.isTrue(1n === 2n-1n);
var x = 2n;
var y = 2n;
assert.isTrue(x === y);
assert.isTrue(--x === 1n);
assert.isTrue(y === 2n);
assert.isFalse(x === y);
}
},
{
name: "Cross scope",
body: function () {
var y = 1n;
var f = () => {
return y;
};
var g = () => {
return 1n;
};
var x = 1n;
assert.isTrue(x === f());
assert.isTrue(x === g());
var o = {a: 1n};
assert.isTrue(x == o.a);
}
},
{
name: "Marshal",
body: function () {
let child_global = WScript.LoadScript('var val = 5n;', 'samethread');
assert.isTrue(5n === child_global.val);
}
},
{
name: "Module",
body: function () {
WScript.RegisterModuleSource("exporter.js", "export var val = 5n;");
WScript.RegisterModuleSource("importer.js",
`
import { val } from 'exporter.js';
assert.isTrue(5n === val);
`);
WScript.LoadScriptFile("importer.js", "module");
}
},
];
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" });

0 comments on commit 0ecab0e

Please sign in to comment.