diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2020-04-10 17:26:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-10 18:26:52 +0200 |
commit | 8b4508338b15dcc08503553dc9179a154c0165c7 (patch) | |
tree | 82d3d283edcff994c5b998d0d948985dc04f1b8c /cli/js/error_stack.ts | |
parent | 195ad4c6264c3563044480685931999ffa9d3d5c (diff) |
fix(core/js_error): Get frame data from prepareStackTrace() (#4690)
Fixes: #2703
Fixes: #2710
Closes: #4153
Closes: #4232
Co-authored-by: Kevin (Kun) Kassimo Qian <kevinkassimo@gmail.com>
Diffstat (limited to 'cli/js/error_stack.ts')
-rw-r--r-- | cli/js/error_stack.ts | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/cli/js/error_stack.ts b/cli/js/error_stack.ts index 97e9f68de..bab179e48 100644 --- a/cli/js/error_stack.ts +++ b/cli/js/error_stack.ts @@ -140,7 +140,7 @@ function callSiteToString(callSite: CallSite): string { result += "async "; } if (isPromiseAll) { - result += `Promise.all (index ${callSite.getPromiseIndex})`; + result += `Promise.all (index ${callSite.getPromiseIndex()})`; return result; } if (isMethodCall) { @@ -163,11 +163,52 @@ function callSiteToString(callSite: CallSite): string { return result; } +interface CallSiteEval { + this: unknown; + typeName: string; + function: Function; + functionName: string; + methodName: string; + fileName: string; + lineNumber: number | null; + columnNumber: number | null; + evalOrigin: string | null; + isToplevel: boolean; + isEval: boolean; + isNative: boolean; + isConstructor: boolean; + isAsync: boolean; + isPromiseAll: boolean; + promiseIndex: number | null; +} + +function evaluateCallSite(callSite: CallSite): CallSiteEval { + return { + this: callSite.getThis(), + typeName: callSite.getTypeName(), + function: callSite.getFunction(), + functionName: callSite.getFunctionName(), + methodName: callSite.getMethodName(), + fileName: callSite.getFileName(), + lineNumber: callSite.getLineNumber(), + columnNumber: callSite.getColumnNumber(), + evalOrigin: callSite.getEvalOrigin(), + isToplevel: callSite.isToplevel(), + isEval: callSite.isEval(), + isNative: callSite.isNative(), + isConstructor: callSite.isConstructor(), + isAsync: callSite.isAsync(), + isPromiseAll: callSite.isPromiseAll(), + promiseIndex: callSite.getPromiseIndex(), + }; +} + function prepareStackTrace( error: Error, structuredStackTrace: CallSite[] ): string { - return ( + Object.defineProperty(error, "__callSiteEvals", { value: [] }); + const errorString = `${error.name}: ${error.message}\n` + structuredStackTrace .map( @@ -188,9 +229,18 @@ function prepareStackTrace( return callSite; } ) - .map((callSite): string => ` at ${callSiteToString(callSite)}`) - .join("\n") - ); + .map((callSite): string => { + const callSiteEv = Object.freeze(evaluateCallSite(callSite)); + if (callSiteEv.lineNumber != null && callSiteEv.columnNumber != null) { + // @ts-ignore + error["__callSiteEvals"].push(callSiteEv); + } + return ` at ${callSiteToString(callSite)}`; + }) + .join("\n"); + // @ts-ignore + Object.freeze(error["__callSiteEvals"]); + return errorString; } // @internal |