From 3b82ed70a11cda170fbde5b7d0c2f792cba94da5 Mon Sep 17 00:00:00 2001 From: "pschwartau%netscape.com" Date: Wed, 8 Jan 2003 22:51:02 +0000 Subject: [PATCH] Correcting testcase and adding more illustrative cases. git-svn-id: svn://10.0.0.236/trunk@136024 18797224-902f-48f8-a5cc-f745e15eee43 --- .../js/tests/js1_5/Scope/regress-185485.js | 66 ++++++++++++++----- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/mozilla/js/tests/js1_5/Scope/regress-185485.js b/mozilla/js/tests/js1_5/Scope/regress-185485.js index fc0118bc1f0..3fb70d7bb44 100644 --- a/mozilla/js/tests/js1_5/Scope/regress-185485.js +++ b/mozilla/js/tests/js1_5/Scope/regress-185485.js @@ -45,16 +45,22 @@ * http://bugzilla.mozilla.org/show_bug.cgi?id=184107 * * -* However, if |x| does have a property |f|, a |with| statement can be -* used to modify the value it contains. This should work even if we use -* a |var| statement, like this: +* However, if |x| already has a property |f|, a |with| statement can be +* used to modify the value it contains: +* +* with (x) {f = 1;} +* +* This should work even if we use a |var| statement, like this: * * with (x) {var f = 1;} * -* or a function statement, like this: +* However, it should NOT work if we use a |function| statement, like this: * * with (x) {function f() {}} * +* Instead, this should newly define a function f in global scope. +* See http://bugzilla.mozilla.org/show_bug.cgi?id=185485 +* */ //----------------------------------------------------------------------------- var UBound = 0; @@ -67,29 +73,55 @@ var actualvalues = []; var expect= ''; var expectedvalues = []; - var x = { f:0, g:0 }; + +with (x) +{ + f = 1; +} +status = inSection(1); +actual = x.f; +expect = 1; +addThis(); + +with (x) +{ + var f = 2; +} +status = inSection(2); +actual = x.f; +expect = 2; +addThis(); + +/* + * Use of a function statement under the with-block should not affect + * the local property |f|, but define a function |f| in global scope - + */ with (x) { function f() {} +} +status = inSection(3); +actual = x.f; +expect = 2; +addThis(); + +status = inSection(4); +actual = typeof this.f; +expect = 'function'; +addThis(); + + +// Compare use of function expression instead of function statement +with (x) +{ var g = function() {} } - -status = inSection(1); -actual = x.f.toString(); -expect = (function f() {}).toString(); -addThis(); - -status = inSection(2); +status = inSection(5); actual = x.g.toString(); expect = (function () {}).toString(); addThis(); -status = inSection(3); -actual = this.f; -expect = undefined; -addThis(); - //-----------------------------------------------------------------------------