1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/Scope/regress-202678-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * 1.11 + * Date: 19 April 2003 1.12 + * SUMMARY: Testing nested function scope capture 1.13 + * 1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=202678 1.15 + * 1.16 + */ 1.17 +//----------------------------------------------------------------------------- 1.18 +var UBound = 0; 1.19 +var BUGNUMBER = 202678; 1.20 +var summary = 'Testing nested function scope capture'; 1.21 +var status = ''; 1.22 +var statusitems = []; 1.23 +var actual = ''; 1.24 +var actualvalues = []; 1.25 +var expect= ''; 1.26 +var expectedvalues = []; 1.27 +var self = this; 1.28 + 1.29 + 1.30 +function myFunc() 1.31 +{ 1.32 + var hidden = 'aaa'; 1.33 + insideFunc(); 1.34 + 1.35 + if (!self.runOnce) 1.36 + { 1.37 + var hidden = 'bbb'; 1.38 + self.outSideFunc = insideFunc; 1.39 + self.runOnce = true; 1.40 + } 1.41 + else 1.42 + { 1.43 + var hidden = 'ccc'; 1.44 + } 1.45 + 1.46 + 1.47 + function insideFunc() 1.48 + { 1.49 + actual = hidden; 1.50 + } 1.51 +} 1.52 + 1.53 + 1.54 + 1.55 +status = inSection(1); 1.56 +myFunc(); // this sets |actual| 1.57 +expect = 'aaa'; 1.58 +addThis(); 1.59 + 1.60 +status = inSection(2); 1.61 +outSideFunc(); // sets |actual| 1.62 +expect = 'bbb'; 1.63 +addThis(); 1.64 + 1.65 +status = inSection(3); 1.66 +myFunc(); // sets |actual| 1.67 +expect = 'aaa'; 1.68 +addThis(); 1.69 + 1.70 +status = inSection(4); 1.71 +outSideFunc(); // sets |actual| 1.72 +expect = 'bbb'; // NOT 'ccc' 1.73 +addThis(); 1.74 + 1.75 + 1.76 + 1.77 + 1.78 +//----------------------------------------------------------------------------- 1.79 +test(); 1.80 +//----------------------------------------------------------------------------- 1.81 + 1.82 + 1.83 + 1.84 +function addThis() 1.85 +{ 1.86 + statusitems[UBound] = status; 1.87 + actualvalues[UBound] = actual; 1.88 + expectedvalues[UBound] = expect; 1.89 + UBound++; 1.90 +} 1.91 + 1.92 + 1.93 +function test() 1.94 +{ 1.95 + enterFunc('test'); 1.96 + printBugNumber(BUGNUMBER); 1.97 + printStatus(summary); 1.98 + 1.99 + for (var i=0; i<UBound; i++) 1.100 + { 1.101 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.102 + } 1.103 + 1.104 + exitFunc ('test'); 1.105 +}