• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bindings/core/v8/ScopedPersistent.h"
30 #include "bindings/core/v8/ScriptState.h"
31 #include "bindings/core/v8/V8HiddenValue.h"
32 #include "bindings/core/v8/WrapperTypeInfo.h"
33 #include "gin/public/gin_embedders.h"
34 #include "gin/public/isolate_holder.h"
35 #include "modules/indexeddb/IDBPendingTransactionMonitor.h"
36 #include "wtf/Forward.h"
37 #include "wtf/HashMap.h"
38 #include "wtf/OwnPtr.h"
39 #include "wtf/Vector.h"
40 #include <v8.h>
41 
42 namespace blink {
43 
44 class DOMDataStore;
45 class GCEventData;
46 class StringCache;
47 struct WrapperTypeInfo;
48 
49 class ExternalStringVisitor;
50 
51 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList;
52 
53 class V8PerIsolateData {
54 public:
55     static v8::Isolate* initialize();
from(v8::Isolate * isolate)56     static V8PerIsolateData* from(v8::Isolate* isolate)
57     {
58         ASSERT(isolate);
59         ASSERT(isolate->GetData(gin::kEmbedderBlink));
60         return static_cast<V8PerIsolateData*>(isolate->GetData(gin::kEmbedderBlink));
61     }
62 
63     static void willBeDestroyed(v8::Isolate*);
64     static void destroy(v8::Isolate*);
65     static v8::Isolate* mainThreadIsolate();
66 
destructionPending()67     bool destructionPending() const { return m_destructionPending; }
isolate()68     v8::Isolate* isolate() { return m_isolateHolder->isolate(); }
69 
70     v8::Handle<v8::FunctionTemplate> toStringTemplate();
71 
stringCache()72     StringCache* stringCache() { return m_stringCache.get(); }
73 
74     v8::Persistent<v8::Value>& ensureLiveRoot();
75 
recursionLevel()76     int recursionLevel() const { return m_recursionLevel; }
incrementRecursionLevel()77     int incrementRecursionLevel() { return ++m_recursionLevel; }
decrementRecursionLevel()78     int decrementRecursionLevel() { return --m_recursionLevel; }
isHandlingRecursionLevelError()79     bool isHandlingRecursionLevelError() const { return m_isHandlingRecursionLevelError; }
setIsHandlingRecursionLevelError(bool value)80     void setIsHandlingRecursionLevelError(bool value) { m_isHandlingRecursionLevelError = value; }
81 
performingMicrotaskCheckpoint()82     bool performingMicrotaskCheckpoint() const { return m_performingMicrotaskCheckpoint; }
setPerformingMicrotaskCheckpoint(bool performingMicrotaskCheckpoint)83     void setPerformingMicrotaskCheckpoint(bool performingMicrotaskCheckpoint) { m_performingMicrotaskCheckpoint = performingMicrotaskCheckpoint; }
84 
85 #if ENABLE(ASSERT)
internalScriptRecursionLevel()86     int internalScriptRecursionLevel() const { return m_internalScriptRecursionLevel; }
incrementInternalScriptRecursionLevel()87     int incrementInternalScriptRecursionLevel() { return ++m_internalScriptRecursionLevel; }
decrementInternalScriptRecursionLevel()88     int decrementInternalScriptRecursionLevel() { return --m_internalScriptRecursionLevel; }
89 #endif
90 
gcEventData()91     GCEventData* gcEventData() { return m_gcEventData.get(); }
hiddenValue()92     V8HiddenValue* hiddenValue() { return m_hiddenValue.get(); }
93 
94     v8::Handle<v8::FunctionTemplate> domTemplate(void* domTemplateKey, v8::FunctionCallback = 0, v8::Handle<v8::Value> data = v8::Handle<v8::Value>(), v8::Handle<v8::Signature> = v8::Handle<v8::Signature>(), int length = 0);
95     v8::Handle<v8::FunctionTemplate> existingDOMTemplate(void* domTemplateKey);
96     void setDOMTemplate(void* domTemplateKey, v8::Handle<v8::FunctionTemplate>);
97 
98     bool hasInstance(const WrapperTypeInfo*, v8::Handle<v8::Value>);
99     v8::Handle<v8::Object> findInstanceInPrototypeChain(const WrapperTypeInfo*, v8::Handle<v8::Value>);
100 
101     v8::Local<v8::Context> ensureScriptRegexpContext();
102 
previousSamplingState()103     const char* previousSamplingState() const { return m_previousSamplingState; }
setPreviousSamplingState(const char * name)104     void setPreviousSamplingState(const char* name) { m_previousSamplingState = name; }
105 
106     IDBPendingTransactionMonitor* ensureIDBPendingTransactionMonitor();
107 
108 private:
109     V8PerIsolateData();
110     ~V8PerIsolateData();
111 
112     typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate> > DOMTemplateMap;
113     DOMTemplateMap& currentDOMTemplateMap();
114     bool hasInstance(const WrapperTypeInfo*, v8::Handle<v8::Value>, DOMTemplateMap&);
115     v8::Handle<v8::Object> findInstanceInPrototypeChain(const WrapperTypeInfo*, v8::Handle<v8::Value>, DOMTemplateMap&);
116 
117     bool m_destructionPending;
118     OwnPtr<gin::IsolateHolder> m_isolateHolder;
119     DOMTemplateMap m_domTemplateMapForMainWorld;
120     DOMTemplateMap m_domTemplateMapForNonMainWorld;
121     ScopedPersistent<v8::FunctionTemplate> m_toStringTemplate;
122     OwnPtr<StringCache> m_stringCache;
123     OwnPtr<V8HiddenValue> m_hiddenValue;
124     ScopedPersistent<v8::Value> m_liveRoot;
125     RefPtr<ScriptState> m_scriptRegexpScriptState;
126 
127     const char* m_previousSamplingState;
128 
129     bool m_constructorMode;
130     friend class ConstructorMode;
131 
132     int m_recursionLevel;
133     bool m_isHandlingRecursionLevelError;
134 
135 #if ENABLE(ASSERT)
136     int m_internalScriptRecursionLevel;
137 #endif
138     OwnPtr<GCEventData> m_gcEventData;
139     bool m_performingMicrotaskCheckpoint;
140 
141     OwnPtr<IDBPendingTransactionMonitor> m_idbPendingTransactionMonitor;
142 };
143 
144 } // namespace blink
145 
146 #endif // V8PerIsolateData_h
147