2
* Copyright (C) 2009 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
26
#ifndef V8PerIsolateData_h
27
#define V8PerIsolateData_h
29
#include "ScopedPersistent.h"
31
#include <wtf/Forward.h>
32
#include <wtf/HashMap.h>
33
#include <wtf/OwnPtr.h>
34
#include <wtf/Vector.h>
42
class V8HiddenPropertyName;
43
struct WrapperTypeInfo;
46
class ExternalStringVisitor;
49
typedef WTF::Vector<DOMDataStore*> DOMDataList;
51
class V8PerIsolateData {
53
static V8PerIsolateData* create(v8::Isolate*);
54
static void ensureInitialized(v8::Isolate*);
55
static V8PerIsolateData* current()
57
return from(v8::Isolate::GetCurrent());
59
static V8PerIsolateData* from(v8::Isolate* isolate)
62
ASSERT(isolate->GetData());
63
return static_cast<V8PerIsolateData*>(isolate->GetData());
65
static void dispose(v8::Isolate*);
67
typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
69
TemplateMap& rawTemplateMap() { return m_rawTemplates; }
70
TemplateMap& templateMap() { return m_templates; }
72
v8::Handle<v8::FunctionTemplate> toStringTemplate();
73
v8::Persistent<v8::FunctionTemplate>& lazyEventListenerToStringTemplate()
75
return m_lazyEventListenerToStringTemplate;
78
StringCache* stringCache() { return m_stringCache.get(); }
79
IntegerCache* integerCache() { return m_integerCache.get(); }
81
v8::Persistent<v8::Value> ensureLiveRoot();
84
void visitExternalStrings(ExternalStringVisitor*);
86
DOMDataList& allStores() { return m_domDataList; }
88
V8HiddenPropertyName* hiddenPropertyName() { return m_hiddenPropertyName.get(); }
90
void registerDOMDataStore(DOMDataStore* domDataStore)
92
ASSERT(m_domDataList.find(domDataStore) == notFound);
93
m_domDataList.append(domDataStore);
96
void unregisterDOMDataStore(DOMDataStore* domDataStore)
98
ASSERT(m_domDataList.find(domDataStore) != notFound);
99
m_domDataList.remove(m_domDataList.find(domDataStore));
102
// DOMDataStore is owned outside V8PerIsolateData.
103
DOMDataStore* domDataStore() { return m_domDataStore; }
104
void setDOMDataStore(DOMDataStore* store) { m_domDataStore = store; }
106
int recursionLevel() const { return m_recursionLevel; }
107
int incrementRecursionLevel() { return ++m_recursionLevel; }
108
int decrementRecursionLevel() { return --m_recursionLevel; }
110
int nextDependentRetainedId() { return m_nextDependentRetainedId++; }
113
int internalScriptRecursionLevel() const { return m_internalScriptRecursionLevel; }
114
int incrementInternalScriptRecursionLevel() { return ++m_internalScriptRecursionLevel; }
115
int decrementInternalScriptRecursionLevel() { return --m_internalScriptRecursionLevel; }
118
GCEventData* gcEventData() { return m_gcEventData.get(); }
120
void reportMemoryUsage(MemoryObjectInfo*) const;
122
// Gives the system a hint that we should request garbage collection
123
// upon the next close or navigation event, because some expensive
124
// objects have been allocated that we want to take every opportunity
126
void setShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = true; }
127
void clearShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = false; }
128
bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
131
explicit V8PerIsolateData(v8::Isolate*);
133
static v8::Handle<v8::Value> constructorOfToString(const v8::Arguments&);
135
TemplateMap m_rawTemplates;
136
TemplateMap m_templates;
137
ScopedPersistent<v8::FunctionTemplate> m_toStringTemplate;
138
v8::Persistent<v8::FunctionTemplate> m_lazyEventListenerToStringTemplate;
139
OwnPtr<StringCache> m_stringCache;
140
OwnPtr<IntegerCache> m_integerCache;
142
Vector<DOMDataStore*> m_domDataList;
143
DOMDataStore* m_domDataStore;
145
OwnPtr<V8HiddenPropertyName> m_hiddenPropertyName;
146
ScopedPersistent<v8::Value> m_liveRoot;
147
ScopedPersistent<v8::Context> m_auxiliaryContext;
149
bool m_constructorMode;
150
friend class ConstructorMode;
152
int m_recursionLevel;
153
int m_nextDependentRetainedId;
156
int m_internalScriptRecursionLevel;
158
OwnPtr<GCEventData> m_gcEventData;
159
bool m_shouldCollectGarbageSoon;
162
} // namespace WebCore
164
#endif // V8PerIsolateData_h