Bug 160712 - CharacterData.data setter optimization is not spec-compliant and is observable
Summary: CharacterData.data setter optimization is not spec-compliant and is observable
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://dom.spec.whatwg.org/#dom-char...
Keywords: WebExposed
Depends on:
Blocks:
 
Reported: 2016-08-09 15:33 PDT by Chris Dumez
Modified: 2016-08-09 17:11 PDT (History)
5 users (show)

See Also:


Attachments
Patch (390.30 KB, patch)
2016-08-09 15:44 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (390.49 KB, patch)
2016-08-09 16:14 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (391.29 KB, patch)
2016-08-09 16:48 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.