Commit 007f8309 authored by weinig@apple.com's avatar weinig@apple.com

Reviewed by Maciej.

        Yet more of http://bugs.webkit.org/show_bug.cgi?id=16385
        Cleanup kjs_window

        - Move ScheduledAction into its own file and put it in the WebCore namespace.

        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * WebCoreSources.bkl:
        * bindings/js/PausedTimeouts.cpp:
        * bindings/js/PausedTimeouts.h:
        * bindings/js/ScheduledAction.cpp: Copied from bindings/js/kjs_window.cpp.
        (WebCore::ScheduledAction::ScheduledAction):
        (WebCore::ScheduledAction::execute):
        * bindings/js/ScheduledAction.h: Copied from bindings/js/kjs_window.h.
        (WebCore::ScheduledAction::ScheduledAction):
        * bindings/js/kjs_window.cpp:
        (KJS::DOMWindowTimer::DOMWindowTimer):
        (KJS::DOMWindowTimer::action):
        (KJS::DOMWindowTimer::takeAction):
        (KJS::Window::installTimeout):
        (KJS::Window::timerFired):
        * bindings/js/kjs_window.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@28794 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 28e8eb90
2007-12-16 Sam Weinig <sam@webkit.org>
Reviewed by Maciej.
Yet more of http://bugs.webkit.org/show_bug.cgi?id=16385
Cleanup kjs_window
- Move ScheduledAction into its own file and put it in the WebCore namespace.
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* WebCoreSources.bkl:
* bindings/js/PausedTimeouts.cpp:
* bindings/js/PausedTimeouts.h:
* bindings/js/ScheduledAction.cpp: Copied from bindings/js/kjs_window.cpp.
(WebCore::ScheduledAction::ScheduledAction):
(WebCore::ScheduledAction::execute):
* bindings/js/ScheduledAction.h: Copied from bindings/js/kjs_window.h.
(WebCore::ScheduledAction::ScheduledAction):
* bindings/js/kjs_window.cpp:
(KJS::DOMWindowTimer::DOMWindowTimer):
(KJS::DOMWindowTimer::action):
(KJS::DOMWindowTimer::takeAction):
(KJS::Window::installTimeout):
(KJS::Window::timerFired):
* bindings/js/kjs_window.h:
2007-12-16 Alp Toker <alp@atoker.com>
Reviewed by Maciej.
......
......@@ -419,6 +419,7 @@ SOURCES += \
bindings/js/kjs_proxy.cpp \
bindings/js/kjs_window.cpp \
bindings/js/PausedTimeouts.cpp \
bindings/js/ScheduledAction.cpp \
css/CSSBorderImageValue.cpp \
css/CSSCharsetRule.cpp \
css/CSSComputedStyleDeclaration.cpp \
......
......@@ -7647,6 +7647,14 @@
RelativePath="..\bindings\js\PausedTimeouts.h"
>
</File>
<File
RelativePath="..\bindings\js\ScheduledAction.cpp"
>
</File>
<File
RelativePath="..\bindings\js\ScheduledAction.h"
>
</File>
</Filter>
</Filter>
<Filter
......
......@@ -3643,6 +3643,8 @@
BCA169A30BFD55B40019CA76 /* JSHTMLTableCaptionElement.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA169A10BFD55B40019CA76 /* JSHTMLTableCaptionElement.h */; };
BCA378160D15C64600B793D6 /* PausedTimeouts.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCA378140D15C64600B793D6 /* PausedTimeouts.cpp */; };
BCA378170D15C64600B793D6 /* PausedTimeouts.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA378150D15C64600B793D6 /* PausedTimeouts.h */; };
BCA378BC0D15F64200B793D6 /* ScheduledAction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */; };
BCA378BD0D15F64200B793D6 /* ScheduledAction.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA378BB0D15F64200B793D6 /* ScheduledAction.h */; };
BCA85A100C3AEAF4006F8308 /* DOMSVGNumberInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = BCA85A0F0C3AEAF4006F8308 /* DOMSVGNumberInternal.h */; };
BCAA90C30A7EBA60008B1229 /* ScrollBar.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCAA90C20A7EBA60008B1229 /* ScrollBar.cpp */; };
BCB16B8B0979B01400467741 /* DeprecatedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB16B880979B01400467741 /* DeprecatedArray.h */; settings = {ATTRIBUTES = (Private, ); }; };
......@@ -7654,6 +7656,8 @@
BCA169A10BFD55B40019CA76 /* JSHTMLTableCaptionElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSHTMLTableCaptionElement.h; sourceTree = "<group>"; };
BCA378140D15C64600B793D6 /* PausedTimeouts.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PausedTimeouts.cpp; sourceTree = "<group>"; };
BCA378150D15C64600B793D6 /* PausedTimeouts.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PausedTimeouts.h; sourceTree = "<group>"; };
BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScheduledAction.cpp; sourceTree = "<group>"; };
BCA378BB0D15F64200B793D6 /* ScheduledAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScheduledAction.h; sourceTree = "<group>"; };
BCA85A0F0C3AEAF4006F8308 /* DOMSVGNumberInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMSVGNumberInternal.h; sourceTree = "<group>"; };
BCAA90C20A7EBA60008B1229 /* ScrollBar.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ScrollBar.cpp; path = platform/ScrollBar.cpp; sourceTree = SOURCE_ROOT; };
BCB16B880979B01400467741 /* DeprecatedArray.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DeprecatedArray.h; sourceTree = "<group>"; };
......@@ -11409,6 +11413,8 @@
93B70D5A09EB0C7C009D8468 /* kjs_window.h */,
BCA378140D15C64600B793D6 /* PausedTimeouts.cpp */,
BCA378150D15C64600B793D6 /* PausedTimeouts.h */,
BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */,
BCA378BB0D15F64200B793D6 /* ScheduledAction.h */,
);
path = js;
sourceTree = "<group>";
......@@ -14106,6 +14112,7 @@
BC4BF9E50D11E133007D247F /* ClassNames.h in Headers */,
B28BC31A0D135E5400CDBA27 /* JSEventTargetBase.lut.h in Headers */,
BCA378170D15C64600B793D6 /* PausedTimeouts.h in Headers */,
BCA378BD0D15F64200B793D6 /* ScheduledAction.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -15818,6 +15825,7 @@
BC904B760D10998F00680D32 /* ClassNodeList.cpp in Sources */,
BC4BF9E40D11E133007D247F /* ClassNames.cpp in Sources */,
BCA378160D15C64600B793D6 /* PausedTimeouts.cpp in Sources */,
BCA378BC0D15F64200B793D6 /* ScheduledAction.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -93,6 +93,7 @@ This file contains the list of files needed to build WebCore.
bindings/js/kjs_proxy.cpp
bindings/js/kjs_window.cpp
bindings/js/PausedTimeouts.cpp
bindings/js/ScheduledAction.cpp
</set>
<set append="1" var="WEBCORE_SOURCES_CSS">
......
......@@ -23,7 +23,7 @@
#include "config.h"
#include "PausedTimeouts.h"
#include "kjs_window.h"
#include "ScheduledAction.h"
namespace WebCore {
......
......@@ -22,18 +22,16 @@
#include <wtf/Noncopyable.h>
namespace KJS {
class ScheduledAction;
}
namespace WebCore {
class ScheduledAction;
struct PausedTimeout {
int timeoutId;
int nestingLevel;
double nextFireInterval;
double repeatInterval;
KJS::ScheduledAction* action;
ScheduledAction* action;
};
class PausedTimeouts : Noncopyable {
......
/*
* Copyright (C) 2000 Harri Porten (porten@kde.org)
* Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
* Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reseved.
* Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
* USA
*/
#include "config.h"
#include "ScheduledAction.h"
#include "CString.h"
#include "Chrome.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "Page.h"
#include "kjs_proxy.h"
#include "kjs_window.h"
using namespace KJS;
namespace WebCore {
ScheduledAction::ScheduledAction(JSValue* func, const List& args)
: m_func(func)
{
List::const_iterator end = args.end();
for (List::const_iterator it = args.begin(); it != end; ++it)
m_args.append(*it);
}
void ScheduledAction::execute(Window* window)
{
RefPtr<Frame> frame = window->impl()->frame();
if (!frame)
return;
KJSProxy* scriptProxy = frame->scriptProxy();
if (!scriptProxy)
return;
Window* globalObject = scriptProxy->globalObject();
scriptProxy->setProcessingTimerCallback(true);
if (JSValue* func = m_func.get()) {
JSLock lock;
if (func->isObject() && static_cast<JSObject*>(func)->implementsCall()) {
ExecState* exec = window->globalExec();
ASSERT(window == globalObject);
List args;
size_t size = m_args.size();
for (size_t i = 0; i < size; ++i)
args.append(m_args[i]);
globalObject->startTimeoutCheck();
static_cast<JSObject*>(func)->call(exec, window, args);
globalObject->stopTimeoutCheck();
if (exec->hadException()) {
JSObject* exception = exec->exception()->toObject(exec);
exec->clearException();
String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
int lineNumber = exception->get(exec, "line")->toInt32(exec);
if (Interpreter::shouldPrintExceptions())
printf("(timer):%s\n", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
}
}
} else
frame->loader()->executeScript(m_code);
// Update our document's rendering following the execution of the timeout callback.
// FIXME: Why not use updateDocumentsRendering to update rendering of all documents?
// FIXME: Is this really the right point to do the update? We need a place that works
// for all possible entry points that might possibly execute script, but this seems
// to be a bit too low-level.
if (Document* doc = frame->document())
doc->updateRendering();
scriptProxy->setProcessingTimerCallback(false);
}
} // namespace WebCore
/*
* Copyright (C) 2000 Harri Porten (porten@kde.org)
* Copyright (C) 2003, 2004, 2005, 2006, 2007 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
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ScheduledAction_h
#define ScheduledAction_h
#include "PlatformString.h"
#include <kjs/protect.h>
#include <wtf/Vector.h>
namespace KJS {
class Window;
class JSValue;
class List;
}
namespace WebCore {
/**
* An action (either function or string) to be executed after a specified
* time interval, either once or repeatedly. Used for window.setTimeout()
* and window.setInterval()
*/
class ScheduledAction {
public:
ScheduledAction(KJS::JSValue* func, const KJS::List& args);
ScheduledAction(const String& code)
: m_code(code)
{
}
void execute(KJS::Window*);
private:
KJS::ProtectedPtr<KJS::JSValue> m_func;
Vector<KJS::ProtectedPtr<KJS::JSValue> > m_args;
String m_code;
};
} // namespace WebCore
#endif // ScheduledAction_h
......@@ -52,6 +52,7 @@
#include "PlatformScreen.h"
#include "PlugInInfoStore.h"
#include "RenderView.h"
#include "ScheduledAction.h"
#include "SecurityOrigin.h"
#include "Settings.h"
#include "WindowFeatures.h"
......@@ -99,7 +100,7 @@ struct WindowPrivate {
class DOMWindowTimer : public TimerBase {
public:
DOMWindowTimer(int timeoutId, int nestingLevel, Window* object, ScheduledAction* action)
DOMWindowTimer(int timeoutId, int nestingLevel, Window* object, WebCore::ScheduledAction* action)
: m_timeoutId(timeoutId)
, m_nestingLevel(nestingLevel)
, m_object(object)
......@@ -118,8 +119,8 @@ public:
int nestingLevel() const { return m_nestingLevel; }
void setNestingLevel(int n) { m_nestingLevel = n; }
ScheduledAction* action() const { return m_action; }
ScheduledAction* takeAction() { ScheduledAction* a = m_action; m_action = 0; return a; }
WebCore::ScheduledAction* action() const { return m_action; }
WebCore::ScheduledAction* takeAction() { WebCore::ScheduledAction* a = m_action; m_action = 0; return a; }
private:
virtual void fired();
......@@ -127,7 +128,7 @@ private:
int m_timeoutId;
int m_nestingLevel;
Window* m_object;
ScheduledAction* m_action;
WebCore::ScheduledAction* m_action;
};
} // namespace KJS
......@@ -1202,62 +1203,6 @@ void Window::setReturnValueSlot(JSValue** slot)
d->m_returnValueSlot = slot;
}
////////////////////// ScheduledAction ////////////////////////
void ScheduledAction::execute(Window* window)
{
RefPtr<Frame> frame = window->impl()->frame();
if (!frame)
return;
KJSProxy* scriptProxy = frame->scriptProxy();
if (!scriptProxy)
return;
Window* globalObject = scriptProxy->globalObject();
scriptProxy->setProcessingTimerCallback(true);
if (JSValue* func = m_func.get()) {
JSLock lock;
if (func->isObject() && static_cast<JSObject*>(func)->implementsCall()) {
ExecState* exec = window->globalExec();
ASSERT(window == globalObject);
List args;
size_t size = m_args.size();
for (size_t i = 0; i < size; ++i) {
args.append(m_args[i]);
}
globalObject->startTimeoutCheck();
static_cast<JSObject*>(func)->call(exec, window, args);
globalObject->stopTimeoutCheck();
if (exec->hadException()) {
JSObject* exception = exec->exception()->toObject(exec);
exec->clearException();
String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
int lineNumber = exception->get(exec, "line")->toInt32(exec);
if (Interpreter::shouldPrintExceptions())
printf("(timer):%s\n", message.utf8().data());
if (Page* page = frame->page())
page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
}
}
} else
frame->loader()->executeScript(m_code);
// Update our document's rendering following the execution of the timeout callback.
// FIXME: Why not use updateDocumentsRendering to update rendering of all documents?
// FIXME: Is this really the right point to do the update? We need a place that works
// for all possible entry points that might possibly execute script, but this seems
// to be a bit too low-level.
if (Document* doc = frame->document())
doc->updateRendering();
scriptProxy->setProcessingTimerCallback(false);
}
////////////////////// timeouts ////////////////////////
void Window::clearAllTimeouts()
......@@ -1266,7 +1211,7 @@ void Window::clearAllTimeouts()
d->m_timeouts.clear();
}
int Window::installTimeout(ScheduledAction* a, int t, bool singleShot)
int Window::installTimeout(WebCore::ScheduledAction* a, int t, bool singleShot)
{
int timeoutId = ++lastUsedTimeoutId;
......@@ -1291,22 +1236,14 @@ int Window::installTimeout(ScheduledAction* a, int t, bool singleShot)
return timeoutId;
}
ScheduledAction::ScheduledAction(JSValue* func, const List& args)
: m_func(func)
{
List::const_iterator end = args.end();
for (List::const_iterator it = args.begin(); it != end; ++it)
m_args.append(*it);
}
int Window::installTimeout(const UString& handler, int t, bool singleShot)
{
return installTimeout(new ScheduledAction(handler), t, singleShot);
return installTimeout(new WebCore::ScheduledAction(handler), t, singleShot);
}
int Window::installTimeout(JSValue* func, const List& args, int t, bool singleShot)
{
return installTimeout(new ScheduledAction(func, args), t, singleShot);
return installTimeout(new WebCore::ScheduledAction(func, args), t, singleShot);
}
WebCore::PausedTimeouts* Window::pauseTimeouts()
......@@ -1378,7 +1315,7 @@ void Window::timerFired(DOMWindowTimer* timer)
}
// Delete timer before executing the action for one-shot timers.
ScheduledAction* action = timer->takeAction();
WebCore::ScheduledAction* action = timer->takeAction();
d->m_timeouts.remove(timer->timeoutId());
delete timer;
action->execute(this);
......
......@@ -34,13 +34,13 @@ namespace WebCore {
class JSEventListener;
class JSUnprotectedEventListener;
class PausedTimeouts;
class ScheduledAction;
}
namespace KJS {
class DOMWindowTimer;
class Location;
class ScheduledAction;
class Window;
class WindowFunc;
class WindowPrivate;
......@@ -48,7 +48,7 @@ namespace KJS {
// This is the only WebCore JS binding which does not inherit from DOMObject
class Window : public JSGlobalObject {
friend class Location;
friend class ScheduledAction;
friend class WebCore::ScheduledAction;
protected:
Window(WebCore::DOMWindow*);
......@@ -155,7 +155,7 @@ namespace KJS {
void clearHelperObjectProperties();
void clearAllTimeouts();
int installTimeout(ScheduledAction*, int interval, bool singleShot);
int installTimeout(WebCore::ScheduledAction*, int interval, bool singleShot);
RefPtr<WebCore::DOMWindow> m_impl;
OwnPtr<WindowPrivate> d;
......@@ -177,27 +177,6 @@ FOR_EACH_CLASS(KJS_IMPLEMENT_PROTOTYPE_FUNCTION_WITH_CREATE)
#undef FOR_EACH_CLASS
/**
* An action (either function or string) to be executed after a specified
* time interval, either once or repeatedly. Used for window.setTimeout()
* and window.setInterval()
*/
class ScheduledAction {
public:
ScheduledAction(JSValue* func, const List& args);
ScheduledAction(const WebCore::String& code)
: m_code(code)
{
}
void execute(Window *);
private:
ProtectedPtr<JSValue> m_func;
Vector<ProtectedPtr<JSValue> > m_args;
WebCore::String m_code;
};
class Location : public DOMObject {
friend class Window;
public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment