JavaScriptCore:
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Jun 2006 17:11:51 +0000 (17:11 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 18 Jun 2006 17:11:51 +0000 (17:11 +0000)
2006-06-18  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Geoff.

        * kjs/interpreter.cpp:
        (KJS::TimeoutChecker::pauseTimeoutCheck):
        Do nothing if the timeout check hasn't been started.

        (KJS::TimeoutChecker::resumeTimeoutCheck):
        Do nothing if the timeout check hasn't been started.
        Use the right signal handler when unblocking.

        (KJS::Interpreter::handleTimeout):
        pause/resume the timeout check around the call to
        shouldInterruptScript().

WebCore:

2006-06-17  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Geoff.

        * bindings/js/kjs_binding.cpp:
        (KJS::ScriptInterpreter::ScriptInterpreter):
        Set the default script timeout.

        (KJS::ScriptInterpreter::shouldInterruptScript):
        New function which asks the frame if the script should be interrupted.

        * bindings/js/kjs_binding.h:

        * bindings/js/kjs_events.cpp:
        (KJS::JSAbstractEventListener::handleEvent):
        * bindings/js/kjs_proxy.cpp:
        (WebCore::KJSProxy::evaluate):
        Add calls to startTimeoutCheck/stopTimeoutCheck

        * bindings/js/kjs_window.cpp:
        (KJS::WindowFunc::callAsFunction):
        Add calls to pauseTimeoutCheck/unpauseTimeoutCheck

        (KJS::ScheduledAction::execute):
        Add calls to startTimeoutCheck/stopTimeoutCheck

        * bridge/mac/FrameMac.h:
        * bridge/mac/FrameMac.mm:
        (WebCore::FrameMac::shouldInterruptJavaScript):
        New function which asks the bridge if the script should be interrupted.

        * bridge/mac/WebCoreFrameBridge.h:
        * page/Frame.h:
        Add function declarations.

WebKit:

2006-06-18  Anders Carlsson  <acarlsson@apple.com>

        Reviewed by Geoff.

        * WebCoreSupport/WebFrameBridge.m:
        (-[WebFrameBridge shouldInterruptJavaScript]):
        Ask the UI delegate if the script should be interrupted.

        * WebView/WebUIDelegatePrivate.h:
        Declare webViewShouldInterruptJavaScript: delegate method

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

16 files changed:
JavaScriptCore/ChangeLog
JavaScriptCore/kjs/interpreter.cpp
JavaScriptCore/kjs/interpreter.h
WebCore/ChangeLog
WebCore/bindings/js/kjs_binding.cpp
WebCore/bindings/js/kjs_binding.h
WebCore/bindings/js/kjs_events.cpp
WebCore/bindings/js/kjs_proxy.cpp
WebCore/bindings/js/kjs_window.cpp
WebCore/bridge/mac/FrameMac.h
WebCore/bridge/mac/FrameMac.mm
WebCore/bridge/mac/WebCoreFrameBridge.h
WebCore/page/Frame.h
WebKit/ChangeLog
WebKit/WebCoreSupport/WebFrameBridge.m
WebKit/WebView/WebUIDelegatePrivate.h

index 0ee0c3842170786e834c24225708b02fbeadc52c..d8921e632f7e63328406922fdbd2774f289fd7b1 100644 (file)
@@ -1,3 +1,19 @@
+2006-06-18  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        * kjs/interpreter.cpp:
+        (KJS::TimeoutChecker::pauseTimeoutCheck):
+        Do nothing if the timeout check hasn't been started.
+        
+        (KJS::TimeoutChecker::resumeTimeoutCheck):
+        Do nothing if the timeout check hasn't been started.
+        Use the right signal handler when unblocking.
+        
+        (KJS::Interpreter::handleTimeout):
+        pause/resume the timeout check around the call to
+        shouldInterruptScript().
+        
 2006-06-16  Ben Goodger <beng@google.com>
         
         Reviewed by Maciej
@@ -11,7 +27,6 @@
         Make sure to only assert equality with s_executingInterpreter when it 
         is being used (i.e. when HAVE(SYS_TIME_H) == true)
 
-
 2006-06-17  David Kilzer  <ddkilzer@kilzer.net>
 
         Reviewed by darin.
index 7fcefa88c564d95b6ad5aa8795f48a27d36d0ac9..7f091b88ffa9d8f908db8b9765ef85274588ecc3 100644 (file)
@@ -142,7 +142,10 @@ void TimeoutChecker::alarmHandler(int)
 
 void TimeoutChecker::pauseTimeoutCheck(Interpreter* interpreter)
 {
-#if HAVE(SYS_TIME_H)
+    if (interpreter->m_startTimeoutCheckCount == 0)
+        return;
+
+#if HAVE(SYS_TIME_H)    
     ASSERT(interpreter == s_executingInterpreter);
 
     void (*currentSignalHandler)(int);
@@ -163,6 +166,9 @@ void TimeoutChecker::pauseTimeoutCheck(Interpreter* interpreter)
 
 void TimeoutChecker::resumeTimeoutCheck(Interpreter* interpreter)
 {
+    if (interpreter->m_startTimeoutCheckCount == 0)
+        return;
+
 #if HAVE(SYS_TIME_H)
     ASSERT(interpreter == s_executingInterpreter);
 #endif
@@ -186,7 +192,7 @@ void TimeoutChecker::resumeTimeoutCheck(Interpreter* interpreter)
     setitimer(ITIMER_REAL, 0L, &m_pausetv);    
 
     // Unblock signal
-    currentSignalHandler = signal(SIGALRM, SIG_IGN);    
+    currentSignalHandler = signal(SIGALRM, alarmHandler);    
 #endif
 }
 
@@ -801,8 +807,12 @@ void Interpreter::resumeTimeoutCheck()
 bool Interpreter::handleTimeout()
 {
     m_timedOut = false;
+
+    pauseTimeoutCheck();
+    bool retval = shouldInterruptScript();
+    resumeTimeoutCheck();
     
-    return shouldInterruptScript();
+    return retval;
 }
 
 
index 2430b0e5fcf816717caaf273640cdd263aa39baa..c55c12e5b645f8fb60ecf3d9e9f845a5130e8bc6 100644 (file)
@@ -336,7 +336,7 @@ namespace KJS {
     bool checkTimeout();
     
 protected:
-    virtual bool shouldInterruptScript() { return true; }
+    virtual bool shouldInterruptScript() const { return true; }
     long m_timeoutTime;
 
 private:
index 056e1922ea09eb872f5d6a4589d12620a1298faf..3c24613e68c91137e6ad4af8d3211ab2166b1152 100644 (file)
@@ -1,3 +1,38 @@
+2006-06-17  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        * bindings/js/kjs_binding.cpp:
+        (KJS::ScriptInterpreter::ScriptInterpreter):
+        Set the default script timeout.
+        
+        (KJS::ScriptInterpreter::shouldInterruptScript):
+        New function which asks the frame if the script should be interrupted.
+        
+        * bindings/js/kjs_binding.h:
+                
+        * bindings/js/kjs_events.cpp:
+        (KJS::JSAbstractEventListener::handleEvent):
+        * bindings/js/kjs_proxy.cpp:
+        (WebCore::KJSProxy::evaluate):
+        Add calls to startTimeoutCheck/stopTimeoutCheck
+        
+        * bindings/js/kjs_window.cpp:
+        (KJS::WindowFunc::callAsFunction):
+        Add calls to pauseTimeoutCheck/unpauseTimeoutCheck 
+        
+        (KJS::ScheduledAction::execute):
+        Add calls to startTimeoutCheck/stopTimeoutCheck
+        
+        * bridge/mac/FrameMac.h:
+        * bridge/mac/FrameMac.mm:
+        (WebCore::FrameMac::shouldInterruptJavaScript):
+        New function which asks the bridge if the script should be interrupted.
+        
+        * bridge/mac/WebCoreFrameBridge.h:
+        * page/Frame.h:
+        Add function declarations.
+        
 2006-06-17  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by ggaren.
index 1b061b48c46235340cf5b4239c0d1ba7a3cf0eeb..db34331b85b952ae18708d5a1de04ae5734e06e4 100644 (file)
@@ -68,6 +68,10 @@ ScriptInterpreter::ScriptInterpreter( JSObject *global, Frame *frame )
   : Interpreter( global ), m_frame(frame),
     m_evt( 0L ), m_inlineCode(false), m_timerCallback(false)
 {
+    // Time in milliseconds before the script timeout handler kicks in
+    const unsigned ScriptTimeoutTimeMS = 5000;
+        
+    setTimeoutTime(ScriptTimeoutTimeMS);
 }
 
 ScriptInterpreter::~ScriptInterpreter()
@@ -246,7 +250,11 @@ void *ScriptInterpreter::createLanguageInstanceForValue (ExecState *exec, int la
     return result;
 }
 
-
+bool ScriptInterpreter::shouldInterruptScript() const
+{
+    return m_frame->shouldInterruptJavaScript();
+}
+    
 //////
 
 JSValue *jsStringOrNull(const String &s)
index f0977cd77781469363a880a442b3bc183d2a4687..59d8b8b7246745ab9236abebcf29dd2eff6a380e 100644 (file)
@@ -101,6 +101,8 @@ namespace KJS {
     virtual void *createLanguageInstanceForValue (ExecState *exec, int language, JSObject *value, const Bindings::RootObject *origin, const Bindings::RootObject *current);
     void *createObjcInstanceForValue (ExecState *exec, JSObject *value, const Bindings::RootObject *origin, const Bindings::RootObject *current);
 
+    virtual bool shouldInterruptScript() const;
+
   private:
     WebCore::Frame* m_frame;
 
index a8492e1a44075f21cb4d896bb67cdb838b52449b..71623a0719ecc16cd639057e28b01c55c147449e 100644 (file)
@@ -94,16 +94,19 @@ void JSAbstractEventListener::handleEvent(Event* ele, bool isWindowEvent)
         interpreter->setCurrentEvent(event);
       
         JSValue* retval;
-        if (handleEventFunc)
+        if (handleEventFunc) {
+            interpreter->startTimeoutCheck();
             retval = handleEventFunc->call(exec, listener, args);
-        else {
+        else {
             JSObject* thisObj;
             if (isWindowEvent)
                 thisObj = window;
             else
                 thisObj = static_cast<JSObject*>(toJS(exec, event->currentTarget()));
+            interpreter->startTimeoutCheck();
             retval = listener->call(exec, thisObj, args);
         }
+        interpreter->stopTimeoutCheck();
 
         window->setCurrentEvent(0);
         interpreter->setCurrentEvent(0);
index 24b445b37592d6bd4a6f3aaa0ab2016033cd4c8e..18a45856e72bc161a76b9d1cd54c2ac176f9b013 100644 (file)
@@ -65,8 +65,11 @@ JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String&
   JSLock lock;
 
   JSValue* thisNode = n ? Window::retrieve(m_frame) : toJS(m_script->globalExec(), n);
+  
+  m_script->startTimeoutCheck();
   Completion comp = m_script->evaluate(filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
-
+  m_script->stopTimeoutCheck();
+  
   if (comp.complType() == Normal || comp.complType() == ReturnValue)
     return comp.value();
 
index 74b8a4b3d1f05d6bfbd1d971c7126be80c40ff6e..0d19e99b351cfb9435d87318109875b7281c2f1e 100644 (file)
@@ -1516,12 +1516,18 @@ JSValue *WindowFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const Li
   case Window::Alert:
     if (frame && frame->document())
       frame->document()->updateRendering();
+    exec->dynamicInterpreter()->pauseTimeoutCheck();
     frame->runJavaScriptAlert(str);
+    exec->dynamicInterpreter()->resumeTimeoutCheck();
     return jsUndefined();
-  case Window::Confirm:
+  case Window::Confirm: {
     if (frame && frame->document())
       frame->document()->updateRendering();
-    return jsBoolean(frame->runJavaScriptConfirm(str));
+    exec->dynamicInterpreter()->pauseTimeoutCheck();
+    bool result = frame->runJavaScriptConfirm(str);
+    exec->dynamicInterpreter()->resumeTimeoutCheck();
+    return jsBoolean(result);
+  }
   case Window::Prompt:
   {
     if (frame && frame->document())
@@ -1772,8 +1778,12 @@ JSValue *WindowFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const Li
             if (Document *doc = frame->document())
                 doc->removeWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec));
         return jsUndefined();
-  case Window::ShowModalDialog:
-    return showModalDialog(exec, window, args);
+  case Window::ShowModalDialog: {
+    exec->dynamicInterpreter()->pauseTimeoutCheck();
+    JSValue* result = showModalDialog(exec, window, args);
+    exec->dynamicInterpreter()->resumeTimeoutCheck();      
+    return result;
+  }
   }
   return jsUndefined();
 }
@@ -1801,7 +1811,9 @@ void ScheduledAction::execute(Window *window)
             ExecState *exec = interpreter->globalExec();
             ASSERT(window == interpreter->globalObject());
             JSLock lock;
+            interpreter->startTimeoutCheck();
             static_cast<JSObject *>(func)->call(exec, window, m_args);
+            interpreter->stopTimeoutCheck();
             if (exec->hadException()) {
                 JSObject* exception = exec->exception()->toObject(exec);
                 exec->clearException();
index 9c524d6b5c2d614f4d46f01477a5f237303f6941..e4a4a2eabc2e570c14ace472ab93991ee3320009 100644 (file)
@@ -166,6 +166,7 @@ public:
     virtual void runJavaScriptAlert(const String&);
     virtual bool runJavaScriptConfirm(const String&);
     virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue, String& result);
+    virtual bool shouldInterruptJavaScript();    
     virtual bool locationbarVisible();
     virtual bool menubarVisible();
     virtual bool personalbarVisible();
index 5fd098aa8a137ae9da8cbf2eae9ffb8d403b33c5..444b1aa84fe846b2ee52ad2d011a46b33b030e21 100644 (file)
@@ -1257,6 +1257,15 @@ bool FrameMac::runJavaScriptPrompt(const String& prompt, const String& defaultVa
     return false;
 }
 
+bool FrameMac::shouldInterruptJavaScript()
+{
+    BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    return [_bridge shouldInterruptJavaScript];
+    END_BLOCK_OBJC_EXCEPTIONS;
+    
+    return false;
+}
+
 bool FrameMac::locationbarVisible()
 {
     return [_bridge areToolbarsVisible];
index 59f05ccbe06cb37dca8bd9e98ddf4e0c0400eff7..9f6ac2ff1e584f6a8f8df219a9e7f1880b5090bd 100644 (file)
@@ -551,6 +551,7 @@ typedef enum {
 - (void)runJavaScriptAlertPanelWithMessage:(NSString *)message;
 - (BOOL)runJavaScriptConfirmPanelWithMessage:(NSString *)message;
 - (BOOL)runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText returningText:(NSString **)result;
+- (BOOL)shouldInterruptJavaScript;
 - (BOOL)canRunBeforeUnloadConfirmPanel;
 - (BOOL)runBeforeUnloadConfirmPanelWithMessage:(NSString *)message;
 - (void)addMessageToConsole:(NSDictionary *)message;
index 94a6caf2587ec68e5af1be64e31b140c83c6c5dc..773e275af2f0b5bcc4ea8052ce0b914cfbc8c2cb 100644 (file)
@@ -534,6 +534,7 @@ public:
   virtual void runJavaScriptAlert(const String& message) = 0;
   virtual bool runJavaScriptConfirm(const String& message) = 0;
   virtual bool runJavaScriptPrompt(const String& message, const String& defaultValue, String& result) = 0;  
+  virtual bool shouldInterruptJavaScript() = 0;
   virtual bool locationbarVisible() = 0;
   virtual bool menubarVisible() = 0;
   virtual bool personalbarVisible() = 0;
index e27b31fa2294eabaeca13a7e756823aea793f375..22cc74eef278d92a0c2de6349e704a0bf85ec66c 100644 (file)
@@ -1,3 +1,14 @@
+2006-06-18  Anders Carlsson  <acarlsson@apple.com>
+
+        Reviewed by Geoff.
+
+        * WebCoreSupport/WebFrameBridge.m:
+        (-[WebFrameBridge shouldInterruptJavaScript]):
+        Ask the UI delegate if the script should be interrupted.
+        
+        * WebView/WebUIDelegatePrivate.h:
+        Declare webViewShouldInterruptJavaScript: delegate method
+
 2006-06-17  Mitz Pettel  <opendarwin.org@mitzpettel.com>
 
         Reviewed by Darin.
index 37a6696a11c44b78a75ffbe163a4ad112dcba84f..287d98a5da37182ba159278105e01f98866553b6 100644 (file)
@@ -407,6 +407,16 @@ NSString *WebPluginContainerKey =   @"WebPluginContainer";
     return [[WebDefaultUIDelegate sharedUIDelegate] webView:wv runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:_frame];
 }
 
+- (BOOL)shouldInterruptJavaScript
+{
+    WebView *wv = [self webView];
+    id wd = [wv UIDelegate];
+    
+    if ([wd respondsToSelector:@selector(webViewShouldInterruptJavaScript:)])
+        return [wd webViewShouldInterruptJavaScript:wv];
+    return NO;
+}
+
 - (BOOL)canRunBeforeUnloadConfirmPanel
 {
     WebView *wv = [self webView];
index 2f20f6388872a9ba933ef8a5a143074ebc4806ea..2a26f40295aadf1585fad91d659ed897b660d316 100644 (file)
 
 - (void)webView:(WebView *)sender dragImage:(NSImage *)anImage at:(NSPoint)viewLocation offset:(NSSize)initialOffset event:(NSEvent *)event pasteboard:(NSPasteboard *)pboard source:(id)sourceObj slideBack:(BOOL)slideFlag forView:(NSView *)view;
 
+- (BOOL)webViewShouldInterruptJavaScript:(WebView *)sender;
+
 @end