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

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

Issue 2751263002: [Bindings] Cache handles for dictionary keys on V8PerIsolateData. (Closed)
Patch Set: findOrCreateEternalNameCache Created 3 years, 8 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 11 matching lines...) Expand all
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 "bindings/core/v8/V8PerIsolateData.h" 26 #include "bindings/core/v8/V8PerIsolateData.h"
27 27
28 #include <memory> 28 #include <memory>
29 29
30 #include "bindings/core/v8/DOMDataStore.h" 30 #include "bindings/core/v8/DOMDataStore.h"
31 #include "bindings/core/v8/ScriptSourceCode.h" 31 #include "bindings/core/v8/ScriptSourceCode.h"
32 #include "bindings/core/v8/V8Binding.h"
32 #include "bindings/core/v8/V8HiddenValue.h" 33 #include "bindings/core/v8/V8HiddenValue.h"
33 #include "bindings/core/v8/V8ObjectConstructor.h" 34 #include "bindings/core/v8/V8ObjectConstructor.h"
34 #include "bindings/core/v8/V8PrivateProperty.h" 35 #include "bindings/core/v8/V8PrivateProperty.h"
35 #include "bindings/core/v8/V8ScriptRunner.h" 36 #include "bindings/core/v8/V8ScriptRunner.h"
36 #include "bindings/core/v8/V8ValueCache.h" 37 #include "bindings/core/v8/V8ValueCache.h"
37 #include "platform/ScriptForbiddenScope.h" 38 #include "platform/ScriptForbiddenScope.h"
38 #include "public/platform/Platform.h" 39 #include "public/platform/Platform.h"
39 #include "v8/include/v8-debug.h" 40 #include "v8/include/v8-debug.h"
40 #include "wtf/LeakAnnotations.h" 41 #include "wtf/LeakAnnotations.h"
41 #include "wtf/PtrUtil.h" 42 #include "wtf/PtrUtil.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 183 }
183 184
184 void V8PerIsolateData::setInterfaceTemplate( 185 void V8PerIsolateData::setInterfaceTemplate(
185 const DOMWrapperWorld& world, 186 const DOMWrapperWorld& world,
186 const void* key, 187 const void* key,
187 v8::Local<v8::FunctionTemplate> value) { 188 v8::Local<v8::FunctionTemplate> value) {
188 auto& map = selectInterfaceTemplateMap(world); 189 auto& map = selectInterfaceTemplateMap(world);
189 map.insert(key, v8::Eternal<v8::FunctionTemplate>(isolate(), value)); 190 map.insert(key, v8::Eternal<v8::FunctionTemplate>(isolate(), value));
190 } 191 }
191 192
193 const v8::Eternal<v8::Name>* V8PerIsolateData::findOrCreateEternalNameCache(
194 const void* lookupKey,
195 const char* const names[],
196 size_t count) {
197 auto it = m_eternalNameCache.find(lookupKey);
198 const Vector<v8::Eternal<v8::Name>>* vector = nullptr;
199 if (UNLIKELY(it == m_eternalNameCache.end())) {
200 v8::Isolate* isolate = this->isolate();
201 Vector<v8::Eternal<v8::Name>> newVector(count);
202 std::transform(
203 names, names + count, newVector.begin(), [isolate](const char* name) {
204 return v8::Eternal<v8::Name>(isolate, v8AtomicString(isolate, name));
205 });
206 vector = &m_eternalNameCache.set(lookupKey, std::move(newVector))
207 .storedValue->value;
208 } else {
209 vector = &it->value;
210 }
211 DCHECK_EQ(vector->size(), count);
212 return vector->data();
213 }
214
192 v8::Local<v8::Context> V8PerIsolateData::ensureScriptRegexpContext() { 215 v8::Local<v8::Context> V8PerIsolateData::ensureScriptRegexpContext() {
193 if (!m_scriptRegexpScriptState) { 216 if (!m_scriptRegexpScriptState) {
194 LEAK_SANITIZER_DISABLED_SCOPE; 217 LEAK_SANITIZER_DISABLED_SCOPE;
195 v8::Local<v8::Context> context(v8::Context::New(isolate())); 218 v8::Local<v8::Context> context(v8::Context::New(isolate()));
196 m_scriptRegexpScriptState = ScriptState::create( 219 m_scriptRegexpScriptState = ScriptState::create(
197 context, 220 context,
198 DOMWrapperWorld::create(isolate(), DOMWrapperWorld::WorldType::RegExp)); 221 DOMWrapperWorld::create(isolate(), DOMWrapperWorld::WorldType::RegExp));
199 } 222 }
200 return m_scriptRegexpScriptState->context(); 223 return m_scriptRegexpScriptState->context();
201 } 224 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 ScriptWrappableVisitor* current = currentVisitor(); 314 ScriptWrappableVisitor* current = currentVisitor();
292 if (current) 315 if (current)
293 current->performCleanup(); 316 current->performCleanup();
294 317
295 V8PerIsolateData::from(m_isolate)->m_scriptWrappableVisitor.swap( 318 V8PerIsolateData::from(m_isolate)->m_scriptWrappableVisitor.swap(
296 m_savedVisitor); 319 m_savedVisitor);
297 m_isolate->SetEmbedderHeapTracer(currentVisitor()); 320 m_isolate->SetEmbedderHeapTracer(currentVisitor());
298 } 321 }
299 322
300 } // namespace blink 323 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698