| 29 | // The finalizer that access JS cannot run synchronously. They are run in the |
| 30 | // next JS loop tick. Thus, we must use gcUntil. |
| 31 | async function runAsyncTests() { |
| 32 | // We do not use common.mustCall() because we want to see the finalizer |
| 33 | // called in response to GC and not as a part of env destruction. |
| 34 | let js_is_called = false; |
| 35 | // We use IIFE for the obj scope instead of {} to be compatible with |
| 36 | // non-V8 JS engines that do not support scoped variables. |
| 37 | (() => { |
| 38 | const obj = {}; |
| 39 | test_finalizer.addFinalizerWithJS(obj, () => { js_is_called = true; }); |
| 40 | })(); |
| 41 | await gcUntil('ensure JS finalizer called', |
| 42 | () => (test_finalizer.getFinalizerCallCount() === 2)); |
| 43 | assert(js_is_called); |
| 44 | } |
| 45 | runAsyncTests(); |