Last Comment Bug 744501 - Variables declared with 'var [...]' have wrong scopes.
: Variables declared with 'var [...]' have wrong scopes.
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
: -- normal with 1 vote (vote)
: ---
Assigned To: Luke Wagner [:luke]
:
: Jason Orendorff [:jorendorff]
Mentors:
javascript:function x(){var [a]=[1];x...
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-11 11:29 PDT by spammed.user
Modified: 2012-04-11 12:08 PDT (History)
2 users (show)
jruderman: in‑testsuite?
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description spammed.user 2012-04-11 11:29:50 PDT
Run the following code:

function x(){var a=1;x=function(){return a;};return a;}
alert(x());
alert(x());

It alerts '1' twice, as it should. However,

function x(){var [a]=[1];x=function(){return a;};return a;}
alert(x());
alert(x());

alerts '1' and then 'undefined'. Also,

function x(){var a=1;x=function(){return a;};return a;}
alert(x());
alert(x());
function x(){var [a]=[1];x=function(){return a;};return a;}
alert(x());
alert(x());

alerts '1', 'undefined', 'undefined', 'undefined', whereas

function x(){var [a]=[1];x=function(){return a;};return a;}
alert(x());
alert(x());
function x(){var a=1;x=function(){return a;};return a;}
alert(x());
alert(x());

works properly – it alerts 4 '1's.
Comment 1 Luke Wagner [:luke] 2012-04-11 11:50:05 PDT
Oops, repros on trunk, not caused by 740259.
Comment 2 Luke Wagner [:luke] 2012-04-11 12:03:45 PDT
Oh, wow, what coincidence: this bug is actually *fixed* by bug 740259 !  (Bug 740259 added some strong asserts that caught a bug in group assignment where we forgot to call MaybeEmitVarDecl.)

(It looks like the patch isn't in Nightly yet, but it should be very soon.)  Thanks for reporting!

*** This bug has been marked as a duplicate of bug 740259 ***

Note You need to log in before you can comment on or make changes to this bug.