Crash fix for event.returnValue

David Faure faure@kde.org
Mon, 27 Jan 2003 14:34:09 +0100


--Boundary-00=_RVTN+gMoajOojT9
Content-Type: Text/Plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline

=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Just applied this to KHTML, you might want to apply it to Safari too
(are you monitoring the kde-cvs mailing-list?)

=2D --=20
David FAURE, faure@kde.org, dfaure@klaralvdalens-datakonsult.se
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
KOffice-1.2.1 is available - http://download.kde.org/stable/koffice-1.2.1/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE+NTVS72KcVAmwbhARAinBAKCUjxSWaivPDnl6grM4/Vif5Er9dQCeJYRL
hJY7CgyVNN2qpeo2x5AIcEo=3D
=3DJpDb
=2D----END PGP SIGNATURE-----

--Boundary-00=_RVTN+gMoajOojT9
Content-Type: text/x-diff;
  charset="us-ascii";
  name="domevent_returnvalue.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="domevent_returnvalue.diff"

Index: xml/dom2_eventsimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/xml/dom2_eventsimpl.h,v
retrieving revision 1.27
diff -u -p -r1.27 dom2_eventsimpl.h
--- xml/dom2_eventsimpl.h	8 Jan 2003 19:29:56 -0000	1.27
+++ xml/dom2_eventsimpl.h	27 Jan 2003 13:25:47 -0000
@@ -107,8 +107,8 @@ public:
     bool cancelable() const { return m_cancelable; }
     DOMTimeStamp timeStamp();
     void stopPropagation(bool stop) { m_propagationStopped = stop; }
+    void preventDefault(bool prevent) { if ( m_cancelable ) m_defaultPrevented = prevent; }
 
-    void preventDefault() { m_defaultPrevented = m_cancelable; }
     void initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg);
 
     virtual bool isUIEvent() { return false; }
Index: ecma/kjs_events.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_events.cpp,v
retrieving revision 1.71
diff -u -p -r1.71 kjs_events.cpp
--- ecma/kjs_events.cpp	25 Jan 2003 04:56:14 -0000	1.71
+++ ecma/kjs_events.cpp	27 Jan 2003 13:25:48 -0000
@@ -241,12 +241,15 @@ Value DOMEvent::getValueProperty(ExecSta
   case EventPhase:
     return Number((unsigned int)event.eventPhase());
   case Bubbles:
-  case CancelBubble: // MSIE extension. not sure if readable. and returnValue ?
     return Boolean(event.bubbles());
   case Cancelable:
     return Boolean(event.cancelable());
   case TimeStamp:
     return Number((long unsigned int)event.timeStamp()); // ### long long ?
+  case ReturnValue: // MSIE extension
+    return Boolean(event.handle()->defaultPrevented());
+  case CancelBubble: // MSIE extension
+    return Boolean(event.handle()->propagationStopped());
   default:
     kdWarning() << "Unhandled token in DOMEvent::getValueProperty : " << token << endl;
     return Value();
@@ -263,13 +266,13 @@ void DOMEvent::tryPut(ExecState *exec, c
 void DOMEvent::putValueProperty(ExecState *exec, int token, const Value& value, int)
 {
   switch (token) {
-  case ReturnValue:
-    if (value.toBoolean(exec))
-      event.preventDefault();
+  case ReturnValue: // MSIE equivalent for "preventDefault" (but with a way to reset it)
+    // returnValue=false means "default action of the event on the source object is canceled",
+    // which means preventDefault(true). Hence the '!'.
+    event.handle()->preventDefault(!value.toBoolean(exec));
     break;
-  case CancelBubble:
-    if (value.toBoolean(exec))
-      event.stopPropagation();
+  case CancelBubble: // MSIE equivalent for "stopPropagation" (but with a way to reset it)
+    event.handle()->stopPropagation(value.toBoolean(exec));
     break;
   default:
     break;
Index: dom/dom2_events.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/dom/dom2_events.cpp,v
retrieving revision 1.10
diff -u -p -r1.10 dom2_events.cpp
--- dom/dom2_events.cpp	10 Jan 2003 05:32:14 -0000	1.10
+++ dom/dom2_events.cpp	27 Jan 2003 13:25:48 -0000
@@ -148,7 +148,7 @@ void Event::preventDefault()
     if (!impl)
 	throw DOMException(DOMException::INVALID_STATE_ERR);
 
-    impl->preventDefault();
+    impl->preventDefault(true);
 }
 
 void Event::initEvent(const DOMString &eventTypeArg, bool canBubbleArg, bool cancelableArg)

--Boundary-00=_RVTN+gMoajOojT9--