Re: [WebIDL] A new way to define UnionTypes

On Wed, Aug 29, 2012 at 8:11 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> On 8/29/12 7:59 AM, Andrei Bucur wrote:
>> I was wondering if it would make sense to use supplemental interfaces as a
>> way to generate union types, like in this example:
>> X implements S
>> Y implements S
>> Z implements S
>>
>> interface someInterface
>> {
>>         NewSyntaxGeneratingUnionTypeFrom(S) someMethod();
>> }
>
> Why can't you just do:
>
>  interface someInterface
>  {
>     S someMethod();
>  };
>
>
> ?
>
>> Having this syntax makes it easy to define functions that will definitely
>> return objects adhering to a certain interface but are not necessary
>> containing S in the prototype chain.
>
> Yes, that's the idea of "implements"...
>
>> A real life use case for this is the Region interface [1]. Right now, the
>> only interface implementing Region is Element. The plan is to also allow
>> pseudo elements [2] implement the Region interface. Because Element and
>> CSSPseudoElement are totally different types it is impossible to define a
>> method that returns a "Region" (e.g. NamedFlow.getRegions() [3]).
>
> Why is it impossible, exactly?  Just define it as returning a Region in the
> IDL.

It's not impossible in IDL.  In fact, it's remarkably easy to define
in IDL.  We just don't want to implement multi-inheritance in WebKit
because it's slow.  However, I don't see how Andrei's proposal makes
the implementation any more efficient.

Note: Gecko already pays this implementation cost because XPCOM
support queryInterface.  We'd rather not add queryInterface to WebKit.

Adam

Received on Wednesday, 29 August 2012 16:07:47 UTC