Patch: Crash: blocking JS alert and deleting a window

Koos Vriezen koos.vriezen at xs4all.nl
Fri Oct 18 13:33:05 BST 2002


Hi,

The crashes with the test cases below, can be fixed by closing all dialogs
of this view before doing a 'Window::DelayedAction( Window::DelayedClose )'


Index: ecma/kjs_window.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_window.cpp,v
retrieving revision 1.277
diff -u -3 -p -r1.277 kjs_window.cpp
--- ecma/kjs_window.cpp 2002/10/07 15:57:33     1.277
+++ ecma/kjs_window.cpp 2002/10/18 12:24:24
@@ -32,6 +32,7 @@
 #include <kconfig.h>
 #include <assert.h>
 #include <qstyle.h>
+#include <qobjectlist.h>

 #include <kjs/collector.h>
 #include "kjs_proxy.h"
@@ -1336,6 +1337,12 @@ Value WindowFunc::tryCall(ExecState *exe
       // then schedule a delayed close (so that the script terminates first).
       // But otherwise, close immediately. This fixes
w=window.open("","name");w.close();window.open("name");
       if ( Window::retrieveActive(exec) == window ) {
+        if (widget) {
+          // quit all modal dialogs of this view
+          QObjectList * dlgs = widget->topLevelWidget()->queryList("QDialog");
+          for (QObject* dlg = dlgs->first(); dlg; dlg = dlgs->next())
+            ((QDialog*)dlg)->hide();
+        }
         // We'll close the window at the end of the script execution
         Window* w = const_cast<Window*>(window);
         w->m_delayed.append( Window::DelayedAction( Window::DelayedClose ) );

Is this correct?

Regards,

Koos

On Sat, 5 Oct 2002, Koos Vriezen wrote:

> On Sat, 5 Oct 2002, Simon Hausmann wrote:
>
> > On Wed, Oct 02, 2002 at 08:44:16PM +0200, Koos Vriezen wrote:
> > > Hi,
> > >
> > > Testcase:
> > >
> > > <html><head><script>
> > >   var win=open("", "xxx");
> > >   var doc=win.document;
> > >   doc.open();
> > >   doc.write("<html><body onLoad=\"alert(somevar)\">");
> > >   doc.write("</body></html>");
> > >   doc.close();
> > > </script></head>
> > > <body></body></html>
> > >
> > > After the second window is created, delete it by clicking the X button.
> > > Even KCrash crashes on this one.
> > > The problem is blocking JS (here the alert box, might as well be a
> > > LiveConnect call). Currently I see these options:
> >
> > On a second though I don't understand how this can happen. The
> > alert() triggers a messagebox with the window as parent, so it
> > shouldn't be possible to close the window in the first place as the
> > messagebox is modal. Any idea?
>
> Same for 'Open Location' dialog. Bug in Qt?
>
> There are other cases, eg calls to Java, that could block JS. Something
> has to be done.
> That khtml currently even self doesn't check if it can close the window
> proves the next testcase
>
> <html><head><script>
>   var win=open("", "xxx");
>   var doc=win.document;
>   doc.open();
>
> doc.write("<html><script>setTimeout('self.close()',1000);alert(somevar);<\/script><body>");
>   doc.write("</body></html>");
>   doc.close();
> </script></head>
> <body></body></html>
>
> Crash with backtrace this time.
>
> Koos
>
>






More information about the kfm-devel mailing list