W3C home > Mailing lists > Public > public-script-coord@w3.org > July to September 2015

[Bug 29004] New: FrozenArray only provides shallow immutability

From: <nobody@w3.org>
Date: Wed, 29 Jul 2015 16:04:48 +0000
To: public-script-coord@w3.org
Message-ID: <bug-29004-3890@http.www.w3.org/Bugs/Public/>

            Bug ID: 29004
           Summary: FrozenArray only provides shallow immutability
           Product: WebAppsWG
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: WebIDL
          Assignee: cam@mcc.id.au
          Reporter: johnme@google.com
        QA Contact: public-webapps-bugzilla@w3.org
                CC: annevk@annevk.nl, bzbarsky@mit.edu, d@domenic.me,
                    jonas@sicking.cc, mike@w3.org,
  Target Milestone: ---

Bug 23682 introduced FrozenArray using Object.freeze as a "fixed length array
of unmodifiable values" (https://heycam.github.io/webidl/#idl-frozen-array).

But Object.freeze only provides shallow immutability: the values are not
writeable, but if the values are objects they can still be mutated.

It might be useful to have a deeper concept of immutability in WebIDL, e.g.:

A) Perhaps FrozenArray should non-recursively call Object.freeze on each of its
non-primitive values?

B) Or perhaps you should be able to declare:
  readonly attribute frozen Array<frozen Foo> foos;

For example, in https://github.com/whatwg/notifications/pull/48 I'm adding
action buttons to notifications with the following WebIDL:

partial dictionary NotificationOptions {
  sequence<NotificationAction> actions = [];
dictionary NotificationAction {
  required DOMString action;
  required DOMString title;

and would like the author to be able to read back the values they set using
something like:

partial interface Notification {
  readonly attribute FrozenArray<NotificationAction> actions;

But currently authors would be able to mutate the NotificationActions (or
specifically, the JS objects that WebIDL converts dictionaries to), and this
may lead to confusion, for example authors might incorrectly expect that
mutating the titles would update the button strings of currently showing or
soon to be shown notifications. It would also be inconsistent with all the
existing attributes on Notification which are immutable.

See also related discussion at

You are receiving this mail because:
You are on the CC list for the bug.
Received on Wednesday, 29 July 2015 16:04:51 UTC

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