mirror of
https://github.com/denoland/deno.git
synced 2025-07-24 05:35:33 +00:00
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>
This commit is contained in:
parent
195ad4c626
commit
8b4508338b
11 changed files with 257 additions and 48 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue