[whatwg] Canvas API: What should happen if non-finite floats are used

Boris Zbarsky bzbarsky at MIT.EDU
Tue Sep 7 21:41:09 PDT 2010


Consider this testcase:

<!doctype html>
<html>
   <body>
     <canvas id="c" width="200" height="200"></canvas>
     <script>
     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); }
     </script>
   </body>
</html>

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.



More information about the whatwg mailing list