From 0c2843703e422fcf9c6daeebcf126eb1fa5f0aab Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 14 Apr 2019 22:44:02 +0200 Subject: [PATCH] worker: improve coverage This improves the worker coverage by using `internal/assert` instead of relying on `assert` in case a faulty worker message type is received. --- lib/internal/main/worker_thread.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 0e463dc9357841..80f515959b1602 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -45,6 +45,8 @@ const { const publicWorker = require('worker_threads'); +const assert = require('internal/assert'); + patchProcessObject(); setupInspectorHooks(); setupDebugEnv(); @@ -122,18 +124,17 @@ port.on('message', (message) => { process.argv[1] = filename; // script filename require('module').runMain(); } - return; } else if (message.type === STDIO_PAYLOAD) { const { stream, chunk, encoding } = message; process[stream].push(chunk, encoding); - return; - } else if (message.type === STDIO_WANTS_MORE_DATA) { + } else { + assert( + message.type === STDIO_WANTS_MORE_DATA, + `Unknown worker message type ${message.type}` + ); const { stream } = message; process[stream][kStdioWantsMoreDataCallback](); - return; } - - require('assert').fail(`Unknown worker message type ${message.type}`); }); // Overwrite fatalException