Browse Source

Merge pull request #1580 from svaarala/fix-dukdebug-source-scan

Fix duk_debug.js source code scan
pull/1597/head
Sami Vaarala 7 years ago
committed by GitHub
parent
commit
ba2b83dd95
  1. 3
      RELEASES.rst
  2. 34
      debugger/duk_debug.js

3
RELEASES.rst

@ -2936,6 +2936,9 @@ Planned
* Fix MSVC cast warning in error augmentation code (GH-1511) * Fix MSVC cast warning in error augmentation code (GH-1511)
* Fix duk_debug.js --source-dirs scanning for file dropdown; the dropdown was
empty (GH-1580)
* Improve support for old MSVC versions without __pragma(), long long, and * Improve support for old MSVC versions without __pragma(), long long, and
LL/ULL constants (GH-1559, GH-1562) LL/ULL constants (GH-1559, GH-1562)

34
debugger/duk_debug.js

@ -432,27 +432,36 @@ RateLimited.prototype.trigger = function () {
function SourceFileManager(directories) { function SourceFileManager(directories) {
this.directories = directories; this.directories = directories;
this.extensions = { '.js': true, '.jsm': true }; this.extensions = { '.js': true, '.jsm': true };
this.files; this.fileMap = {}; // filename as seen by debug target -> file path
this.files = []; // filenames as seen by debug target
} }
SourceFileManager.prototype.scan = function () { SourceFileManager.prototype.scan = function () {
var _this = this; var _this = this;
var fileMap = {}; // absFn -> true var fileMap = {}; // relative path -> file path
var files; var files;
this.directories.forEach(function (dir) { this.directories.forEach(function (dir) {
console.log('Scanning source files: ' + dir); console.log('Scanning source files: ' + dir);
try { try {
recursiveReadSync(dir).forEach(function (fn) { recursiveReadSync(dir).forEach(function (fn) {
var absFn = path.normalize(path.join(dir, fn)); // './foo/bar.js' -> 'foo/bar.js' // Example: dir ../../tests
var ent; // normFn ../../tests/foo/bar.js
// relFn foo/bar.js
if (fs.existsSync(absFn) && var normDir = path.normalize(dir);
fs.lstatSync(absFn).isFile() && var normFn = path.normalize(fn);
_this.extensions[path.extname(fn)]) { var relFn = path.relative(normDir, normFn);
if (fs.existsSync(normFn) && fs.lstatSync(normFn).isFile() &&
_this.extensions[path.extname(normFn)]) {
// We want the fileMap to contain the filename relative to // We want the fileMap to contain the filename relative to
// the search dir root. // the search dir root. First directory containing a
fileMap[fn] = true; // certail relFn wins.
if (relFn in fileMap) {
console.log('Found', relFn, 'multiple times, first match wins');
} else {
fileMap[relFn] = normFn;
}
} }
}); });
} catch (e) { } catch (e) {
@ -464,6 +473,8 @@ SourceFileManager.prototype.scan = function () {
files.sort(); files.sort();
this.files = files; this.files = files;
this.fileMap = fileMap;
console.log('Found ' + files.length + ' source files in ' + this.directories.length + ' search directories'); console.log('Found ' + files.length + ' source files in ' + this.directories.length + ' search directories');
}; };
@ -480,6 +491,9 @@ SourceFileManager.prototype.search = function (fileName) {
// assigned by selecting a file from a dropdown populated by scanning // assigned by selecting a file from a dropdown populated by scanning
// the filesystem for available sources and there's no way of knowing // the filesystem for available sources and there's no way of knowing
// if the debug target uses the exact same name. // if the debug target uses the exact same name.
//
// We intentionally allow any files from the search paths, not just
// those scanned to this.fileMap.
function tryLookup() { function tryLookup() {
var i, fn, data; var i, fn, data;

Loading…
Cancel
Save