Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fixed undefined function when using Long.fromValue with a bigInt #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ if (typeof BigInt === "function") {

// Override
Long.fromValue = function fromValueWithBigInt(value, unsigned) {
if (typeof value === "bigint") return fromBigInt(value, unsigned);
if (typeof value === "bigint") return Long.fromBigInt(value, unsigned);
return fromValue(value, unsigned);
};

Expand Down
9 changes: 9 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,15 @@ var tests = [
assert.strictEqual(unsignedFromUnsigned.toBigInt(), values[i].unsigned);
var signedFromUnsigned = Long.fromBigInt(values[i].unsigned);
assert.strictEqual(signedFromUnsigned.toBigInt(), values[i].signed);

var signedFromSigned = Long.fromValue(values[i].signed);
assert.strictEqual(signedFromSigned.toBigInt(), values[i].signed);
var unsignedFromSigned = Long.fromValue(values[i].signed, true);
assert.strictEqual(unsignedFromSigned.toBigInt(), values[i].unsigned);
var unsignedFromUnsigned = Long.fromValue(values[i].unsigned, true);
assert.strictEqual(unsignedFromUnsigned.toBigInt(), values[i].unsigned);
var signedFromUnsigned = Long.fromValue(values[i].unsigned);
assert.strictEqual(signedFromUnsigned.toBigInt(), values[i].signed);
}
},

Expand Down