W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2009

Handling too few arguments in method calls

From: Cameron McCormack <cam@mcc.id.au>
Date: Mon, 22 Jun 2009 10:53:22 +1000
To: public-webapps@w3.org
Message-ID: <20090622005322.GB27182@arc.mcc.id.au>
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.  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.

Thanks,

Cameron

-- 
Cameron McCormack ≝ http://mcc.id.au/
Received on Monday, 22 June 2009 00:54:13 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:31 GMT