1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/Function/regress-97921.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 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 + * Date: 10 September 2001 1.11 + * 1.12 + * SUMMARY: Testing with() statement with nested functions 1.13 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=97921 1.14 + * 1.15 + * Brendan: "The bug is peculiar to functions that have formal parameters, 1.16 + * but that are called with fewer actual arguments than the declared number 1.17 + * of formal parameters." 1.18 + */ 1.19 +//----------------------------------------------------------------------------- 1.20 +var UBound = 0; 1.21 +var BUGNUMBER = 97921; 1.22 +var summary = 'Testing with() statement with nested functions'; 1.23 +var cnYES = 'Inner value === outer value'; 1.24 +var cnNO = "Inner value !== outer value!"; 1.25 +var status = ''; 1.26 +var statusitems = []; 1.27 +var actual = ''; 1.28 +var actualvalues = []; 1.29 +var expect= ''; 1.30 +var expectedvalues = []; 1.31 +var outerValue = ''; 1.32 +var innerValue = ''; 1.33 +var useWith = ''; 1.34 + 1.35 + 1.36 +function F(i) 1.37 +{ 1.38 + i = 0; 1.39 + if(useWith) with(1){i;} 1.40 + i++; 1.41 + 1.42 + outerValue = i; // capture value of i in outer function 1.43 + F1 = function() {innerValue = i;}; // capture value of i in inner function 1.44 + F1(); 1.45 +} 1.46 + 1.47 + 1.48 +status = inSection(1); 1.49 +useWith=false; 1.50 +F(); // call F without supplying the argument 1.51 +actual = innerValue === outerValue; 1.52 +expect = true; 1.53 +addThis(); 1.54 + 1.55 +status = inSection(2); 1.56 +useWith=true; 1.57 +F(); // call F without supplying the argument 1.58 +actual = innerValue === outerValue; 1.59 +expect = true; 1.60 +addThis(); 1.61 + 1.62 + 1.63 +function G(i) 1.64 +{ 1.65 + i = 0; 1.66 + with (new Object()) {i=100}; 1.67 + i++; 1.68 + 1.69 + outerValue = i; // capture value of i in outer function 1.70 + G1 = function() {innerValue = i;}; // capture value of i in inner function 1.71 + G1(); 1.72 +} 1.73 + 1.74 + 1.75 +status = inSection(3); 1.76 +G(); // call G without supplying the argument 1.77 +actual = innerValue === 101; 1.78 +expect = true; 1.79 +addThis(); 1.80 + 1.81 +status = inSection(4); 1.82 +G(); // call G without supplying the argument 1.83 +actual = innerValue === outerValue; 1.84 +expect = true; 1.85 +addThis(); 1.86 + 1.87 + 1.88 + 1.89 +//----------------------------------------------------------------------------- 1.90 +test(); 1.91 +//----------------------------------------------------------------------------- 1.92 + 1.93 + 1.94 +function addThis() 1.95 +{ 1.96 + statusitems[UBound] = status; 1.97 + actualvalues[UBound] = areTheseEqual(actual); 1.98 + expectedvalues[UBound] = areTheseEqual(expect); 1.99 + UBound++; 1.100 +} 1.101 + 1.102 + 1.103 +function test() 1.104 +{ 1.105 + enterFunc ('test'); 1.106 + printBugNumber(BUGNUMBER); 1.107 + printStatus (summary); 1.108 + 1.109 + for (var i = 0; i < UBound; i++) 1.110 + { 1.111 + reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 1.112 + } 1.113 + 1.114 + exitFunc ('test'); 1.115 +} 1.116 + 1.117 + 1.118 +function areTheseEqual(yes) 1.119 +{ 1.120 + return yes? cnYES : cnNO 1.121 + }