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*); |
114 static v8::Isolate* MainThreadIsolate(); | 122 static v8::Isolate* MainThreadIsolate(); |
115 | 123 |
116 static void EnableIdleTasks(v8::Isolate*, | 124 static void EnableIdleTasks(v8::Isolate*, |
117 std::unique_ptr<gin::V8IdleTaskRunner>); | 125 std::unique_ptr<gin::V8IdleTaskRunner>); |
118 | 126 |
119 v8::Isolate* GetIsolate() { return isolate_holder_.isolate(); } | 127 v8::Isolate* GetIsolate() { return isolate_holder_.isolate(); } |
128 v8::SnapshotCreator* GetSnapshotCreator() { return snapshot_creator_.get(); } | |
120 | 129 |
121 StringCache* GetStringCache() { return string_cache_.get(); } | 130 StringCache* GetStringCache() { return string_cache_.get(); } |
122 | 131 |
123 bool IsHandlingRecursionLevelError() const { | 132 bool IsHandlingRecursionLevelError() const { |
124 return is_handling_recursion_level_error_; | 133 return is_handling_recursion_level_error_; |
125 } | 134 } |
126 void SetIsHandlingRecursionLevelError(bool value) { | 135 void SetIsHandlingRecursionLevelError(bool value) { |
127 is_handling_recursion_level_error_ = value; | 136 is_handling_recursion_level_error_ = value; |
128 } | 137 } |
129 | 138 |
130 bool IsReportingException() const { return is_reporting_exception_; } | 139 bool IsReportingException() const { return is_reporting_exception_; } |
131 void SetReportingException(bool value) { is_reporting_exception_ = value; } | 140 void SetReportingException(bool value) { is_reporting_exception_ = value; } |
132 | 141 |
133 bool IsUseCounterDisabled() const { return use_counter_disabled_; } | 142 bool IsUseCounterDisabled() const { return use_counter_disabled_; } |
134 | 143 |
135 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } | 144 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } |
136 | 145 |
137 // Accessors to the cache of interface templates. | 146 // Accessors to the cache of interface templates. |
138 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, | 147 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, |
139 const void* key); | 148 const void* key); |
140 void SetInterfaceTemplate(const DOMWrapperWorld&, | 149 void SetInterfaceTemplate(const DOMWrapperWorld&, |
141 const void* key, | 150 const void* key, |
142 v8::Local<v8::FunctionTemplate>); | 151 v8::Local<v8::FunctionTemplate>); |
152 void ClearPersistents(); | |
Yuki
2017/05/30 14:35:58
Add a comment what this function does (and why we
peria
2017/06/01 08:33:34
Done.
| |
153 V8ContextMode GetV8ContextMode() const { return v8_context_mode_; } | |
Yuki
2017/05/30 14:35:58
GetV8ContextMode() seems relevant to GetSnapshotCr
peria
2017/06/01 08:33:34
Done.
| |
143 | 154 |
144 // Accessor to the cache of cross-origin accessible operation's templates. | 155 // Accessor to the cache of cross-origin accessible operation's templates. |
145 // Created templates get automatically cached. | 156 // Created templates get automatically cached. |
146 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( | 157 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( |
147 const DOMWrapperWorld&, | 158 const DOMWrapperWorld&, |
148 const void* key, | 159 const void* key, |
149 v8::FunctionCallback, | 160 v8::FunctionCallback, |
150 v8::Local<v8::Value> data, | 161 v8::Local<v8::Value> data, |
151 v8::Local<v8::Signature>, | 162 v8::Local<v8::Signature>, |
152 int length); | 163 int length); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 225 |
215 void SetScriptWrappableVisitor( | 226 void SetScriptWrappableVisitor( |
216 std::unique_ptr<ScriptWrappableVisitor> visitor) { | 227 std::unique_ptr<ScriptWrappableVisitor> visitor) { |
217 script_wrappable_visitor_ = std::move(visitor); | 228 script_wrappable_visitor_ = std::move(visitor); |
218 } | 229 } |
219 ScriptWrappableVisitor* GetScriptWrappableVisitor() { | 230 ScriptWrappableVisitor* GetScriptWrappableVisitor() { |
220 return script_wrappable_visitor_.get(); | 231 return script_wrappable_visitor_.get(); |
221 } | 232 } |
222 | 233 |
223 private: | 234 private: |
224 explicit V8PerIsolateData(WebTaskRunner*); | 235 V8PerIsolateData(WebTaskRunner*, intptr_t* reference_table, V8ContextMode); |
236 // To create with v8::SnapshotCreator. | |
237 V8PerIsolateData(intptr_t* reference_table); | |
225 ~V8PerIsolateData(); | 238 ~V8PerIsolateData(); |
226 | 239 |
227 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>> | 240 using V8FunctionTemplateMap = |
228 V8FunctionTemplateMap; | 241 HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>; |
229 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); | 242 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); |
230 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); | 243 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); |
231 bool HasInstance(const WrapperTypeInfo* untrusted, | 244 bool HasInstance(const WrapperTypeInfo* untrusted, |
232 v8::Local<v8::Value>, | 245 v8::Local<v8::Value>, |
233 V8FunctionTemplateMap&); | 246 V8FunctionTemplateMap&); |
234 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, | 247 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, |
235 v8::Local<v8::Value>, | 248 v8::Local<v8::Value>, |
236 V8FunctionTemplateMap&); | 249 V8FunctionTemplateMap&); |
237 | 250 |
251 // Members requried for snapshotted context, and should be instantiate | |
252 // before IsolateHolder. | |
Yuki
2017/05/30 14:35:58
Members required for snapshotted contexts.
Need to
peria
2017/06/01 08:33:34
Done.
| |
253 std::unique_ptr<v8::SnapshotCreator> snapshot_creator_; | |
254 v8::StartupData startup_data_; | |
255 | |
238 gin::IsolateHolder isolate_holder_; | 256 gin::IsolateHolder isolate_holder_; |
239 | 257 |
240 // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for | 258 // interface_template_map_for_{,non_}main_world holds function templates for |
241 // the inerface objects. | 259 // the inerface objects. |
242 V8FunctionTemplateMap interface_template_map_for_main_world_; | 260 V8FunctionTemplateMap interface_template_map_for_main_world_; |
243 V8FunctionTemplateMap interface_template_map_for_non_main_world_; | 261 V8FunctionTemplateMap interface_template_map_for_non_main_world_; |
262 | |
263 // Members requried for snapshotted context. | |
264 using CopyablePersistent = | |
Yuki
2017/05/30 14:35:58
I think that it's worth commenting that this is us
peria
2017/06/01 08:33:34
Acknowledged.
| |
265 v8::Persistent<v8::FunctionTemplate, | |
266 v8::CopyablePersistentTraits<v8::FunctionTemplate>>; | |
267 using V8FunctionTemplatePersistentMap = | |
268 HashMap<const void*, CopyablePersistent>; | |
269 V8FunctionTemplatePersistentMap interface_template_persistent_map_; | |
Yuki
2017/05/30 14:35:58
interface_template_maps_for_snapshot_;
would be cl
peria
2017/06/01 08:33:34
Done.
| |
270 V8ContextMode v8_context_mode_; | |
271 | |
244 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for | 272 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for |
245 // the cross-origin accessible DOM operations. | 273 // the cross-origin accessible DOM operations. |
246 V8FunctionTemplateMap operation_template_map_for_main_world_; | 274 V8FunctionTemplateMap operation_template_map_for_main_world_; |
247 V8FunctionTemplateMap operation_template_map_for_non_main_world_; | 275 V8FunctionTemplateMap operation_template_map_for_non_main_world_; |
248 | 276 |
249 // Contains lists of eternal names, such as dictionary keys. | 277 // Contains lists of eternal names, such as dictionary keys. |
250 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; | 278 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; |
251 | 279 |
252 std::unique_ptr<StringCache> string_cache_; | 280 std::unique_ptr<StringCache> string_cache_; |
253 std::unique_ptr<V8PrivateProperty> private_property_; | 281 std::unique_ptr<V8PrivateProperty> private_property_; |
(...skipping 11 matching lines...) Expand all Loading... | |
265 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; | 293 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; |
266 std::unique_ptr<Data> thread_debugger_; | 294 std::unique_ptr<Data> thread_debugger_; |
267 | 295 |
268 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; | 296 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; |
269 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; | 297 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; |
270 }; | 298 }; |
271 | 299 |
272 } // namespace blink | 300 } // namespace blink |
273 | 301 |
274 #endif // V8PerIsolateData_h | 302 #endif // V8PerIsolateData_h |
OLD | NEW |