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

Jonas Sicking jonas at sicking.cc
Tue Sep 7 22:36:31 PDT 2010

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 <weinig at apple.com> wrote:
> In 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:
>> <!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