Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

adjust source maps to account for node script wrapping #244

Merged
merged 4 commits into from
Mar 11, 2019
Merged
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
41 changes: 35 additions & 6 deletions front_end/ndb/NdbMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,6 @@ Ndb.RestartActionDelegate = class {
}
};

SDK.DebuggerModel.prototype.scheduleStepIntoAsync = function() {
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 wasn't working anymore.

this._agent.scheduleStepIntoAsync();
this._agent.invoke_stepInto({breakOnAsyncCall: true});
};

// Temporary hack until frontend with fix is rolled.
// fix: TBA.
SDK.Target.prototype.decorateLabel = function(label) {
Expand All @@ -375,6 +370,23 @@ DOMTokenList.prototype.toggle = function(token, force) {
return originalToggle.call(this, token, !!force);
};

/**
* @param {string} sourceURL
* @param {string} modulePrefix
* @param {SDK.DebuggerModel} debuggerModel
* @return {!Promise<boolean>}
*/
async function isNodeWrappedModule(sourceURL, modulePrefix, debuggerModel) {
for (const script of debuggerModel.scripts()) {
if (script.sourceURL === sourceURL) {
const content = await script.originalContentProvider().requestContent();
return content.startsWith(modulePrefix);
}
}

return false;
}

/**
* @param {string} sourceMapURL
* @param {string} compiledURL
Expand All @@ -385,11 +397,28 @@ SDK.TextSourceMap.load = async function(sourceMapURL, compiledURL) {
const {payload, error} = await Ndb.backend.loadSourceMap(sourceMapURL, compiledURL);
if (error || !payload)
return null;

let textSourceMap;
try {
return new SDK.TextSourceMap(compiledURL, sourceMapURL, payload);
textSourceMap = new SDK.TextSourceMap(compiledURL, sourceMapURL, payload);
} catch (e) {
console.error(e);
Common.console.warn('DevTools failed to parse SourceMap: ' + sourceMapURL);
return null;
}

if (textSourceMap._baseURL.startsWith('file://')) {
try {
const modulePrefix = await Ndb.backend.getNodeScriptPrefix();
const debuggerModel = Array.from(Bindings.debuggerWorkspaceBinding._debuggerModelToData.keys())[1];
if (await isNodeWrappedModule(compiledURL, modulePrefix, debuggerModel))
for (const mapping of textSourceMap.mappings()) mapping.columnNumber += modulePrefix.length;
} catch (e) {
console.error(e);
Common.console.warn('DevTools failed to fix SourceMap for node script: ' + sourceMapURL);
// return the source map anyways.
}
}

return textSourceMap;
};
9 changes: 9 additions & 0 deletions lib/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const which = require('which');

const fsReadFile = util.promisify(fs.readFile);

const MODULE_WRAP_PREFIX = (() => {
const wrapped = require('module').wrap('☃');
return wrapped.substring(0, wrapped.indexOf('☃'));
})();

class Backend {
constructor(window) {
this._window = window;
Expand Down Expand Up @@ -72,6 +77,10 @@ class Backend {
}
}

getNodeScriptPrefix() {
return MODULE_WRAP_PREFIX;
}

which(command) {
return new Promise(resolve => which(command, (error, resolvedPath) => resolve({
resolvedPath: resolvedPath,
Expand Down