WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
Bug 18717
SQUIRRELFISH: eval returns the wrong value for a variable declaration statement
https://bugs.webkit.org/show_bug.cgi?id=18717
Summary
SQUIRRELFISH: eval returns the wrong value for a variable declaration statement
Cameron Zwarich (cpst)
Reported
2008-04-24 12:41:04 PDT
The expression eval("var x = 0;") returns 0 instead of undefined. This causes the JavaScriptCore test ecma_3/Expressions/11.9.6-1.js to fail. Oliver suggested sending something other than dst to the expression in VarStatementNode::emitCode(), but that doesn't work, because then eval("f(); var x= 0;") will return the return value of f(). It seems the best way to fix this is to see if a variable statement is the last statement in a list of statements, in which case you generate code to overwrite its return value with undefined.
Attachments
Proposed patch
(3.69 KB, patch)
2008-04-24 15:29 PDT
,
Cameron Zwarich (cpst)
no flags
Details
Formatted Diff
Diff
Revised proposed patch
(3.98 KB, patch)
2008-04-24 15:43 PDT
,
Cameron Zwarich (cpst)
oliver
: review+
Details
Formatted Diff
Diff
Show Obsolete
(1)
View All
Add attachment
proposed patch, testcase, etc.
Cameron Zwarich (cpst)
Comment 1
2008-04-24 12:49:28 PDT
I should also add that there is nothing in the ECMA spec that suggests it should return undefined, at least as far as I can tell.
Oliver Hunt
Comment 2
2008-04-24 13:56:57 PDT
eval("var x = 0") should return undefined as nothing should ever assign to dst. However the rule is (afaict from my testing) that var statements are transparent to the result value, so eval("someExpr; var x = 0;") will return the result of someExpr, assuming someExpr actually has a return value. I believe therefore the example eval("f(); var x=0;") *should* return the result of f().
Cameron Zwarich (cpst)
Comment 3
2008-04-24 15:29:50 PDT
Created
attachment 20802
[details]
Proposed patch Yeah, Oliver, I accidentally misread the spec. Here is a patch that fixes the problem. It seems to be a 0.2% progression on SunSpider. It fixes ecma_3/Expressions/11.9.6-1.js, but causes js1_5/GetSet/getset-005.js to crash, like many other tests using getters and setters.
Darin Adler
Comment 4
2008-04-24 15:37:03 PDT
Comment on
attachment 20802
[details]
Proposed patch It's better to omit or comment out the argument name "dst" rather than doing "UNUSED_PARAM(dst)" when practical. There are times when due to #ifdef's or ASSERT, for example, that UNUSED_PARAM is unavoidable or better. But I don't think this is one of those times.
Cameron Zwarich (cpst)
Comment 5
2008-04-24 15:43:03 PDT
Created
attachment 20803
[details]
Revised proposed patch Here is a revised version of the patch that avoids the use of UNUSED_PARAM.
Oliver Hunt
Comment 6
2008-04-24 16:01:36 PDT
Committed
r32520
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug