MCPcopy Index your code
hub / github.com/nodejs/node / serializeJSStackFrame

Function serializeJSStackFrame

lib/internal/source_map/prepare_stack_trace.js:82–118  ·  view source on GitHub ↗

* Serialize a single call site in the stack trace. * Refer to SerializeJSStackFrame in deps/v8/src/objects/call-site-info.cc for * more details about the default ToString(CallSite). * The CallSite API is documented at https://v8.dev/docs/stack-trace-api. * @param {import('internal/source_map/sou

(sm, callSite, callerCallSite)

Source from the content-addressed store, hash-verified

80 * @returns {string} - the serialized call site
81 */
82function serializeJSStackFrame(sm, callSite, callerCallSite) {
83 // Source Map V3 lines/columns start at 0/0 whereas stack traces
84 // start at 1/1:
85 const {
86 originalLine,
87 originalColumn,
88 originalSource,
89 } = sm.findEntry(callSite.getLineNumber() - 1, callSite.getColumnNumber() - 1);
90 if (originalSource === undefined || originalLine === undefined ||
91 originalColumn === undefined) {
92 return `${callSite}`;
93 }
94 const name = getOriginalSymbolName(sm, callSite, callerCallSite);
95 const originalSourceNoScheme =
96 StringPrototypeStartsWith(originalSource, 'file://') ?
97 fileURLToPath(originalSource) : originalSource;
98 // Construct call site name based on: v8.dev/docs/stack-trace-api:
99 const fnName = callSite.getFunctionName() ?? callSite.getMethodName();
100
101 let prefix = '';
102 if (callSite.isAsync()) {
103 // Promise aggregation operation frame has no locations. This must be an
104 // async stack frame.
105 prefix = 'async ';
106 } else if (callSite.isConstructor()) {
107 prefix = 'new ';
108 }
109
110 const typeName = callSite.getTypeName();
111 const namePrefix = typeName !== null && typeName !== 'global' ? `${typeName}.` : '';
112 const originalName = `${fnName || '<anonymous>'}`;
113 const mappedName = `${namePrefix}${name || originalName}` || '';
114 // Replace the transpiled call site with the original:
115 return `${prefix}${mappedName} (` +
116 `${originalSourceNoScheme}:${originalLine + 1}:` +
117 `${originalColumn + 1})`;
118}
119
120// Transpilers may have removed the original symbol name used in the stack
121// trace, if possible restore it from the names field of the source map:

Callers 1

Calls 4

getOriginalSymbolNameFunction · 0.85
fileURLToPathFunction · 0.85
isConstructorMethod · 0.80
findEntryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…