regress-49286.js (2094B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 * Date: 2001-07-10 8 * 9 * SUMMARY: Invoking try...catch through Function.call 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=49286 11 * 12 * 1) Define a function with a try...catch block in it 13 * 2) Invoke the function via the call method of Function 14 * 3) Pass bad syntax to the try...catch block 15 * 4) We should catch the error! 16 */ 17 //----------------------------------------------------------------------------- 18 var UBound = 0; 19 var BUGNUMBER = 49286; 20 var summary = 'Invoking try...catch through Function.call'; 21 var cnErrorCaught = 'Error caught'; 22 var cnErrorNotCaught = 'Error NOT caught'; 23 var cnGoodSyntax = '1==2'; 24 var cnBadSyntax = '1=2'; 25 var status = ''; 26 var statusitems = []; 27 var actual = ''; 28 var actualvalues = []; 29 var expect= ''; 30 var expectedvalues = []; 31 32 33 var obj = new testObject(); 34 35 status = 'Section A of test: direct call of f'; 36 actual = f.call(obj); 37 expect = cnErrorCaught; 38 addThis(); 39 40 status = 'Section B of test: indirect call of f'; 41 actual = g.call(obj); 42 expect = cnErrorCaught; 43 addThis(); 44 45 46 47 //----------------------------------------- 48 test(); 49 //----------------------------------------- 50 51 52 function test() 53 { 54 printBugNumber(BUGNUMBER); 55 printStatus (summary); 56 57 for (var i=0; i<UBound; i++) 58 { 59 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 60 } 61 } 62 63 64 // An object storing bad syntax as a property - 65 function testObject() 66 { 67 this.badSyntax = cnBadSyntax; 68 this.goodSyntax = cnGoodSyntax; 69 } 70 71 72 // A function wrapping a try...catch block 73 function f() 74 { 75 try 76 { 77 eval(this.badSyntax); 78 } 79 catch(e) 80 { 81 return cnErrorCaught; 82 } 83 return cnErrorNotCaught; 84 } 85 86 87 // A function wrapping a call to f - 88 function g() 89 { 90 return f.call(this); 91 } 92 93 94 function addThis() 95 { 96 statusitems[UBound] = status; 97 actualvalues[UBound] = actual; 98 expectedvalues[UBound] = expect; 99 UBound++; 100 }