Debian Codegraph @

js/src/tests/non262/extensions/clone-sab-failure.js

raw
1 // |reftest| skip-if(!xulRuntime.shell)
2 /* -*- Mode: js2; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /*
4 * Any copyright is dedicated to the Public Domain.
5 * https://creativecommons.org/publicdomain/zero/1.0/
6 */
7
8 // Failure to serialize an object containing a SAB should not leave the SAB's
9 // rawbuffer's reference count incremented.
10
11 if (!this.SharedArrayBuffer || !this.sharedArrayRawBufferRefcount) {
12 reportCompare(true,true);
13 quit(0);
14 }
15
16 let x = new SharedArrayBuffer(1);
17
18 // Initially the reference count is 1.
19 assertEq(sharedArrayRawBufferRefcount(x), 1);
20
21 let y = serialize(x, [], {SharedArrayBuffer: 'allow'});
22
23 // Serializing it successfully increments the reference count.
24 assertEq(sharedArrayRawBufferRefcount(x), 2);
25
26 // Serializing something containing a function should throw.
27 var failed = false;
28 try {
29 serialize([x, function () {}]);
30 }
31 catch (e) {
32 failed = true;
33 }
34 assertEq(failed, true);
35
36 // Serializing the SAB unsuccessfully does not increment the reference count.
37 assertEq(sharedArrayRawBufferRefcount(x), 2);
38
39 reportCompare(true, true);