diff options
Diffstat (limited to 'runtime/js/99_main.js')
-rw-r--r-- | runtime/js/99_main.js | 52 |
1 files changed, 40 insertions, 12 deletions
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". |