Re: Handling too few arguments in method calls

On Mon, 22 Jun 2009 02:53:22 +0200, Cameron McCormack <cam@mcc.id.au>  
wrote:

> From some very brief testing, it seems that Firefox and Opera tend
> to throw an exception when calling a method with too few arguments,
> while IE, Safari and Chrome will assume that the missing arguments were
> the undefined value.

Hmm. What did you use as test case?


> Extra arguments tend to be ignored.
>
> Does anyone have an opinion on which way this should be specified in Web
> IDL?  Assuming this interface:
>
>   interface A {
>     /* f1 */ void f(in DOMString a);
>     /* f2 */ void f(in DOMString a, in float b);
>     /* f3 */ void f(in DOMString a, in float b, in float c, in float d);
>   };
>
> option 1 would be to have:
>
>   a.f() be like calling f1 with (undefined)
>   a.f('a') be like calling f1 with ('a')
>   a.f('a', 1) be like calling f2 with ('a', 1)
>   a.f('a', 2, 3) be like calling f3 with ('a', 2, 3, undefined)
>   a.f('a', 2, 3, 4, 5) be like calling f3 with ('a', 2, 3, 4)
>
> and option 2 would be to have:
>
>   a.f() throw an exception
>   a.f('a') be like calling f1 with ('a')
>   a.f('a', 1) be like calling f2 with ('a', 1)
>   a.f('a', 2, 3) throw an exception
>   a.f('a', 2, 3, 4, 5) be like calling f3 with ('a', 2, 3, 4)
>
> Web IDL currently says to throw on any incorrect number of arguments,
> so it seems that it should change to be one of the above two options.

I think I prefer option 2. It's easier for authors to find their mistake.  
If a spec author wants the behavior of option 1, then that's possible with  
[Optional].

-- 
Simon Pieters
Opera Software

Received on Monday, 22 June 2009 07:06:20 UTC