[iOS] Upstream JSGlobalObject::shouldInterruptScriptBeforeTimeout()
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Oct 2013 23:54:20 +0000 (23:54 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Oct 2013 23:54:20 +0000 (23:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=123045

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

* jsc.cpp: Add function pointer for shouldInterruptScriptBeforeTimeout
to global method table.
* runtime/JSGlobalObject.cpp: Ditto.
* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::shouldInterruptScriptBeforeTimeout): Added.

Source/WebCore:

* bindings/js/JSDOMWindowBase.cpp:
(WebCore::shouldInterruptScriptToPreventInfiniteRecursionWhenClosingPage): Added.
(WebCore::JSDOMWindowBase::shouldInterruptScript): Extracted comment and assertion
about null Page object into WebCore::shouldInterruptScriptToPreventInfiniteRecursionWhenClosingPage()
so that it can be shared by both this function and JSDOMWindowBase::shouldInterruptScriptBeforeTimeout().
(WebCore::JSDOMWindowBase::shouldInterruptScriptBeforeTimeout):
* bindings/js/JSDOMWindowBase.h:
* bindings/js/JSWorkerGlobalScopeBase.cpp:
(WebCore::JSWorkerGlobalScopeBase::shouldInterruptScriptBeforeTimeout): Added.
* bindings/js/JSWorkerGlobalScopeBase.h:
* loader/EmptyClients.h: Added isStopping(). We'll land the iOS chrome client implementation
in a subsequent patch.
* page/ChromeClient.h: Added isStopping().

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

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/jsc.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Source/JavaScriptCore/runtime/JSGlobalObject.h
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMWindowBase.cpp
Source/WebCore/bindings/js/JSDOMWindowBase.h
Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.cpp
Source/WebCore/bindings/js/JSWorkerGlobalScopeBase.h
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/ChromeClient.h

index eda1968..fce69ec 100644 (file)
@@ -1,5 +1,18 @@
 2013-10-21  Daniel Bates  <dabates@apple.com>
 
+        [iOS] Upstream JSGlobalObject::shouldInterruptScriptBeforeTimeout()
+        https://bugs.webkit.org/show_bug.cgi?id=123045
+
+        Reviewed by Joseph Pecoraro.
+
+        * jsc.cpp: Add function pointer for shouldInterruptScriptBeforeTimeout
+        to global method table.
+        * runtime/JSGlobalObject.cpp: Ditto.
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::shouldInterruptScriptBeforeTimeout): Added.
+
+2013-10-21  Daniel Bates  <dabates@apple.com>
+
         [iOS] Upstream JSC Objective-C API compiler warning fixes
         https://bugs.webkit.org/show_bug.cgi?id=123125
 
index 34e39c8..13b0bd0 100644 (file)
@@ -257,7 +257,7 @@ protected:
 };
 
 const ClassInfo GlobalObject::s_info = { "global", &JSGlobalObject::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(GlobalObject) };
-const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0 };
+const GlobalObjectMethodTable GlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0, &shouldInterruptScriptBeforeTimeout };
 
 
 GlobalObject::GlobalObject(VM& vm, Structure* structure)
index e8f3af0..9cb326d 100644 (file)
@@ -122,7 +122,7 @@ namespace JSC {
 
 const ClassInfo JSGlobalObject::s_info = { "GlobalObject", &Base::s_info, 0, ExecState::globalObjectTable, CREATE_METHOD_TABLE(JSGlobalObject) };
 
-const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0 };
+const GlobalObjectMethodTable JSGlobalObject::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, 0, &shouldInterruptScriptBeforeTimeout };
 
 /* Source for JSGlobalObject.lut.h
 @begin globalObjectTable
index 04e0ba7..c8a09fb 100644 (file)
@@ -120,6 +120,9 @@ struct GlobalObjectMethodTable {
     typedef void (*QueueTaskToEventLoopCallbackFunctionPtr)(ExecState*, TaskContext*);
     typedef void (*QueueTaskToEventLoopFunctionPtr)(const JSGlobalObject*, QueueTaskToEventLoopCallbackFunctionPtr, PassRefPtr<TaskContext>);
     QueueTaskToEventLoopFunctionPtr queueTaskToEventLoop;
+
+    typedef bool (*ShouldInterruptScriptBeforeTimeoutPtr)(const JSGlobalObject*);
+    ShouldInterruptScriptBeforeTimeoutPtr shouldInterruptScriptBeforeTimeout;
 };
 
 class JSGlobalObject : public JSSegmentedVariableObject {
@@ -478,6 +481,7 @@ public:
     JS_EXPORT_PRIVATE ExecState* globalExec();
 
     static bool shouldInterruptScript(const JSGlobalObject*) { return true; }
+    static bool shouldInterruptScriptBeforeTimeout(const JSGlobalObject*) { return false; }
     static bool javaScriptExperimentsEnabled(const JSGlobalObject*) { return false; }
 
     bool evalEnabled() const { return m_evalEnabled; }
index 60d703a..3a31083 100644 (file)
@@ -1,3 +1,24 @@
+2013-10-21  Daniel Bates  <dabates@apple.com>
+
+        [iOS] Upstream JSGlobalObject::shouldInterruptScriptBeforeTimeout()
+        https://bugs.webkit.org/show_bug.cgi?id=123045
+
+        Reviewed by Joseph Pecoraro.
+
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::shouldInterruptScriptToPreventInfiniteRecursionWhenClosingPage): Added.
+        (WebCore::JSDOMWindowBase::shouldInterruptScript): Extracted comment and assertion
+        about null Page object into WebCore::shouldInterruptScriptToPreventInfiniteRecursionWhenClosingPage()
+        so that it can be shared by both this function and JSDOMWindowBase::shouldInterruptScriptBeforeTimeout().
+        (WebCore::JSDOMWindowBase::shouldInterruptScriptBeforeTimeout):
+        * bindings/js/JSDOMWindowBase.h:
+        * bindings/js/JSWorkerGlobalScopeBase.cpp:
+        (WebCore::JSWorkerGlobalScopeBase::shouldInterruptScriptBeforeTimeout): Added.
+        * bindings/js/JSWorkerGlobalScopeBase.h:
+        * loader/EmptyClients.h: Added isStopping(). We'll land the iOS chrome client implementation
+        in a subsequent patch.
+        * page/ChromeClient.h: Added isStopping().
+
 2013-10-21  Anders Carlsson  <andersca@apple.com>
 
         Navigation policy callback not called when performing the same fragment navigation twice
index 839f7b3..61da3f5 100644 (file)
@@ -51,7 +51,7 @@ static bool shouldAllowAccessFrom(const JSGlobalObject* thisObject, ExecState* e
 
 const ClassInfo JSDOMWindowBase::s_info = { "Window", &JSDOMGlobalObject::s_info, 0, 0, CREATE_METHOD_TABLE(JSDOMWindowBase) };
 
-const GlobalObjectMethodTable JSDOMWindowBase::s_globalObjectMethodTable = { &shouldAllowAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, &queueTaskToEventLoop };
+const GlobalObjectMethodTable JSDOMWindowBase::s_globalObjectMethodTable = { &shouldAllowAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout };
 
 JSDOMWindowBase::JSDOMWindowBase(VM& vm, Structure* structure, PassRefPtr<DOMWindow> window, JSDOMWindowShell* shell)
     : JSDOMGlobalObject(vm, structure, &shell->world(), &s_globalObjectMethodTable)
@@ -136,12 +136,8 @@ bool JSDOMWindowBase::supportsRichSourceInfo(const JSGlobalObject* object)
 #endif
 }
 
-bool JSDOMWindowBase::shouldInterruptScript(const JSGlobalObject* object)
+static inline bool shouldInterruptScriptToPreventInfiniteRecursionWhenClosingPage(Page* page)
 {
-    const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object);
-    ASSERT(thisObject->impl().frame());
-    Page* page = thisObject->impl().frame()->page();
-
     // See <rdar://problem/5479443>. We don't think that page can ever be NULL
     // in this case, but if it is, we've gotten into a state where we may have
     // hung the UI, with no way to ask the client whether to cancel execution.
@@ -149,10 +145,32 @@ bool JSDOMWindowBase::shouldInterruptScript(const JSGlobalObject* object)
     // ensuring that we never hang. We might want to consider other solutions
     // if we discover problems with this one.
     ASSERT(page);
-    if (!page)
+    return !page;
+}
+
+bool JSDOMWindowBase::shouldInterruptScript(const JSGlobalObject* object)
+{
+    const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object);
+    ASSERT(thisObject->impl().frame());
+    Page* page = thisObject->impl().frame()->page();
+    return shouldInterruptScriptToPreventInfiniteRecursionWhenClosingPage(page) || page->chrome().shouldInterruptJavaScript();
+}
+
+bool JSDOMWindowBase::shouldInterruptScriptBeforeTimeout(const JSGlobalObject* object)
+{
+    const JSDOMWindowBase* thisObject = static_cast<const JSDOMWindowBase*>(object);
+    ASSERT(thisObject->impl().frame());
+    Page* page = thisObject->impl().frame()->page();
+
+    if (shouldInterruptScriptToPreventInfiniteRecursionWhenClosingPage(page))
         return true;
 
-    return page->chrome().shouldInterruptJavaScript();
+#if PLATFORM(IOS)
+    if (page->chrome().client()->isStopping())
+        return true;
+#endif
+
+    return JSGlobalObject::shouldInterruptScriptBeforeTimeout(object);
 }
 
 bool JSDOMWindowBase::javaScriptExperimentsEnabled(const JSGlobalObject* object)
index 659ce0f..476991a 100644 (file)
@@ -63,6 +63,7 @@ namespace WebCore {
         static bool supportsProfiling(const JSC::JSGlobalObject*);
         static bool supportsRichSourceInfo(const JSC::JSGlobalObject*);
         static bool shouldInterruptScript(const JSC::JSGlobalObject*);
+        static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*);
         static bool javaScriptExperimentsEnabled(const JSC::JSGlobalObject*);
 
         static void queueTaskToEventLoop(const JSC::JSGlobalObject*, JSC::GlobalObjectMethodTable::QueueTaskToEventLoopCallbackFunctionPtr, PassRefPtr<JSC::TaskContext>);
index 2f97abb..ff5fdbe 100644 (file)
@@ -47,7 +47,7 @@ namespace WebCore {
 
 const ClassInfo JSWorkerGlobalScopeBase::s_info = { "WorkerGlobalScope", &JSDOMGlobalObject::s_info, 0, 0, CREATE_METHOD_TABLE(JSWorkerGlobalScopeBase) };
 
-const GlobalObjectMethodTable JSWorkerGlobalScopeBase::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, &queueTaskToEventLoop };
+const GlobalObjectMethodTable JSWorkerGlobalScopeBase::s_globalObjectMethodTable = { &allowsAccessFrom, &supportsProfiling, &supportsRichSourceInfo, &shouldInterruptScript, &javaScriptExperimentsEnabled, &queueTaskToEventLoop, &shouldInterruptScriptBeforeTimeout };
 
 JSWorkerGlobalScopeBase::JSWorkerGlobalScopeBase(JSC::VM& vm, JSC::Structure* structure, PassRefPtr<WorkerGlobalScope> impl)
     : JSDOMGlobalObject(vm, structure, &normalWorld(vm), &s_globalObjectMethodTable)
@@ -91,6 +91,11 @@ bool JSWorkerGlobalScopeBase::shouldInterruptScript(const JSGlobalObject* object
     return JSGlobalObject::shouldInterruptScript(object);
 }
 
+bool JSWorkerGlobalScopeBase::shouldInterruptScriptBeforeTimeout(const JSGlobalObject* object)
+{
+    return JSGlobalObject::shouldInterruptScriptBeforeTimeout(object);
+}
+
 bool JSWorkerGlobalScopeBase::javaScriptExperimentsEnabled(const JSGlobalObject* object)
 {
     return JSGlobalObject::javaScriptExperimentsEnabled(object);
index e2772ec..7bc9809 100644 (file)
@@ -59,6 +59,7 @@ namespace WebCore {
         static bool supportsProfiling(const JSC::JSGlobalObject*);
         static bool supportsRichSourceInfo(const JSC::JSGlobalObject*);
         static bool shouldInterruptScript(const JSC::JSGlobalObject*);
+        static bool shouldInterruptScriptBeforeTimeout(const JSC::JSGlobalObject*);
         static bool javaScriptExperimentsEnabled(const JSC::JSGlobalObject*);
         static void queueTaskToEventLoop(const JSC::JSGlobalObject*, JSC::GlobalObjectMethodTable::QueueTaskToEventLoopCallbackFunctionPtr, PassRefPtr<JSC::TaskContext>);
 
index cd45a16..e021347 100644 (file)
@@ -190,6 +190,11 @@ public:
     virtual void AXStartFrameLoad() OVERRIDE { }
     virtual void AXFinishFrameLoad() OVERRIDE { }
 #endif
+
+#if PLATFORM(IOS)
+    virtual bool isStopping() OVERRIDE { return false; }
+#endif
+
 #if ENABLE(TOUCH_EVENTS)
     virtual void needTouchEvents(bool) OVERRIDE { }
 #endif
index e436106..d92f8af 100644 (file)
@@ -304,6 +304,11 @@ public:
     virtual void makeFirstResponder() { }
 #endif
 
+#if PLATFORM(IOS)
+    // FIXME: Come up with a more descriptive name for this function and make it platform independent (if possible).
+    virtual bool isStopping() = 0;
+#endif
+
     virtual void enableSuddenTermination() { }
     virtual void disableSuddenTermination() { }