W3C home > Mailing lists > Public > public-device-apis@w3.org > March 2011

Re: Question about System Information API

From: Robin Berjon <robin@berjon.com>
Date: Mon, 21 Mar 2011 13:38:42 +0100
Cc: Mark Watson <watsonm@netflix.com>, public-device-apis@w3.org
Message-Id: <8C7ADF4D-0D8B-410C-9075-8371A4A703FD@berjon.com>
To: Cameron McCormack <cam@mcc.id.au>
Hi Cameron,

On Mar 17, 2011, at 21:42 , Cameron McCormack wrote:
> Mark Watson:
>> However, in the examples, such as the example in 4.4, a function
>> "success" is defined and it is this function that is supplied as the
>> argument (in this case to the monitor method).
>> How is it that the success function is compliant to the SuccessCB
>> interface, which has the method onSuccess ?
> It is due to the interfaces being defined like this:
>  [Callback=FunctionOnly, NoInterfaceObject]
>  interface SuccessCB {
>    void onSuccess(optional Object obj);
>  };
> The [Callback] indicates that the object may be implemented by user
> script.  That would be sufficient to allow a Function object to be
> passed as a SuccessCB.  The FunctionOnly part disallows passing an
> object { onSuccess: function(obj) {  } }.
> http://dev.w3.org/2006/webapi/WebIDL/#Callback

Mark is not the first one to be (IMHO understandably) confused by this somewhat arcane construct. I know that you already have a lot on your plate with WebIDL, but I was wondering if you'd considered some syntax to make this more straightforward to specify. Since we don't care about Java, I've thought of switching to just Function but I don't like losing the ability to specify the callback's signature.

Mark, some extra information just so you know where this comes from: in JS it's not a problem at all to just pass a Function object and have it be called back. But in other languages that's not possible and you might have to construct a special class of type SuccessCB with a specific onSuccess method in order to handle the callbacks. Since WebIDL is supposed to be language-independent the above construct makes it possible to generate either approach depending on the specific language binding.

Robin Berjon - http://berjon.com/
Received on Monday, 21 March 2011 12:39:10 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 14:53:48 UTC