Closed Bug 309898 Opened 19 years ago Closed 19 years ago

E4X XML object doesn't appear to be reentrant

Categories

(Core :: JavaScript Engine, defect)

1.8 Branch
defect
Not set
major

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: conor, Unassigned)

References

()

Details

User-Agent:       Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4
Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8b4) Gecko/20050908 Firefox/1.4

Try the three examples tests in the test file: the second and third both run two
XML objects in the same context. Both tests should work but only the hokey
workarounds used in the third test actually work. Perhaps the XML object is a
singleton but surely this isn't part of the spec?

Reproducible: Always
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.8 Branch
What's the problem?

js> e4x_test1
function e4x_test1() {
    try {
        var top = <top/>;
        top.oneDown = <oneDown/>;
        top.oneDown.stuff = <stuff>stuff</stuff>;
        alert("Success: " + top.toXMLString());
    } catch (e) {
        alert("Test 1 fails: " + e);
    }
}
js> e4x_test1()
Success: <top>
  <oneDown>
    <stuff>stuff</stuff>
  </oneDown>
</top>

You need to say exactly what result you expect, and why.

/be
And define "reentrant" -- it's not clear what you mean, or how it applies to
objects (not code).

/be
Me sloppy. Here's what's in the test file.
(http://www.the325project.org/Tests/e4x/e4xtest.xul)

First test works. Simple stuff:
		var top = <top/>;
		top.oneDown = <oneDown/>;
		top.oneDown.stuff = <stuff>stuff</stuff>;
and all is well.

Now ... second test fails:

	var top = <top/>;
	top.oneDown = <oneDown/>;
	var top2 = new XML("<top2/>"); // add line to replicate serialized XML loaded
from a file
	// now back to first top - it fails. Context lost? XML not reentrant?
	top.oneDown.stuff = <stuff>stuff</stuff>;

All you do is add a new XML "tree" (is that the term?) or context before the
last assigment and you get an exception!

Third test shows that a subset of XML operations are still available. First
three lines are common but now only a two step, awkward assigment works.

	var top = <top/>;
	top.oneDown = <oneDown/>;
	var top2 = new XML("<top2/>");
	top.oneDown[0].stuff[0] = "";
	top.oneDown.stuff[0] = "stuff";

Why? Does the allocation of a new XML "context" destroy some aspect of the
first/default context. 

BTW, there is no change in any test if you substitute, "var top = new
XML(<top/>)" for the first assignment. 
p.s. this simple sequence shows the "two context" problem. In real life, I read
in an XML file using:

// start new doc
var newXML = <head>stuff</head>;

... load doc to walk into xmlDocument
// serialize contents into XML object
var xmlSerializer = new XMLSerializer();
var xml = new XML(xmlSerializer.serializeToString(xmlDocument.documentElement));

// now walk xml and fill in newXML

... that's the goal but it doesn't work. As the above shows, stick in the
"document" xml and the new xml becomes far to ackward to build using e4x.
From my shell prompt, running the js shell:

$ cat > conor.js
var top = <top/>;
top.oneDown = <oneDown/>;
var top2 = new XML("<top2/>"); // add line to replicate serialized XML loaded
from a file
// now back to first top - it fails. Context lost? XML not reentrant?
top.oneDown.stuff = <stuff>stuff</stuff>;
print(top.toXMLString());

$ Linux_All_DBG.OBJ/js -x conor.js
<top>
  <oneDown>
    <stuff>stuff</stuff>
  </oneDown>
</top>

What exception do you get?  Can you copy and paste exactly what is in the
JavaScript Console?

/be
From test 2 in http://www.the325project.org/Tests/e4x/e4xtest.xul

-------------- console says -------------------
Error: invalid XML markup
Source File: file:///Users/conor/Projects/The325Project/Tests/e4x/e4xtest.xul
Line: 38
Source Code:
<parent xmlns=''><stuff>stuff</stuff></parent>
-----------------------------------------------

... this "<parent ...> " style exception shows up all the time if you assign
markup after asserting an intermediate "new XML()" of the kind in test 2 or 3.
(In reply to comment #6)
> From test 2 in http://www.the325project.org/Tests/e4x/e4xtest.xul
> 
> -------------- console says -------------------
> Error: invalid XML markup
> Source File: file:///Users/conor/Projects/The325Project/Tests/e4x/e4xtest.xul
> Line: 38
> Source Code:
> <parent xmlns=''><stuff>stuff</stuff></parent>
> -----------------------------------------------
> 
> ... this "<parent ...> " style exception shows up all the time if you assign
> markup after asserting an intermediate "new XML()" of the kind in test 2 or 3.

I can't reproduce this on your test page.

What build are you running?  Have you tried the latest, trunk or branch?

/be
All ok in the nightly (at for the small test!). I was running beta 1. Tried:
- beta 1 on windows xp and OS X: test 2 failed on both
- last nights build: succeeded on both!

So it was fixed - whatever it was - between the beta and the nightly. Any more
tests I do, I try the nightly and not just the beta. 

thx. 

So this bug can go the way of the dodo I suppose.
Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.