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

Unified Diff: third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl

Issue 2751263002: [Bindings] Cache handles for dictionary keys on V8PerIsolateData. (Closed)
Patch Set: const Created 3 years, 9 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/templates/dictionary_v8.cpp.tmpl
diff --git a/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl b/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl
index bf6096e026e0b8dfe7d1f006a56f0b80a2891bb4..903e0a9aa0e02215cb18d478772404e53a8673b2 100644
--- a/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl
+++ b/third_party/WebKit/Source/bindings/templates/dictionary_v8.cpp.tmpl
@@ -10,6 +10,18 @@
namespace blink {
+{% if members %}
+static const v8::Eternal<v8::Name>* eternal{{v8_class}}Keys(v8::Isolate* isolate) {
+ static const char* const kKeys[] = {
+ {% for member in members %}
+ "{{member.name}}",
+ {% endfor %}
+ };
+ return V8PerIsolateData::from(isolate)->findOrCreateKeys(
+ kKeys, kKeys, WTF_ARRAY_LENGTH(kKeys));
+}
+{% endif %}
+
{% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %}
void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{cpp_class}}& impl, ExceptionState& exceptionState) {
if (isUndefinedOrNull(v8Value)) {
@@ -38,12 +50,14 @@ void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{
{% endif %}
{# Declare local variables only when the dictionary has members to avoid unused variable warnings. #}
{% if members %}
+ const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate);
v8::TryCatch block(isolate);
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
{% endif %}
{% for member in members %}
{% filter runtime_enabled(member.runtime_enabled_feature_name) %}
v8::Local<v8::Value> {{member.name}}Value;
- if (!v8Object->Get(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}")).ToLocal(&{{member.name}}Value)) {
+ if (!v8Object->Get(context, keys[{{loop.index0}}].Get(isolate)).ToLocal(&{{member.name}}Value)) {
exceptionState.rethrowV8Exception(block.Exception());
return;
}
@@ -99,20 +113,24 @@ bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona
return false;
{% endif %}
+ {% if members %}
+ const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate);
+ v8::Local<v8::Context> context = isolate->GetCurrentContext();
+ {% endif %}
{% for member in members %}
if (impl.{{member.has_method_name}}()) {
{% if member.is_object %}
DCHECK(impl.{{member.getter_name}}().isObject());
{% endif %}
- if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), {{member.cpp_value_to_v8_value}})))
+ if (!v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index0}}].Get(isolate), {{member.cpp_value_to_v8_value}})))
return false;
{% if member.v8_default_value %}
} else {
- if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), {{member.v8_default_value}})))
+ if (!v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index0}}].Get(isolate), {{member.v8_default_value}})))
return false;
{% elif member.is_nullable %}
} else {
- if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), v8::Null(isolate))))
+ if (!v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index0}}].Get(isolate), v8::Null(isolate))))
return false;
{% elif member.is_required %}
} else {

Powered by Google App Engine
This is Rietveld 408576698