Skip to content

Commit d052120

Browse files
author
Eric Wendelin
committed
Merge remote-tracking branch 'origin/pr/77' into stable
2 parents 33d4d84 + 73a05a4 commit d052120

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ It is currently tested and working on:
7777
- K-Meleon 1.5.3+
7878
- Epiphany 2.28.0+
7979
- Iceape 1.1+
80+
- PhantomJS
8081

8182
## Contributions [![Stories in Ready](http://badge.waffle.io/stacktracejs/stacktrace.js.png)](http://waffle.io/stacktracejs/stacktrace.js)
8283

stacktrace.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
* @return {String} mode of operation for the exception
6565
*/
6666
mode: function(e) {
67+
if (typeof window !== 'undefined' && window.navigator.userAgent.indexOf('PhantomJS') > -1) {
68+
return 'phantomjs';
69+
}
70+
6771
if (e['arguments'] && e.stack) {
6872
return 'chrome';
6973
}
@@ -278,6 +282,24 @@
278282
return result;
279283
},
280284

285+
phantomjs: function(e) {
286+
var ANON = '{anonymous}', lineRE = /(\S+) \((\S+)\)/i;
287+
var lines = e.stack.split('\n'), result = [];
288+
289+
for (var i = 1, len = lines.length; i < len; i++) {
290+
lines[i] = lines[i].replace(/^\s+at\s+/gm, '');
291+
var match = lineRE.exec(lines[i]);
292+
if (match) {
293+
result.push(match[1] + '()@' + match[2]);
294+
}
295+
else {
296+
result.push(ANON + '()@' + lines[i]);
297+
}
298+
}
299+
300+
return result;
301+
},
302+
281303
// Safari 5-, IE 9-, and others
282304
other: function(curr) {
283305
var ANON = '{anonymous}', fnRE = /function(?:\s+([\w$]+))?\s*\(/, stack = [], fn, args, maxStackSize = 10;

test/CapturedExceptions.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,20 @@ CapturedExceptions.node_simple = {
350350
' at ReadStream.onkeypress (readline.js:99:10)',
351351
'arguments': [ 'x' ]
352352
};
353+
354+
CapturedExceptions.phantomjs = {
355+
message: "'undefined' is not a function (evaluating 'this.undef()')",
356+
line: 852,
357+
sourceId: 163911584,
358+
sourceURL: 'http://localhost:10015/packages/peerdb.js?fe1089e34c777737beadb68e0657ca0bbe2e54b4',
359+
name: 'TypeError',
360+
stack: "TypeError: 'undefined' is not a function (evaluating 'this.undef()')\n" +
361+
' at http://localhost:10015/packages/peerdb.js?fe1089e34c777737beadb68e0657ca0bbe2e54b4:852\n' +
362+
' at http://localhost:10015/packages/meteor-peerdb:tests.js?36eb638af853e313daf7222afac0edaf9eb3bbc6:4476\n' +
363+
' at http://localhost:10015/packages/meteor-peerdb:tests.js?36eb638af853e313daf7222afac0edaf9eb3bbc6:4481\n' +
364+
' at http://localhost:10015/packages/tinytest.js?3fa2a6f5f9fadecfe9cf5d3420b3a1c719407388:393\n' +
365+
' at http://localhost:10015/packages/meteor.js?148e9381d225ecad703f4b858769b636ff7a2537:794\n' +
366+
' at http://localhost:10015/packages/meteor.js?148e9381d225ecad703f4b858769b636ff7a2537:379\n' +
367+
' at http://localhost:10015/packages/meteor.js?148e9381d225ecad703f4b858769b636ff7a2537:822\n' +
368+
' at onGlobalMessage (http://localhost:10015/packages/meteor.js?148e9381d225ecad703f4b858769b636ff7a2537:316)'
369+
};

test/TestStacktrace.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
};
5353
},
5454
createModeStubs: function(p, stub) {
55-
var modes = ['other', 'opera9', 'opera10a', 'opera10b', 'opera11', 'firefox', 'safari', 'ie', 'chrome'];
55+
var modes = ['other', 'opera9', 'opera10a', 'opera10b', 'opera11', 'firefox', 'safari', 'ie', 'chrome', 'phantomjs'];
5656
for (var i = 0, len = modes.length; i < len; i++) {
5757
var mode = modes[i];
5858
p[mode] = stub || this.createModeStub(mode);
@@ -88,7 +88,7 @@
8888

8989
test("mode", function() {
9090
expect(1);
91-
equals("chrome safari firefox ie other opera9 opera10a opera10b opera11".indexOf(pst.mode(UnitTest.fn.createGenericError())) >= 0, true);
91+
equals("chrome safari firefox ie other opera9 opera10a opera10b opera11 phantomjs".indexOf(pst.mode(UnitTest.fn.createGenericError())) >= 0, true);
9292
});
9393

9494
test("run mode", function() {
@@ -531,6 +531,16 @@
531531
equals(message[2], 'onclick@http://jenkins.eriwen.com/job/stacktrace.js/ws/test/functional/ExceptionLab.html:82:1');
532532
});
533533

534+
test("phantomjs", function() {
535+
var e = [CapturedExceptions.phantomjs];
536+
expect(2); // 2 * e.length
537+
for (var i = 0; i < e.length; i++) {
538+
var message = pst.phantomjs(e[i]);
539+
equals(message.length, 8, 'number of stack entries');
540+
equals(message[message.length - 1].indexOf('onGlobalMessage()') >= 0, true, 'onGlobalMessage() is 1st from the bottom of stack');
541+
}
542+
});
543+
534544
test("other", function() {
535545
expect(5);
536546
var results = [];

0 commit comments

Comments
 (0)