Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
errors: support prepareSourceMap with source-maps
  • Loading branch information
bcoe committed Dec 31, 2019
commit 19a197966c49f37e870401ea230dfd75b3274c77
6 changes: 6 additions & 0 deletions lib/internal/source_map/prepare_stack_trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const prepareStackTrace = (globalThis, error, trace) => {
return f(error, trace);
}

// `globalThis` is the global that contains the constructor which
Comment thread
bcoe marked this conversation as resolved.
Outdated
// 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
Original file line number Diff line number Diff line change
@@ -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);
}