OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; | 53 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; |
54 | 54 |
55 // Used to hold data that is associated with a single v8::Isolate object, and | 55 // Used to hold data that is associated with a single v8::Isolate object, and |
56 // has a 1:1 relationship with v8::Isolate. | 56 // has a 1:1 relationship with v8::Isolate. |
57 class PLATFORM_EXPORT V8PerIsolateData { | 57 class PLATFORM_EXPORT V8PerIsolateData { |
58 USING_FAST_MALLOC(V8PerIsolateData); | 58 USING_FAST_MALLOC(V8PerIsolateData); |
59 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); | 59 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); |
60 | 60 |
61 public: | 61 public: |
| 62 enum class V8ContextMode { |
| 63 kTakeSnapshot, |
| 64 kDontUseSnapshot, |
| 65 kUseSnapshot, |
| 66 }; |
| 67 |
62 class EndOfScopeTask { | 68 class EndOfScopeTask { |
63 USING_FAST_MALLOC(EndOfScopeTask); | 69 USING_FAST_MALLOC(EndOfScopeTask); |
64 | 70 |
65 public: | 71 public: |
66 virtual ~EndOfScopeTask() {} | 72 virtual ~EndOfScopeTask() {} |
67 virtual void Run() = 0; | 73 virtual void Run() = 0; |
68 }; | 74 }; |
69 | 75 |
70 // Disables the UseCounter. | 76 // Disables the UseCounter. |
71 // UseCounter depends on the current context, but it's not available during | 77 // UseCounter depends on the current context, but it's not available during |
(...skipping 21 matching lines...) Expand all Loading... |
93 }; | 99 }; |
94 | 100 |
95 // Use this class to abstract away types of members that are pointers to core/ | 101 // Use this class to abstract away types of members that are pointers to core/ |
96 // objects, which are simply owned and released by V8PerIsolateData (see | 102 // objects, which are simply owned and released by V8PerIsolateData (see |
97 // m_threadDebugger for an example). | 103 // m_threadDebugger for an example). |
98 class PLATFORM_EXPORT Data { | 104 class PLATFORM_EXPORT Data { |
99 public: | 105 public: |
100 virtual ~Data() = default; | 106 virtual ~Data() = default; |
101 }; | 107 }; |
102 | 108 |
103 static v8::Isolate* Initialize(WebTaskRunner*); | 109 static v8::Isolate* Initialize(WebTaskRunner*, |
| 110 intptr_t* refernce_table, |
| 111 V8ContextMode); |
104 | 112 |
105 static V8PerIsolateData* From(v8::Isolate* isolate) { | 113 static V8PerIsolateData* From(v8::Isolate* isolate) { |
106 DCHECK(isolate); | 114 DCHECK(isolate); |
107 DCHECK(isolate->GetData(gin::kEmbedderBlink)); | 115 DCHECK(isolate->GetData(gin::kEmbedderBlink)); |
108 return static_cast<V8PerIsolateData*>( | 116 return static_cast<V8PerIsolateData*>( |
109 isolate->GetData(gin::kEmbedderBlink)); | 117 isolate->GetData(gin::kEmbedderBlink)); |
110 } | 118 } |
111 | 119 |
112 static void WillBeDestroyed(v8::Isolate*); | 120 static void WillBeDestroyed(v8::Isolate*); |
113 static void Destroy(v8::Isolate*); | 121 static void Destroy(v8::Isolate*); |
(...skipping 20 matching lines...) Expand all Loading... |
134 | 142 |
135 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } | 143 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } |
136 | 144 |
137 // Accessors to the cache of interface templates. | 145 // Accessors to the cache of interface templates. |
138 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, | 146 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, |
139 const void* key); | 147 const void* key); |
140 void SetInterfaceTemplate(const DOMWrapperWorld&, | 148 void SetInterfaceTemplate(const DOMWrapperWorld&, |
141 const void* key, | 149 const void* key, |
142 v8::Local<v8::FunctionTemplate>); | 150 v8::Local<v8::FunctionTemplate>); |
143 | 151 |
| 152 // When v8::SnapshotCreator::CreateBlob() is called, we must not have |
| 153 // persistent handles from Blink. This method clears them. |
| 154 void ClearPersistentsForV8Snapshot(); |
| 155 |
| 156 v8::SnapshotCreator* GetSnapshotCreator() const { |
| 157 return isolate_holder_.snapshot_creator(); |
| 158 } |
| 159 V8ContextMode GetV8ContextMode() const { return v8_context_mode_; } |
| 160 |
144 // Accessor to the cache of cross-origin accessible operation's templates. | 161 // Accessor to the cache of cross-origin accessible operation's templates. |
145 // Created templates get automatically cached. | 162 // Created templates get automatically cached. |
146 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( | 163 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( |
147 const DOMWrapperWorld&, | 164 const DOMWrapperWorld&, |
148 const void* key, | 165 const void* key, |
149 v8::FunctionCallback, | 166 v8::FunctionCallback, |
150 v8::Local<v8::Value> data, | 167 v8::Local<v8::Value> data, |
151 v8::Local<v8::Signature>, | 168 v8::Local<v8::Signature>, |
152 int length); | 169 int length); |
153 | 170 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 231 |
215 void SetScriptWrappableVisitor( | 232 void SetScriptWrappableVisitor( |
216 std::unique_ptr<ScriptWrappableVisitor> visitor) { | 233 std::unique_ptr<ScriptWrappableVisitor> visitor) { |
217 script_wrappable_visitor_ = std::move(visitor); | 234 script_wrappable_visitor_ = std::move(visitor); |
218 } | 235 } |
219 ScriptWrappableVisitor* GetScriptWrappableVisitor() { | 236 ScriptWrappableVisitor* GetScriptWrappableVisitor() { |
220 return script_wrappable_visitor_.get(); | 237 return script_wrappable_visitor_.get(); |
221 } | 238 } |
222 | 239 |
223 private: | 240 private: |
224 explicit V8PerIsolateData(WebTaskRunner*); | 241 V8PerIsolateData(WebTaskRunner*, intptr_t* reference_table, V8ContextMode); |
| 242 V8PerIsolateData(intptr_t* reference_table); |
225 ~V8PerIsolateData(); | 243 ~V8PerIsolateData(); |
226 | 244 |
227 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>> | 245 using V8FunctionTemplateMap = |
228 V8FunctionTemplateMap; | 246 HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>; |
229 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); | 247 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); |
230 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); | 248 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); |
231 bool HasInstance(const WrapperTypeInfo* untrusted, | 249 bool HasInstance(const WrapperTypeInfo* untrusted, |
232 v8::Local<v8::Value>, | 250 v8::Local<v8::Value>, |
233 V8FunctionTemplateMap&); | 251 V8FunctionTemplateMap&); |
234 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, | 252 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, |
235 v8::Local<v8::Value>, | 253 v8::Local<v8::Value>, |
236 V8FunctionTemplateMap&); | 254 V8FunctionTemplateMap&); |
237 | 255 |
| 256 // Members requried for snapshotted context. |
| 257 // Snapshotted blob data image to create v8::Context's from. Needs to be |
| 258 // instantiated before |isoalte_holder_| gets instantiated. |
| 259 v8::StartupData startup_data_; |
| 260 // In taking V8 snapshot, we can't keep V8 objects with eternal handles. |
| 261 // So we keep some function templates with clearable handles when we take |
| 262 // snapshots. |
| 263 using CopyablePersistent = |
| 264 v8::Persistent<v8::FunctionTemplate, |
| 265 v8::CopyablePersistentTraits<v8::FunctionTemplate>>; |
| 266 using V8FunctionTemplatePersistentMap = |
| 267 HashMap<const void*, CopyablePersistent>; |
| 268 V8FunctionTemplatePersistentMap interface_template_map_for_v8_snapshot_; |
| 269 |
| 270 V8ContextMode v8_context_mode_; |
238 gin::IsolateHolder isolate_holder_; | 271 gin::IsolateHolder isolate_holder_; |
239 | 272 |
240 // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for | 273 // interface_template_map_for_{,non_}main_world holds function templates for |
241 // the inerface objects. | 274 // the inerface objects. |
242 V8FunctionTemplateMap interface_template_map_for_main_world_; | 275 V8FunctionTemplateMap interface_template_map_for_main_world_; |
243 V8FunctionTemplateMap interface_template_map_for_non_main_world_; | 276 V8FunctionTemplateMap interface_template_map_for_non_main_world_; |
| 277 |
244 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for | 278 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for |
245 // the cross-origin accessible DOM operations. | 279 // the cross-origin accessible DOM operations. |
246 V8FunctionTemplateMap operation_template_map_for_main_world_; | 280 V8FunctionTemplateMap operation_template_map_for_main_world_; |
247 V8FunctionTemplateMap operation_template_map_for_non_main_world_; | 281 V8FunctionTemplateMap operation_template_map_for_non_main_world_; |
248 | 282 |
249 // Contains lists of eternal names, such as dictionary keys. | 283 // Contains lists of eternal names, such as dictionary keys. |
250 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; | 284 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; |
251 | 285 |
252 std::unique_ptr<StringCache> string_cache_; | 286 std::unique_ptr<StringCache> string_cache_; |
253 std::unique_ptr<V8PrivateProperty> private_property_; | 287 std::unique_ptr<V8PrivateProperty> private_property_; |
(...skipping 11 matching lines...) Expand all Loading... |
265 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; | 299 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; |
266 std::unique_ptr<Data> thread_debugger_; | 300 std::unique_ptr<Data> thread_debugger_; |
267 | 301 |
268 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; | 302 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; |
269 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; | 303 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; |
270 }; | 304 }; |
271 | 305 |
272 } // namespace blink | 306 } // namespace blink |
273 | 307 |
274 #endif // V8PerIsolateData_h | 308 #endif // V8PerIsolateData_h |
OLD | NEW |