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

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

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: . 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 }; 91 };
92 92
93 // Use this class to abstract away types of members that are pointers to core/ 93 // Use this class to abstract away types of members that are pointers to core/
94 // objects, which are simply owned and released by V8PerIsolateData (see 94 // objects, which are simply owned and released by V8PerIsolateData (see
95 // m_threadDebugger for an example). 95 // m_threadDebugger for an example).
96 class PLATFORM_EXPORT Data { 96 class PLATFORM_EXPORT Data {
97 public: 97 public:
98 virtual ~Data() = default; 98 virtual ~Data() = default;
99 }; 99 };
100 100
101 static v8::Isolate* Initialize(WebTaskRunner*); 101 static v8::Isolate* Initialize(WebTaskRunner*, intptr_t*, bool);
102 102
103 static V8PerIsolateData* From(v8::Isolate* isolate) { 103 static V8PerIsolateData* From(v8::Isolate* isolate) {
104 DCHECK(isolate); 104 DCHECK(isolate);
105 DCHECK(isolate->GetData(gin::kEmbedderBlink)); 105 DCHECK(isolate->GetData(gin::kEmbedderBlink));
106 return static_cast<V8PerIsolateData*>( 106 return static_cast<V8PerIsolateData*>(
107 isolate->GetData(gin::kEmbedderBlink)); 107 isolate->GetData(gin::kEmbedderBlink));
108 } 108 }
109 109
110 static void WillBeDestroyed(v8::Isolate*); 110 static void WillBeDestroyed(v8::Isolate*);
111 static void Destroy(v8::Isolate*); 111 static void Destroy(v8::Isolate*);
112 static v8::Isolate* MainThreadIsolate(); 112 static v8::Isolate* MainThreadIsolate();
113 113
114 static void EnableIdleTasks(v8::Isolate*, 114 static void EnableIdleTasks(v8::Isolate*,
115 std::unique_ptr<gin::V8IdleTaskRunner>); 115 std::unique_ptr<gin::V8IdleTaskRunner>);
116 116
117 v8::Isolate* GetIsolate() { return isolate_holder_.isolate(); } 117 v8::Isolate* GetIsolate() { return isolate_holder_.isolate(); }
118 v8::SnapshotCreator* GetSnapshotCreator() {
119 return isolate_holder_.snapshot_creator();
120 }
118 121
119 StringCache* GetStringCache() { return string_cache_.get(); } 122 StringCache* GetStringCache() { return string_cache_.get(); }
120 123
121 v8::Persistent<v8::Value>& EnsureLiveRoot(); 124 v8::Persistent<v8::Value>& EnsureLiveRoot();
122 125
123 bool IsHandlingRecursionLevelError() const { 126 bool IsHandlingRecursionLevelError() const {
124 return is_handling_recursion_level_error_; 127 return is_handling_recursion_level_error_;
125 } 128 }
126 void SetIsHandlingRecursionLevelError(bool value) { 129 void SetIsHandlingRecursionLevelError(bool value) {
127 is_handling_recursion_level_error_ = value; 130 is_handling_recursion_level_error_ = value;
128 } 131 }
129 132
130 bool IsReportingException() const { return is_reporting_exception_; } 133 bool IsReportingException() const { return is_reporting_exception_; }
131 void SetReportingException(bool value) { is_reporting_exception_ = value; } 134 void SetReportingException(bool value) { is_reporting_exception_ = value; }
132 135
133 bool IsUseCounterDisabled() const { return use_counter_disabled_; } 136 bool IsUseCounterDisabled() const { return use_counter_disabled_; }
134 137
135 V8PrivateProperty* PrivateProperty() { return private_property_.get(); } 138 V8PrivateProperty* PrivateProperty() { return private_property_.get(); }
136 139
137 // Accessors to the cache of interface templates. 140 // Accessors to the cache of interface templates.
138 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&, 141 v8::Local<v8::FunctionTemplate> FindInterfaceTemplate(const DOMWrapperWorld&,
139 const void* key); 142 const void* key);
143 v8::Local<v8::FunctionTemplate> FindInterfaceTemplateTemp(
144 const DOMWrapperWorld&,
145 const void* key);
140 void SetInterfaceTemplate(const DOMWrapperWorld&, 146 void SetInterfaceTemplate(const DOMWrapperWorld&,
141 const void* key, 147 const void* key,
142 v8::Local<v8::FunctionTemplate>); 148 v8::Local<v8::FunctionTemplate>);
149 void SetInterfaceTemplateTemp(const DOMWrapperWorld&,
150 const void* key,
151 v8::Local<v8::FunctionTemplate>);
152 void ClearAll();
143 153
144 // Accessor to the cache of cross-origin accessible operation's templates. 154 // Accessor to the cache of cross-origin accessible operation's templates.
145 // Created templates get automatically cached. 155 // Created templates get automatically cached.
146 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate( 156 v8::Local<v8::FunctionTemplate> FindOrCreateOperationTemplate(
147 const DOMWrapperWorld&, 157 const DOMWrapperWorld&,
148 const void* key, 158 const void* key,
149 v8::FunctionCallback, 159 v8::FunctionCallback,
150 v8::Local<v8::Value> data, 160 v8::Local<v8::Value> data,
151 v8::Local<v8::Signature>, 161 v8::Local<v8::Signature>,
152 int length); 162 int length);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 }; 223 };
214 224
215 void SetScriptWrappableVisitor( 225 void SetScriptWrappableVisitor(
216 std::unique_ptr<ScriptWrappableVisitor> visitor) { 226 std::unique_ptr<ScriptWrappableVisitor> visitor) {
217 script_wrappable_visitor_ = std::move(visitor); 227 script_wrappable_visitor_ = std::move(visitor);
218 } 228 }
219 ScriptWrappableVisitor* GetScriptWrappableVisitor() { 229 ScriptWrappableVisitor* GetScriptWrappableVisitor() {
220 return script_wrappable_visitor_.get(); 230 return script_wrappable_visitor_.get();
221 } 231 }
222 232
233 bool UseSnapshot() const {
234 return isolate_holder_.v8_context_mode() ==
235 gin::IsolateHolder::kUseSnapshot;
236 }
237
223 private: 238 private:
224 explicit V8PerIsolateData(WebTaskRunner*); 239 explicit V8PerIsolateData(WebTaskRunner*, intptr_t*, bool);
225 ~V8PerIsolateData(); 240 ~V8PerIsolateData();
226 241
242 using CopyableTraits = v8::CopyablePersistentTraits<v8::FunctionTemplate>;
243 using CopyablePersistent =
244 v8::Persistent<v8::FunctionTemplate, CopyableTraits>;
245 using V8TemporaryFunctionTemplateMap =
246 HashMap<const void*, CopyablePersistent>;
247
227 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>> 248 typedef HashMap<const void*, v8::Eternal<v8::FunctionTemplate>>
228 V8FunctionTemplateMap; 249 V8FunctionTemplateMap;
229 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&); 250 V8FunctionTemplateMap& SelectInterfaceTemplateMap(const DOMWrapperWorld&);
230 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&); 251 V8FunctionTemplateMap& SelectOperationTemplateMap(const DOMWrapperWorld&);
231 bool HasInstance(const WrapperTypeInfo* untrusted, 252 bool HasInstance(const WrapperTypeInfo* untrusted,
232 v8::Local<v8::Value>, 253 v8::Local<v8::Value>,
233 V8FunctionTemplateMap&); 254 V8FunctionTemplateMap&);
234 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*, 255 v8::Local<v8::Object> FindInstanceInPrototypeChain(const WrapperTypeInfo*,
235 v8::Local<v8::Value>, 256 v8::Local<v8::Value>,
236 V8FunctionTemplateMap&); 257 V8FunctionTemplateMap&);
237 258
238 gin::IsolateHolder isolate_holder_; 259 gin::IsolateHolder isolate_holder_;
239 260
240 // m_interfaceTemplateMapFor{,Non}MainWorld holds function templates for 261 // interface_template_map_for_{,non_}main_world holds function templates for
241 // the inerface objects. 262 // the inerface objects.
242 V8FunctionTemplateMap interface_template_map_for_main_world_; 263 V8FunctionTemplateMap interface_template_map_for_main_world_;
243 V8FunctionTemplateMap interface_template_map_for_non_main_world_; 264 V8FunctionTemplateMap interface_template_map_for_non_main_world_;
265
266 V8TemporaryFunctionTemplateMap interface_template_temp_map_;
267
244 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for 268 // m_operationTemplateMapFor{,Non}MainWorld holds function templates for
245 // the cross-origin accessible DOM operations. 269 // the cross-origin accessible DOM operations.
246 V8FunctionTemplateMap operation_template_map_for_main_world_; 270 V8FunctionTemplateMap operation_template_map_for_main_world_;
247 V8FunctionTemplateMap operation_template_map_for_non_main_world_; 271 V8FunctionTemplateMap operation_template_map_for_non_main_world_;
248 272
249 // Contains lists of eternal names, such as dictionary keys. 273 // Contains lists of eternal names, such as dictionary keys.
250 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_; 274 HashMap<const void*, Vector<v8::Eternal<v8::Name>>> eternal_name_cache_;
251 275
252 std::unique_ptr<StringCache> string_cache_; 276 std::unique_ptr<StringCache> string_cache_;
253 std::unique_ptr<V8PrivateProperty> private_property_; 277 std::unique_ptr<V8PrivateProperty> private_property_;
(...skipping 12 matching lines...) Expand all
266 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_; 290 Vector<std::unique_ptr<EndOfScopeTask>> end_of_scope_tasks_;
267 std::unique_ptr<Data> thread_debugger_; 291 std::unique_ptr<Data> thread_debugger_;
268 292
269 Persistent<ActiveScriptWrappableSet> active_script_wrappables_; 293 Persistent<ActiveScriptWrappableSet> active_script_wrappables_;
270 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_; 294 std::unique_ptr<ScriptWrappableVisitor> script_wrappable_visitor_;
271 }; 295 };
272 296
273 } // namespace blink 297 } // namespace blink
274 298
275 #endif // V8PerIsolateData_h 299 #endif // V8PerIsolateData_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698