Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix #12370. Explicitly coerce bool/undef to integer.

  • Loading branch information...
commit 0ca936d2c911fe037dda3cb9d6e21f6fe1735a2c 1 parent 3a633b0
Dave Methvin authored August 30, 2012

Showing 1 changed file with 1 addition and 0 deletions. Show diff stats Hide diff stats

  1. 1  src/effects.js
1  src/effects.js
@@ -540,6 +540,7 @@ function genFx( type, includeWidth ) {
540 540
 
541 541
 	// if we include width, step value is 1 to do all cssExpand values,
542 542
 	// if we don't include width, step value is 2 to skip over Left and Right
  543
+	includeWidth = includeWidth? 1 : 0;
543 544
 	for( ; i < 4 ; i += 2 - includeWidth ) {
544 545
 		which = cssExpand[ i ];
545 546
 		attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;

0 notes on commit 0ca936d

David Murdoch

cough*whitespace*cough ;-)

Richard Gibson

If a browser really is failing on ToNumber(boolean) coercion in this expression, we'll have to clean up the other places in which we rely on that behavior. Is there any way for us to get strong confirmation?

Dave Methvin

My only defense is that I got distracted by the thought of using ~~includeWidth in the for loop. It saves a byte but I was concerned that if Android 2.1 is dumb it might also be dumber. I think we're at 1.8.1 now

Dave Methvin

It may have failed on converting undefined instead, I just saw the boolean call first. There are several genFx() calls with just one arg. Kinda makes me wonder how it ever worked... is this covered by a unit test? /cc @gnarf37

Richard Gibson

Yep, that would do it. And undefined casts to NaN, so there's your problem right there.

David Murdoch

Why not just update all calls to genFx to include the includeWith parameter as a Number?

In fact, you could just change includeWidth to stepValue and update all calls to genFx to pass a stepValue (1 or 2). I image there may be a couple of gzipped bytes to be saved here.

Dave Methvin

Could be, but I was primarily looking for a simple and safe fix for 1.8.1. Logically, includeWidth should be boolean; passing in a number doesn't make its purpose as clear.

David Murdoch

That's why I suggested changing the parameter name to stepValue. :-)

Dave Methvin

That's exposing too much of the internal workings imo.

Please sign in to comment.
Something went wrong with that request. Please try again.