Closed Bug 184003 Opened 22 years ago Closed 22 years ago

Javascript functions wont recurse.

Categories

(SeaMonkey :: General, defect)

PowerPC
macOS
defect
Not set
major

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: zaphire, Assigned: asa)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021206 Chimera/0.6+ Build Identifier: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021206 Chimera/0.6+ This doesn't work. Javascript functions in Mozilla and Chimera wont recurse like they do in Explorer. readObj(window, 3); function readObj(thisObj, rlvl) { rlvl--; document.write("Stepping into object...\n"); document.write("<ul>\n"); for (var obj in thisObj) { document.write("<li>"); try { document.write(obj+" ("+typeof(thisObj[obj])+") "); if (typeof(thisObj[obj]) == "object") { if (rlvl > 0) { document.write("\n"); readObj(thisObj[obj], rlvl); } else { document.write("-- Object too deep!"); } } else { if (typeof(thisObj[obj]) == "string" || typeof(thisObj[obj]) == "boolean" || typeof(thisObj[obj]) == "number") { if (thisObj[obj].length > 100) { document.write("= String too long!"); } else { document.write("= "+thisObj[obj]); } } else { document.write("-- Unknown object!"); } } } catch(err) { document.write("Error ("+err+")"); } document.write("<\/li>\n"); } document.write("<\/ul>\n"); } Reproducible: Always Steps to Reproduce: 1. Just try the code I pasted in the details. 2. 3. Actual Results: Not the expected results. Expected Results: It should have recursed.
> for (var obj in thisObj) { This will throw an error if |thisObj == null|. Which it will be quite often with that code. (IE does not throw the error, in violation of the ECMA language spec).
I'm sorry, I guess I didn't make the error quite clear enough. I was being rushed at the time of the post. To clarify, the error is not due to a "null" object, I'm well aware of those types of problems. The error lies in the recursive function call you see on approximately line 11 of the readObj function. When it detects an object of type "object", it calls the readObj function again to read that object. Explorer handles this just fine. But both Mozilla and Chimera generate an error of "ReferenceError: readObj is not defined". Hence it wont recurse.
Attached file testcase
Are you seeing the problem with this HTML file? If not, how does it differ from the testcase you have? (this file works fine for me, Linux build 2002-12-04-22 trunk)
LOL. Sorry. I can't help but laugh at my idiocy on this one. I tried your code, tried mine, tried yours again, tried mine again, tried a few variations of mine, and had no problems. So I pasted the code back into my original page and tried it again and still got the error. I racked my brain on this one for the next 24 hours before I realized what was actually going on. Turns our the error I was getting was acurate and correct. The reason why the function "readObj" was not defined is because the script was replacing the page when it ran (it was being called after the page was fully loaded) and thus removing the scripts. The first loop could run because the script code had been loaded, but once the first write statement occured, it wiped out the script code. The current segment could continue because it was already loaded, but in order for it to recurse and run the function again, it needed to recompile the code each time through. Unfortunately, the code was already gone from the write statement. So, after almost 92 hours of mental torture, it came down to mental retardation. Sorry for the false report. (Ooops)
Status: UNCONFIRMED → RESOLVED
Closed: 22 years ago
Resolution: --- → INVALID
Product: Browser → Seamonkey
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: