Commit 5035dee6 authored by ap@webkit.org's avatar ap@webkit.org

2008-11-26 Dmitry Titov <dimich@chromium.org>

        Reviewed by Darin Adler and Eric Seidel.

        https://bugs.webkit.org/show_bug.cgi?id=22469

        Move the class DOMWindowTimer from JSDOMWindowBase into its own file in
        preparation to making it work for Workers. For now, just move the code and couple
        of global variables.

        * GNUmakefile.am:
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * WebCoreSources.bkl:
        * bindings/js/JSDOMWindowBase.cpp:
        (WebCore::JSDOMWindowBase::installTimeout):
        (WebCore::JSDOMWindowBase::pauseTimeouts):
        (WebCore::JSDOMWindowBase::resumeTimeouts):
        (WebCore::JSDOMWindowBase::timerFired):
        * bindings/js/JSDOMWindowBase.h:
        * bindings/js/DOMTimer.cpp: Added.
        (WebCore::DOMTimer::DOMTimer):
        (WebCore::DOMTimer::~DOMTimer):
        (WebCore::DOMTimer::fired):
        * bindings/js/DOMTimer.h: Added.
        (WebCore::DOMTimer::timeoutId):
        (WebCore::DOMTimer::nestingLevel):
        (WebCore::DOMTimer::setNestingLevel):
        (WebCore::DOMTimer::action):
        (WebCore::DOMTimer::takeAction):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@38780 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1762da7a
2008-11-26 Dmitry Titov <dimich@chromium.org>
Reviewed by Darin Adler and Eric Seidel.
https://bugs.webkit.org/show_bug.cgi?id=22469
Move the class DOMWindowTimer from JSDOMWindowBase into its own file in
preparation to making it work for Workers. For now, just move the code and couple
of global variables.
* GNUmakefile.am:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* WebCoreSources.bkl:
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::installTimeout):
(WebCore::JSDOMWindowBase::pauseTimeouts):
(WebCore::JSDOMWindowBase::resumeTimeouts):
(WebCore::JSDOMWindowBase::timerFired):
* bindings/js/JSDOMWindowBase.h:
* bindings/js/DOMTimer.cpp: Added.
(WebCore::DOMTimer::DOMTimer):
(WebCore::DOMTimer::~DOMTimer):
(WebCore::DOMTimer::fired):
* bindings/js/DOMTimer.h: Added.
(WebCore::DOMTimer::timeoutId):
(WebCore::DOMTimer::nestingLevel):
(WebCore::DOMTimer::setNestingLevel):
(WebCore::DOMTimer::action):
(WebCore::DOMTimer::takeAction):
2008-11-25 Darin Fisher <darin@chromium.org>
Fix bustage.
......@@ -234,6 +234,8 @@ IDL_BINDINGS += \
webcore_sources += \
WebCore/WebCorePrefix.h \
WebCore/bindings/js/CachedScriptSourceProvider.h \
WebCore/bindings/js/DOMTimer.cpp \
WebCore/bindings/js/DOMTimer.h \
WebCore/bindings/js/GCController.cpp \
WebCore/bindings/js/GCController.h \
WebCore/bindings/js/JSAttrCustom.cpp \
......
......@@ -387,6 +387,7 @@ IDL_BINDINGS += \
SOURCES += \
bindings/js/DOMTimer.cpp \
bindings/js/GCController.cpp \
bindings/js/JSAttrCustom.cpp \
bindings/js/JSCanvasRenderingContext2DCustom.cpp \
......
......@@ -13344,6 +13344,14 @@
RelativePath="..\bindings\js\CachedScriptSourceProvider.h"
>
</File>
<File
RelativePath="..\bindings\js\DOMTimer.cpp"
>
</File>
<File
RelativePath="..\bindings\js\DOMTimer.h"
>
</File>
<File
RelativePath="..\bindings\js\GCController.cpp"
>
......
......@@ -126,6 +126,8 @@
14EC268009CA07E000E1EEEC /* EventTargetNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14EC267E09CA07E000E1EEEC /* EventTargetNode.cpp */; };
14FFE31D0AE1963300136BF5 /* HTMLFrameElementBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 14FFE31B0AE1963300136BF5 /* HTMLFrameElementBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
14FFE31E0AE1963300136BF5 /* HTMLFrameElementBase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14FFE31C0AE1963300136BF5 /* HTMLFrameElementBase.cpp */; };
18E687870EDB793500A8E8B7 /* DOMTimer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 18E687850EDB793400A8E8B7 /* DOMTimer.cpp */; };
18E687880EDB793500A8E8B7 /* DOMTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 18E687860EDB793500A8E8B7 /* DOMTimer.h */; };
1A0D57360A5C77FE007EDD4C /* OverflowEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A0D57340A5C77FE007EDD4C /* OverflowEvent.cpp */; };
1A0D57370A5C77FE007EDD4C /* OverflowEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A0D57350A5C77FE007EDD4C /* OverflowEvent.h */; };
1A0D57400A5C7867007EDD4C /* JSOverflowEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A0D573E0A5C7867007EDD4C /* JSOverflowEvent.cpp */; };
......@@ -4893,6 +4895,8 @@
14EC267E09CA07E000E1EEEC /* EventTargetNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventTargetNode.cpp; sourceTree = "<group>"; };
14FFE31B0AE1963300136BF5 /* HTMLFrameElementBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLFrameElementBase.h; sourceTree = "<group>"; };
14FFE31C0AE1963300136BF5 /* HTMLFrameElementBase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLFrameElementBase.cpp; sourceTree = "<group>"; };
18E687850EDB793400A8E8B7 /* DOMTimer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMTimer.cpp; sourceTree = "<group>"; };
18E687860EDB793500A8E8B7 /* DOMTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMTimer.h; sourceTree = "<group>"; };
1A0D57340A5C77FE007EDD4C /* OverflowEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = OverflowEvent.cpp; sourceTree = "<group>"; };
1A0D57350A5C77FE007EDD4C /* OverflowEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = OverflowEvent.h; sourceTree = "<group>"; };
1A0D57380A5C7812007EDD4C /* OverflowEvent.idl */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = OverflowEvent.idl; sourceTree = "<group>"; };
......@@ -13035,6 +13039,8 @@
BC1A3793097C6FB10019F3D8 /* js */ = {
isa = PBXGroup;
children = (
18E687850EDB793400A8E8B7 /* DOMTimer.cpp */,
18E687860EDB793500A8E8B7 /* DOMTimer.h */,
BC4EDEF70C08F414007EDD49 /* Custom */,
14DFB33F0A7DF7630018F769 /* Derived Sources */,
93F8B3060A300FEA00F61AB8 /* CodeGeneratorJS.pm */,
......@@ -16419,6 +16425,7 @@
416F45F00ED7B311008215B6 /* ScriptString.h in Headers */,
080AEC820ED8708B00DF4CCE /* WMLIntrinsicEvent.h in Headers */,
080AEC840ED8708B00DF4CCE /* WMLIntrinsicEventHandler.h in Headers */,
18E687880EDB793500A8E8B7 /* DOMTimer.h in Headers */,
08203AA00ED8C35300B8B61A /* WMLAccessElement.h in Headers */,
934CC10A0EDB223900A658F2 /* ScriptSourceCode.h in Headers */,
934CC1170EDCAC7300A658F2 /* ScriptInstance.h in Headers */,
......@@ -18354,6 +18361,7 @@
E4D687770ED7AE3D006EA978 /* PurgeableBufferMac.cpp in Sources */,
080AEC810ED8708B00DF4CCE /* WMLIntrinsicEvent.cpp in Sources */,
080AEC830ED8708B00DF4CCE /* WMLIntrinsicEventHandler.cpp in Sources */,
18E687870EDB793500A8E8B7 /* DOMTimer.cpp in Sources */,
08203A9F0ED8C35300B8B61A /* WMLAccessElement.cpp in Sources */,
08744BAA0EDB7D86004C9E63 /* WMLOnEventElement.cpp in Sources */,
0818AEE20EDB86BC00647B66 /* WMLEventHandlingElement.cpp in Sources */,
......@@ -33,6 +33,7 @@ This file contains the list of files needed to build WebCore.
<makefile>
<set append="1" var="WEBCORE_SOURCES_JS">
bindings/js/DOMTimer.cpp
bindings/js/GCController.cpp
bindings/js/JSAttrCustom.cpp
bindings/js/JSAudioConstructor.cpp
......
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "config.h"
#include "DOMTimer.h"
#include "JSDOMWindowBase.h"
#include "ScheduledAction.h"
#include <runtime/JSLock.h>
namespace WebCore {
int DOMTimer::m_timerNestingLevel = 0;
DOMTimer::DOMTimer(JSDOMWindowBase* object, ScheduledAction* action)
: m_object(object)
, m_action(action)
{
static int lastUsedTimeoutId = 0;
++lastUsedTimeoutId;
// Avoid wraparound going negative on us.
if (lastUsedTimeoutId <= 0)
lastUsedTimeoutId = 1;
m_timeoutId = lastUsedTimeoutId;
m_nestingLevel = m_timerNestingLevel + 1;
}
DOMTimer::DOMTimer(int timeoutId, int nestingLevel, JSDOMWindowBase* object, ScheduledAction* action)
: m_timeoutId(timeoutId)
, m_nestingLevel(nestingLevel)
, m_object(object)
, m_action(action)
{
ASSERT(timeoutId > 0);
ASSERT(nestingLevel > 0);
}
DOMTimer::~DOMTimer()
{
JSC::JSLock lock(false);
delete m_action;
}
void DOMTimer::fired()
{
m_timerNestingLevel = m_nestingLevel;
m_object->timerFired(this);
m_timerNestingLevel = 0;
}
} // namespace WebCore
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef DOMTimer_h
#define DOMTimer_h
#include "Timer.h"
namespace WebCore {
class JSDOMWindowBase;
class ScheduledAction;
class DOMTimer : public TimerBase {
public:
// Creates a new timer with the next id and nesting level.
DOMTimer(JSDOMWindowBase*, ScheduledAction*);
// Creates a timer from PausedTimeout, takes timeoutId and nestingLevel as they were persisted.
DOMTimer(int timeoutId, int nestingLevel, JSDOMWindowBase*, ScheduledAction*);
virtual ~DOMTimer();
int timeoutId() const { return m_timeoutId; }
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; }
private:
virtual void fired();
int m_timeoutId;
int m_nestingLevel;
JSDOMWindowBase* m_object;
ScheduledAction* m_action;
static int m_timerNestingLevel;
};
} // namespace WebCore
#endif // DOMTimer_h
......@@ -25,6 +25,7 @@
#include "CString.h"
#include "Console.h"
#include "DOMTimer.h"
#include "DOMWindow.h"
#include "Element.h"
#include "EventListener.h"
......@@ -97,45 +98,9 @@ static void setJSDOMWindowBaseXSLTProcessor(ExecState*, JSObject*, JSValue*);
namespace WebCore {
static int lastUsedTimeoutId;
static int timerNestingLevel = 0;
const int cMaxTimerNestingLevel = 5;
const double cMinimumTimerInterval = 0.010;
class DOMWindowTimer : public TimerBase {
public:
DOMWindowTimer(int timeoutId, int nestingLevel, JSDOMWindowBase* object, ScheduledAction* action)
: m_timeoutId(timeoutId)
, m_nestingLevel(nestingLevel)
, m_object(object)
, m_action(action)
{
}
virtual ~DOMWindowTimer()
{
JSLock lock(false);
delete m_action;
}
int timeoutId() const { return m_timeoutId; }
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; }
private:
virtual void fired();
int m_timeoutId;
int m_nestingLevel;
JSDOMWindowBase* m_object;
ScheduledAction* m_action;
};
////////////////////// JSDOMWindowBase Object ////////////////////////
const ClassInfo JSDOMWindowBase::s_info = { "Window", 0, &JSDOMWindowBaseTable, 0 };
......@@ -869,21 +834,15 @@ void JSDOMWindowBase::clearAllTimeouts()
int JSDOMWindowBase::installTimeout(ScheduledAction* a, int t, bool singleShot)
{
int timeoutId = ++lastUsedTimeoutId;
// avoid wraparound going negative on us
if (timeoutId <= 0)
timeoutId = 1;
int nestLevel = timerNestingLevel + 1;
DOMWindowTimer* timer = new DOMWindowTimer(timeoutId, nestLevel, this, a);
DOMTimer* timer = new DOMTimer(this, a);
int timeoutId = timer->timeoutId();
ASSERT(!d()->timeouts.get(timeoutId));
d()->timeouts.set(timeoutId, timer);
// Use a minimum interval of 10 ms to match other browsers, but only once we've
// nested enough to notice that we're repeating.
// Faster timers might be "better", but they're incompatible.
double interval = max(0.001, t * 0.001);
if (interval < cMinimumTimerInterval && nestLevel >= cMaxTimerNestingLevel)
if (interval < cMinimumTimerInterval && timer->nestingLevel() >= cMaxTimerNestingLevel)
interval = cMinimumTimerInterval;
if (singleShot)
timer->startOneShot(interval);
......@@ -916,7 +875,7 @@ void JSDOMWindowBase::pauseTimeouts(OwnPtr<PausedTimeouts>& result)
JSDOMWindowBaseData::TimeoutsMap::iterator it = d()->timeouts.begin();
for (size_t i = 0; i != timeoutsCount; ++i, ++it) {
int timeoutId = it->first;
DOMWindowTimer* timer = it->second;
DOMTimer* timer = it->second;
t[i].timeoutId = timeoutId;
t[i].nestingLevel = timer->nestingLevel();
t[i].nextFireInterval = timer->nextFireInterval();
......@@ -937,7 +896,7 @@ void JSDOMWindowBase::resumeTimeouts(OwnPtr<PausedTimeouts>& timeouts)
PausedTimeout* array = timeouts->takeTimeouts();
for (size_t i = 0; i != count; ++i) {
int timeoutId = array[i].timeoutId;
DOMWindowTimer* timer = new DOMWindowTimer(timeoutId, array[i].nestingLevel, this, array[i].action);
DOMTimer* timer = new DOMTimer(timeoutId, array[i].nestingLevel, this, array[i].action);
d()->timeouts.set(timeoutId, timer);
timer->start(array[i].nextFireInterval, array[i].repeatInterval);
}
......@@ -956,14 +915,14 @@ void JSDOMWindowBase::removeTimeout(int timeoutId, bool delAction)
delete d()->timeouts.take(timeoutId);
}
void JSDOMWindowBase::timerFired(DOMWindowTimer* timer)
void JSDOMWindowBase::timerFired(DOMTimer* timer)
{
// Simple case for non-one-shot timers.
if (timer->isActive()) {
int timeoutId = timer->timeoutId();
timer->action()->execute(shell());
// The DOMWindowTimer object may have been deleted or replaced during execution,
// The DOMTimer object may have been deleted or replaced during execution,
// so we re-fetch it.
timer = d()->timeouts.get(timeoutId);
if (!timer)
......@@ -992,13 +951,6 @@ void JSDOMWindowBase::disconnectFrame()
clearAllTimeouts();
}
void DOMWindowTimer::fired()
{
timerNestingLevel = m_nestingLevel;
m_object->timerFired(this);
timerNestingLevel = 0;
}
JSValue* toJS(ExecState*, DOMWindow* domWindow)
{
if (!domWindow)
......
......@@ -29,8 +29,8 @@
namespace WebCore {
class AtomicString;
class DOMTimer;
class DOMWindow;
class DOMWindowTimer;
class Event;
class Frame;
class JSDOMWindow;
......@@ -72,7 +72,7 @@ namespace WebCore {
void pauseTimeouts(OwnPtr<PausedTimeouts>&);
void resumeTimeouts(OwnPtr<PausedTimeouts>&);
void timerFired(DOMWindowTimer*);
void timerFired(DOMTimer*);
void clear();
......@@ -113,7 +113,7 @@ namespace WebCore {
JSC::JSValue** returnValueSlot;
JSDOMWindowShell* shell;
typedef HashMap<int, DOMWindowTimer*> TimeoutsMap;
typedef HashMap<int, DOMTimer*> TimeoutsMap;
TimeoutsMap timeouts;
};
......
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