[[Get]] method on HTMLDocument (detailed review of the DOM)

(This is part of my detailed review of the Document Object Model section.)

The spec doesn't say what UAs are to do with the [[Get]] method on the  
HTMLDocument interface. There are some interoperability problems. See:

    http://simon.html5.org/test/html/dom/interfaces/HTMLDocument/Get-method/demos/

For reference I'll include my findings below:


-----------------8<-----------------

Firefox:

1. look for all _name elements_ element with the name="" X.
2. if one element was found, return that and abort these steps.
3. otherwise if two or more elements were found, return a nodelist of those
    elements and abort these steps.
4. otherwise, if document.getElementById(X) returns an _id element_
    return that and abort these steps.
5. return undefined.

A _name element_ is applet, embed, form, img, object

An _id element_ is applet, embed, img, object


Safari:

1. look for all _name elements_ and _id elements_ with the name="" or id=""
    X, respectively.
2. if one element was found, return that and abort these steps.
3. otherwise if two or more elements were found, return an HTMLCollection
    of those elements and abort these steps.
4. return undefined.

A _name element_ is applet, embed, form, iframe, img, object.

An _id element_ is applet, object.

object above means object that contains only whitespace and <param>s.

For iframes, return the element's contentWindow instead of the element.


IE:

It's hard to pin down what IE does. It seems to have special tokenization  
rules for <object>. It's like a pseudo-CDATA element that knows about  
<param>s. Whether the <object> will be replaced with its contents (which  
will be parsed as HTML at that point) depends on how the <param> tags are  
placed and where whitespace occurs, and the phase of the moon. Anyway, if  
it is to be replaced, it will be replaced after the load event has fired.  
See: http://krijnhoetmer.nl/irc-logs/whatwg/20071005#l-193

As an aside: it seems that setAttribute("name", "x") does nothing in IE on  
applet, embed, form, iframe, img, object, if the element didn't have a  
name="" attribute before.

Whether it is replaced of course affects what [[Get]] returns, and when  
you call [[Get]] (before or after the load event).

Anyway.

1. look for all _name elements_ and _id elements_ with the name="" or id=""
    X, respectively.
2. if one element was found, return that and abort these steps.
3. otherwise if two or more elements were found, return a collection of
    those elements and abort these steps.
4. return undefined.

A _name element_ is applet, embed, form, iframe, img, object.

An _id element_ is applet, object.

For iframes, return the element's contentWindow instead of the element.


Opera:

1. look for all _name elements_ and _id elements_ with the name="" or id=""
    X, respectively.
2. if one element was found, return that and abort these steps.
3. otherwise if two or more elements were found, return a collection of
    those elements and abort these steps.
4. return undefined.

A _name element_ is applet, embed, form, iframe, img, object.

An _id element_ is applet, embed, form, iframe, img, object.


  * * *

Now, as you might imagine, the biggest interoperability problem arises  
 from the fact that IE does its crazy thing with replacing object elements  
with their contents. In particular the following case:

    <object id=x><embed name=x></object>

Scripts will assume that document.x returns an element and not an array.  
Opera will return an array. We can't do what IE does. So that leaves the  
Safari approach and the Firefox approach. Safari seems to be closer to IE.

----------------->8-----------------


I'd suggest to spec what Safari does, except s/whitespace and  
<param>s/comments, PIs, whitespace and <param>s/

Test cases for that:  
http://simon.html5.org/test/html/dom/interfaces/HTMLDocument/Get-method/

-- 
Simon Pieters
Opera Software

Received on Friday, 5 October 2007 16:55:16 UTC