Closed Bug 208496 Opened 21 years ago Closed 21 years ago

Incorrect scope when |with (f)| is used inside the definition of |function f()|

Categories

(Core :: JavaScript Engine, defect, P2)

x86
All
defect

Tracking

()

VERIFIED FIXED
mozilla1.5alpha

People

(Reporter: pschwartau, Assigned: brendan)

Details

(Keywords: js1.5)

Attachments

(1 file)

Reported by Itaj Sherman in the Mozilla JS Engine newsgroup:

----
... there is another incompatibility there (with ECMA and IE):

function MyFunc(par)
{
  var a = par;

  with(MyFunc)
  {
    var b = par;
  }
}

In IE both |a| and |b| get the value the actual passed argument.

With SpiderMonkey of Mozilla 1.31, |b| will be undefined, because the
lookup finds 'par' on |MyFunc| which is the first on the scope chain,
and then getProperty is activated on |MyFunc|, using js_GetArgument().
----
Testcase added to JS testsuite:

      mozilla/js/tests/js1_5/Scope/regress-208496.js

Currently passing in Rhino; failing in SpiderMonkey.
Patch in a second.

/be
Status: NEW → ASSIGNED
Priority: -- → P2
Target Milestone: --- → mozilla1.5alpha
I'm not going to rip out the reflection of args and local vars as properties of
their function object -- that's too big an incompatibility, and too big a
change.  It could easily increase code footprint, even though we could do
without hacks such as this one.  And it would increase data footprint for sure,
because it would require adding a separate, secondary scope (or equivalent) per
function, used only by the compiler.

/be
Attachment #125112 - Flags: review?(rogerl)
Comment on attachment 125112 [details] [diff] [review]
ad-hoc fix, ugly but small

Just for my edification; the change in jsinterp.c is an optimization because
argv is NULL so the error handling in JS_InstanceOf isn't going to be used?
(But why not the same change on line 484?)
Attachment #125112 - Flags: review?(rogerl) → review+
Rogerl: oops, missed that one -- I was not vigilant enough in hunting down
JS_InstanceOf(..., NULL) uses inside the engine.  Now that I've expanded and
reduced the one you pointed out, only the jsfile.c one is left -- and jsfile.c
is orphaned code.  Thanks, checking in.

/be
Status: ASSIGNED → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
We now have two regression tests for this bug:

   mozilla/js/tests/js1_5/Scope/regress-208496-001.js
   mozilla/js/tests/js1_5/Scope/regress-208496-002.js

I renamed mozilla/js/tests/js1_5/Scope/regress-208496.js
as regress-208496-001.js, and added regress-208496-002.

The new test, again from Itaj, checks access of static
properties of |f| from inside the |with(f)| block.

Both tests are passing in the current JS shell, and I see
no test regressions when running the JS testsuite on Linux.

Therefore marking Verified FIXED -
Status: RESOLVED → VERIFIED
Flags: testcase+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: