2009-04-28 Sam Weinig <sam@webkit.org>
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Apr 2009 20:30:52 +0000 (20:30 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Apr 2009 20:30:52 +0000 (20:30 +0000)
        Reviewed by Beth Dakin.

        Consolidate ScheduleAction creation into ScheduledAction::create.
        Autogenerate JSWorkerContext.clearTimeout and clearInterval.

        * bindings/js/JSDOMWindowCustom.cpp:
        (WebCore::JSDOMWindow::setTimeout):
        (WebCore::JSDOMWindow::setInterval):
        * bindings/js/JSWorkerContextCustom.cpp:
        (WebCore::JSWorkerContext::setTimeout):
        (WebCore::JSWorkerContext::setInterval):
        * bindings/js/ScheduledAction.cpp:
        (WebCore::ScheduledAction::create):
        (WebCore::ScheduledAction::ScheduledAction):
        (WebCore::ScheduledAction::execute):
        * bindings/js/ScheduledAction.h:
        * workers/WorkerContext.cpp:
        (WebCore::DOMWindow::setTimeout):
        (WebCore::DOMWindow::clearTimeout):
        (WebCore::DOMWindow::setInterval):
        (WebCore::DOMWindow::clearInterval):
        * workers/WorkerContext.h:
        * workers/WorkerContext.idl:

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

WebCore/ChangeLog
WebCore/bindings/js/JSDOMWindowCustom.cpp
WebCore/bindings/js/JSWorkerContextCustom.cpp
WebCore/bindings/js/ScheduledAction.cpp
WebCore/bindings/js/ScheduledAction.h
WebCore/workers/WorkerContext.cpp
WebCore/workers/WorkerContext.h
WebCore/workers/WorkerContext.idl

index e569a4b..d42a124 100644 (file)
@@ -1,3 +1,29 @@
+2009-04-28  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Beth Dakin.
+
+        Consolidate ScheduleAction creation into ScheduledAction::create.
+        Autogenerate JSWorkerContext.clearTimeout and clearInterval.
+
+        * bindings/js/JSDOMWindowCustom.cpp:
+        (WebCore::JSDOMWindow::setTimeout):
+        (WebCore::JSDOMWindow::setInterval):
+        * bindings/js/JSWorkerContextCustom.cpp:
+        (WebCore::JSWorkerContext::setTimeout):
+        (WebCore::JSWorkerContext::setInterval):
+        * bindings/js/ScheduledAction.cpp:
+        (WebCore::ScheduledAction::create):
+        (WebCore::ScheduledAction::ScheduledAction):
+        (WebCore::ScheduledAction::execute):
+        * bindings/js/ScheduledAction.h:
+        * workers/WorkerContext.cpp:
+        (WebCore::DOMWindow::setTimeout):
+        (WebCore::DOMWindow::clearTimeout):
+        (WebCore::DOMWindow::setInterval):
+        (WebCore::DOMWindow::clearInterval):
+        * workers/WorkerContext.h:
+        * workers/WorkerContext.idl:
+
 2009-04-28  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Darin Adler
index 7b20e09..887ea61 100644 (file)
@@ -495,22 +495,9 @@ JSValuePtr JSDOMWindow::postMessage(ExecState* exec, const ArgList& args)
     return jsUndefined();
 }
 
-static ScheduledAction* createScheduledAction(ExecState* exec, const ArgList& args)
-{
-    JSValuePtr v = args.at(exec, 0);
-    if (v.isString())
-        return new ScheduledAction(asString(v)->value());
-    CallData callData;
-    if (v.getCallData(callData) == CallTypeNone)
-        return 0;
-    ArgList argsTail;
-    args.getSlice(2, argsTail);
-    return new ScheduledAction(exec, v, argsTail);
-}
-
 JSValuePtr JSDOMWindow::setTimeout(ExecState* exec, const ArgList& args)
 {
-    ScheduledAction* action = createScheduledAction(exec, args);
+    ScheduledAction* action = ScheduledAction::create(exec, args);
     if (!action)
         return jsUndefined();
     int delay = args.at(exec, 1).toInt32(exec);
@@ -519,7 +506,7 @@ JSValuePtr JSDOMWindow::setTimeout(ExecState* exec, const ArgList& args)
 
 JSValuePtr JSDOMWindow::setInterval(ExecState* exec, const ArgList& args)
 {
-    ScheduledAction* action = createScheduledAction(exec, args);
+    ScheduledAction* action = ScheduledAction::create(exec, args);
     if (!action)
         return jsUndefined();
     int delay = args.at(exec, 1).toInt32(exec);
index 71cdf0a..c5219f0 100644 (file)
@@ -121,40 +121,22 @@ JSValuePtr JSWorkerContext::removeEventListener(ExecState* exec, const ArgList&
     return jsUndefined();
 }
 
-static JSValuePtr setTimeoutOrInterval(ExecState* exec, WorkerContext* workerContext, const ArgList& args, bool singleShot)
-{
-    JSValuePtr v = args.at(exec, 0);
-    int delay = args.at(exec, 1).toInt32(exec);
-    if (v.isString())
-        return jsNumber(exec, workerContext->installTimeout(new ScheduledAction(asString(v)->value()), delay, singleShot));
-    CallData callData;
-    if (v.getCallData(callData) == CallTypeNone)
-        return jsUndefined();
-    ArgList argsTail;
-    args.getSlice(2, argsTail);
-    return jsNumber(exec, workerContext->installTimeout(new ScheduledAction(exec, v, argsTail), delay, singleShot));
-}
-
 JSValuePtr JSWorkerContext::setTimeout(ExecState* exec, const ArgList& args)
 {
-    return setTimeoutOrInterval(exec, impl(), args, true);
-}
-
-JSValuePtr JSWorkerContext::clearTimeout(ExecState* exec, const ArgList& args)
-{
-    impl()->removeTimeout(args.at(exec, 0).toInt32(exec));
-    return jsUndefined();
+    ScheduledAction* action = ScheduledAction::create(exec, args);
+    if (!action)
+        return jsUndefined();
+    int delay = args.at(exec, 1).toInt32(exec);
+    return jsNumber(exec, impl()->setTimeout(action, delay));
 }
 
 JSValuePtr JSWorkerContext::setInterval(ExecState* exec, const ArgList& args)
 {
-    return setTimeoutOrInterval(exec, impl(), args, false);
-}
-
-JSValuePtr JSWorkerContext::clearInterval(ExecState* exec, const ArgList& args)
-{
-    impl()->removeTimeout(args.at(exec, 0).toInt32(exec));
-    return jsUndefined();
+    ScheduledAction* action = ScheduledAction::create(exec, args);
+    if (!action)
+        return jsUndefined();
+    int delay = args.at(exec, 1).toInt32(exec);
+    return jsNumber(exec, impl()->setInterval(action, delay));
 }
 
 } // namespace WebCore
index 6b531bd..506e439 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  Copyright (C) 2000 Harri Porten (porten@kde.org)
  *  Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
- *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
+ *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved.
  *  Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
  *  Copyright (C) 2009 Google Inc. All rights reseved.
  *
@@ -47,13 +47,25 @@ using namespace JSC;
 
 namespace WebCore {
 
+ScheduledAction* ScheduledAction::create(ExecState* exec, const ArgList& args)
+{
+    JSValuePtr v = args.at(exec, 0);
+    if (v.isString())
+        return new ScheduledAction(asString(v)->value());
+    CallData callData;
+    if (v.getCallData(callData) == CallTypeNone)
+        return 0;
+    ArgList argsTail;
+    args.getSlice(2, argsTail);
+    return new ScheduledAction(exec, v, argsTail);
+}
+
 ScheduledAction::ScheduledAction(ExecState* exec, JSValuePtr function, const ArgList& args)
     : m_function(function)
 {
     ArgList::const_iterator end = args.end();
-    for (ArgList::const_iterator it = args.begin(); it != end; ++it) {
+    for (ArgList::const_iterator it = args.begin(); it != end; ++it)
         m_args.append((*it).jsValue(exec));
-    }
 }
 
 void ScheduledAction::execute(ScriptExecutionContext* context)
@@ -95,24 +107,6 @@ void ScheduledAction::executeFunctionInContext(JSGlobalObject* globalObject, JSV
         reportCurrentException(exec);
 }
 
-#if ENABLE(WORKERS)
-void ScheduledAction::execute(WorkerContext* workerContext)
-{
-    // In a Worker, the execution should always happen on a worker thread.
-    ASSERT(workerContext->thread()->threadID() == currentThread());
-
-    WorkerScriptController* scriptController = workerContext->script();
-
-    if (m_function) {
-        JSWorkerContext* contextWrapper = scriptController->workerContextWrapper();
-        executeFunctionInContext(contextWrapper, contextWrapper);
-    } else {
-        ScriptSourceCode code(m_code, workerContext->url());
-        scriptController->evaluate(code);
-    }
-}
-#endif // ENABLE(WORKERS)
-
 void ScheduledAction::execute(Document* document)
 {
     JSDOMWindow* window = toJSDOMWindow(document->frame());
@@ -134,4 +128,22 @@ void ScheduledAction::execute(Document* document)
     frame->script()->setProcessingTimerCallback(false);
 }
 
+#if ENABLE(WORKERS)
+void ScheduledAction::execute(WorkerContext* workerContext)
+{
+    // In a Worker, the execution should always happen on a worker thread.
+    ASSERT(workerContext->thread()->threadID() == currentThread());
+
+    WorkerScriptController* scriptController = workerContext->script();
+
+    if (m_function) {
+        JSWorkerContext* contextWrapper = scriptController->workerContextWrapper();
+        executeFunctionInContext(contextWrapper, contextWrapper);
+    } else {
+        ScriptSourceCode code(m_code, workerContext->url());
+        scriptController->evaluate(code);
+    }
+}
+#endif // ENABLE(WORKERS)
+
 } // namespace WebCore
index a1dbbe4..e7b5d64 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 2000 Harri Porten (porten@kde.org)
- *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
+ *  Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reseved.
  *
  *  This library is free software; you can redistribute it and/or
  *  modify it under the terms of the GNU Lesser General Public
@@ -40,15 +40,17 @@ namespace WebCore {
     */
     class ScheduledAction {
     public:
+        static ScheduledAction* create(JSC::ExecState*, const JSC::ArgList&);
+
+        void execute(ScriptExecutionContext*);
+
+    private:
         ScheduledAction(JSC::ExecState* exec, JSC::JSValuePtr function, const JSC::ArgList&);
         ScheduledAction(const String& code)
             : m_code(code)
         {
         }
 
-        void execute(ScriptExecutionContext*);
-
-    private:
         void executeFunctionInContext(JSC::JSGlobalObject*, JSC::JSValuePtr thisValue);
         void execute(Document*);
 #if ENABLE(WORKERS)        
index 8cf431e..bd05000 100644 (file)
@@ -201,12 +201,22 @@ void WorkerContext::postTask(PassRefPtr<Task> task)
     thread()->runLoop().postTask(task);
 }
 
-int WorkerContext::installTimeout(ScheduledAction* action, int timeout, bool singleShot)
+int WorkerContext::setTimeout(ScheduledAction* action, int timeout)
 {
-    return DOMTimer::install(scriptExecutionContext(), action, timeout, singleShot);
+    return DOMTimer::install(scriptExecutionContext(), action, timeout, true);
 }
 
-void WorkerContext::removeTimeout(int timeoutId)
+void WorkerContext::clearTimeout(int timeoutId)
+{
+    DOMTimer::removeById(scriptExecutionContext(), timeoutId);
+}
+
+int WorkerContext::setInterval(ScheduledAction* action, int timeout)
+{
+    return DOMTimer::install(scriptExecutionContext(), action, timeout, false);
+}
+
+void WorkerContext::clearInterval(int timeoutId)
 {
     DOMTimer::removeById(scriptExecutionContext(), timeoutId);
 }
index 39a5b9b..c42712d 100644 (file)
@@ -83,8 +83,11 @@ namespace WebCore {
         void postMessage(const String& message);
         virtual void postTask(PassRefPtr<Task>); // Executes the task on context's thread asynchronously.
 
-        int installTimeout(ScheduledAction*, int timeout, bool singleShot);
-        void removeTimeout(int timeoutId);
+        // Timers
+        int setTimeout(ScheduledAction*, int timeout);
+        void clearTimeout(int timeoutId);
+        int setInterval(ScheduledAction*, int timeout);
+        void clearInterval(int timeoutId);
 
         void dispatchMessage(const String&);
 
index 91d87aa..f6ec3b4 100644 (file)
@@ -53,11 +53,11 @@ module threads {
         // Timers
         [Custom] long setTimeout(in TimeoutHandler handler, in long timeout);
         // [Custom] long setTimeout(in DOMString code, in long timeout);
-        [Custom] void clearTimeout(in long handle);
+        void clearTimeout(in long handle);
 
         [Custom] long setInterval(in TimeoutHandler handler, in long timeout);
         // [Custom] long setInterval(in DOMString code, in long timeout);
-        [Custom] void clearInterval(in long handle);
+        void clearInterval(in long handle);
 
         // EventTarget interface
         [Custom] void addEventListener(in DOMString type,