Re: Why are dictionary-typed attributes not allowed?

Boris Zbarsky:
> WebIDL allows passing dictionaries to methods and returning dictionaries
> from methods.  Why are dictionary-typed attributes not allowed?
>
> Or put another way, why is this not OK:
>
>    attribute DictType foo;
>
> while this is OK:
>
>    void setFoo(DictType arg);
>    DictType getFoo();
>
> ?

Because dictionaries are meant to be "pass by value" types, like 
sequences.  Because you would be returning a plain JS object – and a new 
one each time at that – it wouldn't be suitable for use as an attribute 
type.  The platform object wouldn't be able to "watch" for modifications 
of the JS object, if you did

   myObject.foo.member = 123;

just as if you were allowed to have:

   interface A {
     sequence<long> xs;
   };

where

   a.xs[5] = 1;

would not have the effect that authors would expect.  Requiring them to 
be passed to and returned from operations helps convey that a copy of 
the object is going to be made (or at least the effect is going to be as 
if a copy is made).

Received on Thursday, 7 June 2012 05:38:51 UTC