Variables declared with 'var [...]' have wrong scopes.

RESOLVED FIXED

Status

()

Core
JavaScript Engine
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: spammed.user, Assigned: luke)

Tracking

Trunk
Points:
---
Bug Flags:
in-testsuite ?

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

5 years ago
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.
(Reporter)

Updated

5 years ago
Summary: Variables declared with 'var [...]' have improper scopes. → Variables declared with 'var [...]' have wrong scopes.
(Assignee)

Updated

5 years ago
Assignee: general → luke
Blocks: 740259
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Assignee)

Comment 1

5 years ago
Oops, repros on trunk, not caused by 740259.
No longer blocks: 740259
(Assignee)

Comment 2

5 years ago
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!
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 740259

Updated

5 years ago
Flags: in-testsuite?
Resolution: DUPLICATE → FIXED
You need to log in before you can comment on or make changes to this bug.