Skip to content

Commit 4d72b5c

Browse files
author
homyakov
committed
Bug in findFunctionName with commented code
1 parent 9b077a4 commit 4d72b5c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

stacktrace.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,12 @@ printStackTrace.implementation.prototype = {
383383
var reFunctionEvaluation = /['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*(?:eval|new Function)\b/;
384384
// Walk backwards in the source lines until we find
385385
// the line which matches one of the patterns above
386-
var code = "", line, maxLines = 10, m;
386+
var code = "", line, maxLines = 20, m;
387387
for (var i = 0; i < maxLines; ++i) {
388-
// FIXME lineNo is 1-based, source[] is 0-based
389-
line = source[lineNo - i];
388+
// lineNo is 1-based, source[] is 0-based
389+
line = source[lineNo - i - 1];
390+
// line.replace(/(.*)\/\//, '$1')
391+
// FIXME skip/clean comments? Commented code may lead to false positive
390392
if (line) {
391393
code = line + code;
392394
m = reFunctionExpression.exec(code);

test/TestStacktrace.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@
563563
equals(pst.findFunctionName(['var a = function aa() {', 'var b = 2;', '};'], 2), 'a');
564564
equals(pst.findFunctionName(['var a = function () {', 'var b = 2;', '};'], 2), 'a');
565565
equals(pst.findFunctionName(['var a = function() {', 'var b = 2;', '};'], 2), 'a');
566-
// FIXME: currently failing becuase we don't have a way to distinguish which fn is being sought
566+
// FIXME: currently failing because we don't have a way to distinguish which fn is being sought
567567
// equals(pst.findFunctionName(['a:function(){},b:function(){', '};'], 1), 'b');
568568
equals(pst.findFunctionName(['"a": function(){', '};'], 1), 'a');
569569

@@ -577,6 +577,8 @@
577577
equals(pst.findFunctionName(['var data = new Function("s,r",', '"return s + r;");'], 1), 'data');
578578

579579
equals(pst.findFunctionName(['var a = 1;', 'var b = 2;', 'var c = 3;'], 2), '(?)');
580+
581+
equals(pst.findFunctionName(['function a() {', ' // function commented()', ' error here', '}'], 3), 'a');
580582
});
581583

582584
test("getSource cache miss", function() {

0 commit comments

Comments
 (0)