Skip to content

We should probably reinstate HTMLDocument, with a named getter, in the spec #4792

@bzbarsky

Description

@bzbarsky

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:

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 undefined in 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 undefined in 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 as text/html and undefined in all browsers when served as text/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].

Metadata

Metadata

Assignees

No one assigned

    Labels

    interopImplementations are not interoperable with each otherneeds testsMoving the issue forward requires someone to write tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions