Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node.JS bindings Worker threads segfault reproduction #510

Merged
merged 2 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bindings/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"scripts": {
"install": "node-gyp-build",
"test": "node test.js",
"test": "node test/index.js && node test/worker.js",
"prebuildify": "prebuildify --napi --strip"
},
"homepage": "https://github.com/tdewolff/minify#readme",
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions bindings/js/test/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Worker, isMainThread, workerData, parentPort } from 'node:worker_threads';

if (isMainThread) {
let input = "<html><span style=\"color:#ff0000;\">A phrase</span>";
const worker = new Worker(new URL(import.meta.url), {
workerData: input,
});

let expected = "<html><span style=color:red>A phrase</span>";
let output = await new Promise((resolve, reject) => {
worker.on('message', resolve);
worker.on('error', reject);
worker.on('exit', (code) => {
if (code !== 0)
reject(new Error(`Worker stopped with exit code ${code}`));
});
})
if (output != expected) {
throw "unexpected output using worker threads: '"+output+"' instead of '"+expected+"'";
}
await worker.terminate();
} else {
const { config, string } = await import('@tdewolff/minify');
config({'html-keep-document-tags': true})
parentPort.postMessage(string("text/html", workerData));
}