michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * Date: 2001-07-16 michael@0: * michael@0: * SUMMARY: Testing visiblity of variables from within a with block. michael@0: * See http://bugzilla.mozilla.org/show_bug.cgi?id=90325 michael@0: */ michael@0: //----------------------------------------------------------------------------- michael@0: var UBound = 0; michael@0: var BUGNUMBER = 90325; michael@0: var summary = 'Testing visiblity of variables from within a with block'; michael@0: var status = ''; michael@0: var statusitems = []; michael@0: var actual = ''; michael@0: var actualvalues = []; michael@0: var expect= ''; michael@0: var expectedvalues = []; michael@0: michael@0: // (compare local definitions which follow) - michael@0: var A = 'global A'; michael@0: var B = 'global B'; michael@0: var C = 'global C'; michael@0: var D = 'global D'; michael@0: michael@0: // an object with 'C' and 'D' properties - michael@0: var objTEST = new Object(); michael@0: objTEST.C = C; michael@0: objTEST.D = D; michael@0: michael@0: michael@0: status = 'Section 1 of test'; michael@0: with (new Object()) michael@0: { michael@0: actual = A; michael@0: expect = 'global A'; michael@0: } michael@0: addThis(); michael@0: michael@0: michael@0: status = 'Section 2 of test'; michael@0: with (Function) michael@0: { michael@0: actual = B; michael@0: expect = 'global B'; michael@0: } michael@0: addThis(); michael@0: michael@0: michael@0: status = 'Section 3 of test'; michael@0: with (this) michael@0: { michael@0: actual = C; michael@0: expect = 'global C'; michael@0: } michael@0: addThis(); michael@0: michael@0: michael@0: status = 'Section 4 of test'; michael@0: localA(); michael@0: addThis(); michael@0: michael@0: status = 'Section 5 of test'; michael@0: localB(); michael@0: addThis(); michael@0: michael@0: status = 'Section 6 of test'; michael@0: localC(); michael@0: addThis(); michael@0: michael@0: status = 'Section 7 of test'; michael@0: localC(new Object()); michael@0: addThis(); michael@0: michael@0: status = 'Section 8 of test'; michael@0: localC.apply(new Object()); michael@0: addThis(); michael@0: michael@0: status = 'Section 9 of test'; michael@0: localC.apply(new Object(), [objTEST]); michael@0: addThis(); michael@0: michael@0: status = 'Section 10 of test'; michael@0: localC.apply(objTEST, [objTEST]); michael@0: addThis(); michael@0: michael@0: status = 'Section 11 of test'; michael@0: localD(new Object()); michael@0: addThis(); michael@0: michael@0: status = 'Section 12 of test'; michael@0: localD.apply(new Object(), [objTEST]); michael@0: addThis(); michael@0: michael@0: status = 'Section 13 of test'; michael@0: localD.apply(objTEST, [objTEST]); michael@0: addThis(); michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------------------------------- michael@0: test(); michael@0: //------------------------------------------------------------------------------------------------- michael@0: michael@0: michael@0: michael@0: // contains a with(new Object()) block - michael@0: function localA() michael@0: { michael@0: var A = 'local A'; michael@0: michael@0: with(new Object()) michael@0: { michael@0: actual = A; michael@0: expect = 'local A'; michael@0: } michael@0: } michael@0: michael@0: michael@0: // contains a with(Number) block - michael@0: function localB() michael@0: { michael@0: var B = 'local B'; michael@0: michael@0: with(Number) michael@0: { michael@0: actual = B; michael@0: expect = 'local B'; michael@0: } michael@0: } michael@0: michael@0: michael@0: // contains a with(this) block - michael@0: function localC(obj) michael@0: { michael@0: var C = 'local C'; michael@0: michael@0: with(this) michael@0: { michael@0: actual = C; michael@0: } michael@0: michael@0: if ('C' in this) michael@0: expect = this.C; michael@0: else michael@0: expect = 'local C'; michael@0: } michael@0: michael@0: michael@0: // contains a with(obj) block - michael@0: function localD(obj) michael@0: { michael@0: var D = 'local D'; michael@0: michael@0: with(obj) michael@0: { michael@0: actual = D; michael@0: } michael@0: michael@0: if ('D' in obj) michael@0: expect = obj.D; michael@0: else michael@0: expect = 'local D'; michael@0: } michael@0: michael@0: michael@0: function addThis() michael@0: { michael@0: statusitems[UBound] = status; michael@0: actualvalues[UBound] = actual; michael@0: expectedvalues[UBound] = expect; michael@0: UBound++; michael@0: } michael@0: michael@0: michael@0: function test() michael@0: { michael@0: enterFunc ('test'); michael@0: printBugNumber(BUGNUMBER); michael@0: printStatus (summary); michael@0: michael@0: for (var i = 0; i < UBound; i++) michael@0: { michael@0: reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); michael@0: } michael@0: michael@0: exitFunc ('test'); michael@0: }