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

Function lazyGetStructuredStack

lib/internal/util.js:549–567  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

547let getStructuredStackImpl;
548
549function lazyGetStructuredStack() {
550 if (getStructuredStackImpl === undefined) {
551 // Lazy-load to avoid a circular dependency.
552 const { runInNewContext } = require('vm');
553 // Use `runInNewContext()` to get something tamper-proof and
554 // side-effect-free. Since this is currently only used for a deprecated API
555 // and module mocking, the perf implications should be okay.
556 getStructuredStackImpl = runInNewContext(`(function() {
557 try { Error.stackTraceLimit = Infinity; } catch {}
558 return function structuredStack() {
559 const e = new Error();
560 overrideStackTrace.set(e, (err, trace) => trace);
561 return e.stack;
562 };
563 })()`, { overrideStackTrace }, { filename: 'structured-stack' });
564 }
565
566 return getStructuredStackImpl;
567}
568
569function getStructuredStack() {
570 const getStructuredStackImpl = lazyGetStructuredStack();

Callers 1

getStructuredStackFunction · 0.85

Calls 2

runInNewContextFunction · 0.85
requireFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…