regress-184107.js (1998B)
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: 09 December 2002 9 * SUMMARY: with(...) { function f ...} should set f in the global scope 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=184107 11 * 12 * In fact, any variable defined in a with-block should be created 13 * in global scope, i.e. should be a property of the global object. 14 * 15 * The with-block syntax allows existing local variables to be SET, 16 * but does not allow new local variables to be CREATED. 17 * 18 * See http://bugzilla.mozilla.org/show_bug.cgi?id=159849#c11 19 */ 20 //----------------------------------------------------------------------------- 21 var UBound = 0; 22 var BUGNUMBER = 184107; 23 var summary = 'with(...) { function f ...} should set f in the global scope'; 24 var status = ''; 25 var statusitems = []; 26 var actual = ''; 27 var actualvalues = []; 28 var expect= ''; 29 var expectedvalues = []; 30 31 var obj = {y:10}; 32 with (obj) 33 { 34 // function statement 35 function f() 36 { 37 return y; 38 } 39 40 // function expression 41 g = function() {return y;} 42 } 43 44 status = inSection(1); 45 actual = obj.f; 46 expect = undefined; 47 addThis(); 48 49 status = inSection(2); 50 actual = f(); 51 expect = obj.y; 52 addThis(); 53 54 status = inSection(3); 55 actual = obj.g; 56 expect = undefined; 57 addThis(); 58 59 status = inSection(4); 60 actual = g(); 61 expect = obj.y; 62 addThis(); 63 64 65 66 //----------------------------------------------------------------------------- 67 test(); 68 //----------------------------------------------------------------------------- 69 70 71 72 function addThis() 73 { 74 statusitems[UBound] = status; 75 actualvalues[UBound] = actual; 76 expectedvalues[UBound] = expect; 77 UBound++; 78 } 79 80 81 function test() 82 { 83 printBugNumber(BUGNUMBER); 84 printStatus(summary); 85 86 for (var i=0; i<UBound; i++) 87 { 88 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); 89 } 90 }