1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/Scope/regress-220362.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 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: 27 Sep 2003 1.12 + * SUMMARY: Calling a local function from global scope 1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=220362 1.14 + * 1.15 + */ 1.16 +//----------------------------------------------------------------------------- 1.17 +var UBound = 0; 1.18 +var BUGNUMBER = 220362; 1.19 +var summary = 'Calling a local function from global scope'; 1.20 +var status = ''; 1.21 +var statusitems = []; 1.22 +var actual = ''; 1.23 +var actualvalues = []; 1.24 +var expect= ''; 1.25 +var expectedvalues = []; 1.26 + 1.27 + 1.28 +// creates a local function and calls it immediately 1.29 +function a() 1.30 +{ 1.31 + var x = 'A'; 1.32 + var f = function() {return x;}; 1.33 + return f(); 1.34 +} 1.35 + 1.36 +// creates and returns a local function 1.37 +function b() 1.38 +{ 1.39 + var x = 'B'; 1.40 + var f = function() {return x;}; 1.41 + return f; 1.42 +} 1.43 + 1.44 + 1.45 +status = inSection(1); 1.46 +actual = a(); 1.47 +expect = 'A'; 1.48 +addThis(); 1.49 + 1.50 +status = inSection(2); 1.51 +var f = b(); 1.52 +actual = f(); 1.53 +expect = 'B'; 1.54 +addThis(); 1.55 + 1.56 + 1.57 + 1.58 +//----------------------------------------------------------------------------- 1.59 +test(); 1.60 +//----------------------------------------------------------------------------- 1.61 + 1.62 + 1.63 + 1.64 +function addThis() 1.65 +{ 1.66 + statusitems[UBound] = status; 1.67 + actualvalues[UBound] = actual; 1.68 + expectedvalues[UBound] = expect; 1.69 + UBound++; 1.70 +} 1.71 + 1.72 + 1.73 +function test() 1.74 +{ 1.75 + enterFunc('test'); 1.76 + printBugNumber(BUGNUMBER); 1.77 + printStatus(summary); 1.78 + 1.79 + for (var i=0; i<UBound; i++) 1.80 + { 1.81 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.82 + } 1.83 + 1.84 + exitFunc ('test'); 1.85 +}