This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23189 - Better defaults for #observe options
Summary: Better defaults for #observe options
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-09 19:22 UTC by Robin Berjon
Modified: 2013-09-10 12:10 UTC (History)
4 users (show)

See Also:


Attachments

Description Robin Berjon 2013-09-09 19:22:51 UTC
http://dom.spec.whatwg.org/#interface-mutationobserver

[[
If attributeOldValue is true and attributes is not true, throw a "SyntaxError".

If attributeFilter is a non-empty array and attributes is not true, throw a "SyntaxError".

If characterDataOldValue is true and characterData is not true, throw a "SyntaxError". 
]]

Why not consider that attributes is automatically set to true for the first two, and likewise characterData for the third? It's certainly what the developer meant, and it's less typing.
Comment 1 Jonas Sicking (Not reading bugmail) 2013-09-09 21:11:47 UTC
I do think we want

{ attributes: false, attributeOldValue: true }
and
{ characterData: false, characterOldData: true }

to both throw an exception. What we could do is to make the default value of attributes/characterData depend on the value of the *Old* properties though, rather than being statically set in the WebIDL.
Comment 2 Olli Pettay 2013-09-09 23:27:29 UTC
Yeah, if attributes is not set and attributeOldValue or attributeFilter is set
(true or false and any array), then attributes becomes implicitly true.
Same with characterData
Comment 3 Anne 2013-09-10 11:04:27 UTC
So a new model would look like:

dictionary MutationObserverInit {
  boolean childList = false;
  boolean attributes;
  boolean characterData;
  boolean subtree = false;
  boolean attributeOldValue = false;
  boolean characterDataOldValue = false;
  sequence<DOMString> attributeFilter;
};

* If options' attributeOldValue is true and options' attributes is omitted, set options' attributes to true.

* If options' attributeFilter is present and options' attributes is omitted, set
options' attributes to true.

* If options' characterDataOldValue is true and options' characterData is omitted, set options' characterData to true.

* If none of options' childList, attributes, and characterData is true, throw a TypeError.

* If attributeOldValue is true and attributes is false, throw a TypeError.

* If attributeFilter is a non-empty array and attributes is false, throw a TypeError.

* If characterDataOldValue is true and characterData is false, throw a TypeError.

(I also changed the exception to a JavaScript TypeError in our quest to more closely integrate with JavaScript.)
Comment 4 Robin Berjon 2013-09-10 12:05:05 UTC
That LGTM.
Comment 5 Anne 2013-09-10 12:10:07 UTC
I made a few more tweaks relative to comment 3.

Only check for attributeFilter being present, rather than non-empty. Not have default values at all for the *OldValue members and check for their presence rather than checking if they are true when setting attributes/characterData to true.

https://github.com/whatwg/dom/commit/a770b11981f4c147f98753cf726e44b14d17affc