forked from nodejs/node-api-cts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestFinalizerException.js
More file actions
26 lines (23 loc) · 885 Bytes
/
Copy pathtestFinalizerException.js
File metadata and controls
26 lines (23 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// A C finalizer that throws during GC surfaces as an uncaught exception. This
// mirrors test_reference/test_finalizer.js, except the addon here throws from
// Init; its exports are still reachable via the error's `.binding`, so a
// finalizer can be installed even though initialization failed.
const binding = (function() {
let resultingException;
try {
loadAddon('test_exception');
} catch (anException) {
resultingException = anException;
}
assert.strictEqual(resultingException.message, 'Error during Init');
return resultingException.binding;
})();
onUncaughtException(mustCall((err) => {
assert.match(err.message, /Error during Finalize/);
}));
(async function() {
binding.createExternal();
// GC until the finalizer fires; the counter just bounds the loop.
let gcCount = 10;
await gcUntil('test', () => --gcCount <= 0);
})().then(mustCall());