Speed up initial parsing of source-map URLs

`ScriptManager._getSourceMapUrl` accepts an optional parameter
`scriptSource`.

`DebuggerAgent._reloadScript` asks V8 to include script sources
in the response.

This way it's not necessary to send another request for each script
that is loaded by V8 at the time when Node Inspector is attaching to
the process.
This commit is contained in:
Miroslav Bajtoš 2014-02-18 18:19:37 +01:00
Родитель c370aa8146
Коммит 39fe73b620
2 изменённых файлов: 20 добавлений и 4 удалений

Просмотреть файл

@ -96,7 +96,7 @@ DebuggerAgent.prototype = {
this._debuggerClient.request(
'scripts',
{
includeSource: false,
includeSource: true,
types: 4
},
function handleScriptsResponse(err, result) {

Просмотреть файл

@ -1,5 +1,6 @@
var events = require('events'),
async = require('async'),
debug = require('debug')('node-inspector:ScriptManager'),
convert = require('./convert.js');
// see Blink inspector > ContentSearchUtils.cpp > findMagicComment()
@ -83,11 +84,15 @@ ScriptManager.prototype = Object.create(events.EventEmitter.prototype, {
var inspectorScriptData = this._doAddScript(v8data, hidden);
debug('addScript id: %s localPath: %s hidden? %s source? %s',
v8data.id, localPath, hidden, !!v8data.source);
if (hidden || this._isNodeInternal(localPath)) {
notifyFrontEnd.call(this);
} else {
this._getSourceMapUrl(
v8data.id,
v8data.source,
function onGetSourceMapUrlReturn(err, sourceMapUrl) {
if (err) {
console.log(
@ -96,6 +101,8 @@ ScriptManager.prototype = Object.create(events.EventEmitter.prototype, {
v8data.id,
err);
}
debug('sourceMapUrl for script %s:%s is %s',
v8data.id, localPath, sourceMapUrl);
inspectorScriptData.sourceMapURL = sourceMapUrl;
notifyFrontEnd.call(this);
}.bind(this)
@ -142,11 +149,20 @@ ScriptManager.prototype = Object.create(events.EventEmitter.prototype, {
},
_getSourceMapUrl: {
value: function(scriptId, callback) {
value: function(scriptId, scriptSource, callback) {
var getSource;
if (scriptSource == null) {
debug('_getSourceMapUrl(%s) - fetching source from V8', scriptId);
getSource = this._debuggerClient.getScriptSourceById
.bind(this._debuggerClient, scriptId);
} else {
debug('_getSourceMapUrl(%s) - using the suplied source', scriptId);
getSource = function(cb) { cb(null, scriptSource); };
}
async.waterfall(
[
this._debuggerClient.getScriptSourceById
.bind(this._debuggerClient, scriptId),
getSource,
this._parseSourceMapUrlFromScriptSource.bind(this)
],
callback