[whatwg] relationship between Document and HTMLDocument

?3.1.1 includes the following:

interface HTMLDocument { ... };
Document implements HTMLDocument;

If I'm reading WebIDL correctly, this means that this expression must be 
false:

    document instanceof HTMLDocument

And also that this code will have no visible effect on the document object:

     HTMLDocument.prototype.foo = function() { ... }

Furthermore, if I want to monkeypatch a method like getElementsByName() 
that is defined by HTML, the correct place to do that is on 
Document.prototype, not HTMLDocument.prototype

Currently, of course (tested in FF, Chrome and Safari), browsers treat 
HTMLDocument as if it were declared like this:

     interface HTMLDocument : Document { ... };

This means that in the current generation of browsers:

    document instanceof HTMLDocument    // => true
    HTMLDocument.prototype.foo = function() {...}  // affects document
    Document.prototype.getElementsByName // undefined; can't monkeypatch it

I would guess (but have no data) that web compatibility will make these 
behaviors difficult to change.

I assume that the use of an implements declaration rather than direct 
inheritance is done to create a clean boundary between the DOM spec and 
the HTML spec.  But it seems to me that this clean boundary does not 
reflect messy reality.

Ian: any chance you'd change HTML to specify that HTMLDocument is a 
regular subclass of Document?

Anne: that would probably mean that you'd have to change the DOM spec to 
say that DOMImplementation.create*Document() creates an HTMLDocument 
even though your spec does not define that interface...

     David

Received on Tuesday, 9 August 2011 08:18:17 UTC