mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
28 lines
863 B
JavaScript
28 lines
863 B
JavaScript
const nativeTests = require("./build/Release/napitests.node");
|
|
|
|
nativeTests.test_napi_class_constructor_handle_scope = () => {
|
|
const NapiClass = nativeTests.get_class_with_constructor();
|
|
const x = new NapiClass();
|
|
console.log("x.foo =", x.foo);
|
|
};
|
|
|
|
nativeTests.test_napi_handle_scope_finalizer = async () => {
|
|
// Create a weak reference, which will be collected eventually
|
|
// Pass false in Node.js so it does not create a handle scope
|
|
nativeTests.create_ref_with_finalizer(Boolean(process.isBun));
|
|
|
|
// Wait until it actually has been collected by ticking the event loop and forcing GC
|
|
while (!nativeTests.was_finalize_called()) {
|
|
await new Promise(resolve => {
|
|
setTimeout(() => resolve(), 0);
|
|
});
|
|
if (process.isBun) {
|
|
Bun.gc(true);
|
|
} else if (global.gc) {
|
|
global.gc();
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = nativeTests;
|