Not getting a JavaScript strict warning for reassigning to a const

VERIFIED FIXED

Status

()

VERIFIED FIXED
17 years ago
12 years ago

People

(Reporter: pschwartau, Unassigned)

Tracking

Trunk
x86
All
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

17 years ago
This was discovered by jrgm. Here is a session in the JS shell: 

[]./js -w

js> const one=1;

js> const one=2;
4: TypeError: redeclaration of const one

js> one=2;
2

This shows that we get a warning if we try to redeclare a const,
but we do not get a warning if we try to reassign to a const.
It's true, the new value doesn't take: 

js> one
1

but there should be a warning, no?
(Reporter)

Comment 1

17 years ago
Created attachment 52476 [details]
HTML testcase by jrgm

Updated

17 years ago
Status: NEW → ASSIGNED
Target Milestone: --- → mozilla0.9.8
Oh, wow.  That's not good.

0.9.8 is coming up fast, any indications of work on this?
(Reporter)

Comment 3

17 years ago
cc'ing Brendan in case this is of interest -
That's per ECMA (don't blame me, I fought for what Netscape always did: throw an
error [could be a catchable exception since 1.3]).  Readonly properties, when
set by assignment, are not changed, but no error or exception is thrown.  The
value of the assignment expression is the value of the r.h.s.

If you want a *strict* warning, please change the summary of this bug to say so.

/be

Comment 5

17 years ago
Yeah, I only meant strict. I'm not particularly worried about whether/when this 
gets done. I just noticed that there was no warning for this, and it seems like 
something a strict mode should flag.
Summary: Not getting a JS warning if I try to reassign to a const → Not getting a JS strict warning if I try to reassign to a const

Updated

17 years ago
Summary: Not getting a JS strict warning if I try to reassign to a const → Not getting a JS strict warning for reassigning to a const
(Reporter)

Comment 6

17 years ago
Same behavior occurring with the -s option as with the -w option above: 

[]./js -s
js> const one=1;
js> one=2;
2
js> one
1

but no warning is given -
(Reporter)

Comment 7

17 years ago
Testcase added to JS testsuite to ensure what Brendan described in Comment #4:

          mozilla/js/tests/js1_5/Regress/regress-103602.js
shaver reminded me that exceptions didn't show up until js1.4.  This is a low
priority bug, are we sure it should be targeted at 0.9.8?

/be
targeting future.
Target Milestone: mozilla0.9.8 → Future

Comment 10

17 years ago
sorry for the spam: just so it shows up in my javascript query...
Summary: Not getting a JS strict warning for reassigning to a const → Not getting a JavaScript strict warning for reassigning to a const

Updated

13 years ago
Assignee: khanson → general
Status: ASSIGNED → NEW
QA Contact: pschwartau → general
Target Milestone: Future → ---

Comment 11

12 years ago
Tested this out just now, I think it is fixed:

js> const one = 1
js> one = 2
typein:2: strict warning: one is read-only
2
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → FIXED

Comment 12

12 years ago
verified on 1.8, 1.9 windows.
Status: RESOLVED → VERIFIED
Tradition would mark this bug WFM unless we know the bug that was patched to fix this symptom.  A little cvs annotate -r and cvs diff archeology discloses:

revision 3.230
date: 2005/12/01 21:05:12;  author: brendan%mozilla.org;  state: Exp;  lines: +24 -24
Followup to maximize error-reporting code sharing (315436, r=daumling).
----------------------------
revision 3.229
date: 2005/12/01 02:26:35;  author: brendan%mozilla.org;  state: Exp;  lines: +25 -7
Fix from Michael Daumling <daumling@adobe.com> to make read-only assignment a strict warning (315436, r/sr=mrbkap/brendan).

This is when the fix went in.

/be

Comment 14

12 years ago
Will Moffat posted in mozilla.dev.tech.js-engine


I'm using Gran Paradiso rv:1.9a2 with javascript.options.strict = true
and JavaScript Shell 1.4

const one=1;
const one=2; --> TypeError on line 1: redeclaration of const one
one=2; --> 2  *No warning*
one --> 1

According to Bug 103602 - "Not getting a JavaScript strict warning for
reassigning to a const" this was verified fixed on 1.8, 1.9 windows.
Shouldn't Gran Paradiso contain this fix?

Any ideas why I don't see a warning?
regards,
--Will


I've tested this issue with nightly build from trunk [Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.9a3pre) Gecko/20070222 SeaMonkey/1.5a] where I get the warning as desired. So I can not verify a new regression. For me it still looks fixed.
Assignment is not declaration. The redeclaration warning is only when const is used to declare the constant identifier.

I don't think this regressed:

$ ./Darwin_DBG.OBJ/js -sw
js> const one=1
js> one=2
typein:2: strict warning: one is read-only
2

Are you (is Will, I mean) sure you have strict warnings turned on?

/be

Comment 16

12 years ago
My bad, there is no regression. Two factors confused me:

The reassignment warnings go straight to the JS Console, they are not exceptions which can be caught and displayed by the JS Shell extension.

I was using an old build with bug 324142, so nothing appeared in the JS Console
You need to log in before you can comment on or make changes to this bug.