Skip to content

Commit

Permalink
errors: support prepareSourceMap with source-maps
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Dec 31, 2019
1 parent baa3621 commit 19a1979
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/internal/source_map/prepare_stack_trace.js
Expand Up @@ -17,6 +17,12 @@ const prepareStackTrace = (globalThis, error, trace) => {
return f(error, trace);
}

// `globalThis` is the global that contains the constructor which
// created `error`.
if (typeof globalThis.Error.prepareStackTrace === 'function') {
return globalThis.Error.prepareStackTrace(error, trace);
}

const { SourceMap } = require('internal/source_map/source_map');
const errorString = ErrorToString.call(error);

Expand Down
19 changes: 19 additions & 0 deletions test/parallel/test-error-prepare-stack-trace.js
@@ -0,0 +1,19 @@
// Flags: --enable-source-maps
'use strict';

require('../common');
const assert = require('assert');

// Error.prepareStackTrace() can be overridden with source maps enabled.
{
let prepareCalled = false;
Error.prepareStackTrace = (_error, trace) => {
prepareCalled = true;
};
try {
throw new Error('foo');
} catch (err) {
err.stack;
}
assert(prepareCalled);
}

0 comments on commit 19a1979

Please sign in to comment.