Closed Bug 184107 Opened 22 years ago Closed 22 years ago

with(...) { function f ...} should set f in the global scope

Categories

(Rhino Graveyard :: Core, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: user, Assigned: norrisboyd)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003 Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20021003 When evaluationg the following test: var x = {y:10}; with (x) { function f() { return y; } } var result = f(); var ok1 = (x.f === undefined) print(ok1) var ok2 = (result === x.y); print(ok2) Rhino incorrectly put f into the x object instead of the global scope. The test would work as expected if function f()... would be replaced by f = function()... Reproducible: Always Steps to Reproduce:
Testcase added to JS testsuite: mozilla/js/tests/js1_5/Scope/regress-184107.js Currently passing in SpiderMonkey. In Rhino, the test fails in both compiled and interpreted modes. As Igor states, function expressions f = function()... are correctly created by Rhino in global scope, but function statements function f() ... are being created in local scope.
Summary: with(...) { function f ...} should set f in the global scope → with(...) { function f ...} should set f in the global scope
After the patch js1_5/Scope/regress-185485.js will fail as the patch follows SM path there and SM copes with this Ecma extension in a different way as Netscape 4.* and it was decided that it was OK to keep the current SM behavior in this obscure case.
I commited the fix.
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Verified FIXED. The above testcase, js1_5/Scope/regress-184107.js, now passes in both Rhino interpreted and comiled modes. The testcase js1_5/Scope/regress-185485.js has now been corrected. It now passes in Rhino as well as in SpiderMonkey -
Status: RESOLVED → VERIFIED
Targeting as resolved against 1.5R4
Target Milestone: --- → 1.5R4
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: