Debian Codegraph @

js/src/jit-test/tests/structured-clone/bug1888727.js

raw
1 function test() {
2 // Construct a structured clone of a random BigInt value.
3 const n = 0xfeeddeadbeef2dadfeeddeadbeef2dadfeeddeadbeef2dadfeeddeadbeef2dadn;
4 const s = serialize(n, [], {scope: 'DifferentProcess'});
5 assertEq(deserialize(s), n);
6
7 // Truncate it by chopping off the last 8 bytes.
8 s.clonebuffer = s.arraybuffer.slice(0, -8);
9
10 // Deserialization should now throw a catchable exception.
11 try {
12 deserialize(s);
13 // The bug was throwing an uncatchable error, so this next assertion won't
14 // be reached in either the buggy or fixed code.
15 assertEq(true, false, "should have thrown truncation error");
16 } catch (e) {
17 assertEq(e.message.includes("truncated"), true);
18 }
19 }
20
21 test();