Closed
Bug 395907
Opened 18 years ago
Closed 18 years ago
eval of function declaration does not change existing variable
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
People
(Reporter: martin.honnen, Assigned: brendan)
References
Details
Attachments
(3 files, 1 obsolete file)
|
210 bytes,
text/javascript
|
Details | |
|
453 bytes,
text/html
|
Details | |
|
4.09 KB,
patch
|
brendan
:
review+
brendan
:
approval1.9+
|
Details | Diff | Splinter Review |
Test code looks like this:
var x = "string";
function f () {
var x = 0;
print('typeof x: ' + (typeof x));
eval('function x() { return true; }');
print('typeof x: ' + (typeof x));
print('x(): ' + x());
}
f();
When run with Rhino the output is as follows:
typeof x: number
typeof x: function
x(): true
so the eval on the function declaration assigns the created function as the valu of the local variable x.
With Spidermonkey however the result is as follows:
typeof x: number
typeof x: number
and then a script error trying to call x with the message "x is not a function".
Tested with Spidermonkey in the latest Firefox nightly (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007091204 Minefield/3.0a8pre) but this seems to be a long standing Spidermonkey bug, not a regression.
Spidermonkey's behaviour is a bug in my view as the ECMAScript edition 3 in section 10.1.3 says:
"For each FunctionDeclaration in the code, in source text order, create a property of the variable object whose
name is the Identifier in the FunctionDeclaration, whose value is the result returned by creating a Function object
as described in section 13, and whose attributes are determined by the type of code. If the variable object
already has a property with this name, replace its value and attributes."
So the value of the already existing variable x should be replaced with the function object resulting from the evaluation of the function declaration.
| Reporter | ||
Comment 1•18 years ago
|
||
| Reporter | ||
Comment 2•18 years ago
|
||
| Reporter | ||
Comment 3•18 years ago
|
||
I have tried https://bugzilla.mozilla.org/attachment.cgi?id=280605 with Opera and with IE and the result is the same as with Rhino.
| Assignee | ||
Comment 5•18 years ago
|
||
Old bug.
/be
Assignee: general → brendan
OS: Windows XP → All
Hardware: PC → All
| Assignee | ||
Updated•18 years ago
|
Status: NEW → ASSIGNED
| Assignee | ||
Comment 6•18 years ago
|
||
I considered trying to set TCF_IN_FUNCTION for a cg created indirectly by eval, but the object in which to search for a hidden property varies too. So brute force testing in the TOK_FUNCTION case of js_EmitTree seems best, and fixes the bug.
/be
Attachment #280693 -
Flags: review?(mrbkap)
Should have turned off my precognative abilities...
The attached fix now triggers Bug 395868 (which wasn't there before).
| Assignee | ||
Comment 8•18 years ago
|
||
(In reply to comment #7)
> Should have turned off my precognative abilities...
> The attached fix now triggers Bug 395868 (which wasn't there before).
Triggers or fixes? The attached fix here has not been checked in, so it can't be the cause of another bug report.
/be
Comment 9•18 years ago
|
||
Comment on attachment 280693 [details] [diff] [review]
fix
>- JS_ASSERT(prop && pobj == obj);
>- sprop = (JSScopeProperty *) prop;
>- JS_ASSERT(sprop->getter == js_GetLocalVariable);
>- slot = sprop->shortid;
>- OBJ_DROP_PROPERTY(cx, pobj, prop);
>+ if (prop) {
Worth asserting that !(cg->treeContext.flags & TCF_IN_FUNCTION) if prop is null?
Attachment #280693 -
Flags: review?(mrbkap) → review+
| Assignee | ||
Comment 10•18 years ago
|
||
Sure.
/be
Attachment #280693 -
Attachment is obsolete: true
Attachment #280959 -
Flags: review+
Attachment #280959 -
Flags: approval1.9+
| Assignee | ||
Comment 11•18 years ago
|
||
Fixed:
js/src/jsemit.c 3.273
/be
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
Comment 12•18 years ago
|
||
I applied the patch by hand, and now Bug 395868 is relevant. As I said, I submitted the bug-report about 24h too early. Only with this fix, the bug-report actually makes sense. I have hence reopened Bug 395868.
| Reporter | ||
Comment 13•18 years ago
|
||
Verified as fixed with Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a8pre) Gecko/2007091504 Minefield/3.0a8pre
Status: RESOLVED → VERIFIED
Comment 14•18 years ago
|
||
resurrected old test id with new test...
Checking in 10.1.3-2.js;
/cvsroot/mozilla/js/tests/ecma_3/ExecutionContexts/10.1.3-2.js,v <-- 10.1.3-2.js
new revision: 1.5; previous revision: 1.4
Flags: in-testsuite+
You need to log in
before you can comment on or make changes to this bug.
Description
•