JavaScriptCore:
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jul 2006 06:06:30 +0000 (06:06 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jul 2006 06:06:30 +0000 (06:06 +0000)
        Reviewed by Maciej.

        Bug 9686: [Drosera] Need the ability to break into Drosera on Javascript exceptions
        http://bugzilla.opendarwin.org/show_bug.cgi?id=9686

        JavaScriptCore portion of the fix.

        * JavaScriptCore.exp: Update symbol for change in argument type.
        * kjs/debugger.cpp:
        (Debugger::detach): Clear map of recent exceptions.
        (Debugger::hasHandledException): Track the most recent exception
        thrown by an interpreter.
        (Debugger::exception): Change exception argument to a JSValue.
        * kjs/debugger.h:
        * kjs/nodes.cpp:
        (Node::debugExceptionIfNeeded): Notify the debugger of an exception
        if it hasn't seen it before.
        (ThrowNode::execute): Notify the debugger that an exception is being thrown.
        * kjs/nodes.h:

    2006-07-23  Geoffrey Garen  <ggaren@apple.com>

        Patch by Eric Albert, reviewed by Darin and me.

        - Fixed <rdar://problem/4645931> JavaScriptCore stack-scanning code
        crashes (Collector::markStackObjectsConservatively)

        * bindings/jni/jni_jsobject.cpp: On 64bit systems, jint is a long, not an
        int.
        (JavaJSObject::getSlot):
        (JavaJSObject::setSlot):
        * kjs/collector.cpp:
        (KJS::Collector::markCurrentThreadConservatively): Use a pointer instead of
        an int as 'dummy,' because on LP64 systems, an int is not pointer-aligned,
        and we want to scan the stack for pointers.
        * JavaScriptCore.xcodeproj/project.pbxproj: After a tense cease-fire, the
        XCode war has started up again!

WebCore:

        Reviewed by maciej.

        Bug 9686: [Drosera] Need the ability to break into Drosera on Javascript exceptions
        http://bugzilla.opendarwin.org/show_bug.cgi?id=9686

        WebCore portion of the fix.

        * bridge/mac/WebCoreScriptDebugger.h:
        (-[WebScriptDebugger exceptionRaised:sourceId:line::]): Add delegate method.
        * bridge/mac/WebCoreScriptDebugger.mm:
        (WebCoreScriptDebuggerImp::exception): Call delegate method when an exception is raised.

WebKit:

        Reviewed by Maciej.

        Bug 9686: [Drosera] Need the ability to break into Drosera on Javascript exceptions
        http://bugzilla.opendarwin.org/show_bug.cgi?id=9686

        WebKit portion of the fix.

        * DefaultDelegates/WebDefaultScriptDebugDelegate.m:
        (-[WebDefaultScriptDebugDelegate webView:exceptionWasRaised:sourceId:line:forWebFrame:]):
        * DefaultDelegates/WebScriptDebugServer.h:
        * DefaultDelegates/WebScriptDebugServer.m:
        (-[WebScriptDebugServer webView:exceptionWasRaised:sourceId:line:forWebFrame:]): Notify
        listeners that an exception has been raised.
        * WebView/WebScriptDebugDelegate.h:
        * WebView/WebScriptDebugDelegate.m:
        (-[WebScriptCallFrame exceptionRaised:sourceId:line:]): Dispatch through to delegate and
        WebScriptDebugServer.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15593 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/JavaScriptCore.exp
JavaScriptCore/kjs/debugger.cpp
JavaScriptCore/kjs/debugger.h
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h
WebCore/ChangeLog
WebCore/bridge/mac/WebCoreScriptDebugger.h
WebCore/bridge/mac/WebCoreScriptDebugger.mm
WebKit/ChangeLog
WebKit/DefaultDelegates/WebDefaultScriptDebugDelegate.m
WebKit/DefaultDelegates/WebScriptDebugServer.h
WebKit/DefaultDelegates/WebScriptDebugServer.m
WebKit/WebKit.xcodeproj/project.pbxproj
WebKit/WebView/WebScriptDebugDelegate.h
WebKit/WebView/WebScriptDebugDelegate.m

index ead967594dc0d0d6d5281811c1f62004559c09fb..c1e5d9c3054b0f430a4ddcedcbc2d3cfbdb9b10a 100644 (file)
@@ -1,3 +1,25 @@
+2006-07-23  Mark Rowe  <opendarwin.org@bdash.net.nz>
+
+        Reviewed by Maciej.
+
+        Bug 9686: [Drosera] Need the ability to break into Drosera on Javascript exceptions
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=9686
+
+        JavaScriptCore portion of the fix.
+
+        * JavaScriptCore.exp: Update symbol for change in argument type.
+        * kjs/debugger.cpp:
+        (Debugger::detach): Clear map of recent exceptions.
+        (Debugger::hasHandledException): Track the most recent exception
+        thrown by an interpreter.
+        (Debugger::exception): Change exception argument to a JSValue.
+        * kjs/debugger.h:
+        * kjs/nodes.cpp:
+        (Node::debugExceptionIfNeeded): Notify the debugger of an exception
+        if it hasn't seen it before.
+        (ThrowNode::execute): Notify the debugger that an exception is being thrown.
+        * kjs/nodes.h:
+
     2006-07-23  Geoffrey Garen  <ggaren@apple.com>
 
         Patch by Eric Albert, reviewed by Darin and me.
index d1413bff940e2de04f337a1d825393493915d239..72b7470eeb60c2673e2132eafa6a11f359a2ce11 100644 (file)
@@ -193,7 +193,7 @@ __ZN3KJS8Bindings8Instance21setDidExecuteFunctionEPFvPNS_9ExecStateEPNS_8JSObjec
 __ZN3KJS8Bindings8Instance32createBindingForLanguageInstanceENS1_15BindingLanguageEPvPKNS0_10RootObjectE
 __ZN3KJS8Debugger12sourceUnusedEPNS_9ExecStateEi
 __ZN3KJS8Debugger6attachEPNS_11InterpreterE
-__ZN3KJS8Debugger9exceptionEPNS_9ExecStateEiiPNS_8JSObjectE
+__ZN3KJS8Debugger9exceptionEPNS_9ExecStateEiiPNS_7JSValueE
 __ZN3KJS8DebuggerC2Ev
 __ZN3KJS8DebuggerD2Ev
 __ZN3KJS8JSObject11hasInstanceEPNS_9ExecStateEPNS_7JSValueE
index adaed7fc00fec3dfe63bfeb66689ee9289322d48..653e5bbd99ea4b197781cf354e8418cdf86e4e10 100644 (file)
@@ -80,6 +80,20 @@ void Debugger::detach(Interpreter* interp)
     } else
       p = &q->next;
   }
+
+  if (interp)
+    latestExceptions.remove(interp);
+  else
+    latestExceptions.clear();
+}
+
+bool Debugger::hasHandledException(ExecState *exec, JSValue *exception)
+{
+    if (latestExceptions.get(exec->dynamicInterpreter()).get() == exception)
+        return true;
+
+    latestExceptions.set(exec->dynamicInterpreter(), exception);
+    return false;
 }
 
 bool Debugger::sourceParsed(ExecState */*exec*/, int /*sourceId*/, const UString &/*sourceURL*/, 
@@ -94,7 +108,7 @@ bool Debugger::sourceUnused(ExecState */*exec*/, int /*sourceId*/)
 }
 
 bool Debugger::exception(ExecState */*exec*/, int /*sourceId*/, int /*lineno*/,
-                         JSObject */*exceptionObj*/)
+                         JSValue */*exception*/)
 {
   return true;
 }
index b59a70ef938bfa635a37a773f5f285fe65f15347..70a5ffdb5009753f92e34e864589d790b266be36 100644 (file)
 #ifndef _KJSDEBUGGER_H_
 #define _KJSDEBUGGER_H_
 
+#include <wtf/HashMap.h>
+#include "protect.h"
+
 namespace KJS {
 
   class DebuggerImp;
   class Interpreter;
   class ExecState;
   class JSObject;
+  class JSValue;
   class UString;
   class List;
 
@@ -144,7 +148,9 @@ namespace KJS {
      * be aborted
      */
     virtual bool exception(ExecState *exec, int sourceId, int lineno,
-                           JSObject *exceptionObj);
+                           JSValue *exception);
+
+    bool hasHandledException(ExecState *, JSValue *);
 
     /**
      * Called when a line of the script is reached (before it is executed)
@@ -209,6 +215,7 @@ namespace KJS {
 
   private:
     DebuggerImp *rep;
+    HashMap<Interpreter*, ProtectedPtr<JSValue> > latestExceptions;
 
   public:
     static int debuggersPresent;
index 01209ca3324fb509cae7816f8051baaed057ca9d..bf7273844cb3b04aa722b36efc53ae5266233d21 100644 (file)
@@ -57,6 +57,7 @@ using namespace KJS;
     setExceptionDetailsIfNeeded(exec); \
     JSValue *ex = exec->exception(); \
     exec->clearException(); \
+    debugExceptionIfNeeded(exec, ex); \
     return Completion(Throw, ex); \
   } \
   if (Collector::isOutOfMemory()) \
@@ -65,6 +66,7 @@ using namespace KJS;
 #define KJS_CHECKEXCEPTIONVALUE \
   if (exec->hadException()) { \
     setExceptionDetailsIfNeeded(exec); \
+    debugExceptionIfNeeded(exec, exec->exception()); \
     return jsUndefined(); \
   } \
   if (Collector::isOutOfMemory()) \
@@ -73,6 +75,7 @@ using namespace KJS;
 #define KJS_CHECKEXCEPTIONLIST \
   if (exec->hadException()) { \
     setExceptionDetailsIfNeeded(exec); \
+    debugExceptionIfNeeded(exec, exec->exception()); \
     return List(); \
   } \
   if (Collector::isOutOfMemory()) \
@@ -269,6 +272,16 @@ void Node::setExceptionDetailsIfNeeded(ExecState *exec)
     }
 }
 
+void Node::debugExceptionIfNeeded(ExecState* exec, JSValue* exceptionValue)
+{
+    Debugger* dbg = exec->dynamicInterpreter()->debugger();
+    if (dbg && !dbg->hasHandledException(exec, exceptionValue)) {
+        bool cont = dbg->exception(exec, currentSourceId(exec), m_line, exceptionValue);
+        if (!cont)
+            dbg->imp()->abort();
+    }
+}
+
 Node *Node::nodeInsideAllParens()
 {
     return this;
@@ -2269,6 +2282,8 @@ Completion ThrowNode::execute(ExecState *exec)
   JSValue *v = expr->evaluate(exec);
   KJS_CHECKEXCEPTION
 
+  debugExceptionIfNeeded(exec, v);
+
   return Completion(Throw, v);
 }
 
index 848438989086e672c9a24ab501aebdd9c55d03df..d6b2258afa55e51bf1f8127f0f16af3dd355c585 100644 (file)
@@ -109,6 +109,7 @@ namespace KJS {
     JSValue *throwUndefinedVariableError(ExecState *, const Identifier &);
 
     void setExceptionDetailsIfNeeded(ExecState*);
+    void debugExceptionIfNeeded(ExecState*, JSValue*);
 
     int m_line;
   private:
index 9cf0f8e52ac135e50b23680026227035b17e00af..ccb3f37221fb5c28caef1a6aab5bd5eb054b0b2e 100644 (file)
@@ -1,3 +1,17 @@
+2006-07-23  Mark Rowe  <opendarwin.org@bdash.net.nz>
+
+        Reviewed by maciej.
+
+        Bug 9686: [Drosera] Need the ability to break into Drosera on Javascript exceptions
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=9686
+
+        WebCore portion of the fix.
+
+        * bridge/mac/WebCoreScriptDebugger.h:
+        (-[WebScriptDebugger exceptionRaised:sourceId:line::]): Add delegate method.
+        * bridge/mac/WebCoreScriptDebugger.mm:
+        (WebCoreScriptDebuggerImp::exception): Call delegate method when an exception is raised.
+
 2006-07-23  Alice Liu  <alice.liu@apple.com>
 
         Reviewed by Adele.
index 5595b66b740f706e144a5d07de0e186da1ed4303..fd56632f690688a457afa210085d30fa15beb93e 100644 (file)
@@ -52,6 +52,7 @@ using KJS::ExecState;
 - (void)enteredFrame:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno;
 - (void)hitStatement:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno;
 - (void)leavingFrame:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno;
+- (void)exceptionRaised:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno;
 
 @end
 
index 8a74c731ed9d01a5c12f1872da7d44b7a2b56ab3..75fa8f695515a1dbd0f34d954d8ce9dcf82e71d6 100644 (file)
@@ -122,6 +122,15 @@ class WebCoreScriptDebuggerImp : public KJS::Debugger {
         }
         return true;
     }
+    virtual bool exception(ExecState *state, int sid, int lineno, JSValue *exception) {
+        if (!_nested) {
+            _nested = true;
+            [[_objc delegate] exceptionRaised:_current sourceId:sid line:lineno];
+            _nested = false;
+        }
+        return true;
+    }
+
 };
 
 
index 98dafdc206b40f38f132b19d3a3d062c3fcb13fd..ffcd1bd59427a16dc26d9f8c41ad96162efb642a 100644 (file)
@@ -1,3 +1,23 @@
+2006-07-23  Mark Rowe  <opendarwin.org@bdash.net.nz>
+
+        Reviewed by Maciej.
+
+        Bug 9686: [Drosera] Need the ability to break into Drosera on Javascript exceptions
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=9686
+
+        WebKit portion of the fix.
+
+        * DefaultDelegates/WebDefaultScriptDebugDelegate.m:
+        (-[WebDefaultScriptDebugDelegate webView:exceptionWasRaised:sourceId:line:forWebFrame:]):
+        * DefaultDelegates/WebScriptDebugServer.h:
+        * DefaultDelegates/WebScriptDebugServer.m:
+        (-[WebScriptDebugServer webView:exceptionWasRaised:sourceId:line:forWebFrame:]): Notify
+        listeners that an exception has been raised.
+        * WebView/WebScriptDebugDelegate.h:
+        * WebView/WebScriptDebugDelegate.m:
+        (-[WebScriptCallFrame exceptionRaised:sourceId:line:]): Dispatch through to delegate and
+        WebScriptDebugServer.
+
 2006-07-23  Adele Peterson  <adele@apple.com>
 
         Reviewed by Darin.
 
         http://bugzilla.opendarwin.org/show_bug.cgi?id=9624
         REGRESSION: After ctrl-clicking in a EMPTY input or textarea field, the contextual menu shows "Search in Google" and "Search in Spotlight" as active menu items
-        
+
         * DefaultDelegates/WebDefaultContextMenuDelegate.m:
         (-[WebDefaultUIDelegate editingContextMenuItemsForElement:defaultMenuItems:]):
         Don't create Dictionary, Spotlight or Google lookup items if there's no selection.
-        
+
 2006-07-12  Mark Rowe  <opendarwin.org@bdash.net.nz>
 
         Reviewed by Timothy.
index b9487d151a59aac05e50b2ac321512fdc881ab0e..972f013fe8b7ab8dea0baf3722d0b2a988a8490f 100644 (file)
@@ -86,4 +86,11 @@ static WebDefaultScriptDebugDelegate *sharedDelegate = nil;
 {
 }
 
+- (void)webView:(WebView *)webView   exceptionWasRaised:(WebScriptCallFrame *)frame
+                                               sourceId:(int)sid
+                                                   line:(int)lineno
+                                            forWebFrame:(WebFrame *)webFrame
+{
+}
+
 @end
index c0f7d718e15f29c05399c16e3a68e140305e0f94..c6824f5a091dbc2adb52acc16ef62fd50b908b2a 100644 (file)
@@ -69,6 +69,11 @@ extern NSString *WebScriptDebugServerWillUnloadNotification;
                                                sourceId:(int)sid
                                                    line:(int)lineno
                                             forWebFrame:(WebFrame *)webFrame;
+
+- (void)webView:(WebView *)webView   exceptionWasRaised:(WebScriptCallFrame *)frame
+                                               sourceId:(int)sid
+                                                   line:(int)lineno
+                                            forWebFrame:(WebFrame *)webFrame;
 @end
 
 @protocol WebScriptDebugServer <NSObject>
index 1516f57a23aae5b973ad592d8e53d229dccee5f4..3ab476b298a2b23abe05ce871daa2e68389f1f8f 100644 (file)
@@ -329,4 +329,26 @@ static unsigned listenerCount = 0;
     [self suspendProcessIfPaused];
 }
 
+- (void)webView:(WebView *)webView   exceptionWasRaised:(WebScriptCallFrame *)frame
+                                               sourceId:(int)sid
+                                                   line:(int)lineno
+                                            forWebFrame:(WebFrame *)webFrame
+{
+    if (![listeners count])
+        return;
+
+    NSEnumerator *enumerator = [listeners objectEnumerator];
+    NSDistantObject <WebScriptDebugListener> *listener = nil;
+
+    while ((listener = [enumerator nextObject])) {
+        if ([[listener connectionForProxy] isValid])
+            [listener webView:webView exceptionWasRaised:frame sourceId:sid line:lineno forWebFrame:webFrame];
+    }
+
+    // check for messages from the listeners, so they can pause immediately
+    [[NSRunLoop currentRunLoop] runMode:NSConnectionReplyMode beforeDate:[NSDate distantPast]];
+
+    [self suspendProcessIfPaused];
+}
+
 @end
index 1174853e1bdc20b81a693275206d46693e4d2b79..7f053240b3a26b832945be1dda52f0e482deef0c 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C283208902B0F008A9EFC /* Build configuration list for PBXProject "WebKit" */;
-                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        mainGroup = 0867D691FE84028FC02AAC07 /* WebKit */;
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
-                       shouldCheckCompatibility = 1;
                        targets = (
                                9398100A0824BF01008DF038 /* WebKit */,
                        );
index 96062158b5ed83203da1e09edc47bd9ef3dfb9a6..fc79c0170c992033eea9e1a007387fa08a954f8c 100644 (file)
@@ -84,6 +84,11 @@ enum {
                                                    line:(int)lineno
                                             forWebFrame:(WebFrame *)webFrame;
 
+// exception is being thrown
+- (void)webView:(WebView *)webView   exceptionWasRaised:(WebScriptCallFrame *)frame
+                                               sourceId:(int)sid
+                                                   line:(int)lineno
+                                            forWebFrame:(WebFrame *)webFrame;
 @end
 
 
index b3ff2d685d2638cac84385b38fc5a92ad1d940f2..03a15fd61085bf31fd7b417db818370cf699811e 100644 (file)
@@ -118,6 +118,14 @@ NSString * const WebScriptErrorLineNumberKey = @"WebScriptErrorLineNumber";
         [[WebScriptDebugServer sharedScriptDebugServer] webView:webView willLeaveCallFrame:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
 }
 
+- (void)exceptionRaised:(WebCoreScriptCallFrame *)frame sourceId:(int)sid line:(int)lineno
+{
+    WebView *webView = [_webFrame webView];
+    [[webView _scriptDebugDelegateForwarder] webView:webView exceptionWasRaised:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
+    if ([WebScriptDebugServer listenerCount])
+        [[WebScriptDebugServer sharedScriptDebugServer] webView:webView exceptionWasRaised:[frame wrapper] sourceId:sid line:lineno forWebFrame:_webFrame];
+}
+
 @end