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

Conversation

Alphapage
Copy link

No description provided.

@msftclas
Copy link

@Alphapage,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

@Alphapage
Copy link
Author

This PR could solve:
#205
microsoft/vscode-node-debug2#122
maybe https://github.com/Microsoft/vscode-chrome-debug/issues/460 and older issues I found.

@Alphapage
Copy link
Author

For info, I use global to register evaled sources. This is ugly, but modules were not working. Maybe different process !

@Alphapage
Copy link
Author

The main problems I was unable to solve:

  • you need to add debugger; at the beginning of eval code or add a breakpoint in a non eval code otherwise breakpoints will never be applied.
  • it only works with node-debug2. node-debug or chrome-debug shows the evaled code instead of mapped one
  • you need to show a link somewhere in console or in UI to be able to open the evaled code in a tab. I wasn't able to find a way to do it.

@@ -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 ?

@@ -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.

@@ -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.

@roblourens
Copy link
Member

Please see tslint issues as well

@Alphapage
Copy link
Author

I don't know how chrome debugger works, but the best way to solve this problem would be to send the eval file from //#sourceURL and sourcemap file from //#sourceMappingURL to chrome debugger and let chrome debugger do the job, apply breakpoints...
But I don't know if v8 debugger api provides such a feature.

@Alphapage Alphapage closed this Jul 22, 2017
digeff pushed a commit to digeff/vscode-chrome-debug-core that referenced this pull request Jul 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants