Re: [whatwg] Why CanvasRenderingContext2D uses WebIDL unrestricted float type?

On Tue, Mar 24, 2015 at 1:06 PM, Tetsuharu OHZEKI <saneyuki.snyk@gmail.com>
wrote:

> Hi everybody.
>
> I have a question about the definition of CanvasRenderingContext2D's
> behavior.
>
> The current spec about CanvasRenderingContext2D says the following:
>
> > 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.
>
> https://html.spec.whatwg.org/multipage/scripting.html#canvasrenderingcontext2d
>
> But I think that, why don't  CanvasRenderingContext2D use restricted
> float type defined in WebIDL if these methods ignore the value when
> its is not finite?
>
> By the current WebIDL spec
> (http://heycam.github.io/webidl/#es-double), restricted values,
> 'float' & 'double', will raise TypeError in conversion phase under
> ECMAScript environment if the passed value is a NaN or +-Infinity.
>
> For the purpose to ignore non-restricted values, I feel that it's more
> better to restrict by IDL type. So the definitions by the current spec
> is for backward compatibility, or simply a spec issue?
>

We had a long discussion on this about a year ago.
In short, we want web APIs to be robust so that if a developer makes a
mistakes and passes a NaN or other strange value, the application will
attempt to keep on running.
Worst case, the app will crash later on anyway and best case, it will show
up as a short flicker or not at all.

Received on Tuesday, 24 March 2015 20:34:58 UTC