generate.py lint and dangling comma in array initialization

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

generate.py lint and dangling comma in array initialization

Dietrich Streifert
Hi all,

I've been running into an error situation with an accidently forgotten
comma behind the last element of an array initialization. Something like:

var a = [
     { name: 'bla' },
     { name: 'blu' },
];

console.log(a.length);

If this code is executed in IE8 you get an array length of 3 whereas in
IE9 and higher and all other current browsers the length seems to be 2.
At least the error only shows up in IE8.

I'm frequently using "generate.py on my project" to find code flaws like
this, but unfortunately the linter in the toolchain did not detect the
false code.

Shouldn't lint warn about the dangling comma?

Or is this a valid javascript code?

Thank you for your attention.

Regards
Dietrich





------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Dietrich Streifert
Sorry should be:

I'm frequently using "generate.py lint" on my project to find code flaws
like this, but unfortunately the linter in the toolchain did not detect
the false code.

Am 30.10.2013 13:01, schrieb Dietrich Streifert:
> I'm frequently using "generate.py on my project" to find code flaws
> like this, but unfortunately the linter in the toolchain did not
> detect the false code.


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Thomas Herchenroeder
In reply to this post by Dietrich Streifert
Hi Dietrich,

On 10/30/2013 01:01 PM, Dietrich Streifert wrote:

> Hi all,
>
> I've been running into an error situation with an accidently forgotten
> comma behind the last element of an array initialization. Something like:
>
> var a = [
>       { name: 'bla' },
>       { name: 'blu' },
> ];
>
> console.log(a.length);
>
> If this code is executed in IE8 you get an array length of 3 whereas in
> IE9 and higher and all other current browsers the length seems to be 2.
> At least the error only shows up in IE8.
>
> I'm frequently using "generate.py on my project" to find code flaws like
> this, but unfortunately the linter in the toolchain did not detect the
> false code.
>
> Shouldn't lint warn about the dangling comma?
>
> Or is this a valid javascript code?


"Dangling commas" in arrays are not only permitted in the ES spec, they
have their own name, they're called "elisions". You can look at them as
if an 'undefined' value had been inserted at this position in the array.
So in that respect they are legal, and hence the lint job doesn't warn
(But we could add an option to the lint-check to enable this, if you
care to open a bug for it). The Generator also makes some effort to
retain elisions in optimized code, exactly because of the length semantics.

As for this array length issue, it really depends on which version of
the ES spec you comparing against. The JS 1.5 spec says about elisions:

"Array elements may be elided at the beginning, middle or end of the
element list. Whenever a comma in
the element list is not preceded by an AssignmentExpression (i.e., a
comma at the beginning or after
another comma), the missing array element contributes to the length of
the Array and increases the index
of subsequent elements. Elided array elements are not defined."

In that light IE6-8 (IIRC) conform very closely to that specification.

But the latest ES spec (ES, ed. 5.1) takes a slightly different approach:

"Array elements may be elided at the beginning, middle or end of the
element list. Whenever a comma in the
element list is not preceded by an AssignmentExpression (i.e., a comma
at the beginning or after another
comma), the missing array element contributes to the length of the Array
and increases the index of
subsequent elements. Elided array elements are not defined. If an
element is elided at the end of an array,
that element does not contribute to the length of the Array."

The two paragraphs are identical except there is an extra sentence at
the end of the newer version. In that version elisions *at the end* of
the array do not contribute to the array length. So in that light, more
current browsers are right and are conformant to the newer spec. :-)

HTH,
T.

------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Dietrich Streifert
Hi Thomas,

Well it seems learning never stops!

Thank you (again) for your detailed explanation.

Here is the submitted bug:
http://bugzilla.qooxdoo.org/show_bug.cgi?id=7834

Regards
Dietrich

Am 30.10.2013 14:13, schrieb thron7:

> Hi Dietrich,
>
>
> "Dangling commas" in arrays are not only permitted in the ES spec, they
> have their own name, they're called "elisions". You can look at them as
> if an 'undefined' value had been inserted at this position in the array.
> So in that respect they are legal, and hence the lint job doesn't warn
> (But we could add an option to the lint-check to enable this, if you
> care to open a bug for it). The Generator also makes some effort to
> retain elisions in optimized code, exactly because of the length semantics.
>
> As for this array length issue, it really depends on which version of
> the ES spec you comparing against. The JS 1.5 spec says about elisions:
>
> "Array elements may be elided at the beginning, middle or end of the
> element list. Whenever a comma in
> the element list is not preceded by an AssignmentExpression (i.e., a
> comma at the beginning or after
> another comma), the missing array element contributes to the length of
> the Array and increases the index
> of subsequent elements. Elided array elements are not defined."
>
> In that light IE6-8 (IIRC) conform very closely to that specification.
>
> But the latest ES spec (ES, ed. 5.1) takes a slightly different approach:
>
> "Array elements may be elided at the beginning, middle or end of the
> element list. Whenever a comma in the
> element list is not preceded by an AssignmentExpression (i.e., a comma
> at the beginning or after another
> comma), the missing array element contributes to the length of the Array
> and increases the index of
> subsequent elements. Elided array elements are not defined. If an
> element is elided at the end of an array,
> that element does not contribute to the length of the Array."
>
> The two paragraphs are identical except there is an extra sentence at
> the end of the newer version. In that version elisions *at the end* of
> the array do not contribute to the array length. So in that light, more
> current browsers are right and are conformant to the newer spec. :-)
>
> HTH,
> T.
>
> ------------------------------------------------------------------------------
> Android is increasing in popularity, but the open development platform that
> developers love is also attractive to malware creators. Download this white
> paper to learn more about secure code signing practices that can help keep
> Android apps secure.
> http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Richard Sternagel
Hi Dietrich,

if you need a solution today you could also run js[hl]int on your code
(e.g. via Node.js as globally installed package). They are already able
to catch exactly that case:

http://jslinterrors.com/extra-comma/

More on those tools:
http://www.jshint.com
http://www.jslint.com

Regards
Richard

------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Dietrich Streifert
Hi Richard,

Thank you for the hint!

I've managed to install and use jshint which gave the following output:

table.js: line 109, col 61, Extra comma. (it breaks older versions of IE)

Now I have to get rid of those "Mixed spaces and tabs." warnings which
currently pollute the output of jshint.

Regards
Dietrich

Am 30.10.2013 15:15, schrieb Richard Sternagel:

> Hi Dietrich,
>
> if you need a solution today you could also run js[hl]int on your code
> (e.g. via Node.js as globally installed package). They are already able
> to catch exactly that case:
>
> http://jslinterrors.com/extra-comma/
>
> More on those tools:
> http://www.jshint.com
> http://www.jslint.com
>
> Regards
> Richard
>
> ------------------------------------------------------------------------------
> Android is increasing in popularity, but the open development platform that
> developers love is also attractive to malware creators. Download this white
> paper to learn more about secure code signing practices that can help keep
> Android apps secure.
> http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Thomas Herchenroeder
On 10/30/2013 05:21 PM, Dietrich Streifert wrote:

> Hi Richard,
>
> Thank you for the hint!
>
> I've managed to install and use jshint which gave the following output:
>
> table.js: line 109, col 61, Extra comma. (it breaks older versions of IE)
>
> Now I have to get rid of those "Mixed spaces and tabs." warnings which
> currently pollute the output of jshint.

Have a go at 'generate.py fix' :-)

T.


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Dietrich Streifert
Yes! Thank you for the hint.

But that would change to much of my coding style.

Meanwhile I've managed to master the output of jshint by using a config
file (json.lint) like this:

{
     "globals": { "qx": false },
     "es3" : true,
     "-W099": true
}

You have to pass this file to jshint like this:

     jshint --config /somewhere/json.lint

The parameter "-W099" disables the specific warning about mixed tabs and
spaces.

To detect the problems with elisions in array initializers you have to
use the parameter "es3" and set it to true.

"globals": { "qx": false } disables the warning about the (in file
scope) undeclared global qx.


Am 30.10.2013 17:35, schrieb thron7:
> Have a go at 'generate.py fix':-)
>
> T.


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

fritz
You could also replace all tabs in your source code with spaces
in your editor. Emacs has the "untabify" function for this.

Cheers,
Fritz

On Thu, 31 Oct 2013, Dietrich Streifert wrote:

> Yes! Thank you for the hint.
>
> But that would change to much of my coding style.
>
> Meanwhile I've managed to master the output of jshint by using a config
> file (json.lint) like this:
>
> {
>     "globals": { "qx": false },
>     "es3" : true,
>     "-W099": true
> }
>
> You have to pass this file to jshint like this:
>
>     jshint --config /somewhere/json.lint
>
> The parameter "-W099" disables the specific warning about mixed tabs and
> spaces.
>
> To detect the problems with elisions in array initializers you have to
> use the parameter "es3" and set it to true.
>
> "globals": { "qx": false } disables the warning about the (in file
> scope) undeclared global qx.
>
>
> Am 30.10.2013 17:35, schrieb thron7:
>> Have a go at 'generate.py fix':-)
>>
>> T.
>
>
> ------------------------------------------------------------------------------
> Android is increasing in popularity, but the open development platform that
> developers love is also attractive to malware creators. Download this white
> paper to learn more about secure code signing practices that can help keep
> Android apps secure.
> http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
> _______________________________________________
> qooxdoo-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
>
>

--
Oetiker+Partner AG              tel: +41 62 775 9903 (direct)
Fritz Zaucker                        +41 62 775 9900 (switch board)
Aarweg 15                            +41 79 675 0630 (mobile)
CH-4600 Olten                   fax: +41 62 775 9905
Schweiz                         web: www.oetiker.ch

------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Thomas Herchenroeder
In reply to this post by Dietrich Streifert
On 10/31/2013 01:47 PM, Dietrich Streifert wrote:
> Yes! Thank you for the hint.
>
> But that would change to much of my coding style.

Really?! Fix shouldn't be so invasive, only fixing line endings,
tabs-to-spaces etc. ...

>
> Meanwhile I've managed to master the output of jshint by using a config
> file (json.lint) like this:
>
> {
>       "globals": { "qx": false },
>       "es3" : true,
>       "-W099": true
> }
>
> You have to pass this file to jshint like this:
>
>       jshint --config /somewhere/json.lint
>
> The parameter "-W099" disables the specific warning about mixed tabs and
> spaces.

Oh, and so intuitively, isn't it ;-).

>
> To detect the problems with elisions in array initializers you have to
> use the parameter "es3" and set it to true.
>
> "globals": { "qx": false } disables the warning about the (in file
> scope) undeclared global qx.

Thanks for letting us know.

T.


------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel
Reply | Threaded
Open this post in threaded view
|

Re: generate.py lint and dangling comma in array initialization

Dietrich Streifert
Hi Thomas,

you're right! I've mixed up "generate.py fix" with "generate.py pretty".

generate.py fix works unobtrusive in regard of my coding style ;-)

Regards
Dietrich

Am 31.10.2013 15:51, schrieb thron7:
> On 10/31/2013 01:47 PM, Dietrich Streifert wrote:
>> >Yes! Thank you for the hint.
>> >
>> >But that would change to much of my coding style.
> Really?! Fix shouldn't be so invasive, only fixing line endings,
> tabs-to-spaces etc. ...
>


------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
qooxdoo-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel