From 23e6b12edb0b792b82ff948e3b6c5cb2038c17bf Mon Sep 17 00:00:00 2001 From: XadillaX Date: Fri, 28 Apr 2023 20:31:18 +0800 Subject: vm,lib: refactor microtaskQueue assignment logic Simplify the assignment of the `microtaskQueue` variable in the `vm` module by replacing the conditional block with a more concise ternary operator. This change improves code readability and maintainability. PR-URL: https://github.com/nodejs/node/pull/47765 Reviewed-By: theanarkh Reviewed-By: Mestery Reviewed-By: Luigi Pinca --- lib/vm.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/vm.js b/lib/vm.js index 1fdea84334..b48e79c282 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -235,14 +235,12 @@ function createContext(contextObject = {}, options = kEmptyObject) { validateBoolean(wasm, 'options.codeGeneration.wasm'); } - let microtaskQueue = null; - if (microtaskMode !== undefined) { - validateOneOf(microtaskMode, 'options.microtaskMode', - ['afterEvaluate', undefined]); - - if (microtaskMode === 'afterEvaluate') - microtaskQueue = new MicrotaskQueue(); - } + validateOneOf(microtaskMode, + 'options.microtaskMode', + ['afterEvaluate', undefined]); + const microtaskQueue = microtaskMode === 'afterEvaluate' ? + new MicrotaskQueue() : + null; makeContext(contextObject, name, origin, strings, wasm, microtaskQueue); return contextObject; -- cgit v1.2.1