From 8b31fc23cd80de9baa62535e95367da7a21c9cfd Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Fri, 15 Apr 2022 15:08:09 +0100 Subject: refactor: Move source map lookups to core (#14274) The following transformations gradually faced by "JsError" have all been moved up front to "JsError::from_v8_exception()": - finding the first non-"deno:" source line; - moving "JsError::script_resource_name" etc. into the first error stack in case of syntax errors; - source mapping "JsError::script_resource_name" etc. when wrapping the error even though the frame locations are source mapped earlier; - removing "JsError::{script_resource_name,line_number,start_column,end_column}" entirely in favour of "js_error.frames.get(0)". We also no longer pass a js-side callback to "core/02_error.js" from cli. I avoided doing this on previous occasions because the source map lookups were in an awkward place. --- core/02_error.js | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'core/02_error.js') diff --git a/core/02_error.js b/core/02_error.js index 756098738..c6b808169 100644 --- a/core/02_error.js +++ b/core/02_error.js @@ -2,6 +2,7 @@ "use strict"; ((window) => { + const core = Deno.core; const { Error, ObjectFreeze, @@ -188,24 +189,8 @@ }; } - /** - * Returns a function that can be used as `Error.prepareStackTrace`. - * - * This function accepts an optional argument, a function that performs - * source mapping. It is not required to pass this argument, but - * in such case only JavaScript sources will have proper position in - * stack frames. - * @param {( - * fileName: string, - * lineNumber: number, - * columnNumber: number - * ) => { - * fileName: string, - * lineNumber: number, - * columnNumber: number - * }} sourceMappingFn - */ - function createPrepareStackTrace(sourceMappingFn, formatFileNameFn) { + /** Returns a function that can be used as `Error.prepareStackTrace`. */ + function createPrepareStackTrace(formatFileNameFn) { return function prepareStackTrace( error, callSites, @@ -214,13 +199,10 @@ const fileName = callSite.getFileName(); const lineNumber = callSite.getLineNumber(); const columnNumber = callSite.getColumnNumber(); - if ( - sourceMappingFn && fileName && lineNumber != null && - columnNumber != null - ) { + if (fileName && lineNumber != null && columnNumber != null) { return patchCallSite( callSite, - sourceMappingFn({ + core.applySourceMap({ fileName, lineNumber, columnNumber, -- cgit v1.2.3