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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; | 54 typedef WTF::Vector<DOMDataStore*> DOMDataStoreList; |
55 | 55 |
56 // Used to hold data that is associated with a single v8::Isolate object, and | 56 // Used to hold data that is associated with a single v8::Isolate object, and |
57 // has a 1:1 relationship with v8::Isolate. | 57 // has a 1:1 relationship with v8::Isolate. |
58 class PLATFORM_EXPORT V8PerIsolateData { | 58 class PLATFORM_EXPORT V8PerIsolateData { |
59 USING_FAST_MALLOC(V8PerIsolateData); | 59 USING_FAST_MALLOC(V8PerIsolateData); |
60 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); | 60 WTF_MAKE_NONCOPYABLE(V8PerIsolateData); |
61 | 61 |
62 public: | 62 public: |
| 63 enum class V8ContextSnapshotMode { |
| 64 kTakeSnapshot, |
| 65 kDontUseSnapshot, |
| 66 kUseSnapshot, |
| 67 }; |
| 68 |
63 class EndOfScopeTask { | 69 class EndOfScopeTask { |
64 USING_FAST_MALLOC(EndOfScopeTask); | 70 USING_FAST_MALLOC(EndOfScopeTask); |
65 | 71 |
66 public: | 72 public: |
67 virtual ~EndOfScopeTask() {} | 73 virtual ~EndOfScopeTask() {} |
68 virtual void Run() = 0; | 74 virtual void Run() = 0; |
69 }; | 75 }; |
70 | 76 |
71 // Disables the UseCounter. | 77 // Disables the UseCounter. |
72 // UseCounter depends on the current context, but it's not available during | 78 // UseCounter depends on the current context, but it's not available during |
(...skipping 21 matching lines...) Expand all Loading... |
94 }; | 100 }; |
95 | 101 |
96 // Use this class to abstract away types of members that are pointers to core/ | 102 // Use this class to abstract away types of members that are pointers to core/ |
97 // objects, which are simply owned and released by V8PerIsolateData (see | 103 // objects, which are simply owned and released by V8PerIsolateData (see |
98 // m_threadDebugger for an example). | 104 // m_threadDebugger for an example). |
99 class PLATFORM_EXPORT Data { | 105 class PLATFORM_EXPORT Data { |
100 public: | 106 public: |
101 virtual ~Data() = default; | 107 virtual ~Data() = default; |
102 }; | 108 }; |
103 | 109 |
104 static v8::Isolate* Initialize(WebTaskRunner*); | 110 static v8::Isolate* Initialize(WebTaskRunner*, |
| 111 intptr_t* refernce_table, |
| 112 V8ContextSnapshotMode); |
105 | 113 |
106 static V8PerIsolateData* From(v8::Isolate* isolate) { | 114 static V8PerIsolateData* From(v8::Isolate* isolate) { |
107 DCHECK(isolate); | 115 DCHECK(isolate); |
108 DCHECK(isolate->GetData(gin::kEmbedderBlink)); | 116 DCHECK(isolate->GetData(gin::kEmbedderBlink)); |
109 return static_cast<V8PerIsolateData*>( | 117 return static_cast<V8PerIsolateData*>( |
110 isolate->GetData(gin::kEmbedderBlink)); | 118 isolate->GetData(gin::kEmbedderBlink)); |
111 } | 119 } |
112 | 120 |
113 static void WillBeDestroyed(v8::Isolate*); | 121 static void WillBeDestroyed(v8::Isolate*); |
114 static void Destroy(v8::Isolate*); | 122 static void Destroy(v8::Isolate*); |
(...skipping 22 matching lines...) Expand all Loading... |
137 | 145 |
138 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } | 146 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } |
139 | 147 |
140 // Accessors to the cache of interface templates. | 148 // Accessors to the cache of interface templates. |
141 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, | 149 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, |
142 const void* key); | 150 const void* key); |
143 void SetInterfaceTemplate(const DOMWrapperWorld&, | 151 void SetInterfaceTemplate(const DOMWrapperWorld&, |
144 const void* key, | 152 const void* key, |
145 v8::Local<v8::FunctionTemplate>); | 153 v8::Local<v8::FunctionTemplate>); |
146 | 154 |
| 155 // When v8::SnapshotCreator::CreateBlob() is called, we must not have |
| 156 // persistent handles in Blink. This method clears them. |
| 157 void ClearPersistentsForV8ContextSnapshot(); |
| 158 |
| 159 v8::SnapshotCreator* GetSnapshotCreator() const { |
| 160 return isolate_holder_.snapshot_creator(); |
| 161 } |
| 162 V8ContextSnapshotMode GetV8ContextSnapshotMode() const { |
| 163 return v8_context_snapshot_mode_; |
| 164 } |
| 165 |
147 // Accessor to the cache of cross-origin accessible operation's templates. | 166 // Accessor to the cache of cross-origin accessible operation's templates. |
148 // Created templates get automatically cached. | 167 // Created templates get automatically cached. |
149 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( | 168 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( |
150 const DOMWrapperWorld&, | 169 const DOMWrapperWorld&, |
151 const void* key, | 170 const void* key, |
152 v8::FunctionCallback, | 171 v8::FunctionCallback, |
153 v8::Local<v8::Value> data, | 172 v8::Local<v8::Value> data, |
154 v8::Local<v8::Signature>, | 173 v8::Local<v8::Signature>, |
155 int length); | 174 int length); |
156 | 175 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 236 |
218 void SetScriptWrappableVisitor( | 237 void SetScriptWrappableVisitor( |
219 std::unique_ptr<ScriptWrappableVisitor> visitor) { | 238 std::unique_ptr<ScriptWrappableVisitor> visitor) { |
220 script_wrappable_visitor_ = std::move(visitor); | 239 script_wrappable_visitor_ = std::move(visitor); |
221 } | 240 } |
222 ScriptWrappableVisitor* GetScriptWrappableVisitor() { | 241 ScriptWrappableVisitor* GetScriptWrappableVisitor() { |
223 return script_wrappable_visitor_.get(); | 242 return script_wrappable_visitor_.get(); |
224 } | 243 } |
225 | 244 |
226 private: | 245 private: |
227 explicit V8PerIsolateData(WebTaskRunner*); | 246 V8PerIsolateData(WebTaskRunner*, |
| 247 intptr_t* reference_table, |
| 248 V8ContextSnapshotMode); |
| 249 explicit V8PerIsolateData(intptr_t* reference_table); |
228 ~V8PerIsolateData(); | 250 ~V8PerIsolateData(); |
229 | 251 |
230 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>> | 252 using V8FunctionTemplateMap = |
231 V8FunctionTemplateMap; | 253 HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>; |
232 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); | 254 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); |
233 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); | 255 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); |
234 bool HasInstance(const WrapperTypeInfo* untrusted, | 256 bool HasInstance(const WrapperTypeInfo* untrusted, |
235 v8::Local<v8::Value>, | 257 v8::Local<v8::Value>, |
236 V8FunctionTemplateMap&); | 258 V8FunctionTemplateMap&); |
237 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, | 259 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, |
238 v8::Local<v8::Value>, | 260 v8::Local<v8::Value>, |
239 V8FunctionTemplateMap&); | 261 V8FunctionTemplateMap&); |
240 | 262 |
| 263 V8ContextSnapshotMode v8_context_snapshot_mode_; |
| 264 // This isolate_holder_ must be initialized before initializing some other |
| 265 // members below. |
241 gin::IsolateHolder isolate_holder_; | 266 gin::IsolateHolder isolate_holder_; |
242 | 267 |
243 // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for | 268 // interface_template_map_for_{,non_}main_world holds function templates for |
244 // the inerface objects. | 269 // the inerface objects. |
245 V8FunctionTemplateMap interface_template_map_for_main_world_; | 270 V8FunctionTemplateMap interface_template_map_for_main_world_; |
246 V8FunctionTemplateMap interface_template_map_for_non_main_world_; | 271 V8FunctionTemplateMap interface_template_map_for_non_main_world_; |
| 272 |
247 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for | 273 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for |
248 // the cross-origin accessible DOM operations. | 274 // the cross-origin accessible DOM operations. |
249 V8FunctionTemplateMap operation_template_map_for_main_world_; | 275 V8FunctionTemplateMap operation_template_map_for_main_world_; |
250 V8FunctionTemplateMap operation_template_map_for_non_main_world_; | 276 V8FunctionTemplateMap operation_template_map_for_non_main_world_; |
251 | 277 |
252 // Contains lists of eternal names, such as dictionary keys. | 278 // Contains lists of eternal names, such as dictionary keys. |
253 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; | 279 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; |
254 | 280 |
| 281 // Members required for the V8 context snapshot. |
| 282 // v8::Context is created from this blob data image. This needs to be |
| 283 // instantiated before |isolate_holder_| gets instantiated. |
| 284 v8::StartupData startup_data_; |
| 285 // When taking a V8 context snapshot, we can't keep V8 objects with eternal |
| 286 // handles. So we use a special interface map that doesn't use eternal handles |
| 287 // instead of the default V8FunctionTemplateMap. |
| 288 V8GlobalValueMap<const WrapperTypeInfo*, v8::FunctionTemplate, v8::kNotWeak> |
| 289 interface_template_map_for_v8_context_snapshot_; |
| 290 |
255 std::unique_ptr<StringCache> string_cache_; | 291 std::unique_ptr<StringCache> string_cache_; |
256 std::unique_ptr<V8PrivateProperty> private_property_; | 292 std::unique_ptr<V8PrivateProperty> private_property_; |
257 RefPtr<ScriptState> script_regexp_script_state_; | 293 RefPtr<ScriptState> script_regexp_script_state_; |
258 | 294 |
259 bool constructor_mode_; | 295 bool constructor_mode_; |
260 friend class ConstructorMode; | 296 friend class ConstructorMode; |
261 | 297 |
262 bool use_counter_disabled_; | 298 bool use_counter_disabled_; |
263 friend class UseCounterDisabledScope; | 299 friend class UseCounterDisabledScope; |
264 | 300 |
265 bool is_handling_recursion_level_error_; | 301 bool is_handling_recursion_level_error_; |
266 bool is_reporting_exception_; | 302 bool is_reporting_exception_; |
267 | 303 |
268 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; | 304 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; |
269 std::unique_ptr<Data> thread_debugger_; | 305 std::unique_ptr<Data> thread_debugger_; |
270 | 306 |
271 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; | 307 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; |
272 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; | 308 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; |
273 | 309 |
274 RuntimeCallStats runtime_call_stats_; | 310 RuntimeCallStats runtime_call_stats_; |
275 }; | 311 }; |
276 | 312 |
277 } // namespace blink | 313 } // namespace blink |
278 | 314 |
279 #endif // V8PerIsolateData_h | 315 #endif // V8PerIsolateData_h |
OLD | NEW |