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 0ee0c38..d8921e6 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 7fcefa8..7f091b8 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 2430b0e..c55c12e 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 056e192..3c24613 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 1b061b4..db34331 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 f0977cd..59d8b8b 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 a8492e1..71623a0 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 24b445b..18a4585 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 74b8a4b..0d19e99 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 9c524d6..e4a4a2e 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 5fd098a..444b1aa 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 59f05cc..9f6ac2f 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 94a6caf..773e275 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 e27b31f..22cc74e 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 37a6696..287d98a 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 2f20f63..2a26f40 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