Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: third_party/WebKit/Source/platform/bindings/V8PerIsolateData.h

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Work for some comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 }; 93 };
94 94
95 // Use this class to abstract away types of members that are pointers to core/ 95 // 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 96 // objects, which are simply owned and released by V8PerIsolateData (see
97 // m_threadDebugger for an example). 97 // m_threadDebugger for an example).
98 class PLATFORM_EXPORT Data { 98 class PLATFORM_EXPORT Data {
99 public: 99 public:
100 virtual ~Data() = default; 100 virtual ~Data() = default;
101 }; 101 };
102 102
103 static v8::Isolate* Initialize(WebTaskRunner*); 103 static v8::Isolate* Initialize(WebTaskRunner*,
104 intptr_t*,
105 gin::IsolateHolder::V8ContextMode);
104 106
105 static V8PerIsolateData* From(v8::Isolate* isolate) { 107 static V8PerIsolateData* From(v8::Isolate* isolate) {
106 DCHECK(isolate); 108 DCHECK(isolate);
107 DCHECK(isolate->GetData(gin::kEmbedderBlink)); 109 DCHECK(isolate->GetData(gin::kEmbedderBlink));
108 return static_cast<V8PerIsolateData*>( 110 return static_cast<V8PerIsolateData*>(
109 isolate->GetData(gin::kEmbedderBlink)); 111 isolate->GetData(gin::kEmbedderBlink));
110 } 112 }
111 113
112 static void WillBeDestroyed(v8::Isolate*); 114 static void WillBeDestroyed(v8::Isolate*);
113 static void Destroy(v8::Isolate*); 115 static void Destroy(v8::Isolate*);
114 static v8::Isolate* MainThreadIsolate(); 116 static v8::Isolate* MainThreadIsolate();
115 117
116 static void EnableIdleTasks(v8::Isolate*, 118 static void EnableIdleTasks(v8::Isolate*,
117 std::unique_ptr<gin::V8IdleTaskRunner>); 119 std::unique_ptr<gin::V8IdleTaskRunner>);
118 120
119 v8::Isolate* GetIsolate() { return isolate_holder_.isolate(); } 121 v8::Isolate* GetIsolate() { return isolate_holder_.isolate(); }
122 v8::SnapshotCreator* GetSnapshotCreator() {
123 return isolate_holder_.snapshot_creator();
124 }
120 125
121 StringCache* GetStringCache() { return string_cache_.get(); } 126 StringCache* GetStringCache() { return string_cache_.get(); }
122 127
123 bool IsHandlingRecursionLevelError() const { 128 bool IsHandlingRecursionLevelError() const {
124 return is_handling_recursion_level_error_; 129 return is_handling_recursion_level_error_;
125 } 130 }
126 void SetIsHandlingRecursionLevelError(bool value) { 131 void SetIsHandlingRecursionLevelError(bool value) {
127 is_handling_recursion_level_error_ = value; 132 is_handling_recursion_level_error_ = value;
128 } 133 }
129 134
130 bool IsReportingException() const { return is_reporting_exception_; } 135 bool IsReportingException() const { return is_reporting_exception_; }
131 void SetReportingException(bool value) { is_reporting_exception_ = value; } 136 void SetReportingException(bool value) { is_reporting_exception_ = value; }
132 137
133 bool IsUseCounterDisabled() const { return use_counter_disabled_; } 138 bool IsUseCounterDisabled() const { return use_counter_disabled_; }
134 139
135 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } 140 V8PrivateProperty* PrivateProperty() { return private_property_.get(); }
136 141
137 // Accessors to the cache of interface templates. 142 // Accessors to the cache of interface templates.
138 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, 143 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&,
139 const void* key); 144 const void* key);
140 void SetInterfaceTemplate(const DOMWrapperWorld&, 145 void SetInterfaceTemplate(const DOMWrapperWorld&,
141 const void* key, 146 const void* key,
142 v8::Local<v8::FunctionTemplate>); 147 v8::Local<v8::FunctionTemplate>);
148 void ClearPersistents();
149 gin::IsolateHolder::V8ContextMode GetV8ContextMode() const {
150 return isolate_holder_.v8_context_mode();
151 }
143 152
144 // Accessor to the cache of cross-origin accessible operation's templates. 153 // Accessor to the cache of cross-origin accessible operation's templates.
145 // Created templates get automatically cached. 154 // Created templates get automatically cached.
146 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( 155 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate(
147 const DOMWrapperWorld&, 156 const DOMWrapperWorld&,
148 const void* key, 157 const void* key,
149 v8::FunctionCallback, 158 v8::FunctionCallback,
150 v8::Local<v8::Value> data, 159 v8::Local<v8::Value> data,
151 v8::Local<v8::Signature>, 160 v8::Local<v8::Signature>,
152 int length); 161 int length);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 223
215 void SetScriptWrappableVisitor( 224 void SetScriptWrappableVisitor(
216 std::unique_ptr<ScriptWrappableVisitor> visitor) { 225 std::unique_ptr<ScriptWrappableVisitor> visitor) {
217 script_wrappable_visitor_ = std::move(visitor); 226 script_wrappable_visitor_ = std::move(visitor);
218 } 227 }
219 ScriptWrappableVisitor* GetScriptWrappableVisitor() { 228 ScriptWrappableVisitor* GetScriptWrappableVisitor() {
220 return script_wrappable_visitor_.get(); 229 return script_wrappable_visitor_.get();
221 } 230 }
222 231
223 private: 232 private:
224 explicit V8PerIsolateData(WebTaskRunner*); 233 explicit V8PerIsolateData(WebTaskRunner*,
234 intptr_t*,
235 gin::IsolateHolder::V8ContextMode);
225 ~V8PerIsolateData(); 236 ~V8PerIsolateData();
226 237
227 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>> 238 using V8FunctionTemplateMap =
228 V8FunctionTemplateMap; 239 HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>;
229 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); 240 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&);
230 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); 241 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&);
231 bool HasInstance(const WrapperTypeInfo* untrusted, 242 bool HasInstance(const WrapperTypeInfo* untrusted,
232 v8::Local<v8::Value>, 243 v8::Local<v8::Value>,
233 V8FunctionTemplateMap&); 244 V8FunctionTemplateMap&);
234 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, 245 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*,
235 v8::Local<v8::Value>, 246 v8::Local<v8::Value>,
236 V8FunctionTemplateMap&); 247 V8FunctionTemplateMap&);
237 248
238 gin::IsolateHolder isolate_holder_; 249 gin::IsolateHolder isolate_holder_;
239 250
240 // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for 251 // interface_template_map_for_{,non_}main_world holds function templates for
241 // the inerface objects. 252 // the inerface objects.
242 V8FunctionTemplateMap interface_template_map_for_main_world_; 253 V8FunctionTemplateMap interface_template_map_for_main_world_;
243 V8FunctionTemplateMap interface_template_map_for_non_main_world_; 254 V8FunctionTemplateMap interface_template_map_for_non_main_world_;
255
256 using CopyablePersistent =
haraken 2017/05/20 19:10:03 Would you help me understand why you need to use C
peria 2017/05/30 08:25:44 Will replace with ScopedPersistent or something us
257 v8::Persistent<v8::FunctionTemplate,
258 v8::CopyablePersistentTraits<v8::FunctionTemplate>>;
259 using V8FunctionTemplatePersistentMap =
260 HashMap<const void*, CopyablePersistent>;
261 V8FunctionTemplatePersistentMap interface_template_persistent_map_;
262
244 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for 263 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for
245 // the cross-origin accessible DOM operations. 264 // the cross-origin accessible DOM operations.
246 V8FunctionTemplateMap operation_template_map_for_main_world_; 265 V8FunctionTemplateMap operation_template_map_for_main_world_;
247 V8FunctionTemplateMap operation_template_map_for_non_main_world_; 266 V8FunctionTemplateMap operation_template_map_for_non_main_world_;
248 267
249 // Contains lists of eternal names, such as dictionary keys. 268 // Contains lists of eternal names, such as dictionary keys.
250 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; 269 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_;
251 270
252 std::unique_ptr<StringCache> string_cache_; 271 std::unique_ptr<StringCache> string_cache_;
253 std::unique_ptr<V8PrivateProperty> private_property_; 272 std::unique_ptr<V8PrivateProperty> private_property_;
(...skipping 11 matching lines...) Expand all
265 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; 284 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_;
266 std::unique_ptr<Data> thread_debugger_; 285 std::unique_ptr<Data> thread_debugger_;
267 286
268 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; 287 Persistent<ActiveScriptWrappableSet> active_script_wrappables_;
269 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; 288 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_;
270 }; 289 };
271 290
272 } // namespace blink 291 } // namespace blink
273 292
274 #endif // V8PerIsolateData_h 293 #endif // V8PerIsolateData_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698