Bug 160712

Summary: CharacterData.data setter optimization is not spec-compliant and is observable
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: DOMAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, commit-queue, esprehn+autocc, kangil.han, rniwa
Priority: P2 Keywords: WebExposed
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
URL: https://dom.spec.whatwg.org/#dom-characterdata-data
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Chris Dumez 2016-08-09 15:33:34 PDT
We have an optimization in CharacterData.setData() that avoid doing any work if the new data is identical to the old data. However, this optimization is not spec-compliant:
- https://dom.spec.whatwg.org/#dom-characterdata-data

This is an issue because this is observable using DOM mutation observer or ranges.
Comment 1 Chris Dumez 2016-08-09 15:44:05 PDT
Created attachment 285682 [details]
Patch
Comment 2 Ryosuke Niwa 2016-08-09 15:53:42 PDT
Comment on attachment 285682 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=285682&action=review

> Source/WebCore/dom/CharacterData.cpp:44
> +    auto& document = node.document();
> +    return !document.hasListenerType(Document::DOMCHARACTERDATAMODIFIED_LISTENER) && !document.hasMutationObserversOfType(MutationObserver::CharacterData);

We also need to check subtreemodified event.

> Source/WebCore/dom/CharacterData.cpp:53
> +        document().textRemoved(this, 0, oldLength);

We also need to call document().frame()->selection().textWasReplaced to be consistent.
Comment 3 Chris Dumez 2016-08-09 16:14:06 PDT
Created attachment 285685 [details]
Patch
Comment 4 Chris Dumez 2016-08-09 16:48:51 PDT
Created attachment 285689 [details]
Patch
Comment 5 WebKit Commit Bot 2016-08-09 17:11:53 PDT
Comment on attachment 285689 [details]
Patch

Clearing flags on attachment: 285689

Committed r204316: <http://trac.webkit.org/changeset/204316>
Comment 6 WebKit Commit Bot 2016-08-09 17:11:58 PDT
All reviewed patches have been landed.  Closing bug.