Skip to content

Commit 142a29c

Browse files
author
homyakov
committed
Opera modes opera9 opera10a detection improved
1 parent 8536aaa commit 142a29c

2 files changed

Lines changed: 46 additions & 36 deletions

File tree

‎stacktrace.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ printStackTrace.implementation.prototype = {
6363
if (!e.stacktrace) {
6464
return 'opera9'; // use e.message
6565
}
66+
// 'opera#sourceloc' in e -> opera9, opera10a
67+
if (e.message.indexOf('\n') > -1 && e.message.split('\n').length > e.stacktrace.split('\n').length) {
68+
return 'opera9'; // use e.message
69+
}
6670
// e.stacktrace && !e.stack -> opera10a
6771
if (!e.stack) {
6872
return 'opera10a'; // use e.stacktrace

‎test/TestStacktrace.js‎

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
});
135135

136136
test("run opera9", function() {
137-
expect(4);
137+
expect(5);
138138
var p = new printStackTrace.implementation();
139139
p.opera10a = p.opera10b = p.opera11 = p.other = p.firefox = p.chrome = function() {
140140
equals(1, 0, 'must not call run for any mode other than "opera9"');
@@ -158,11 +158,12 @@
158158
p.run(CapturedExceptions.opera_854);
159159
p.run(CapturedExceptions.opera_902);
160160
p.run(CapturedExceptions.opera_927);
161+
p.run(CapturedExceptions.opera_964);
161162
UnitTest.fn.clearFakeOperaEnvironment();
162163
});
163164

164165
test("run opera10a", function() {
165-
expect(2);
166+
expect(1);
166167
var p = new printStackTrace.implementation();
167168
p.opera9 = p.opera10b = p.opera11 = p.other = p.firefox = p.chrome = function() {
168169
equals(1, 0, 'must not call run for any mode other than "opera10a"');
@@ -171,7 +172,6 @@
171172
equals(1, 1, 'called run for "opera10a"');
172173
};
173174
UnitTest.fn.prepareFakeOperaEnvironment();
174-
p.run(CapturedExceptions.opera_964);
175175
p.run(CapturedExceptions.opera_1010);
176176
UnitTest.fn.clearFakeOperaEnvironment();
177177
});
@@ -403,8 +403,8 @@
403403
});
404404

405405
test("opera9", function() {
406-
var e = [CapturedExceptions.opera_854, CapturedExceptions.opera_902, CapturedExceptions.opera_927];
407-
expect(9); // 3 * e.length
406+
var e = [CapturedExceptions.opera_854, CapturedExceptions.opera_902, CapturedExceptions.opera_927, CapturedExceptions.opera_964];
407+
expect(12); // 3 * e.length
408408
for (var i = 0; i < e.length; i++) {
409409
var message = pst.opera9(e[i]);
410410
//equals(message.join("\n"), 'debug', 'debug');
@@ -415,14 +415,14 @@
415415
});
416416

417417
test("opera10a", function() {
418-
var e = [CapturedExceptions.opera_964, CapturedExceptions.opera_1010];
419-
expect(6); // 3 * e.length
418+
var e = [CapturedExceptions.opera_1010];
419+
expect(5); // 5 * e.length
420420
for (var i = 0; i < e.length; i++) {
421421
var message = pst.opera10a(e[i]);
422422
//equals(message.join("\n"), 'debug', 'debug');
423-
// NOTE: the important thing here is that the user sees calls to bar and foo in the correct order
424-
// We cannot test the size of the stack because it's inconsistent
425-
equals(message[message.length - 3].indexOf('bar(') >= 0, true, 'bar is 3nd from the bottom of stack');
423+
equals(message.length, 7, 'number of stack entries');
424+
equals(message[0].indexOf('this.undef()') >= 0, true, 'this.undef() is at the top of stack');
425+
equals(message[message.length - 3].indexOf('bar(') >= 0, true, 'bar is 3rd from the bottom of stack');
426426
equals(message[message.length - 2].indexOf('bar(2)') >= 0, true, 'bar is 2nd from the bottom of stack');
427427
equals(message[message.length - 1].indexOf('foo()') >= 0, true, 'foo() is at the bottom of stack');
428428
}
@@ -455,30 +455,37 @@
455455
test("opera11", function() {
456456
var mode = pst.mode(UnitTest.fn.createGenericError());
457457
var e = [];
458+
458459
/*e.push({
459-
stack: 'ignored\n' +
460-
'f1([arguments not available])@http://site.com/main.js:2\n' +
461-
'<anonymous function: f2>([arguments not available])@http://site.com/main.js:4\n' +
462-
'@',
463-
stacktrace: 'Error thrown at line 129, column 5 in <anonymous function>():\n' +
464-
'ignored\n' +
465-
'Error thrown at line 129, column 5 in <anonymous function>():\n' +
466-
'ignored\n' +
467-
'Error thrown at line 124, column 4 in <anonymous function>():\n' +
468-
'ignored\n' +
469-
'Error thrown at line 594, column 2 in process():\n' +
470-
'ignored\n' +
471-
'Error thrown at line 124, column 4 in <anonymous function>():\n' +
472-
'ignored\n' +
473-
'Error thrown at line 1, column 55 in discarded():\n' +
474-
' this.undef();\n' +
475-
'called from line 1, column 333 in f1(arg1, arg2):\n' +
476-
' discarded();\n' +
477-
'called from line 1, column 470 in <anonymous function>():\n' +
478-
' f1(1, "abc");\n' +
479-
'called from line 1, column 278 in program code:\n' +
480-
' f2();'
460+
message: "'this.undef' is not a function",
461+
462+
stack: "discarded([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:461\n" +
463+
"f1([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:468\n" +
464+
"<anonymous function>([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:471\n" +
465+
"<anonymous function>([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:473\n" +
466+
"<anonymous function: run>([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:102\n" +
467+
"<anonymous function: queue>([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:232\n" +
468+
"process([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:864\n" +
469+
"<anonymous function: start>([arguments not available])@http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:408",
470+
471+
stacktrace: "Error thrown at line 461, column 10 in discarded() in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:\n" +
472+
" this.undef();\n" +
473+
"called from line 468, column 8 in f1(arg1, arg2) in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:\n" +
474+
" discarded();\n" +
475+
"called from line 471, column 8 in <anonymous function>() in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:\n" +
476+
" f1(1, \"abc\");\n" +
477+
"called from line 473, column 6 in <anonymous function>() in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/TestStacktrace.js:\n" +
478+
" f2();\n" +
479+
"called from line 102, column 12 in <anonymous function: run>() in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:\n" +
480+
" this.callback.call(this.testEnvironment);\n" +
481+
"called via Function.prototype.call() from line 232, column 16 in <anonymous function: queue>() in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:\n" +
482+
" test.run();\n" +
483+
"called from line 864, column 12 in process() in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:\n" +
484+
" config.queue.shift()();\n" +
485+
"called from line 408, column 16 in <anonymous function: start>() in http://127.0.0.1:8000/DevTools/stacktrace/javascript-stacktrace/test/qunit.js:\n" +
486+
" process();"
481487
});*/
488+
482489
if (mode == 'opera11') {
483490
function discarded() {
484491
try {
@@ -499,11 +506,10 @@
499506
expect(3 * e.length);
500507
for (var i = 0; i < e.length; i++) {
501508
var stack = pst.opera11(e[i]), stack_string = stack.join('\n');
502-
equals(stack_string, 'debug', 'debug');
509+
//equals(stack_string, 'debug', 'debug');
503510
equals(stack_string.indexOf('ignored'), -1, 'ignored');
504-
equals(stack[5].indexOf('f1(') >= 0, true, 'f1 function name: ' + stack[5]);
505-
equals(stack[6].indexOf('{anonymous}()') >= 0, true, 'f2 is anonymous: ' + stack[6]);
506-
//FIXME: Clean up stack[2], opera has some internal stack weirdness
511+
equals(stack[1].indexOf('f1(') >= 0, true, 'f1 function name: ' + stack[1]);
512+
equals(stack[2].indexOf('{anonymous}()') >= 0, true, 'f2 is anonymous: ' + stack[2]);
507513
}
508514
});
509515

0 commit comments

Comments
 (0)