Skip to content

Passing tests again #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 18 additions & 12 deletions source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,6 @@ function retrieveSourceMap(source) {
}

function mapSourcePosition(position) {
// Fix position in Node where some (internal) code is prepended.
// See https://github.com/evanw/node-source-map-support/issues/36
if (!isInBrowser() && position.line === 1) {
position.column -= 62
}

var sourceMap = sourceMapCache[position.source];
if (!sourceMap) {
// Call the (overrideable) retrieveSourceMap function to get the source map.
Expand Down Expand Up @@ -267,17 +261,23 @@ function cloneCallSite(frame) {
return object;
}

function wrapCallSite(frame) {
function wrapCallSite(frame, offset) {
if (!offset) {
offset = 0;
}
// Most call sites will return the source file from getFileName(), but code
// passed to eval() ending in "//# sourceURL=..." will return the source file
// from getScriptNameOrSourceURL() instead
var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
if (source) {
var position = mapSourcePosition({
var position = {
source: source,
line: frame.getLineNumber(),
column: frame.getColumnNumber() - 1
});
// Fix position in Node where some (internal) code is prepended.
// See https://github.com/evanw/node-source-map-support/issues/36
column: frame.getColumnNumber() - (1 + offset)
};
position = mapSourcePosition(position);
frame = cloneCallSite(frame);
frame.getFileName = function() { return position.source; };
frame.getLineNumber = function() { return position.line; };
Expand Down Expand Up @@ -306,8 +306,14 @@ function prepareStackTrace(error, stack) {
fileContentsCache = {};
sourceMapCache = {};
}
return error + stack.map(function(frame) {
return '\n at ' + wrapCallSite(frame);
return error + stack.map(function(frame, index) {
// Fix position in Node where some (internal) code is prepended.
// See https://github.com/evanw/node-source-map-support/issues/36
var isFromModuleAndFirstLine = (!isInBrowser() &&
frame.getLineNumber() === 1 &&
index + 1 < stack.length &&
stack[index + 1].getFileName() === 'module.js');
return '\n at ' + wrapCallSite(frame, isFromModuleAndFirstLine ? 62 : 0);
}).join('');
}

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ it('function constructor', function() {
'throw new Function(")");'
], [
'SyntaxError: Unexpected token )',
/^ at Object\.Function \((?:unknown source|<anonymous>)\)$/,
/^ at Function \((?:unknown source|<anonymous>|native)\)$/,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change, how is it related to #47?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change may be necessary due to some change in Node 0.12 and/or io.js, am I right?
If so, it should be move in its own PR.

Also, simply removing the Object\. prefix may be breaking the tests on some platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relevant for Node 0.12. I'll move it into its own PR

/^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/,
]);
});
Expand Down