1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_5/Scope/regress-208496-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 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: 05 June 2003 1.12 + * SUMMARY: Testing |with (f)| inside the definition of |function f()| 1.13 + * 1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=208496 1.15 + * 1.16 + */ 1.17 +//----------------------------------------------------------------------------- 1.18 +var UBound = 0; 1.19 +var BUGNUMBER = 208496; 1.20 +var summary = 'Testing |with (f)| inside the definition of |function f()|'; 1.21 +var status = ''; 1.22 +var statusitems = []; 1.23 +var actual = '(TEST FAILURE)'; 1.24 +var actualvalues = []; 1.25 +var expect= ''; 1.26 +var expectedvalues = []; 1.27 + 1.28 + 1.29 +/* 1.30 + * GLOBAL SCOPE 1.31 + */ 1.32 +function f(par) 1.33 +{ 1.34 + var a = par; 1.35 + 1.36 + with(f) 1.37 + { 1.38 + var b = par; 1.39 + actual = b; 1.40 + } 1.41 +} 1.42 + 1.43 +status = inSection(1); 1.44 +f('abc'); // this sets |actual| 1.45 +expect = 'abc'; 1.46 +addThis(); 1.47 + 1.48 +status = inSection(2); 1.49 +f(111 + 222); // sets |actual| 1.50 +expect = 333; 1.51 +addThis(); 1.52 + 1.53 + 1.54 +/* 1.55 + * EVAL SCOPE 1.56 + */ 1.57 +var s = ''; 1.58 +s += 'function F(par)'; 1.59 +s += '{'; 1.60 +s += ' var a = par;'; 1.61 + 1.62 +s += ' with(F)'; 1.63 +s += ' {'; 1.64 +s += ' var b = par;'; 1.65 +s += ' actual = b;'; 1.66 +s += ' }'; 1.67 +s += '}'; 1.68 + 1.69 +s += 'status = inSection(3);'; 1.70 +s += 'F("abc");'; // sets |actual| 1.71 +s += 'expect = "abc";'; 1.72 +s += 'addThis();'; 1.73 + 1.74 +s += 'status = inSection(4);'; 1.75 +s += 'F(111 + 222);'; // sets |actual| 1.76 +s += 'expect = 333;'; 1.77 +s += 'addThis();'; 1.78 +eval(s); 1.79 + 1.80 + 1.81 +/* 1.82 + * FUNCTION SCOPE 1.83 + */ 1.84 +function g(par) 1.85 +{ 1.86 + // Add outer variables to complicate the scope chain - 1.87 + var a = '(TEST FAILURE)'; 1.88 + var b = '(TEST FAILURE)'; 1.89 + h(par); 1.90 + 1.91 + function h(par) 1.92 + { 1.93 + var a = par; 1.94 + 1.95 + with(h) 1.96 + { 1.97 + var b = par; 1.98 + actual = b; 1.99 + } 1.100 + } 1.101 +} 1.102 + 1.103 +status = inSection(5); 1.104 +g('abc'); // sets |actual| 1.105 +expect = 'abc'; 1.106 +addThis(); 1.107 + 1.108 +status = inSection(6); 1.109 +g(111 + 222); // sets |actual| 1.110 +expect = 333; 1.111 +addThis(); 1.112 + 1.113 + 1.114 + 1.115 + 1.116 +//----------------------------------------------------------------------------- 1.117 +test(); 1.118 +//----------------------------------------------------------------------------- 1.119 + 1.120 + 1.121 + 1.122 +function addThis() 1.123 +{ 1.124 + statusitems[UBound] = status; 1.125 + actualvalues[UBound] = actual; 1.126 + expectedvalues[UBound] = expect; 1.127 + UBound++; 1.128 +} 1.129 + 1.130 + 1.131 +function test() 1.132 +{ 1.133 + enterFunc('test'); 1.134 + printBugNumber(BUGNUMBER); 1.135 + printStatus(summary); 1.136 + 1.137 + for (var i=0; i<UBound; i++) 1.138 + { 1.139 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.140 + } 1.141 + 1.142 + exitFunc ('test'); 1.143 +}