Closed Bug 290442 Opened 20 years ago Closed 20 years ago

Javascript code is reloaded unexpectedly during recursive calls

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
critical

Tracking

()

RESOLVED INVALID

People

(Reporter: anthony.groyer, Assigned: bugzilla)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0

Let's consider this code :
//////////////////////////////////
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
var myimg;

var j=0;
var nbMaxDisplayedItems = 1000;

function dumpPropsOnScreen(objstr, maxlevel) {
	if (maxlevel==0) { document.write("****** Reached maximum search level
******<BR>"); return;}
	maxlevel--;
	obj = eval(objstr);
	for (var i in obj) {
		type = typeof(obj[i]);
		msg = objstr + "." + i;
		printmsg = msg+"="+obj[i]+"<br>   - NbElements = "+j;
		document.write(printmsg+'<BR>');//(1)
		j++;
		if (j>nbMaxDisplayedItems) { document.write("****** Reached maximum displayed
items ******<BR>"); return;}
		if (type == "object" && obj[i]!=null && isNaN(i)) { 
			dumpPropsOnScreen(msg, maxlevel);
			obj = eval(objstr);
		}
	}
}

myimg = new Image();

if (confirm('Start scripting...'))
{
	alert("Confirm is OK");
	dumpPropsOnScreen("myimg",15);
}

//-->
</SCRIPT>
</BODY>
</HTML>
///////////////////////////////////

This javascript code writes on the screen all the properties of the "myimg" object
At the 330th "document.write" (1), this javascript code restarts from the
beginning ?!??
We can see the confirm msgbox 'Start scripting...' appearing again
I suppose that this is a software stack issue - If I remove the "maxlevel"
parameter from my function, I can go up to 3000 items.


Reproducible: Always

Steps to Reproduce:
1.Load the web page in Firefox
2.Answer 'OK' to the confirm msgbox 'Start scripting'
3.You will see the msgbox 'Confirm is OK'
4.You will see again the confirm msgbox 'Start scripting' (the code is being
reloaded)

Actual Results:  
If you answer 'Cancel', you will see again the confirm msgbox 'Start scripting'
After 15 times answering 'Cancel', the page will finish loading because it stops
on an exception :
Error: uncaught exception: [Exception... "Component returned failure code:
0x80004001 (NS_ERROR_NOT_IMPLEMENTED) [nsIDOM3Document.domConfig]"  nsresult:
"0x80004001 (NS_ERROR_NOT_IMPLEMENTED)"  location: "JS frame ::
file:///I:/Mozilla%20Page%20Restart%20Bug.html :: dumpPropsOnScreen :: line 25"
 data: no]
This exception is another issue : please note that the access to
"myimg.textContent" and "myimg.ownerDocument.domConfig" return an error.



Expected Results:  
Not restart the javascript code - exception because of a software stack limitation.
This is probably caused by yourself - "eval(objstr)" and changing "obj" content
while execution of "for(i in obj)".

See what is returned to "for(i in obj){obj[i];}".
 msg=''; myimage = new Image();
 for (i in myimage) { msg=msg+myimage[i]+"<"+"br>" ; }
 document.writeln("<"+"p"+msg;"<"+"/p">) ;

obj[i] becomes "HTML document element".
And since you change content of obj while execution of "for(i in obj)", this is
done on higher element object than "myimage" object("HTML document object"
etc.), and obj[i] becomes your script text in your HTML.
Then your script is executed again by your "eval(objstr)".
Correction.(Sorry for spam)
 document.writeln("<"+"p>"+msg+"<"+"/p>") ;
In fact, restoring "obj" by doing "eval(objstr)" works perfectly.

After more investigation, I found that this behaviour is caused by a
"document.write" of the "innerHTML" property.
In fact, I write again the actual contents of the HTML page, including the
Javascript code. This Javascript code is immediately interpreted that causes to
restart my code with the "confirm" dialog box.

Everything is clear now. 
This bug is not a bug. It should be resolved.
(In reply to comment #3)
> Everything is clear now. 
Congraturations.
Closing as INVALID.

By the way, Bugzila.mozilla.org is NOT Help Center.
Please check at least whether user error is involved or not before open bug.
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.