[whatwg] Canvas - Should setLineDash be a nullable sequence?

Ian Hickson ian at hixie.ch
Tue Sep 17 10:06:32 PDT 2013


On Tue, 20 Aug 2013, Simon Sarris wrote:
>
> This is minor, but it did recently break formerly-working functionality 
> in Google Chrome, so maybe its worth a discussion.
> 
> The specification reads:
> 
>   void setLineDash(sequence<unrestricted double> segments); // default empty
>   sequence<unrestricted double> getLineDash();
> 
> This means we *cannot* use:
> 
> ctx.setLineDash(null);
>
> In Chrome 28 and previous (for at least 6 months) null was an allowed
> value, but in Chrome 30 (at least) it switched to throwing a TypeError.

I couldn't find any currently-shipping browsers that supported this, so it 
seems unlikely that there'd be much legacy content that depends on it. 
(Not saying there's none, just that it's limited in scope.) Thus, the 
compatibility issue here is not the only thing we should consider. (It's 
still a factor, just not an automatic win, as it might otherwise be.)

There's certainly an advantage to failing if the input is "null" here -- 
it's more likely to catch underlying errors quicker. Instead of just 
getting a solid line where you expected a dashed one, you get an error 
with a precise line number from which to start your search.


> In any case, I think it would be better if setLineDash was defined in 
> the spec as a nullable sequence, so that when setting it back to nothing 
> to return to normal not-dashed path stroking (which could happen 
> thousands of times in a an animation frame) less stuff gets allocated in 
> the draw loop.

A literal empty array can get optimised out by compilers, so it really 
shouldn't be that big a deal on the long run.


> I think part of the issue is that setLineDash does two things. It sets 
> the dashing properties, but it also acts as the only way to 
> enable/disable dashing, I think that null seems appropriate.

All lines are dashed, it's just that some have an infinitely long dash 
with no space. Don't look at it as enabling/disabling dashing. :-)

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list