regress-202678-001.js (1840B)
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 * 8 * Date: 19 April 2003 9 * SUMMARY: Testing nested function scope capture 10 * 11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=202678 12 * 13 */ 14 //----------------------------------------------------------------------------- 15 var UBound = 0; 16 var BUGNUMBER = 202678; 17 var summary = 'Testing nested function scope capture'; 18 var status = ''; 19 var statusitems = []; 20 var actual = ''; 21 var actualvalues = []; 22 var expect= ''; 23 var expectedvalues = []; 24 var self = this; 25 26 27 function myFunc() 28 { 29 var hidden = 'aaa'; 30 insideFunc(); 31 32 if (!self.runOnce) 33 { 34 var hidden = 'bbb'; 35 self.outSideFunc = insideFunc; 36 self.runOnce = true; 37 } 38 else 39 { 40 var hidden = 'ccc'; 41 } 42 43 44 function insideFunc() 45 { 46 actual = hidden; 47 } 48 } 49 50 51 52 status = inSection(1); 53 myFunc(); // this sets |actual| 54 expect = 'aaa'; 55 addThis(); 56 57 status = inSection(2); 58 outSideFunc(); // sets |actual| 59 expect = 'bbb'; 60 addThis(); 61 62 status = inSection(3); 63 myFunc(); // sets |actual| 64 expect = 'aaa'; 65 addThis(); 66 67 status = inSection(4); 68 outSideFunc(); // sets |actual| 69 expect = 'bbb'; // NOT 'ccc' 70 addThis(); 71 72 73 74 75 //----------------------------------------------------------------------------- 76 test(); 77 //----------------------------------------------------------------------------- 78 79 80 81 function addThis() 82 { 83 statusitems[UBound] = status; 84 actualvalues[UBound] = actual; 85 expectedvalues[UBound] = expect; 86 UBound++; 87 } 88 89 90 function test() 91 { 92 printBugNumber(BUGNUMBER); 93 printStatus(summary); 94 95 for (var i=0; i<UBound; i++) 96 { 97 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 98 } 99 }