diff options
author | Asher Gomez <ashersaupingomez@gmail.com> | 2024-01-24 08:46:59 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-23 21:46:59 +0000 |
commit | 5aa25f08be0be6c097dd35cd5ea2c8c154b06929 (patch) | |
tree | b39e1b98edef432753f93b8c83b244f94685adaf /runtime/js | |
parent | ee0cfd3fd55910d3d8e8f802ec6401942dc71d5f (diff) |
feat: Add deprecation warning for `Deno.customInspect` (#22027)
This change sets the removal version of `Deno.customInspect` for Deno
v2.
Towards #22021
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/90_deno_ns.js | 3 | ||||
-rw-r--r-- | runtime/js/99_main.js | 52 |
2 files changed, 40 insertions, 15 deletions
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index e404d34d7..25ba2ef26 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -83,9 +83,6 @@ const denoNs = { futime: fs.futime, futimeSync: fs.futimeSync, errors: errors.errors, - // TODO(kt3k): Remove this export at v2 - // See https://github.com/denoland/deno/issues/9294 - customInspect: console.customInspect, inspect: console.inspect, env: os.env, exit: os.exit, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 54a4406b2..a038de518 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -43,6 +43,7 @@ import * as version from "ext:runtime/01_version.ts"; import * as os from "ext:runtime/30_os.js"; import * as timers from "ext:deno_web/02_timers.js"; import { + customInspect, getDefaultInspectOptions, getNoColor, inspectArgs, @@ -111,12 +112,13 @@ function warnOnDeprecatedApi(apiName, stack, suggestion) { // to make it more useful. const stackLines = StringPrototypeSplit(stack, "\n"); ArrayPrototypeShift(stackLines); - while (true) { + while (stackLines.length > 0) { // Filter out internal frames at the top of the stack - they are not useful // to the user. if ( StringPrototypeIncludes(stackLines[0], "(ext:") || - StringPrototypeIncludes(stackLines[0], "(node:") + StringPrototypeIncludes(stackLines[0], "(node:") || + StringPrototypeIncludes(stackLines[0], "<anonymous>") ) { ArrayPrototypeShift(stackLines); } else { @@ -127,6 +129,7 @@ function warnOnDeprecatedApi(apiName, stack, suggestion) { // event loop tick or promise handler calling a user function - again not // useful to the user. if ( + stackLines.length > 0 && StringPrototypeIncludes(stackLines[stackLines.length - 1], "(ext:core/") ) { ArrayPrototypePop(stackLines); @@ -168,16 +171,17 @@ function warnOnDeprecatedApi(apiName, stack, suggestion) { "color: yellow;", ); } - - console.error("%c\u2502", "color: yellow;"); - console.error("%c\u2514 Stack trace:", "color: yellow;"); - for (let i = 0; i < stackLines.length; i++) { - console.error( - `%c ${i == stackLines.length - 1 ? "\u2514" : "\u251c"}\u2500 ${ - StringPrototypeTrim(stackLines[i]) - }`, - "color: yellow;", - ); + if (stackLines.length > 0) { + console.error("%c\u2502", "color: yellow;"); + console.error("%c\u2514 Stack trace:", "color: yellow;"); + for (let i = 0; i < stackLines.length; i++) { + console.error( + `%c ${i == stackLines.length - 1 ? "\u2514" : "\u251c"}\u2500 ${ + StringPrototypeTrim(stackLines[i]) + }`, + "color: yellow;", + ); + } } console.error(); } @@ -626,6 +630,18 @@ function bootstrapMainRuntime(runtimeOptions) { noColor: util.getterOnly(() => ops.op_bootstrap_no_color()), args: util.getterOnly(opArgs), mainModule: util.getterOnly(opMainModule), + // TODO(kt3k): Remove this export at v2 + // See https://github.com/denoland/deno/issues/9294 + customInspect: { + get() { + warnOnDeprecatedApi( + "Deno.customInspect", + new Error().stack, + 'Use `Symbol.for("Deno.customInspect")` instead.', + ); + return customInspect; + }, + }, }); // TODO(bartlomieju): deprecate --unstable @@ -769,6 +785,18 @@ function bootstrapWorkerRuntime( pid: util.getterOnly(opPid), noColor: util.getterOnly(() => ops.op_bootstrap_no_color()), args: util.getterOnly(opArgs), + // TODO(kt3k): Remove this export at v2 + // See https://github.com/denoland/deno/issues/9294 + customInspect: { + get() { + warnOnDeprecatedApi( + "Deno.customInspect", + new Error().stack, + 'Use `Symbol.for("Deno.customInspect")` instead.', + ); + return customInspect; + }, + }, }); // Setup `Deno` global - we're actually overriding already // existing global `Deno` with `Deno` namespace from "./deno.ts". |