regress-77578-001.js (2694B)
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-11 8 * 9 * SUMMARY: Testing eval scope inside a function. 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=77578 11 */ 12 //----------------------------------------------------------------------------- 13 var UBound = 0; 14 var BUGNUMBER = 77578; 15 var summary = 'Testing eval scope inside a function'; 16 var cnEquals = '='; 17 var status = ''; 18 var statusitems = []; 19 var actual = ''; 20 var actualvalues = []; 21 var expect= ''; 22 var expectedvalues = []; 23 24 // Note contrast with local variables i,j,k defined below - 25 var i = 999; 26 var j = 999; 27 var k = 999; 28 29 30 //-------------------------------------------------- 31 test(); 32 //-------------------------------------------------- 33 34 35 function test() 36 { 37 printBugNumber(BUGNUMBER); 38 printStatus (summary); 39 40 testA(); 41 testB(); 42 testC(); 43 44 // Compare actual values to expected values - 45 for (var i=0; i<UBound; i++) 46 { 47 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 48 } 49 } 50 51 52 function testA() 53 { 54 // eval the test, so it compiles AFTER version() has executed - 55 var sTestScript = ""; 56 57 // Define a local variable i 58 sTestScript += "status = 'Section A of test';"; 59 sTestScript += "var i=1;"; 60 sTestScript += "actual = eval('i');"; 61 sTestScript += "expect = 1;"; 62 sTestScript += "captureThis('i');"; 63 64 eval(sTestScript); 65 } 66 67 68 function testB() 69 { 70 // eval the test, so it compiles AFTER version() has executed - 71 var sTestScript = ""; 72 73 // Define a local for-loop iterator j 74 sTestScript += "status = 'Section B of test';"; 75 sTestScript += "for(var j=1; j<2; j++)"; 76 sTestScript += "{"; 77 sTestScript += " actual = eval('j');"; 78 sTestScript += "};"; 79 sTestScript += "expect = 1;"; 80 sTestScript += "captureThis('j');"; 81 82 eval(sTestScript); 83 } 84 85 86 function testC() 87 { 88 // eval the test, so it compiles AFTER version() has executed - 89 var sTestScript = ""; 90 91 // Define a local variable k in a try-catch block - 92 sTestScript += "status = 'Section C of test';"; 93 sTestScript += "try"; 94 sTestScript += "{"; 95 sTestScript += " var k=1;"; 96 sTestScript += " actual = eval('k');"; 97 sTestScript += "}"; 98 sTestScript += "catch(e)"; 99 sTestScript += "{"; 100 sTestScript += "};"; 101 sTestScript += "expect = 1;"; 102 sTestScript += "captureThis('k');"; 103 104 eval(sTestScript); 105 } 106 107 108 function captureThis(varName) 109 { 110 statusitems[UBound] = status; 111 actualvalues[UBound] = varName + cnEquals + actual; 112 expectedvalues[UBound] = varName + cnEquals + expect; 113 UBound++; 114 }