-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
The spec currently has a named getter on Document and all documents implementing the Document interface, with HTMLDocument an alias for Document.
There is no UA that implements that behavior. The implemented behavior is as follows, at this point:
- Firefox, Safari: HTML documents implement
HTMLDocument; other documents implementDocumentorXMLDocument, depending. The only thing on theHTMLDocumentinterface is the named getter. - Chrome: HTML Documents implement
HTMLDocument; other documents implementDocumentorXMLDocument, depending. The named getter is implemented only for HTML documents, and not even for all of those; see https://bugs.chromium.org/p/chromium/issues/detail?id=594008 for example. In general, the thing Chrome does matches no possible interpretation of the spec and can't be expressed in Web IDL; it's also generally considered buggy by the Chrome engineers, based on comments like https://cs.chromium.org/chromium/src/third_party/blink/renderer/bindings/core/v8/local_window_proxy.cc?l=523-526&rcl=620f938927faae403375f33d63e2a760a5ce0186
In practice, that means that XML documents returned from XHR's responseXML do not implement the named getter in any browser. Adding the named getter to those would be a pretty serious compat risk due to the [OverrideBuiltins] on Document: attribute values inside the document could then cause APIs to be overridden on the document object, where they are not overridden in any browsers right now.
It seems to me that the simplest path to interop and web compat here is to converge on the Firefox/Safari behavior: reintroduce HTMLDocument with a named getter on it and remove the named getter from Document.
Relevant testcases:
- Alerts
undefinedin Chrome and[object HTMLFormElement]in Safari/Firefox:
<!doctype html>
<script>
var url = 'data:text/html,<html xmlns="http://www.w3.org/1999/xhtml"><form name="x"/></html>';
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "document";
xhr.onload = function() {
alert(xhr.responseXML.x);
};
xhr.send();
</script>
- Alerts
undefinedin all browsers:
<!doctype html>
<script>
var url = 'data:text/xml,<html xmlns="http://www.w3.org/1999/xhtml"><form name="x"/></html>';
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "document";
xhr.onload = function() {
alert(xhr.responseXML.x);
};
xhr.send();
</script>
- Alerts
[object HTMLFormElement]in all browsers when served astext/htmlandundefinedin all browsers when served astext/xml:
<html xmlns="http://www.w3.org/1999/xhtml">
<form name="x"></form>
<script>
alert(document.x);
</script>
</html>
Per current spec, all of those testcases should always alert [object HTMLFormElement].