From 1ef617e8f3d48098e69e222b6eb6fe981aeca1c3 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Sun, 12 Nov 2023 20:52:59 -0800 Subject: perf: lazy bootstrap options - first pass (#21164) Move most runtime options to be lazily loaded. Constant options will be covered in a different PR. Towards https://github.com/denoland/deno/issues/21133 --- runtime/js/06_util.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'runtime/js/06_util.js') diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js index 971957b7e..c9fd4befe 100644 --- a/runtime/js/06_util.js +++ b/runtime/js/06_util.js @@ -1,5 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +const core = globalThis.Deno.core; +const ops = core.ops; const primordials = globalThis.__bootstrap.primordials; const { Promise, @@ -14,18 +16,18 @@ const LogLevel = { Debug: 4, }; -let logLevel = 3; -let logSource = "JS"; +const logSource = "JS"; -function setLogLevel(level, source) { - logLevel = level; - if (source) { - logSource = source; +let logLevel_ = null; +function logLevel() { + if (logLevel_ === null) { + logLevel_ = ops.op_bootstrap_log_level() || 3; } + return logLevel_; } function log(...args) { - if (logLevel >= LogLevel.Debug) { + if (logLevel() >= LogLevel.Debug) { // if we destructure `console` off `globalThis` too early, we don't bind to // the right console, therefore we don't log anything out. globalThis.console.error( @@ -83,12 +85,4 @@ function getterOnly(getter) { }; } -export { - createResolvable, - getterOnly, - log, - nonEnumerable, - readOnly, - setLogLevel, - writable, -}; +export { createResolvable, getterOnly, log, nonEnumerable, readOnly, writable }; -- cgit v1.2.3