node/test/addons/worker-addon-exit/test.js
Mohamed Akram be7ea272e3 test: add regression test for using ObjectWrap in worker
This content is taken from https://github.com/nodejs/node/pull/63575.
The original commit message is preserved below:

---

worker: fix premature addon unload

Weak callbacks could run after addons were unloaded, leading to a crash.

Signed-off-by: Mohamed Akram <mohd.akram@outlook.com>
PR-URL: https://github.com/nodejs/node/pull/63642
Fixes: https://github.com/nodejs/node/issues/63540
Refs: https://github.com/nodejs/node/pull/63575
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2026-06-05 12:53:44 +00:00

15 lines
373 B
JavaScript

'use strict';
const common = require('../../common');
const { isMainThread, Worker } = require('worker_threads');
if (!isMainThread) {
const addon = require(`./build/${common.buildType}/binding`);
new addon.MyObject(10);
// Should not segfault
throw new Error('exit');
} else {
const worker = new Worker(__filename);
worker.on('error', common.mustCall());
}