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 9e71c4872edbf64afc3e6003796ee97b835435b9..cad3566b8f85d33da7330d02acd7e53152a698bd 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)->findOrCreateEternalNameCache( |
+ 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,6 +113,10 @@ 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 %} |
v8::Local<v8::Value> {{member.name}}Value; |
bool {{member.name}}HasValueOrDefault = false; |
@@ -126,7 +144,7 @@ bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona |
If there is not, then the compiler will inline this call into the only branch that sets it to true. |
Either way, the code is efficient and the variable is completely elided. #} |
if ({{member.name}}HasValueOrDefault && |
- !v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{member.name}}"), {{member.name}}Value))) { |
+ !v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index0}}].Get(isolate), {{member.name}}Value))) { |
return false; |
} |