W3C home > Mailing lists > Public > public-script-coord@w3.org > April to June 2012

Re: Why are dictionary-typed attributes not allowed?

From: Cameron McCormack <cam@mcc.id.au>
Date: Thu, 07 Jun 2012 15:38:14 +1000
Message-ID: <4FD03E46.6010606@mcc.id.au>
To: Boris Zbarsky <bzbarsky@MIT.EDU>
CC: public-script-coord@w3.org
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;


   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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 17:14:06 UTC