Closed GoogleCodeExporter closed 8 years ago
I've got another one of those -- "m[2]||0" on the last line of the below code
causes
the "Code has no side effect" warning:
Date.parseDuration = function(str) {
/* Converts an iCalendar (ISO8601 except year and month values) duration to a
number of milliseconds. */
var m;
if (m =
str.match(/^\s*([+-]?)P(?:(\d+)W)?(?:(\d+)D)?T?(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?
\s*$/)) {
return (m[1] === '-' ? -1000 : 1000) * (parseInt(m[6]||0,10) +
60 * (parseInt(m[5]||0,10) +
60 * (parseInt(m[4]||0,10) +
24 * (parseInt(m[3]||0,10) +
7 *
parseInt((m[2]||0,10))))));
}
};
Original comment by andreasl...@gmail.com
on 11 Jun 2008 at 8:36
The first example is fixed already.
Andreas's example is fixed for the next release.
I'm not sure why Rhino checks expressions for side-effects; the check at the
statement level seems sufficient. I've removed the former and kept the latter,
and
it fixes this.
Original comment by steve.ye...@gmail.com
on 16 Jun 2008 at 6:06
Original comment by steve.ye...@gmail.com
on 16 Jun 2008 at 8:04
Whoops, wait a second. I didn't see the extra set of parentheses way down there:
parseInt((m[2]||0,10))
That comma is actually interpreted as the C-like comma operator that takes two
expressions and returns the second one, so (m[2]||0,10) will always evaluate to
10,
no matter what m[2] is.
Please keep that warning after all!
Original comment by andreasl...@gmail.com
on 16 Jun 2008 at 10:05
Original issue reported on code.google.com by
huntermo...@gmail.com
on 30 Apr 2008 at 1:02