Closed
Bug 237579
Opened 21 years ago
Closed 21 years ago
Strict warnings for trailing comma in array initializers
Categories
(Core :: JavaScript Engine, enhancement)
Core
JavaScript Engine
Tracking
()
RESOLVED
DUPLICATE
of bug 219308
People
(Reporter: paul_gregg, Unassigned)
Details
(Keywords: testcase)
Attachments
(1 file)
786 bytes,
text/html
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7a) Gecko/20040219
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7a) Gecko/20040219
Similar feature request to Bug 103602, Bug 164400 & Bug 179628.
Basically asking for the JS engine to produce a warning when in strict mode for
a trailing comma in array initializers.
After seeing the Bug 235260, it prompted me to raise a RFE, after I was bitten
by a similar problem (array initializers not object initializers, which seem to
fire a strict warning).
The reason this bites for web developers is that IE4, 5, 5.5 and 6 increase the
reported length of the array by one (maybe more if there's more commas), which
can stuff up loop calculations. Moz1.6, NN4 and Opera7.11 all report the proper
array length while ignoring the trailing comma.
Therefore, it would be nice if Moz reported a warning in strict mode when the
trailing comma appears.
Reproducible: Always
Steps to Reproduce:
1. Load some JS with an array that has a trailing comma after the initializers.
Actual Results:
No warning in strict mode.
Expected Results:
Warning generated and displayed in JS console when an array initializer has a
trailing comma.
Will attach a reduced testcase soon.
Reporter | ||
Comment 1•21 years ago
|
||
In Moz1.6, NN4 and Opera7.11:-
groups.length = 4
In IE4, 5, 5.5 and 6:-
groups.length = 5
This should raise a JS strict warning in the JS console.
Reporter | ||
Comment 2•21 years ago
|
||
Adding "testcase" keyword (would be nice if you could from the Create a New
Attachment page...), since I uploaded a simple testcase that should fine a
strict warning.
Keywords: testcase
Comment 3•21 years ago
|
||
this sounds like a duplicate of bug 219308... so it looks the other person
wanted in bug 219308 comment 10 has shown up :)
*** This bug has been marked as a duplicate of 219308 ***
Status: UNCONFIRMED → RESOLVED
Closed: 21 years ago
Resolution: --- → DUPLICATE
Comment 4•21 years ago
|
||
Re: comment 3, see bug 219308 comment 6, in particular:
One problematic, subtle issue here: IE is simply botching the array length for
[1,2,3,], which misleads code to expect (3 < a.length) and (3 in a) to be true.
We will never emulate this bug, so just a warning may not be enough to cause
the few who were misled by IE's bug to fix their code -- but it may bug the heck
out of people who (based on righteous Perl or trad-C experience) want to put a
trailing , in array initializers.
I went on to say that since a warning is not enough to gain compatibility, and
as we are *not* going to emulate IE's broken-ness in computing length, I'm not
in favor of adding a warning.
Maybe we could have a different kind of option than strict: "iebugs". It would
warn about any construct buggily implemented by IE's JScript engine. But I have
zero time or interest in doing that.
/be
You need to log in
before you can comment on or make changes to this bug.
Description
•