Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On Wed, 8 Sep 2010, Boris Zbarsky wrote: > > Consider this testcase: > > > > > > > try { > var c = document.getElementById("c"), > t = c.getContext("2d"); > t.moveTo(100, 100); > t.lineTo(NaN, NaN); > t.lineTo(50, 25); > t.stroke(); > } catch (e) {alert(e); } > > > > > Behavior in the spec seems to be undefined (in particular, no mention is > made as to what the canvas API functions are supposed to do if > non-finite values are passed in). [...] On Tue, 7 Sep 2010, Sam Weinig wrote: > > In 4.8.11.1 the spec does state: > > "Except where otherwise specified, for the 2D context interface, any > method call with a numeric argument whose value is infinite or a NaN > value must be ignored." Right. This was intentional; if I recall correctly it was based on the idea that "3D" code rendering to a 2D canvas would often find itself dealing with asymptotic behaviour and that it was better to silently ignore such edge cases than to bail entirely as used to happen. There's actually a comment to that effect in the spec source: Except where otherwise specified, for the 2D context interface, any method call with a numeric argument whose value is infinite or a NaN value must be ignored. I don't personally have a strong opinion on this, and will likely just update the spec to match what the majority of implementations do in due course, if that changes. Currently it seems to be a bit of a mixed bag. -- Ian Hickson U+1047E)\._.,--,'``.fL http://ln.hixie.ch/ U+263A/, _.. \ _\ ;`._ ,. Things that are impossible just take longer. `._.-(,_..'--(,_..'`-.;.'
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On 9/8/10 7:04 PM, Philip Taylor wrote: I think the relevant bug is https://bugs.webkit.org/show_bug.cgi?id=13537 which was actually caused by passing 0 sizes to drawImage, not by non-finite values. Ah, yes. The drawImage size check for 0 in Gecko is still nonthrowing, and has never thrown to my knowledge. But that has nothing to do with the issue I initially raised. Nor does the fix for that Webkit bug have anything to do with the issue I raised. -Boris
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On Wed, Sep 8, 2010 at 9:02 PM, Boris Zbarsky wrote: > On 9/8/10 2:22 PM, Oliver Hunt wrote: >> One old case that failed in the presence of exceptions was the old canvex >> demo at http://canvex.lazyilluminati.com/83/play.xhtml - this was one of the >> first cases i saw after trying to make webkit's implementation conform to >> the (older) spec by throwing exceptions on non-finite values we had many >> canvas using sites break so had to stop throwing. > > OK. I can believe that this was the case at the time, but it certainly > wasn't due to Firefox not throwing. I can see how given people's penchant > to create browser-specific content changing the webkit behavior could cause > issues with sites that were targeting only webkit and didn't bother testing > in anything else. Canvex was originally written for and tested in Firefox 1.5/2.0 and Opera 9. It wasn't tested in Safari (due to lack of Mac). I think the relevant bug is https://bugs.webkit.org/show_bug.cgi?id=13537 which was actually caused by passing 0 sizes to drawImage, not by non-finite values. -- Philip Taylor exc...@gmail.com
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On 9/8/10 2:22 PM, Oliver Hunt wrote: I can see a number of canvas discussions in late 2007/early 2008 on the whatwg list, so i presume that covers some of it. OK. All versions of Firefox threw at that point. It also only leads to incorrect rendering if the behaviour if it's unexpected. Well... I guess that depends on how you define "correct rendering". The case where I ran into was graphing a function; due to Webkit ignoring the calls that use NaN the graph is completely wrong (the actual function has a singularity at 0 which entirely disappears, with a smooth interpolation between two points pretty far away from zero shown instead). One old case that failed in the presence of exceptions was the old canvex demo at http://canvex.lazyilluminati.com/83/play.xhtml - this was one of the first cases i saw after trying to make webkit's implementation conform to the (older) spec by throwing exceptions on non-finite values we had many canvas using sites break so had to stop throwing. OK. I can believe that this was the case at the time, but it certainly wasn't due to Firefox not throwing. I can see how given people's penchant to create browser-specific content changing the webkit behavior could cause issues with sites that were targeting only webkit and didn't bother testing in anything else. It seems to work these days but a quick scan of the minified source seemed to indicate that they now put try/catch around every use of canvas is now wrapped in try/catch Right. Which raises the question of whether this would be an issue nowadays. With the exception of that one graphing demo (which was on a "Chrome demos" site, iirc so again is targeting webkit), we have had no reports of this being an issue in Gecko. -Boris
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On Sep 8, 2010, at 11:00 AM, Boris Zbarsky wrote: > On 9/8/10 12:45 PM, Oliver Hunt wrote: >> I suggested this behaviour a long time ago after running into yet >> another piece of code that hit this case in webkit (back when the >> spec said to throw an exception) yet firefox and opera did not throw. >> In some cases firefox does throw, and in others it doesn't (or maybe >> didn't? has ffx behaviour changed?) > > Gecko behavior for lineTo and most other canvas methods I see has been to > throw since late 2006, and shipped with the initial release of Firefox 3.0. > At the time, the change was also backported to the Firefox 1.5 and Firefox 2 > branches. > >> and we came to the conclusion that as much as possible the canvas should >> silently ignore >> NaN/Infinite values. > > Well, except that leads to incorrect rendering, as I said. Was this > discussion public, perchance? I can see a number of canvas discussions in late 2007/early 2008 on the whatwg list, so i presume that covers some of it. It also only leads to incorrect rendering if the behaviour if it's unexpected. One old case that failed in the presence of exceptions was the old canvex demo at http://canvex.lazyilluminati.com/83/play.xhtml - this was one of the first cases i saw after trying to make webkit's implementation conform to the (older) spec by throwing exceptions on non-finite values we had many canvas using sites break so had to stop throwing. It seems to work these days but a quick scan of the minified source seemed to indicate that they now put try/catch around every use of canvas is now wrapped in try/catch --Oliver
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On 9/8/10 1:33 PM, Oliver Hunt wrote: Additionally there is content that depends on the non-throwing behaviour, in webkit we had to drop the exceptions that we threw due to content that worked in firefox because of the absence of exceptions. I'm really curious about this claim. Looking at the code, we seem to throw on all the functions I see that take floats if the float is non-finite, and those checks all go back to November 2006. Were you running into compat issues _before_ that or something? Note that before we added the checks we just passed the non-finite values to the drawing library, which typically crashed rather than "silently working". -Boris
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On Wed, Sep 8, 2010 at 10:33 AM, Oliver Hunt wrote: > In a lot of cases all you want to do is ignore NaN and Infinite values, > otherwise you basically have to prepend every call to canvas with NaN and > Infinity checks if you're computing values unless you can absolutely > guarantee your values won't have gone nuts at any point in the computation -- > otherwise you're going to get reports that occasionally your content breaks > but with no repro case (typical users will not be seeing error messages, it > just "doesn't work"). Does this mean that you're expecting that the ignored calls didn't matter? Surely having parts of the drawing be missing will often be noticed by users as well! Mike
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On 9/8/10 12:45 PM, Oliver Hunt wrote: I suggested this behaviour a long time ago after running into yet another piece of code that hit this case in webkit (back when the spec said to throw an exception) yet firefox and opera did not throw. In some cases firefox does throw, and in others it doesn't (or maybe didn't? has ffx behaviour changed?) Gecko behavior for lineTo and most other canvas methods I see has been to throw since late 2006, and shipped with the initial release of Firefox 3.0. At the time, the change was also backported to the Firefox 1.5 and Firefox 2 branches. and we came to the conclusion that as much as possible the canvas should silently ignore NaN/Infinite values. Well, except that leads to incorrect rendering, as I said. Was this discussion public, perchance? -Boris
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On Sep 8, 2010, at 10:20 AM, Eric Uhrhane wrote: > On Wed, Sep 8, 2010 at 9:45 AM, Oliver Hunt wrote: >> The problem with throwing an exception is that it's fairly common for code >> to end up accidentally producing a NaN or Infinite value, and throwing an >> exception would prevent all subsequent drawing from occurring. > > I believe that was the point: you throw an exception, the bug becomes > obvious, and you fix it. Without the exception, you draw the wrong > thing, and it's much harder to find the problem. In a lot of cases all you want to do is ignore NaN and Infinite values, otherwise you basically have to prepend every call to canvas with NaN and Infinity checks if you're computing values unless you can absolutely guarantee your values won't have gone nuts at any point in the computation -- otherwise you're going to get reports that occasionally your content breaks but with no repro case (typical users will not be seeing error messages, it just "doesn't work"). Additionally there is content that depends on the non-throwing behaviour, in webkit we had to drop the exceptions that we threw due to content that worked in firefox because of the absence of exceptions. In the ended we spec'd these values as being ignored so that there was some degree of consistency through the API (and because the various UAs that support canvas would through on non-finite values in differing functions). --Oliver
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
On Wed, Sep 8, 2010 at 9:45 AM, Oliver Hunt wrote: > The problem with throwing an exception is that it's fairly common for code to > end up accidentally producing a NaN or Infinite value, and throwing an > exception would prevent all subsequent drawing from occurring. I believe that was the point: you throw an exception, the bug becomes obvious, and you fix it. Without the exception, you draw the wrong thing, and it's much harder to find the problem. > I suggested this behaviour a long time ago after running into yet another > piece of code that hit this case in webkit (back when the spec said to throw > an exception) yet firefox and opera did not throw. In some cases firefox > does throw, and in others it doesn't (or maybe didn't? has ffx behaviour > changed?) and we came to the conclusion that as much as possible the canvas > should silently ignore NaN/Infinite values. > > --Oliver > > On Sep 7, 2010, at 10:36 PM, Jonas Sicking wrote: > >> This seems like a strange choice of behavior. Given that this is very >> likely a bug in the program, wouldn't it make more sense to throw an >> exception as to make it easier to debug? Similar to for example >> Node.appendChild when called with a null argument. >> >> / Jonas >> >> On Tue, Sep 7, 2010 at 10:32 PM, Sam Weinig wrote: >>> In 4.8.11.1 the spec does state: >>> >>> "Except where otherwise specified, for the 2D context interface, any method >>> call with a numeric argument whose value is infinite or a NaN value must be >>> ignored." >>> >>> -Sam >>> >>> On Sep 7, 2010, at 9:41 PM, Boris Zbarsky wrote: >>> Consider this testcase: try { var c = document.getElementById("c"), t = c.getContext("2d"); t.moveTo(100, 100); t.lineTo(NaN, NaN); t.lineTo(50, 25); t.stroke(); } catch (e) {alert(e); } Behavior in the spec seems to be undefined (in particular, no mention is made as to what the canvas API functions are supposed to do if non-finite values are passed in). Behavior in browsers is: Presto: Throws NOT_SUPPORTED_ERR on that lineTo(NaN, NaN) call. Gecko: Throws DOM_SYNTAX_ERR on that lineTo(NaN, NaN) call. Webkit: Silently ignores the lineTo(NaN, NaN) call, and then draws a line from (100,100) to (50, 25). Seems like the spec needs to define this. -Boris P.S. This isn't a hypothetical issue; this came up in a page that was trying to graph things using canvas and ending up with divide-by-0 all over the place. It "worked" in webkit (though not drawing the right thing, so much). It failed to draw anything in Presto or Gecko. >>> >>> > >
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
The problem with throwing an exception is that it's fairly common for code to end up accidentally producing a NaN or Infinite value, and throwing an exception would prevent all subsequent drawing from occurring. I suggested this behaviour a long time ago after running into yet another piece of code that hit this case in webkit (back when the spec said to throw an exception) yet firefox and opera did not throw. In some cases firefox does throw, and in others it doesn't (or maybe didn't? has ffx behaviour changed?) and we came to the conclusion that as much as possible the canvas should silently ignore NaN/Infinite values. --Oliver On Sep 7, 2010, at 10:36 PM, Jonas Sicking wrote: > This seems like a strange choice of behavior. Given that this is very > likely a bug in the program, wouldn't it make more sense to throw an > exception as to make it easier to debug? Similar to for example > Node.appendChild when called with a null argument. > > / Jonas > > On Tue, Sep 7, 2010 at 10:32 PM, Sam Weinig wrote: >> In 4.8.11.1 the spec does state: >> >> "Except where otherwise specified, for the 2D context interface, any method >> call with a numeric argument whose value is infinite or a NaN value must be >> ignored." >> >> -Sam >> >> On Sep 7, 2010, at 9:41 PM, Boris Zbarsky wrote: >> >>> Consider this testcase: >>> >>> >>> >>> >>> >>> >>>try { >>> var c = document.getElementById("c"), >>> t = c.getContext("2d"); >>> t.moveTo(100, 100); >>> t.lineTo(NaN, NaN); >>> t.lineTo(50, 25); >>> t.stroke(); >>>} catch (e) {alert(e); } >>> >>> >>> >>> >>> Behavior in the spec seems to be undefined (in particular, no mention is >>> made as to what the canvas API functions are supposed to do if non-finite >>> values are passed in). Behavior in browsers is: >>> >>> Presto: Throws NOT_SUPPORTED_ERR on that lineTo(NaN, NaN) call. >>> Gecko: Throws DOM_SYNTAX_ERR on that lineTo(NaN, NaN) call. >>> Webkit: Silently ignores the lineTo(NaN, NaN) call, and then >>>draws a line from (100,100) to (50, 25). >>> >>> Seems like the spec needs to define this. >>> >>> -Boris >>> >>> P.S. This isn't a hypothetical issue; this came up in a page that was >>> trying to graph things using canvas and ending up with divide-by-0 all over >>> the place. It "worked" in webkit (though not drawing the right thing, so >>> much). It failed to draw anything in Presto or Gecko. >> >>
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
This seems like a strange choice of behavior. Given that this is very likely a bug in the program, wouldn't it make more sense to throw an exception as to make it easier to debug? Similar to for example Node.appendChild when called with a null argument. / Jonas On Tue, Sep 7, 2010 at 10:32 PM, Sam Weinig wrote: > In 4.8.11.1 the spec does state: > > "Except where otherwise specified, for the 2D context interface, any method > call with a numeric argument whose value is infinite or a NaN value must be > ignored." > > -Sam > > On Sep 7, 2010, at 9:41 PM, Boris Zbarsky wrote: > >> Consider this testcase: >> >> >> >> >> >> >> try { >> var c = document.getElementById("c"), >> t = c.getContext("2d"); >> t.moveTo(100, 100); >> t.lineTo(NaN, NaN); >> t.lineTo(50, 25); >> t.stroke(); >> } catch (e) {alert(e); } >> >> >> >> >> Behavior in the spec seems to be undefined (in particular, no mention is >> made as to what the canvas API functions are supposed to do if non-finite >> values are passed in). Behavior in browsers is: >> >> Presto: Throws NOT_SUPPORTED_ERR on that lineTo(NaN, NaN) call. >> Gecko: Throws DOM_SYNTAX_ERR on that lineTo(NaN, NaN) call. >> Webkit: Silently ignores the lineTo(NaN, NaN) call, and then >> draws a line from (100,100) to (50, 25). >> >> Seems like the spec needs to define this. >> >> -Boris >> >> P.S. This isn't a hypothetical issue; this came up in a page that was >> trying to graph things using canvas and ending up with divide-by-0 all over >> the place. It "worked" in webkit (though not drawing the right thing, so >> much). It failed to draw anything in Presto or Gecko. > >
Re: [whatwg] Canvas API: What should happen if non-finite floats are used
In 4.8.11.1 the spec does state: "Except where otherwise specified, for the 2D context interface, any method call with a numeric argument whose value is infinite or a NaN value must be ignored." -Sam On Sep 7, 2010, at 9:41 PM, Boris Zbarsky wrote: > Consider this testcase: > > > > > > >try { > var c = document.getElementById("c"), > t = c.getContext("2d"); > t.moveTo(100, 100); > t.lineTo(NaN, NaN); > t.lineTo(50, 25); > t.stroke(); >} catch (e) {alert(e); } > > > > > Behavior in the spec seems to be undefined (in particular, no mention is made > as to what the canvas API functions are supposed to do if non-finite values > are passed in). Behavior in browsers is: > > Presto: Throws NOT_SUPPORTED_ERR on that lineTo(NaN, NaN) call. > Gecko: Throws DOM_SYNTAX_ERR on that lineTo(NaN, NaN) call. > Webkit: Silently ignores the lineTo(NaN, NaN) call, and then >draws a line from (100,100) to (50, 25). > > Seems like the spec needs to define this. > > -Boris > > P.S. This isn't a hypothetical issue; this came up in a page that was trying > to graph things using canvas and ending up with divide-by-0 all over the > place. It "worked" in webkit (though not drawing the right thing, so much). > It failed to draw anything in Presto or Gecko.
[whatwg] Canvas API: What should happen if non-finite floats are used
Consider this testcase: try { var c = document.getElementById("c"), t = c.getContext("2d"); t.moveTo(100, 100); t.lineTo(NaN, NaN); t.lineTo(50, 25); t.stroke(); } catch (e) {alert(e); } Behavior in the spec seems to be undefined (in particular, no mention is made as to what the canvas API functions are supposed to do if non-finite values are passed in). Behavior in browsers is: Presto: Throws NOT_SUPPORTED_ERR on that lineTo(NaN, NaN) call. Gecko: Throws DOM_SYNTAX_ERR on that lineTo(NaN, NaN) call. Webkit: Silently ignores the lineTo(NaN, NaN) call, and then draws a line from (100,100) to (50, 25). Seems like the spec needs to define this. -Boris P.S. This isn't a hypothetical issue; this came up in a page that was trying to graph things using canvas and ending up with divide-by-0 all over the place. It "worked" in webkit (though not drawing the right thing, so much). It failed to draw anything in Presto or Gecko.