Last Comment Bug 615927 - document.open/write fails 2nd time through
: document.open/write fails 2nd time through
Status: UNCONFIRMED
:
Product: Core
Classification: Components
Component: DOM: Core & HTML (show other bugs)
: unspecified
: x86 Windows 7
: -- normal (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
: Andrew Overholt [:overholt]
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-12-01 10:51 PST by stephen
Modified: 2010-12-29 10:45 PST (History)
3 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
repro example (672 bytes, application/x-zip-compressed)
2010-12-01 11:38 PST, stephen
no flags Details

Description stephen 2010-12-01 10:51:21 PST
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.44 Safari/534.7
Build Identifier: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0b7) Gecko/20100101 Firefox/4.0b7


It appears that the snippet below will work the first time through but then the second time through document will be null after document.open().

	try {
		if (document == null) { throw new Error("before open"); }
		document.open();
		if (document == null) { throw new Error("before write"); }
		document.write(newDocSource);
		if (document == null) { throw new Error("before close"); }
		document.close();
	} catch (ex) {
		if (window.console) {
			console.write(ex);
		} else {
			alert(ex);
		}
	}


Reproducible: Always

Steps to Reproduce:
1. load a page with a button to trigger document.open()/write()/close()
2. trigger the script (everything works fine)
3. trigger it again (document becomes null)
Actual Results:  
document is null

Expected Results:  
In FF 3.x this could be repeated indefinitely.

The page source has the script in an external JavaScript file, so it should be executing it each time the page is rebuilt. document is being refereced (not stored) so it should be pointing to the current document (rather than an old instance).

Storing the value returned from document.open() and using that for the remaining steps seems to be a workaround.

	var doc = document.open();
	doc.write(...);
	doc.close();
Comment 1 stephen 2010-12-01 10:55:27 PST
I forgot to mention the alert that pops up says "before write".

Note also there's a typo in the console line.
Comment 2 Boris Zbarsky [:bz] (still a bit busy) 2010-12-01 11:09:51 PST
Can you attach a complete web page that shows the problem?
Comment 3 stephen 2010-12-01 11:38:42 PST
Created attachment 494459 [details]
repro example

Attachment is a simple web page and script which demonstrates the problem. Works fine in Firefox 3.6.13 but not in Firefox 4.0b7. Thanks.
Comment 4 Boris Zbarsky [:bz] (still a bit busy) 2010-12-01 15:01:10 PST
Hmm.  I see the issue in b7, but not on trunk.  Looks like this got fixed somewhere in this range: http://hg.mozilla.org/mozilla-central/pushloghtml?fromchange=ad227939db82&tochange=789f0f85f75a
Comment 5 stephen 2010-12-29 10:45:45 PST
NOTE: this now appears to have been fixed in the released version of 4.0b8.

Note You need to log in before you can comment on or make changes to this bug.