Closed
Bug 69724
Opened 24 years ago
Closed 24 years ago
nested functions do not have access to variables defined in their parent function
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
VERIFIED
WORKSFORME
People
(Reporter: rginda, Assigned: rogerl)
Details
(Keywords: js1.5)
Here is most of the text from an email I got from Steve Newman, snewman@macromedia.com: ...nested functions do not seem to have access to variables defined in their parent function, at least in some cases. Here is a test case that reproduces the bug: function test() { var param = 5; // var foo = test.__call__; (function() {alert(param*param);}) (); } test(); When I execute this script, I get an undefined-identifier error for the use of "param" in the anonymous function. However, if I enable the declaration of "var foo" (by removing the comment slashes), the code executes properly. As far as I can tell, the problem is that in the code for "case JSOP_ANONFUNOBJ:" in jsinterp.c, the inner function's parent chain is set to fp->varobj, but fp->varobj is null. Referencing test.__call__ causes js_GetCallObject to be called, which has the side effect of filling in fp->varobj with the call object for the test() function, and so the ANONFUNOBJ code then sets up the parent chain correctly.
Comment 1•24 years ago
|
||
This like so worksforme, and works even better with the brendan/shaver patch in bug 65308. Unless someone removed the logic to set JSFUN_HEAVYWEIGHT for the outer function, I don't see how it could have broken. I also believe (hope!) that cases like this are covered by our testsuite. What version of the engine is Steve using? /be
Status: NEW → RESOLVED
Closed: 24 years ago
Resolution: --- → WORKSFORME
Comment 2•24 years ago
|
||
Verifying WORKSFORME on WinNT. Steve's testcase and variations that I've tried seem to work just fine. I will add all this to the JS test suite -
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•