Bug 14968 - document.open() erroneously returns void instead of the new Document
Summary: document.open() erroneously returns void instead of the new Document
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 523.x (Safari 3)
Hardware: All All
: P2 Normal
Assignee: Alexey Proskuryakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-14 15:40 PDT by Darin Fisher (:fishd, Google)
Modified: 2008-11-29 10:29 PST (History)
1 user (show)

See Also:


Attachments
test case (193 bytes, text/html)
2007-08-14 21:52 PDT, Alexey Proskuryakov
no flags Details
test case (as originally reported) (327 bytes, text/html)
2007-08-15 20:27 PDT, Darin Fisher (:fishd, Google)
no flags Details
proposed fix (3.67 KB, patch)
2008-11-29 01:13 PST, Alexey Proskuryakov
eric: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Fisher (:fishd, Google) 2007-08-14 15:40:25 PDT
document.open() erroneously returns void instead of the new Document

in other browsers (IE, FF, and Opera), document.open() returns the new Document, and you can write into it to generate content.

example:

  var d = document.open("text/html", "replace");
  d.write("foo");
  d.close();

apparently, the html5 spec does not describe this behavior:
http://www.whatwg.org/specs/web-apps/current-work/#htmldocument

mozilla defines the form of document.open that returns a new document here (as a Netscape extension to the DOM):
http://lxr.mozilla.org/seamonkey/source/dom/public/idl/html/nsIDOMNSHTMLDocument.idl
Comment 1 Alexey Proskuryakov 2007-08-14 21:52:32 PDT
Created attachment 15975 [details]
test case

This test works in Firefox 2, but not in Opera. Haven't tried with IE yet.
Comment 2 Alexey Proskuryakov 2007-08-15 03:12:44 PDT
This test fails in IE, too.
Comment 3 Darin Fisher (:fishd, Google) 2007-08-15 20:23:55 PDT
Alexey, your test case does not match the one in comment #0.  If you try that you should see that FF2, IE6 and Opera9 all generate a page with the text "foo"
Comment 4 Darin Fisher (:fishd, Google) 2007-08-15 20:27:14 PDT
Created attachment 15992 [details]
test case (as originally reported)
Comment 5 Alexey Proskuryakov 2007-08-15 21:54:59 PDT
(In reply to comment #3)
> Alexey, your test case does not match the one in comment #0.

Do you mean that the second parameter is true instead of "replace" in my test case? Indeed, I mistakenly used he linked Mozilla IDL to check the type - but it doesn't matter anyway, as the behavior WRT this issue is the same AFAICT.

It seems that the main difference between our test cases is that the code runs during parsing in the first one, and after parsing has finished in the second one.
Comment 6 Darin Fisher (:fishd, Google) 2007-08-17 08:49:33 PDT
Ah, yes...  It is interesting that the behavior varies depending on whether or not we are done parsing the main document.
Comment 7 Alexey Proskuryakov 2008-11-29 01:13:12 PST
Created attachment 25588 [details]
proposed fix

Note that parameters are currently ignored (except for checking their number, and forwarding to DOMWindow if necessary).
Comment 8 Eric Seidel (no email) 2008-11-29 01:21:20 PST
Comment on attachment 25588 [details]
proposed fix

This would ideally be one of the fancy new js-only tests... then again, ideally it would be easier (and more documented) to write a newer-fancy-js-only test.  Sad that this has to be custom.  But glad to see this fix!
Comment 9 Alexey Proskuryakov 2008-11-29 01:49:30 PST
(In reply to comment #8)
> This would ideally be one of the fancy new js-only tests...

Are you talking about js-test-pre.js and friends? I can think of many minor shortcomings, but not a single benefit - these tests are slower because of the need to load external subresources, they cannot be easily copied to another directory, they often need to be written in roundabout ways to convert a behavior check into a simple shouldBe().

Of course, fast/js is a special case, because the intention is to make those work from pure JS environment eventually.

Thanks for review!
Comment 10 Alexey Proskuryakov 2008-11-29 10:29:32 PST
Committed revision 38842.