From f91fa16661fa10fd029e6cf26008faee95233143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 10 Dec 2020 14:45:41 +0100 Subject: refactor(core): stack trace mapping (#8660) This commit adds "Deno.core.createPrepareStackTrace". This function was moved from "cli/rt/40_error_stack.js" to unify handling of stack frames in core (before this PR there was implicit dependency on logic in "core/error.rs::JsError"). Unfortunately formatting logic must still be duplicated in "cli/error.js::PrettyJsError" to provide coloring, but currently there's no solution to this problem. "createPrepareStackTrace" can accept a single argument; a function that takes a location and provides source mapped location back. --- cli/tests/unit/error_stack_test.ts | 99 -------------------------------------- 1 file changed, 99 deletions(-) (limited to 'cli/tests') diff --git a/cli/tests/unit/error_stack_test.ts b/cli/tests/unit/error_stack_test.ts index a5fe13796..ad5f2e093 100644 --- a/cli/tests/unit/error_stack_test.ts +++ b/cli/tests/unit/error_stack_test.ts @@ -1,87 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. import { assert, assertEquals, assertMatch, unitTest } from "./test_util.ts"; -// @ts-expect-error TypeScript (as of 3.7) does not support indexing namespaces by symbol -const { setPrepareStackTrace } = Deno[Deno.internal]; - -interface CallSite { - getThis(): unknown; - getTypeName(): string | null; - // deno-lint-ignore ban-types - getFunction(): Function | null; - getFunctionName(): string | null; - getMethodName(): string | null; - getFileName(): string | null; - getLineNumber(): number | null; - getColumnNumber(): number | null; - getEvalOrigin(): string | null; - isToplevel(): boolean | null; - isEval(): boolean; - isNative(): boolean; - isConstructor(): boolean; - isAsync(): boolean; - isPromiseAll(): boolean; - getPromiseIndex(): number | null; -} - -function getMockCallSite( - fileName: string, - lineNumber: number | null, - columnNumber: number | null, -): CallSite { - return { - getThis(): unknown { - return undefined; - }, - getTypeName(): string { - return ""; - }, - // deno-lint-ignore ban-types - getFunction(): Function { - return (): void => {}; - }, - getFunctionName(): string { - return ""; - }, - getMethodName(): string { - return ""; - }, - getFileName(): string { - return fileName; - }, - getLineNumber(): number | null { - return lineNumber; - }, - getColumnNumber(): number | null { - return columnNumber; - }, - getEvalOrigin(): null { - return null; - }, - isToplevel(): false { - return false; - }, - isEval(): false { - return false; - }, - isNative(): false { - return false; - }, - isConstructor(): false { - return false; - }, - isAsync(): false { - return false; - }, - isPromiseAll(): false { - return false; - }, - getPromiseIndex(): null { - return null; - }, - }; -} - unitTest(function errorStackMessageLine(): void { const e1 = new Error(); e1.name = "Foo"; @@ -122,24 +41,6 @@ unitTest(function errorStackMessageLine(): void { assertMatch(e6.stack!, /^null: null\n/); }); -// FIXME(bartlomieju): no longer works after migrating -// to JavaScript runtime code -unitTest({ ignore: true }, function prepareStackTrace(): void { - // deno-lint-ignore no-explicit-any - const MockError = {} as any; - setPrepareStackTrace(MockError); - assert(typeof MockError.prepareStackTrace === "function"); - const prepareStackTrace: ( - error: Error, - structuredStackTrace: CallSite[], - ) => string = MockError.prepareStackTrace; - const result = prepareStackTrace(new Error("foo"), [ - getMockCallSite("CLI_SNAPSHOT.js", 23, 0), - ]); - assert(result.startsWith("Error: foo\n")); - assert(result.includes(".ts:"), "should remap to something in 'js/'"); -}); - unitTest(function captureStackTrace(): void { function foo(): void { const error = new Error(); -- cgit v1.2.3