|
70 | 70 |
|
71 | 71 | test("mode", function() { |
72 | 72 | expect(1); |
73 | | - equals("chrome firefox other opera9 opera10a opera10b opera11".indexOf(pst.mode(UnitTest.fn.createGenericError())) >= 0, true); |
| 73 | + equals("chrome safari firefox other opera9 opera10a opera10b opera11".indexOf(pst.mode(UnitTest.fn.createGenericError())) >= 0, true); |
74 | 74 | }); |
75 | 75 |
|
76 | 76 | test("run mode", function() { |
77 | 77 | expect(1); |
78 | 78 | var p = new printStackTrace.implementation(); |
79 | | - p.other = p.firefox = p.chrome = p.opera9 = p.opera10a = p.opera10b = p.opera11 = function() { |
| 79 | + p.other = p.firefox = p.chrome = p.safari = p.opera9 = p.opera10a = p.opera10b = p.opera11 = function() { |
80 | 80 | equals(1, 1, 'called mode() successfully'); |
81 | 81 | }; |
82 | 82 | p.run(); |
|
245 | 245 | ok(!this.toInstrument._instrumented, 'function deinstrumented'); |
246 | 246 | this.toInstrument = this.callback = null; |
247 | 247 | }); |
248 | | - |
| 248 | + |
249 | 249 | test("firefox", function() { |
250 | 250 | var e = [], ex; |
251 | | - var stack = 'f1(1,"abc")@file.js:40\n' + |
252 | | - '()@file.js:41\n' + |
253 | | - '@:0 \n' + |
254 | | - 'f44()@file.js:494'; |
| 251 | + var fakeStack = 'f1@file.js:40\n' + |
| 252 | + '@file.js:41\n' + |
| 253 | + '@:0 \n' + |
| 254 | + 'f44@file.js:494'; |
255 | 255 | e.push({ |
256 | | - stack: stack |
| 256 | + stack: fakeStack |
257 | 257 | }); // test saved Firefox stacktrace |
258 | 258 | function f1(arg1, arg2) { |
259 | 259 | try { |
|
272 | 272 | expect(3 * e.length); |
273 | 273 | for (var i = 0; i < e.length; i++) { |
274 | 274 | var stack = pst.firefox(e[i]); |
275 | | - // equals(stack.join("\n"), '', 'debug'); |
276 | | - equals(stack[0].indexOf('f1(1,"abc")') >= 0, true, 'f1'); |
277 | | - equals(stack[1].indexOf('{anonymous}()@') >= 0, true, 'f2 anonymous'); |
| 275 | + //equals(stack.join("\n"), '', 'debug'); |
| 276 | + equals(stack[0].indexOf('f1') === 0, true, 'f1'); |
| 277 | + equals(stack[1].indexOf('{anonymous}()') === 0, true, 'f2 anonymous'); |
278 | 278 | equals(stack[2].indexOf('@:0'), -1, '@:0 discarded'); |
279 | 279 | } |
280 | 280 | }); |
|
615 | 615 | }); |
616 | 616 |
|
617 | 617 | test("guessAnonymousFunction exception", function() { |
| 618 | + // FIXME: this test seems to affect guessAnonymousFunction opera11 |
618 | 619 | expect(1); |
619 | 620 | var p = new printStackTrace.implementation(); |
| 621 | + var oldGetSource = p.getSource; |
620 | 622 | p.getSource = function() { |
621 | 623 | throw 'permission denied'; |
622 | 624 | }; |
623 | 625 | var file = 'file:///test'; |
624 | 626 | equals(p.guessAnonymousFunction(file, 2), 'getSource failed with url: file:///test, exception: permission denied'); |
| 627 | + // Reset mocked function |
| 628 | + p.getSource = oldGetSource; |
625 | 629 | }); |
626 | 630 |
|
627 | 631 | test("guessAnonymousFunctions firefox", function() { |
|
641 | 645 | } |
642 | 646 | })(); |
643 | 647 |
|
644 | | - expect(results.length * 1); |
| 648 | + expect(results.length); |
645 | 649 | for (var i = 0; i < results.length; ++i) { |
646 | 650 | //equals(results[i], '', 'stack trace'); |
647 | 651 | var functions = p.guessAnonymousFunctions(results[i]); |
648 | | - // equals(functions.join("\n"), '', 'stack trace after guessing'); |
649 | | - equals(functions[2].substring(0, 4), 'f2()', 'guessed f2 as 3rd result: ' + functions[2]); |
| 652 | + //equals(functions.join("\n"), '', 'stack trace after guessing'); |
| 653 | + equals(functions[2].substring(0, 2), 'f2', 'guessed f2 as 3rd result: ' + functions[2]); |
650 | 654 | //equals(functions[2].indexOf('f2'), 0, 'guessed f2 as 3rd result'); |
651 | 655 | } |
652 | 656 | }); |
|
677 | 681 | equals(functions[2].indexOf('f2'), 0, 'guessed f2 in ' + functions[2]); |
678 | 682 | } |
679 | 683 | }); |
680 | | - |
| 684 | + |
681 | 685 | // Test for issue #34 |
682 | 686 | test("guessAnonymousFunctions chrome with eval", function() { |
683 | | - var unit = new printStackTrace.implementation(), |
684 | | - expected = '{anonymous}()@eval at buildTmplFn (http://domain.com/file.js:17:10)', |
685 | | - actual = unit.guessAnonymousFunctions([expected]); |
| 687 | + var unit = new printStackTrace.implementation(); |
| 688 | + var expected = '{anonymous}()@eval at buildTmplFn (http://domain.com/file.js:17:10)'; |
| 689 | + var actual = unit.guessAnonymousFunctions([expected]); |
686 | 690 | expect(1); |
687 | 691 | // Nothing should change since no anonymous function in stack |
688 | 692 | equals(expected, actual); |
689 | 693 | }); |
690 | 694 |
|
691 | 695 | test("guessAnonymousFunctions opera9", function() { |
692 | | - var results = [], p = new printStackTrace.implementation(); |
| 696 | + var results = []; |
| 697 | + var p = new printStackTrace.implementation(); |
693 | 698 | var file = 'http://' + window.location.hostname + '/file.js'; |
694 | 699 | p.sourceCache[file] = ['var f2 = function() {', 'bar();', '};']; |
695 | 700 | results.push(['{anonymous}()@' + file + ':2 -- bar();']); |
|
716 | 721 |
|
717 | 722 | test("guessAnonymousFunctions opera10", function() { |
718 | 723 | // FIXME: currently failing in Opera 10.60 |
719 | | - var results = [], p = new printStackTrace.implementation(); |
| 724 | + var results = []; |
| 725 | + var p = new printStackTrace.implementation(); |
720 | 726 | var file = 'http://' + window.location.hostname + '/file.js'; |
721 | 727 | p.sourceCache[file] = ['var f2 = function() {', 'var b = 2;', '};']; |
722 | 728 | results.push(["{anonymous}()@" + file + ":1:1", "{anonymous}()@" + file + ":1:1"]); |
|
743 | 749 | }); |
744 | 750 |
|
745 | 751 | test("guessAnonymousFunctions opera11", function() { |
746 | | - var results = [], p = new printStackTrace.implementation(); |
| 752 | + var results = []; |
| 753 | + var p = new printStackTrace.implementation(); |
747 | 754 | var file = 'http://' + window.location.hostname + '/file.js'; |
748 | 755 | p.sourceCache[file] = ['var f2 = function() {', 'bar();', '};']; |
749 | 756 | results.push(["{anonymous}()@" + file + ":2:1 -- bar();"]); |
|
753 | 760 | this.undef(); |
754 | 761 | } catch (e) { |
755 | 762 | if (p.mode(e) == 'opera11') { |
756 | | - //alert("e.stacktrace: " + e.stacktrace); |
757 | | - results.push(p.run(e)); |
| 763 | + results.push(p.run()); |
758 | 764 | } |
759 | 765 | } |
760 | 766 | }; |
|
771 | 777 |
|
772 | 778 | test("guessAnonymousFunctions other", function() { |
773 | 779 | var results = []; |
774 | | - var p = new printStackTrace.implementation(), mode = p.mode(UnitTest.fn.createGenericError()); |
775 | | - p._mode = 'other'; |
| 780 | + var p = new printStackTrace.implementation(); |
776 | 781 | var file = 'http://' + window.location.hostname + '/file.js'; |
777 | 782 | p.sourceCache[file] = ['var f2 = function() {', 'var b = 2;', '};']; |
778 | 783 | results.push(['{anonymous}()']); |
779 | 784 |
|
780 | | - if (mode == 'other') { |
781 | | - var f2 = function() { |
782 | | - try { |
783 | | - this.undef(); |
784 | | - } catch (e) { |
| 785 | + (function f2() { |
| 786 | + try { |
| 787 | + this.undef(); |
| 788 | + } catch (e) { |
| 789 | + if (p.mode(e) == 'other') { |
785 | 790 | results.push(p.run()); |
786 | 791 | } |
787 | | - }; |
788 | | - f2(); |
789 | | - } |
| 792 | + } |
| 793 | + })(); |
790 | 794 |
|
791 | | - expect(1 * results.length); |
| 795 | + expect(results.length); |
792 | 796 | for (var i = 0; i < results.length; ++i) { |
793 | 797 | //equals((results[i]), '', 'debug'); |
794 | 798 | equals(p.guessAnonymousFunctions(results[i])[0].indexOf('{anonymous}'), 0, 'no file and line number in "other" mode'); |
|
0 commit comments