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