Bug 249114
| Summary: | Remove non-standard Range.compareNode() | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Ahmad Saleem <ahmad.saleem792> |
| Component: | DOM | Assignee: | Ahmad Saleem <ahmad.saleem792> |
| Status: | NEW | ||
| Severity: | Normal | CC: | karlcow, rniwa, webkit-bug-importer |
| Priority: | P2 | Keywords: | BrowserCompat, InRadar |
| Version: | Safari Technology Preview | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Ahmad Saleem
Hi Team,
While going through Blink commit's, I came across another non-standard, which is now only present in Webkit from quick Github search:
e.g., https://github.com/WebKit/WebKit/blob/bf6ec0b71883ada1ee6d8d0c66a8ea7e421c5e27/Source/WebCore/dom/Range.idl#L68 & https://github.com/WebKit/WebKit/blob/bf6ec0b71883ada1ee6d8d0c66a8ea7e421c5e27/Source/WebCore/dom/Range.cpp#L187
Blink Commit - https://chromium.googlesource.com/chromium/blink/+/9cec195ebb459d3ebdc7ef91a6336047c07ae5b7
Intent to Remove Thread - https://groups.google.com/a/chromium.org/g/blink-dev/c/5dNJaHFNFGM
Some background: Added in 2006 - https://trac.webkit.org/changeset/16302/webkit
MDN - https://developer.mozilla.org/en-US/docs/Web/API/range/compareNode (Removed from Firefox in 1.9)
Web-Spec - https://dom.spec.whatwg.org/#interface-range
Just wanted to raise bug to track it for discussion or for future tracking.
Thanks!
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Ryosuke Niwa
A quick GitHub search finds quite a few entries:
https://github.com/search?q=Range.compareNode+language%3AJavaScript&type=code&l=JavaScript
I don't think it's safe to remove this API.
Radar WebKit Bug Importer
<rdar://problem/103499504>
Karl Dubost
https://searchfox.org/wubkat/rev/36d40c7dfd972e688c9c0febea6821825a85d6ac/Source/WebCore/dom/Range.cpp#207-239
```cpp
ExceptionOr<Range::CompareResults> Range::compareNode(Node& node) const
{
// FIXME: This deprecated function should be removed.
// We originally added it for interoperability with Firefox.
// Recent versions of Firefox have removed it.
// http://developer.mozilla.org/en/docs/DOM:range.compareNode
// This method returns 0, 1, 2, or 3 based on if the node is before, after,
// before and after(surrounds), or inside the range, respectively.
if (!node.isConnected() || &node.document() != m_ownerDocument.ptr()) {
// Match historical Firefox behavior.
return NODE_BEFORE;
}
auto nodeRange = makeRangeSelectingNode(node);
if (!nodeRange) {
// Match historical Firefox behavior.
return Exception { ExceptionCode::NotFoundError };
}
auto startOrdering = treeOrder(nodeRange->start, makeBoundaryPoint(m_start));
auto endOrdering = treeOrder(nodeRange->end, makeBoundaryPoint(m_end));
if (is_gteq(startOrdering) && is_lteq(endOrdering))
return NODE_INSIDE;
if (is_lteq(startOrdering) && is_gteq(endOrdering))
return NODE_BEFORE_AND_AFTER;
if (is_lteq(startOrdering))
return NODE_BEFORE;
if (is_gteq(endOrdering))
return NODE_AFTER;
return Exception { ExceptionCode::WrongDocumentError };
}
```
Karl Dubost
I see 84 instances on GitHub
https://github.com/search?q=Range.compareNode+language%3AJavaScript&type=code&l=JavaScript
BUT but most of them have this pattern:
```
range.compareNode(editableHost) !== range.NODE_BEFORE_AND_AFTER
```
which comes from a DEPRECATED library
https://github.com/Fixxpunkt/editable.js/
They link
editable.js ⛔ [DEPRECATED] Active at https://github.com/Fixxpunkt/sto/
Which is itself dead.
The fork was from
https://github.com/search?q=repo%3AlivingdocsIO%2Feditable.js%20compareNode&type=code
which contains no compareNode hit.
Another one which has been archived
https://github.com/wymeditor/wymeditor
Ahmad Saleem
Pull request: https://github.com/WebKit/WebKit/pull/38385