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

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

Issue 2841443005: [Bindings] Create and use V8 context snapshots (Closed)
Patch Set: Fix some behaviors 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "platform/bindings/V8PerIsolateData.h" 26 #include "platform/bindings/V8PerIsolateData.h"
27 27
28 #include <memory> 28 #include <memory>
29 29
30 #include "platform/RuntimeEnabledFeatures.h"
30 #include "platform/ScriptForbiddenScope.h" 31 #include "platform/ScriptForbiddenScope.h"
31 #include "platform/WebTaskRunner.h" 32 #include "platform/WebTaskRunner.h"
32 #include "platform/bindings/DOMDataStore.h" 33 #include "platform/bindings/DOMDataStore.h"
33 #include "platform/bindings/V8Binding.h" 34 #include "platform/bindings/V8Binding.h"
34 #include "platform/bindings/V8ObjectConstructor.h" 35 #include "platform/bindings/V8ObjectConstructor.h"
35 #include "platform/bindings/V8PrivateProperty.h" 36 #include "platform/bindings/V8PrivateProperty.h"
36 #include "platform/bindings/V8ValueCache.h" 37 #include "platform/bindings/V8ValueCache.h"
37 #include "platform/wtf/LeakAnnotations.h" 38 #include "platform/wtf/LeakAnnotations.h"
38 #include "platform/wtf/PtrUtil.h" 39 #include "platform/wtf/PtrUtil.h"
39 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
40 #include "v8/include/v8-debug.h" 41 #include "v8/include/v8-debug.h"
41 42
42 namespace blink { 43 namespace blink {
43 44
44 static V8PerIsolateData* g_main_thread_per_isolate_data = 0; 45 static V8PerIsolateData* g_main_thread_per_isolate_data = 0;
45 46
46 static void BeforeCallEnteredCallback(v8::Isolate* isolate) { 47 static void BeforeCallEnteredCallback(v8::Isolate* isolate) {
47 CHECK(!ScriptForbiddenScope::IsScriptForbidden()); 48 CHECK(!ScriptForbiddenScope::IsScriptForbidden());
48 } 49 }
49 50
50 static void MicrotasksCompletedCallback(v8::Isolate* isolate) { 51 static void MicrotasksCompletedCallback(v8::Isolate* isolate) {
51 V8PerIsolateData::From(isolate)->RunEndOfScopeTasks(); 52 V8PerIsolateData::From(isolate)->RunEndOfScopeTasks();
52 } 53 }
53 54
54 V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner) 55 V8PerIsolateData::V8PerIsolateData(WebTaskRunner* task_runner,
56 intptr_t* table,
57 bool take_snapshot)
Yuki 2017/05/12 15:20:10 bool argument, which is ambiguous, is not recommen
peria 2017/05/30 08:25:43 Acknowledged.
55 : isolate_holder_( 58 : isolate_holder_(
56 task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr, 59 task_runner ? task_runner->ToSingleThreadTaskRunner() : nullptr,
57 gin::IsolateHolder::kSingleThread, 60 gin::IsolateHolder::kSingleThread,
58 IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait 61 IsMainThread() ? gin::IsolateHolder::kDisallowAtomicsWait
59 : gin::IsolateHolder::kAllowAtomicsWait), 62 : gin::IsolateHolder::kAllowAtomicsWait,
63 table,
64 take_snapshot ? gin::IsolateHolder::kTakeSnapshot
65 : gin::IsolateHolder::kDefault),
60 string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))), 66 string_cache_(WTF::WrapUnique(new StringCache(GetIsolate()))),
61 private_property_(V8PrivateProperty::Create()), 67 private_property_(V8PrivateProperty::Create()),
62 constructor_mode_(ConstructorMode::kCreateNewObject), 68 constructor_mode_(ConstructorMode::kCreateNewObject),
63 use_counter_disabled_(false), 69 use_counter_disabled_(false),
64 is_handling_recursion_level_error_(false), 70 is_handling_recursion_level_error_(false),
65 is_reporting_exception_(false) { 71 is_reporting_exception_(false) {
66 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone. 72 // FIXME: Remove once all v8::Isolate::GetCurrent() calls are gone.
67 GetIsolate()->Enter(); 73 GetIsolate()->Enter();
68 GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback); 74 GetIsolate()->AddBeforeCallEnteredCallback(&BeforeCallEnteredCallback);
69 GetIsolate()->AddMicrotasksCompletedCallback(&MicrotasksCompletedCallback); 75 GetIsolate()->AddMicrotasksCompletedCallback(&MicrotasksCompletedCallback);
70 if (IsMainThread()) 76 if (IsMainThread())
71 g_main_thread_per_isolate_data = this; 77 g_main_thread_per_isolate_data = this;
72 } 78 }
73 79
74 V8PerIsolateData::~V8PerIsolateData() {} 80 V8PerIsolateData::~V8PerIsolateData() {}
75 81
76 v8::Isolate* V8PerIsolateData::MainThreadIsolate() { 82 v8::Isolate* V8PerIsolateData::MainThreadIsolate() {
77 DCHECK(g_main_thread_per_isolate_data); 83 DCHECK(g_main_thread_per_isolate_data);
78 return g_main_thread_per_isolate_data->GetIsolate(); 84 return g_main_thread_per_isolate_data->GetIsolate();
79 } 85 }
80 86
81 v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner) { 87 v8::Isolate* V8PerIsolateData::Initialize(WebTaskRunner* task_runner,
82 V8PerIsolateData* data = new V8PerIsolateData(task_runner); 88 intptr_t* table,
89 bool take_snapshot) {
90 if (!take_snapshot && !RuntimeEnabledFeatures::v8ContextSnapshotEnabled()) {
91 table = nullptr;
92 }
93
94 V8PerIsolateData* data =
95 new V8PerIsolateData(task_runner, table, take_snapshot);
83 v8::Isolate* isolate = data->GetIsolate(); 96 v8::Isolate* isolate = data->GetIsolate();
84 isolate->SetData(gin::kEmbedderBlink, data); 97 isolate->SetData(gin::kEmbedderBlink, data);
85 return isolate; 98 return isolate;
86 } 99 }
87 100
88 void V8PerIsolateData::EnableIdleTasks( 101 void V8PerIsolateData::EnableIdleTasks(
89 v8::Isolate* isolate, 102 v8::Isolate* isolate,
90 std::unique_ptr<gin::V8IdleTaskRunner> task_runner) { 103 std::unique_ptr<gin::V8IdleTaskRunner> task_runner) {
91 From(isolate)->isolate_holder_.EnableIdleTasks(std::move(task_runner)); 104 From(isolate)->isolate_holder_.EnableIdleTasks(std::move(task_runner));
92 } 105 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 191 }
179 192
180 void V8PerIsolateData::SetInterfaceTemplate( 193 void V8PerIsolateData::SetInterfaceTemplate(
181 const DOMWrapperWorld& world, 194 const DOMWrapperWorld& world,
182 const void* key, 195 const void* key,
183 v8::Local<v8::FunctionTemplate> value) { 196 v8::Local<v8::FunctionTemplate> value) {
184 auto& map = SelectInterfaceTemplateMap(world); 197 auto& map = SelectInterfaceTemplateMap(world);
185 map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value)); 198 map.insert(key, v8::Eternal<v8::FunctionTemplate>(GetIsolate(), value));
186 } 199 }
187 200
201 v8::Local<v8::FunctionTemplate> V8PerIsolateData::FindInterfaceTemplateTemp(
202 const DOMWrapperWorld& world,
203 const void* key) {
204 auto& map = interface_template_temp_map_;
205 auto result = map.find(key);
206 if (result != map.end())
207 return result->value.Get(GetIsolate());
208 return v8::Local<v8::FunctionTemplate>();
209 }
210
211 void V8PerIsolateData::SetInterfaceTemplateTemp(
212 const DOMWrapperWorld& world,
213 const void* key,
214 v8::Local<v8::FunctionTemplate> value) {
215 auto& map = interface_template_temp_map_;
216 map.insert(key, CopyablePersistent(GetIsolate(), value));
217 }
218
219 void V8PerIsolateData::ClearAll() {
220 interface_template_temp_map_.clear();
221 private_property_.reset();
222 }
223
188 const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache( 224 const v8::Eternal<v8::Name>* V8PerIsolateData::FindOrCreateEternalNameCache(
189 const void* lookup_key, 225 const void* lookup_key,
190 const char* const names[], 226 const char* const names[],
191 size_t count) { 227 size_t count) {
192 auto it = eternal_name_cache_.find(lookup_key); 228 auto it = eternal_name_cache_.find(lookup_key);
193 const Vector<v8::Eternal<v8::Name>>* vector = nullptr; 229 const Vector<v8::Eternal<v8::Name>>* vector = nullptr;
194 if (UNLIKELY(it == eternal_name_cache_.end())) { 230 if (UNLIKELY(it == eternal_name_cache_.end())) {
195 v8::Isolate* isolate = this->GetIsolate(); 231 v8::Isolate* isolate = this->GetIsolate();
196 Vector<v8::Eternal<v8::Name>> new_vector(count); 232 Vector<v8::Eternal<v8::Name>> new_vector(count);
197 std::transform( 233 std::transform(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 ScriptWrappableVisitor* current = CurrentVisitor(); 345 ScriptWrappableVisitor* current = CurrentVisitor();
310 if (current) 346 if (current)
311 current->PerformCleanup(); 347 current->PerformCleanup();
312 348
313 V8PerIsolateData::From(isolate_)->script_wrappable_visitor_.swap( 349 V8PerIsolateData::From(isolate_)->script_wrappable_visitor_.swap(
314 saved_visitor_); 350 saved_visitor_);
315 isolate_->SetEmbedderHeapTracer(CurrentVisitor()); 351 isolate_->SetEmbedderHeapTracer(CurrentVisitor());
316 } 352 }
317 353
318 } // namespace blink 354 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698