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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp

Issue 2335203006: Add [CachedAccessor] attribute to cache (almost) constant accessors (window.document). (Closed)
Patch Set: Fix rebase dirt Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp b/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp
index 5a986f739091bd959d72f0229f4121a53a09c62f..3f91d839ca044b948ab6753f86b9ef0ac00ed9ce 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/V8DOMConfiguration.cpp
@@ -90,15 +90,21 @@ void installAttributeInternal(v8::Isolate* isolate, v8::Local<v8::Object> instan
NOTREACHED();
}
-template<class FunctionOrTemplate>
-v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(v8::Isolate*, v8::FunctionCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature>, int length);
+template <class FunctionOrTemplate>
+v8::Local<FunctionOrTemplate> createAccessorFunctionOrTemplate(v8::Isolate*, v8::FunctionCallback, V8DOMConfiguration::CachedAccessorCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature>, int length);
-template<>
-v8::Local<v8::FunctionTemplate> createAccessorFunctionOrTemplate<v8::FunctionTemplate>(v8::Isolate* isolate, v8::FunctionCallback callback, v8::Local<v8::Value> data, v8::Local<v8::Signature> signature, int length)
+template <>
+v8::Local<v8::FunctionTemplate> createAccessorFunctionOrTemplate<v8::FunctionTemplate>(v8::Isolate* isolate, v8::FunctionCallback callback, V8DOMConfiguration::CachedAccessorCallback cachedAccessorCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature> signature, int length)
{
v8::Local<v8::FunctionTemplate> functionTemplate;
if (callback) {
- functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, signature, length);
+ if (cachedAccessorCallback) {
+ functionTemplate = v8::FunctionTemplate::NewWithCache(isolate, callback,
+ cachedAccessorCallback(isolate), data, signature, length);
+ } else {
+ functionTemplate = v8::FunctionTemplate::New(isolate, callback, data, signature, length);
+ }
+
if (!functionTemplate.IsEmpty()) {
functionTemplate->RemovePrototype();
functionTemplate->SetAcceptAnyReceiver(false);
@@ -107,13 +113,13 @@ v8::Local<v8::FunctionTemplate> createAccessorFunctionOrTemplate<v8::FunctionTem
return functionTemplate;
}
-template<>
-v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>(v8::Isolate* isolate, v8::FunctionCallback callback, v8::Local<v8::Value> data, v8::Local<v8::Signature> signature, int length)
+template <>
+v8::Local<v8::Function> createAccessorFunctionOrTemplate<v8::Function>(v8::Isolate* isolate, v8::FunctionCallback callback, V8DOMConfiguration::CachedAccessorCallback, v8::Local<v8::Value> data, v8::Local<v8::Signature> signature, int length)
{
if (!callback)
return v8::Local<v8::Function>();
- v8::Local<v8::FunctionTemplate> functionTemplate = createAccessorFunctionOrTemplate<v8::FunctionTemplate>(isolate, callback, data, signature, length);
+ v8::Local<v8::FunctionTemplate> functionTemplate = createAccessorFunctionOrTemplate<v8::FunctionTemplate>(isolate, callback, nullptr, data, signature, length);
if (functionTemplate.IsEmpty())
return v8::Local<v8::Function>();
@@ -150,8 +156,8 @@ void installAccessorInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> i
DCHECK(accessor.propertyLocationConfiguration);
if (accessor.propertyLocationConfiguration &
(V8DOMConfiguration::OnInstance | V8DOMConfiguration::OnPrototype)) {
- v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, getterCallback, data, signature, 0);
- v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, setterCallback, data, signature, 1);
+ v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, getterCallback, accessor.cachedAccessorCallback, data, signature, 0);
+ v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, setterCallback, nullptr, data, signature, 1);
if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnInstance)
instanceOrTemplate->SetAccessorProperty(name, getter, setter, static_cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(accessor.settings));
if (accessor.propertyLocationConfiguration & V8DOMConfiguration::OnPrototype)
@@ -161,8 +167,8 @@ void installAccessorInternal(v8::Isolate* isolate, v8::Local<ObjectOrTemplate> i
// Attributes installed on the interface object must be static
// attributes, so no need to specify a signature, i.e. no need to do
// type check against a holder.
- v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, getterCallback, data, v8::Local<v8::Signature>(), 0);
- v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, setterCallback, data, v8::Local<v8::Signature>(), 1);
+ v8::Local<FunctionOrTemplate> getter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, getterCallback, nullptr, data, v8::Local<v8::Signature>(), 0);
+ v8::Local<FunctionOrTemplate> setter = createAccessorFunctionOrTemplate<FunctionOrTemplate>(isolate, setterCallback, nullptr, data, v8::Local<v8::Signature>(), 1);
interfaceOrTemplate->SetAccessorProperty(name, getter, setter, static_cast<v8::PropertyAttribute>(accessor.attribute), static_cast<v8::AccessControl>(accessor.settings));
}
}

Powered by Google App Engine
This is Rietveld 408576698