W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2013

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

From: Ian Hickson <ian@hixie.ch>
Date: Tue, 17 Sep 2013 17:06:32 +0000 (UTC)
To: Simon Sarris <simon.sarris@gmail.com>
Message-ID: <alpine.DEB.2.00.1309171657450.12199@ps20323.dreamhostps.com>
Cc: whatwg@lists.whatwg.org
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.   `._.-(,_..'--(,_..'`-.;.'
Received on Tuesday, 17 September 2013 17:07:01 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 17:00:09 UTC