~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/bindings/v8/V8PerIsolateData.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
 
 
26
#ifndef V8PerIsolateData_h
 
27
#define V8PerIsolateData_h
 
28
 
 
29
#include "ScopedPersistent.h"
 
30
#include <v8.h>
 
31
#include <wtf/Forward.h>
 
32
#include <wtf/HashMap.h>
 
33
#include <wtf/OwnPtr.h>
 
34
#include <wtf/Vector.h>
 
35
 
 
36
namespace WebCore {
 
37
 
 
38
class DOMDataStore;
 
39
class GCEventData;
 
40
class IntegerCache;
 
41
class StringCache;
 
42
class V8HiddenPropertyName;
 
43
struct WrapperTypeInfo;
 
44
 
 
45
#if ENABLE(INSPECTOR)
 
46
class ExternalStringVisitor;
 
47
#endif
 
48
 
 
49
typedef WTF::Vector<DOMDataStore*> DOMDataList;
 
50
 
 
51
class V8PerIsolateData {
 
52
public:
 
53
    static V8PerIsolateData* create(v8::Isolate*);
 
54
    static void ensureInitialized(v8::Isolate*);
 
55
    static V8PerIsolateData* current()
 
56
    {
 
57
        return from(v8::Isolate::GetCurrent());
 
58
    }
 
59
    static V8PerIsolateData* from(v8::Isolate* isolate)
 
60
    {
 
61
        ASSERT(isolate);
 
62
        ASSERT(isolate->GetData());
 
63
        return static_cast<V8PerIsolateData*>(isolate->GetData()); 
 
64
    }
 
65
    static void dispose(v8::Isolate*);
 
66
 
 
67
    typedef HashMap<WrapperTypeInfo*, v8::Persistent<v8::FunctionTemplate> > TemplateMap;
 
68
 
 
69
    TemplateMap& rawTemplateMap() { return m_rawTemplates; }
 
70
    TemplateMap& templateMap() { return m_templates; }
 
71
 
 
72
    v8::Handle<v8::FunctionTemplate> toStringTemplate();
 
73
    v8::Persistent<v8::FunctionTemplate>& lazyEventListenerToStringTemplate()
 
74
    {
 
75
        return m_lazyEventListenerToStringTemplate;
 
76
    }
 
77
 
 
78
    StringCache* stringCache() { return m_stringCache.get(); }
 
79
    IntegerCache* integerCache() { return m_integerCache.get(); }
 
80
 
 
81
    v8::Persistent<v8::Value> ensureLiveRoot();
 
82
 
 
83
#if ENABLE(INSPECTOR)
 
84
    void visitExternalStrings(ExternalStringVisitor*);
 
85
#endif
 
86
    DOMDataList& allStores() { return m_domDataList; }
 
87
 
 
88
    V8HiddenPropertyName* hiddenPropertyName() { return m_hiddenPropertyName.get(); }
 
89
 
 
90
    void registerDOMDataStore(DOMDataStore* domDataStore) 
 
91
    {
 
92
        ASSERT(m_domDataList.find(domDataStore) == notFound);
 
93
        m_domDataList.append(domDataStore);
 
94
    }
 
95
 
 
96
    void unregisterDOMDataStore(DOMDataStore* domDataStore)
 
97
    {
 
98
        ASSERT(m_domDataList.find(domDataStore) != notFound);
 
99
        m_domDataList.remove(m_domDataList.find(domDataStore));
 
100
    }
 
101
 
 
102
    // DOMDataStore is owned outside V8PerIsolateData.
 
103
    DOMDataStore* domDataStore() { return m_domDataStore; }
 
104
    void setDOMDataStore(DOMDataStore* store) { m_domDataStore = store; }
 
105
 
 
106
    int recursionLevel() const { return m_recursionLevel; }
 
107
    int incrementRecursionLevel() { return ++m_recursionLevel; }
 
108
    int decrementRecursionLevel() { return --m_recursionLevel; }
 
109
 
 
110
    int nextDependentRetainedId() { return m_nextDependentRetainedId++; }
 
111
 
 
112
#ifndef NDEBUG
 
113
    int internalScriptRecursionLevel() const { return m_internalScriptRecursionLevel; }
 
114
    int incrementInternalScriptRecursionLevel() { return ++m_internalScriptRecursionLevel; }
 
115
    int decrementInternalScriptRecursionLevel() { return --m_internalScriptRecursionLevel; }
 
116
#endif
 
117
 
 
118
    GCEventData* gcEventData() { return m_gcEventData.get(); }
 
119
 
 
120
    void reportMemoryUsage(MemoryObjectInfo*) const;
 
121
 
 
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
 
125
    // to collect.
 
126
    void setShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = true; }
 
127
    void clearShouldCollectGarbageSoon() { m_shouldCollectGarbageSoon = false; }
 
128
    bool shouldCollectGarbageSoon() const { return m_shouldCollectGarbageSoon; }
 
129
 
 
130
private:
 
131
    explicit V8PerIsolateData(v8::Isolate*);
 
132
    ~V8PerIsolateData();
 
133
    static v8::Handle<v8::Value> constructorOfToString(const v8::Arguments&);
 
134
 
 
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;
 
141
 
 
142
    Vector<DOMDataStore*> m_domDataList;
 
143
    DOMDataStore* m_domDataStore;
 
144
 
 
145
    OwnPtr<V8HiddenPropertyName> m_hiddenPropertyName;
 
146
    ScopedPersistent<v8::Value> m_liveRoot;
 
147
    ScopedPersistent<v8::Context> m_auxiliaryContext;
 
148
 
 
149
    bool m_constructorMode;
 
150
    friend class ConstructorMode;
 
151
 
 
152
    int m_recursionLevel;
 
153
    int m_nextDependentRetainedId;
 
154
 
 
155
#ifndef NDEBUG
 
156
    int m_internalScriptRecursionLevel;
 
157
#endif
 
158
    OwnPtr<GCEventData> m_gcEventData;
 
159
    bool m_shouldCollectGarbageSoon;
 
160
};
 
161
 
 
162
} // namespace WebCore
 
163
 
 
164
#endif // V8PerIsolateData_h