Open Bug 843881 Opened 11 years ago Updated 2 years ago

createElement image returns HTMLElement instead of HTMLUnknownElement

Categories

(Core :: DOM: Core & HTML, defect, P5)

x86_64
Linux
defect

Tracking

()

People

(Reporter: erik, Unassigned)

Details

The following fails

assert(document.createElement('image').constructor === HTMLImageElement);
assert(document.createElement('image').constructor !== HTMLSpanElement);

It is really confusing to get an HTMLSpanElement out of this
We've had this behavior for a decade.  Not really sure why.
Maybe we used to use span for what now is just a generic html element?
Henri might remember.
image is odd element.
"image" is not special for purposes of createElement.  It's just like "foo" or "xyzw" or "noSuchElementName".

So we should be creating an HTMLUnknownElement here, as far as I can tell (but aren't, for silly historical reasons that predate the existence of HTMLUnknownElement as I recall).  We should consider going through nsHTMLTagList.h and fixing up the various things that claim "Span" for the second argument; some of these should be HTMLUnknownElement and some apparently actually have interfaces for them in HTML5 (basefont???).
Whiteboard: [mentor=bz][lang=c++][good first bug]
(In reply to Erik Arvidsson from comment #0)
> The following fails
> 
> assert(document.createElement('image').constructor === HTMLImageElement);

This should fail. That it doesn't is a bug in WebKit.
OS: Linux → All
Hardware: x86_64 → All
(In reply to :Ms2ger from comment #5)
> (In reply to Erik Arvidsson from comment #0)
> > The following fails
> > 
> > assert(document.createElement('image').constructor === HTMLImageElement);
> 
> This should fail. That it doesn't is a bug in WebKit.

document.createElement("image"); results in an HTMLImageElement in IE10, too. Maybe we should just align instead of fighting it. Need more testing first to see if such elements actually work in WebKit and IE.
OS: All → Linux
Hardware: All → x86_64
ccing Anne, since this would need domcore spec changes to create an element with localName "img" when createElement("image") is called...  At least that's what WebKit does, so I would expect that it "works" just fine once created.
Not just createElement() it seems. :-(

http://software.hixie.ch/utilities/js/live-dom-viewer/

<script>w(document.createElementNS("http://www.w3.org/1999/xhtml", "image"))</script>

Maybe the conceptual model should be that the local name and namespace are decided by the class that is mapped to. Might also work better for custom elements.
> Not just createElement() it seems. :-(

Just in WebKit, or in IE10 too?
IE9 at least, cannot test IE10.
So maybe we should spin off a separate bug on our use of "Span" when we should use "Unknown", independent of what happens with the "image" mess?  Or spin the "image" mess into a separate bug, either way.
Filed bug 844127 on Span vs Unknown. Removing good first bug flags as we first need to decide whether we want the "image" "magic" or not.
Whiteboard: [mentor=bz][lang=c++][good first bug]
Priority: -- → P5
Summary: createElement image returns HTMLSpanElement → createElement image returns HTMLElement instead of HTMLUnknownElement
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.