Skip to content

Commit 0206f74

Browse files
committed
Merge pull request stacktracejs#24 from victor-homyakov/master
Failing test added
2 parents dd68ea9 + 2db0f5a commit 0206f74

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

stacktrace.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,21 @@ printStackTrace.implementation.prototype = {
333333
},
334334

335335
findFunctionName: function(source, lineNo) {
336+
// FIXME findFunctionName fails for compressed source
337+
// (more than one function on the same line)
336338
// TODO use captured args
337339
// function {name}({args}) m[1]=name m[2]=args
338340
var reFunctionDeclaration = /function\s+([^(]*?)\s*\(([^)]*)\)/;
339341
// {name} = function ({args}) TODO args capture
340-
var reFunctionExpression = /['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*function(?:[^(]*)/;
342+
// /['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*function(?:[^(]*)/
343+
var reFunctionExpression = /['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*function\b/;
341344
// {name} = eval()
342-
var reFunctionEvaluation = /['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*(?:eval|new Function)/;
345+
var reFunctionEvaluation = /['"]?([0-9A-Za-z_]+)['"]?\s*[:=]\s*(?:eval|new Function)\b/;
343346
// Walk backwards in the source lines until we find
344347
// the line which matches one of the patterns above
345348
var code = "", line, maxLines = 10, m;
346349
for (var i = 0; i < maxLines; ++i) {
350+
// FIXME lineNo is 1-based, source[] is 0-based
347351
line = source[lineNo - i];
348352
if (line) {
349353
code = line + code;

test/test-stacktrace.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
Copyright (C) 2008 Johan Euphrosine <proppy@aminche.com>
44
Copyright (C) 2008 Loic Dachary <loic@dachary.org>
55
Copyright (C) 2011 Eric Wendelin <emwendelin@gmail.com>
6-
6+
77
This program is free software: you can redistribute it and/or modify
88
it under the terms of the GNU General Public License as published by
99
the Free Software Foundation, either version 3 of the License, or
1010
(at your option) any later version.
11-
11+
1212
This program is distributed in the hope that it will be useful,
1313
but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
GNU General Public License for more details.
16-
16+
1717
You should have received a copy of the GNU General Public License
1818
along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
-->
@@ -22,14 +22,14 @@
2222
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
2323
<title>stacktrace.js Test Suite</title>
2424
<link rel='stylesheet' href='qunit.css' type='text/css' />
25-
<script language='JavaScript' type='text/javascript' src='qunit.js'></script>
26-
<script language='JavaScript' type='text/javascript' src='../stacktrace.js'></script>
27-
<script language='JavaScript' type='text/javascript' src='test-stacktrace.js'></script>
25+
<script type='text/javascript' src='qunit.js'></script>
26+
<script type='text/javascript' src='../stacktrace.js'></script>
27+
<script type='text/javascript' src='test-stacktrace.js'></script>
2828
</head>
2929
<body>
3030
<h1 id='qunit-header'>stacktrace.js Test Suite</h1>
31-
<h2 id='qunit-banner'></h2>
32-
<h2 id='qunit-userAgent'></h2>
31+
<h2 id='qunit-banner'></h2>
32+
<h2 id='qunit-userAgent'></h2>
3333
<ol id='qunit-tests'></ol>
3434
</body>
3535
</html>

test/test-stacktrace.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,12 @@
440440
});
441441

442442
test("findFunctionName", function() {
443-
expect(12);
443+
// TODO currently failing
444+
expect(13);
444445
equals(pst.findFunctionName(['var a = function aa() {', 'var b = 2;', '};'], 2), 'a');
445446
equals(pst.findFunctionName(['var a = function () {', 'var b = 2;', '};'], 2), 'a');
446447
equals(pst.findFunctionName(['var a = function() {', 'var b = 2;', '};'], 2), 'a');
448+
equals(pst.findFunctionName(['a:function(){},b:function(){', '};'], 1), 'b');
447449
equals(pst.findFunctionName(['"a": function(){', '};'], 1), 'a');
448450

449451
equals(pst.findFunctionName(['function a() {', 'var b = 2;', '}'], 2), 'a');
@@ -511,8 +513,8 @@
511513
var results = [];
512514
var p = new printStackTrace.implementation();
513515
var file = 'http://' + window.location.hostname + '/file.js';
514-
p.sourceCache[file] = ['var f2 = function() {', 'var b = 2;', '};'];
515-
results.push(['(?)()@' + file + ':74', 'run()@' + file + ':72', 'f2()@' + file + ':1']);
516+
p.sourceCache[file] = ['var f2 = function () {', 'var b = 2;', '};', 'function run() {', 'return true;', '}'];
517+
results.push(['{anonymous}()@' + file + ':74', '{anonymous}()@' + file + ':5', '{anonymous}()@' + file + ':2']);
516518

517519
(function f2() {
518520
try {
@@ -526,8 +528,9 @@
526528

527529
expect(results.length * 1);
528530
for (var i = 0; i < results.length; ++i) {
531+
//equals(results[i], '', 'stack trace');
529532
var functions = p.guessAnonymousFunctions(results[i]);
530-
//equals(functions.join("\n"), '', 'debug');
533+
//equals(functions.join("\n"), '', 'stack trace after guessing');
531534
equals(functions[2].substring(0, 4), 'f2()', 'guessed f2 as 3rd result: ' + functions[2]);
532535
//equals(functions[2].indexOf('f2'), 0, 'guessed f2 as 3rd result');
533536
}

0 commit comments

Comments
 (0)