Skip to content

Commit

Permalink
Reproduce segmantation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
perrin4869 committed Jul 3, 2022
1 parent 0b8831c commit a01c7d6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
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/index.js",
"test": "node test/index.js && node test/worker.js",
"prebuildify": "prebuildify --napi --strip"
},
"homepage": "https://github.com/tdewolff/minify#readme",
Expand Down
17 changes: 0 additions & 17 deletions bindings/js/test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { config, string } from '@tdewolff/minify';
import { Worker } from 'node:worker_threads';

config({'html-keep-document-tags': true})

Expand All @@ -9,19 +8,3 @@ let output = string("text/html", input);
if (output != expected) {
throw "unexpected output: '"+output+"' instead of '"+expected+"'";
}

const worker = new Worker(new URL("worker.js", import.meta.url), {
workerData: input,
});
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();
29 changes: 25 additions & 4 deletions bindings/js/test/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import { config, string } from '@tdewolff/minify';
import { workerData, parentPort } from 'node:worker_threads';
import { Worker, isMainThread, workerData, parentPort } from 'node:worker_threads';

config({'html-keep-document-tags': true})
parentPort.postMessage(string("text/html", workerData));
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));
}

0 comments on commit a01c7d6

Please sign in to comment.