Debian Codegraph @

js/src/jsapi-tests/testSABAccounting.cpp

raw
1 #include "builtin/TestingFunctions.h"
2 #include "js/SharedArrayBuffer.h"
3 #include "jsapi-tests/tests.h"
4
5 BEGIN_TEST(testSABAccounting) {
6 // Purge what we can
7 JS::PrepareForFullGC(cx);
8 NonIncrementalGC(cx, JS::GCOptions::Shrink, JS::GCReason::API);
9
10 // Self-hosting and chrome code should not use SABs, or the point of this
11 // predicate is completely lost.
12 CHECK(!JS::ContainsSharedArrayBuffer(cx));
13
14 JS::RootedObject obj(cx), obj2(cx);
15 CHECK(obj = JS::NewSharedArrayBuffer(cx, 4096));
16 CHECK(JS::ContainsSharedArrayBuffer(cx));
17 CHECK(obj2 = JS::NewSharedArrayBuffer(cx, 4096));
18 CHECK(JS::ContainsSharedArrayBuffer(cx));
19
20 // Discard those objects again.
21 obj = nullptr;
22 obj2 = nullptr;
23 JS::PrepareForFullGC(cx);
24 NonIncrementalGC(cx, JS::GCOptions::Shrink, JS::GCReason::API);
25
26 // Should be back to base state.
27 CHECK(!JS::ContainsSharedArrayBuffer(cx));
28
29 return true;
30 }
31 END_TEST(testSABAccounting)