Closed Bug 651465 Opened 13 years ago Closed 8 years ago

Replacing document with document.write() does not clear timeouts, causes inconsistent behavior

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: jwkbugzilla, Unassigned)

References

Details

(Keywords: regression)

Attachments

(2 files)

If a page calls document.write() after the page loads the current document will be replaced. It seems that in Firefox 4 this will no longer clear the timeouts defined for the previous document.

Steps to reproduce:

* Open the attached test page (the one with the event handler not inlined)

Expected results:

The page text says "replaced text" and no alert message appears (timeout doesn't fire), also no error message in Error Console (like in Firefox 3.6, MSIE and Opera). Note: Chrome and Safari behave differently and allow the timeout to fire, an alert message is shown there.

Actual results:

Firefox attempts to execute the timeout but fails with "attempt to run compile-and-go script on a cleared scope" error message (visible in Error Console). Not sure whether this is related to bug 635548.

Reproduced in Firefox 4.0 and current mozilla-central nightly (build 20110419) on Windows 7 x64.
Second testcase is slightly different - the event handler is inlined, for some reason it prevents the error and the timeout actually fires (an alert message is shown like in Chrome or Safari). The second alert message says "window.test == undefined", this indicates that the timeout runs in a new scope which is empty (that's not the case for Chrome and Safari, there the timeout runs in the same scope and the message says "window test == set").
This seems bad...
Assignee: general → nobody
Component: JavaScript Engine → DOM
QA Contact: general → general
Sure, but it's a duplicate of the general "we clear the scope" thing.

The "right" behavior here is to run the timeout, imo (as we do now).  The fact that we can't actually manage to run it is due to the JS_ClearScope and the fact that our jits can't handle it.  Which is bug 635548, as far as I can tell.
Depends on: 635548
User Agent 	Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:49.0) Gecko/20100101 Firefox/49.0
Build ID 	20160524030227

I've tested this on latest Nightly (49.0a1):

*Testcase with the event handler not inlined - the event fires (an alert appears) and no error is shown in console

*Testcase with the event handler inlined - still behaves as described in comment 1.
Version: 2.0 Branch → Trunk
Yes, the behavior is mostly consistent with Chrome and Safari now - replacing the document via document.write() doesn't prevent timeouts from executing. Scope is still being cleared however, Chrome and Safari don't do that. Not sure whether this still warrants keeping this bug open.
> Scope is still being cleared however, Chrome and Safari don't do that.

We're doing what the spec says to do here.
I read https://www.w3.org/TR/html5/webappapis.html#dom-document-open but I must be missing something. Feel free to add a pointer to the exact part of the spec saying that and resolve as WORKSFORME.
https://html.spec.whatwg.org/multipage/webappapis.html#dom-document-open steps 15 to 18.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → WORKSFORME
I guess that's all lumped under step 15 in the fork you linked to.
The way I see it, it's rather the W3C spec and the WHATWG spec disagreeing as far as clearing the scope is concerned - which explains different behavior in different browsers. Well, luckily I don't need to care about this mess...
W3C HTML is pretty clear
"Replace the Document's singleton objects with new instances of those objects. (This includes in particular the Window,..."
WhatWG HTML then actually defines how that is supposed to be done.
Yeah.  The reason behavior is different in different browsers is that browsers aren't very good about actually implementing the HTML spec.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: