diff --git a/assets/js/deserializer.mjs b/assets/js/deserializer.mjs index 285405c61..60ecc8a7f 100644 --- a/assets/js/deserializer.mjs +++ b/assets/js/deserializer.mjs @@ -10,6 +10,10 @@ export default class Deserializer { return Type.atom(value.slice(9)); } + if (value.startsWith("__bigint__:")) { + return BigInt(value.slice(11)); + } + if (value.startsWith("__binary__:")) { return Type.bitstring(value.slice(11)); } diff --git a/test/javascript/deserializer_test.mjs b/test/javascript/deserializer_test.mjs index 24e1c00b8..01e0204a9 100644 --- a/test/javascript/deserializer_test.mjs +++ b/test/javascript/deserializer_test.mjs @@ -229,5 +229,30 @@ describe("Deserializer", () => { }); }); }); + + describe("JS terms", () => { + describe("BigInt", () => { + const bigint = 123n; + + it("top-level", () => { + const serialized = serialize(bigint); + + assert.equal(deserialize(serialized), bigint); + }); + + it("nested", () => { + const term = {a: bigint, b: 2}; + const serialized = serialize(term); + + assert.deepStrictEqual(deserialize(serialized), term); + }); + + it("not versioned", () => { + const serialized = serialize(bigint, true, false); + + assert.equal(deserialize(serialized, false), bigint); + }); + }); + }); }); });