[whatwg] relationship between Document and HTMLDocument

On 8/9/11 12:53 PM, Ian Hickson wrote:
> On Tue, 9 Aug 2011, David Flanagan wrote:
>> ?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.
> Possibly. I think an alternative is to make the HTML spec just add all the
> members to Document, and then define window.HTMLDocument as returning the
> Document interface object. This would make instanceof and "monkeypatching"
> work as today.
>
So you'd declare HTMLDocument with the [NoInterfaceObject] extended 
attribute and then add attribute HTMLDocument to the Window interface?  
That changes HTMLDocument from non-enumerable to enumerable, but that 
seems unlikely to be a compatibility issue.  That works for me, I think.

     David

Received on Tuesday, 9 August 2011 13:10:30 UTC