Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

add support to eval code and solve file:// url bug #220

Closed
wants to merge 1 commit 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
4 changes: 4 additions & 0 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,10 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
// If the frame doesn't have a function name, it's either an anonymous function
// or eval script. If its source has a name, it's probably an anonymous function.
const frameName = functionName || (script.url ? '(anonymous function)' : '(eval code)');
if (script.hasSourceURL) {
if (!global["evalSources"]) global["evalSources"] = [];
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use global, try to find another way to share this list between modules.

Copy link
Author

Choose a reason for hiding this comment

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

I tried import/export without success. Do you have another idea ?

global["evalSources"].push(script.url);
}
return {
id: this._frameHandles.create(frame),
name: frameName,
Expand Down
3 changes: 2 additions & 1 deletion src/sourceMaps/sourceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class SourceMap {
* Will return null instead of a mapping on the next line (different from generatedPositionFor).
*/
public authoredPositionFor(line: number, column: number): MappedPosition {
if (global['evalSources'] && global['evalSources'].find(s => this._generatedPath == s) && line > 0) line--; // check if eval code
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to adjust the line differently based on whether it's an eval script or not?

Copy link
Author

Choose a reason for hiding this comment

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

I think when code is an eval script, then (function(){\n is added and chrome debugger result is offset by 1 line vs source-map which use the script code.

// source-map lib uses 1-indexed lines.
line++;

Expand Down Expand Up @@ -223,7 +224,7 @@ export class SourceMap {
return null;
} else {
return {
line: position.line - 1, // Back to 0-indexed lines
line: global["evalSources"] && global["evalSources"].find(s => s == this._generatedPath) ? position.line : position.line - 1, // check if eval code else Back to 0-indexed lines
Copy link
Member

Choose a reason for hiding this comment

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

Same here - the 0-indexed or 1-indexed lines are a property of the source-map lib, it doesn't matter whether the code originated as an eval script or not.

Copy link
Author

Choose a reason for hiding this comment

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

Same as previous answer. I think either generated and authored code relay on(function(){\n problem.
in my opinion, it is more +1 indexed than 1-indexed: I keep the base index but add some adjustments.

column: position.column,
source: this._generatedPath
};
Expand Down
3 changes: 2 additions & 1 deletion src/sourceMaps/sourceMapFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ function getSourceMapContent(pathToGenerated: string, mapPath: string): Promise<

function loadSourceMapContents(mapPathOrURL: string): Promise<string> {
let contentsP: Promise<string>;
if (utils.isURL(mapPathOrURL)) {
if (utils.isURL(mapPathOrURL) && !mapPathOrURL.startsWith('file://')) {
logger.log(`SourceMaps.loadSourceMapContents: Downloading sourcemap file from ${mapPathOrURL}`);
contentsP = downloadSourceMapContents(mapPathOrURL).catch(e => {
logger.error(`SourceMaps.loadSourceMapContents: Could not download sourcemap from ${mapPathOrURL}`);
return null;
});
} else {
if (utils.isURL(mapPathOrURL)) mapPathOrURL = utils.canonicalizeUrl(mapPathOrURL);
contentsP = new Promise((resolve, reject) => {
logger.log(`SourceMaps.loadSourceMapContents: Reading local sourcemap file from ${mapPathOrURL}`);
fs.readFile(mapPathOrURL, (err, data) => {
Expand Down