From d070f5d9659fbf562eaefac78ff7e8d4bedc1fd5 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. PR-URL: https://github.com/nodejs/node/pull/27230 Reviewed-By: Anna Henningsen Reviewed-By: Richard Lau Reviewed-By: Yongsheng Zhang Reviewed-By: James M Snell Reviewed-By: Michael Dawson --- 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 f290a4acb29a79..a06fda7a59cd87 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