From 1156f726a92d3d3985e591327c7526cd3e2b0473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 28 Sep 2022 12:28:38 +0200 Subject: [PATCH] refactor(runtime): don't use destructuring assignment in JS code (#16050) --- runtime/js/99_main.js | 62 +++++++++++++------------------------------ 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 27dc7111a5..755eac9395 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -252,8 +252,10 @@ delete Intl.v8BreakIterator; ); build.setBuildInfo(runtimeOptions.target); util.setLogDebug(runtimeOptions.debugFlag, source); + colors.setNoColor(runtimeOptions.noColor || !runtimeOptions.isTty); // deno-lint-ignore prefer-primordials Error.prepareStackTrace = core.prepareStackTrace; + registerErrors(); } function registerErrors() { @@ -639,19 +641,6 @@ delete Intl.v8BreakIterator; throw new Error("Worker runtime already bootstrapped"); } - const { - args, - location: locationHref, - noColor, - isTty, - pid, - ppid, - unstableFlag, - cpuCount, - inspectFlag, - userAgent: userAgentInfo, - } = runtimeOptions; - performance.setTimeOrigin(DateNow()); const consoleFromV8 = window.console; const wrapConsole = window.__bootstrap.console.wrapConsole; @@ -665,12 +654,12 @@ delete Intl.v8BreakIterator; // If the `--location` flag isn't set, make `globalThis.location` `undefined` and // writable, so that they can mock it themselves if they like. If the flag was // set, define `globalThis.location`, using the provided value. - if (locationHref == null) { + if (runtimeOptions.location == null) { mainRuntimeGlobalProperties.location = { writable: true, }; } else { - location.setLocationHref(locationHref); + location.setLocationHref(runtimeOptions.location); } ObjectDefineProperties(globalThis, windowOrWorkerGlobalScope); @@ -680,7 +669,7 @@ delete Intl.v8BreakIterator; ObjectDefineProperties(globalThis, mainRuntimeGlobalProperties); ObjectSetPrototypeOf(globalThis, Window.prototype); - if (inspectFlag) { + if (runtimeOptions.inspectFlag) { const consoleFromDeno = globalThis.console; wrapConsole(consoleFromDeno, consoleFromV8); } @@ -706,10 +695,8 @@ delete Intl.v8BreakIterator; runtimeStart(runtimeOptions); - colors.setNoColor(noColor || !isTty); - numCpus = cpuCount; - userAgent = userAgentInfo; - registerErrors(); + numCpus = runtimeOptions.cpuCount; + userAgent = runtimeOptions.userAgent; const internalSymbol = Symbol("Deno.internal"); @@ -722,14 +709,14 @@ delete Intl.v8BreakIterator; ...denoNs, }; ObjectDefineProperties(finalDenoNs, { - pid: util.readOnly(pid), - ppid: util.readOnly(ppid), - noColor: util.readOnly(noColor), - args: util.readOnly(ObjectFreeze(args)), + pid: util.readOnly(runtimeOptions.pid), + ppid: util.readOnly(runtimeOptions.ppid), + noColor: util.readOnly(runtimeOptions.noColor), + args: util.readOnly(ObjectFreeze(runtimeOptions.args)), mainModule: util.getterOnly(opMainModule), }); - if (unstableFlag) { + if (runtimeOptions.unstableFlag) { ObjectAssign(finalDenoNs, denoNsUnstable); } @@ -738,7 +725,7 @@ delete Intl.v8BreakIterator; ObjectDefineProperty(globalThis, "Deno", util.readOnly(finalDenoNs)); ObjectFreeze(globalThis.Deno.core); - util.log("args", args); + util.log("args", runtimeOptions.args); } function bootstrapWorkerRuntime( @@ -795,20 +782,9 @@ delete Intl.v8BreakIterator; runtimeOptions, internalName ?? name, ); - const { - unstableFlag, - pid, - noColor, - isTty, - args, - location: locationHref, - cpuCount, - } = runtimeOptions; - colors.setNoColor(noColor || !isTty); - location.setLocationHref(locationHref); - numCpus = cpuCount; - registerErrors(); + location.setLocationHref(runtimeOptions.location); + numCpus = runtimeOptions.cpuCount; globalThis.pollForMessages = pollForMessages; @@ -822,13 +798,13 @@ delete Intl.v8BreakIterator; close: core.close, ...denoNs, }; - if (unstableFlag) { + if (runtimeOptions.unstableFlag) { ObjectAssign(finalDenoNs, denoNsUnstable); } ObjectDefineProperties(finalDenoNs, { - pid: util.readOnly(pid), - noColor: util.readOnly(noColor), - args: util.readOnly(ObjectFreeze(args)), + pid: util.readOnly(runtimeOptions.pid), + noColor: util.readOnly(runtimeOptions.noColor), + args: util.readOnly(ObjectFreeze(runtimeOptions.args)), }); // Setup `Deno` global - we're actually overriding already // existing global `Deno` with `Deno` namespace from "./deno.ts".