window.open returns HTMLDocument instead of SVGDocument

UNCONFIRMED
Unassigned

Status

()

Core
DOM
UNCONFIRMED
11 years ago
2 years ago

People

(Reporter: Cory Cohen, Unassigned)

Tracking

(Depends on: 1 bug, {dev-doc-needed})

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

11 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4

This looks like a bug to me, but 

Reproducible: Always

Steps to Reproduce:
test.html
----8<--------8<--------8<--------8<--------8<----
<html><script>
function init() {
  var win = window.open('test.svg', '', '');
  alert(win.document);
  var myrect = win.document.createElementNS("http://www.w3.org/2000/svg", "rect");
  win.document.appendChild(myrect);
}
</script>
<body onLoad="init()"></body>
</html>
----8<--------8<--------8<--------8<--------8<----
test.svg
----8<--------8<--------8<--------8<--------8<----
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <rect x="10" y="10" width="100" height="100" fill="red"/>
</svg>
----8<--------8<--------8<--------8<--------8<----
Actual Results:  
The alert displays "[object HTMLDocument]".  Subsequent attempts to use the document produces errors like:

Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy"  code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)"  location: "file:///C:test.html Line: 8"]

Error: uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLHtmlElement.appendChild]"  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"  location: "JS frame :: chrome://xxx/test.xul :: init :: line 38"  data: no]


Expected Results:  
I would expect win.document to have a document of type of SVGDocument, and display  "[object SVGDocument]".

If this is somehow expected behavior, sorry for the bogus bug report, but this appears to be broken to me...
(Reporter)

Comment 1

11 years ago
If I wait a while, the correct result is returned.  It looks like simply getting out of the onLoad event is enough. Changing the code to: 

var win;
function init() {
  win = window.open('test.svg', '', '');
  setTimeout("later()", 1);
}
function later() {
  alert(win.document);
}

correctly alerts "[object SVGDocument]".  This seems very hackish, and strongly suggests to me that this behavior is indeed a bug.  On the other hand, now that I see that the problem is clearly an ordering issue, and that the window.open doesn't occur until after the onLoad event exits, I suppose it's possible that nothing can be done to correct it.

Is there anywhere that all this fine print gets recorded?  I sometimes find it nearly impossible to code using Javascript and the DOM because functions do _NOT_ behave exactly as documented, but rather that way most of the time.  This routinely leaves me figuring out _why_ it doesn't do what it says it will. :-(

Comment 2

11 years ago
There is much of DOM and DOM:Events changes on trunk. What happens if you try your code against trunk? 

Updated

6 years ago
Depends on: 512688
No longer depends on: 512688
Depends on: 897815
Keywords: dev-doc-needed
You need to log in before you can comment on or make changes to this bug.