Re: Question about System Information API

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