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

Side by Side 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 unified diff | Download patch
OLDNEW
1 {% filter format_blink_cpp_source_code %} 1 {% filter format_blink_cpp_source_code %}
2 2
3 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable %} 3 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable %}
4 {% include 'copyright_block.txt' %} 4 {% include 'copyright_block.txt' %}
5 #include "{{v8_original_class}}.h" 5 #include "{{v8_original_class}}.h"
6 6
7 {% for filename in cpp_includes if filename != '%s.h' % v8_class %} 7 {% for filename in cpp_includes if filename != '%s.h' % v8_class %}
8 #include "{{filename}}" 8 #include "{{filename}}"
9 {% endfor %} 9 {% endfor %}
10 10
11 namespace blink { 11 namespace blink {
12 12
13 {% if members %}
14 static const v8::Eternal<v8::Name>* eternal{{v8_class}}Keys(v8::Isolate* isolate ) {
15 static const char* const kKeys[] = {
16 {% for member in members %}
17 "{{member.name}}",
18 {% endfor %}
19 };
20 return V8PerIsolateData::from(isolate)->findOrCreateKeys(
21 kKeys, kKeys, WTF_ARRAY_LENGTH(kKeys));
22 }
23 {% endif %}
24
13 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %} 25 {% from 'utilities.cpp.tmpl' import v8_value_to_local_cpp_value %}
14 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{ cpp_class}}& impl, ExceptionState& exceptionState) { 26 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{ cpp_class}}& impl, ExceptionState& exceptionState) {
15 if (isUndefinedOrNull(v8Value)) { 27 if (isUndefinedOrNull(v8Value)) {
16 {% if required_member_names %} 28 {% if required_member_names %}
17 exceptionState.throwTypeError("Missing required member(s): {{required_member _names|join(', ')}}."); 29 exceptionState.throwTypeError("Missing required member(s): {{required_member _names|join(', ')}}.");
18 {% endif %} 30 {% endif %}
19 return; 31 return;
20 } 32 }
21 if (!v8Value->IsObject()) { 33 if (!v8Value->IsObject()) {
22 {% if use_permissive_dictionary_conversion %} 34 {% if use_permissive_dictionary_conversion %}
23 // Do nothing. 35 // Do nothing.
24 return; 36 return;
25 {% else %} 37 {% else %}
26 exceptionState.throwTypeError("cannot convert to dictionary."); 38 exceptionState.throwTypeError("cannot convert to dictionary.");
27 return; 39 return;
28 {% endif %} 40 {% endif %}
29 } 41 }
30 v8::Local<v8::Object> v8Object = v8Value.As<v8::Object>(); 42 v8::Local<v8::Object> v8Object = v8Value.As<v8::Object>();
31 ALLOW_UNUSED_LOCAL(v8Object); 43 ALLOW_UNUSED_LOCAL(v8Object);
32 44
33 {% if parent_v8_class %} 45 {% if parent_v8_class %}
34 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState); 46 {{parent_v8_class}}::toImpl(isolate, v8Value, impl, exceptionState);
35 if (exceptionState.hadException()) 47 if (exceptionState.hadException())
36 return; 48 return;
37 49
38 {% endif %} 50 {% endif %}
39 {# Declare local variables only when the dictionary has members to avoid unuse d variable warnings. #} 51 {# Declare local variables only when the dictionary has members to avoid unuse d variable warnings. #}
40 {% if members %} 52 {% if members %}
53 const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate);
41 v8::TryCatch block(isolate); 54 v8::TryCatch block(isolate);
55 v8::Local<v8::Context> context = isolate->GetCurrentContext();
42 {% endif %} 56 {% endif %}
43 {% for member in members %} 57 {% for member in members %}
44 {% filter runtime_enabled(member.runtime_enabled_feature_name) %} 58 {% filter runtime_enabled(member.runtime_enabled_feature_name) %}
45 v8::Local<v8::Value> {{member.name}}Value; 59 v8::Local<v8::Value> {{member.name}}Value;
46 if (!v8Object->Get(isolate->GetCurrentContext(), v8AtomicString(isolate, "{{me mber.name}}")).ToLocal(&{{member.name}}Value)) { 60 if (!v8Object->Get(context, keys[{{loop.index0}}].Get(isolate)).ToLocal(&{{mem ber.name}}Value)) {
47 exceptionState.rethrowV8Exception(block.Exception()); 61 exceptionState.rethrowV8Exception(block.Exception());
48 return; 62 return;
49 } 63 }
50 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) { 64 if ({{member.name}}Value.IsEmpty() || {{member.name}}Value->IsUndefined()) {
51 {% if member.is_required %} 65 {% if member.is_required %}
52 exceptionState.throwTypeError("required member {{member.name}} is undefined. "); 66 exceptionState.throwTypeError("required member {{member.name}} is undefined. ");
53 return; 67 return;
54 {% else %} 68 {% else %}
55 // Do nothing. 69 // Do nothing.
56 {% endif %} 70 {% endif %}
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return v8::Undefined(isolate); 106 return v8::Undefined(isolate);
93 return v8Object; 107 return v8Object;
94 } 108 }
95 109
96 bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona ry, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) { 110 bool toV8{{cpp_class}}(const {{cpp_class}}& impl, v8::Local<v8::Object> dictiona ry, v8::Local<v8::Object> creationContext, v8::Isolate* isolate) {
97 {% if parent_v8_class %} 111 {% if parent_v8_class %}
98 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate)) 112 if (!toV8{{parent_cpp_class}}(impl, dictionary, creationContext, isolate))
99 return false; 113 return false;
100 114
101 {% endif %} 115 {% endif %}
116 {% if members %}
117 const v8::Eternal<v8::Name>* keys = eternal{{v8_class}}Keys(isolate);
118 v8::Local<v8::Context> context = isolate->GetCurrentContext();
119 {% endif %}
102 {% for member in members %} 120 {% for member in members %}
103 if (impl.{{member.has_method_name}}()) { 121 if (impl.{{member.has_method_name}}()) {
104 {% if member.is_object %} 122 {% if member.is_object %}
105 DCHECK(impl.{{member.getter_name}}().isObject()); 123 DCHECK(impl.{{member.getter_name}}().isObject());
106 {% endif %} 124 {% endif %}
107 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext (), v8AtomicString(isolate, "{{member.name}}"), {{member.cpp_value_to_v8_value}} ))) 125 if (!v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index 0}}].Get(isolate), {{member.cpp_value_to_v8_value}})))
108 return false; 126 return false;
109 {% if member.v8_default_value %} 127 {% if member.v8_default_value %}
110 } else { 128 } else {
111 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext (), v8AtomicString(isolate, "{{member.name}}"), {{member.v8_default_value}}))) 129 if (!v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index 0}}].Get(isolate), {{member.v8_default_value}})))
112 return false; 130 return false;
113 {% elif member.is_nullable %} 131 {% elif member.is_nullable %}
114 } else { 132 } else {
115 if (!v8CallBoolean(dictionary->CreateDataProperty(isolate->GetCurrentContext (), v8AtomicString(isolate, "{{member.name}}"), v8::Null(isolate)))) 133 if (!v8CallBoolean(dictionary->CreateDataProperty(context, keys[{{loop.index 0}}].Get(isolate), v8::Null(isolate))))
116 return false; 134 return false;
117 {% elif member.is_required %} 135 {% elif member.is_required %}
118 } else { 136 } else {
119 NOTREACHED(); 137 NOTREACHED();
120 {% endif %} 138 {% endif %}
121 } 139 }
122 140
123 {% endfor %} 141 {% endfor %}
124 return true; 142 return true;
125 } 143 }
126 144
127 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate , v8::Local<v8::Value> value, ExceptionState& exceptionState) { 145 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate , v8::Local<v8::Value> value, ExceptionState& exceptionState) {
128 {{cpp_class}} impl; 146 {{cpp_class}} impl;
129 {{v8_class}}::toImpl(isolate, value, impl, exceptionState); 147 {{v8_class}}::toImpl(isolate, value, impl, exceptionState);
130 return impl; 148 return impl;
131 } 149 }
132 150
133 } // namespace blink 151 } // namespace blink
134 152
135 {% endfilter %}{# format_blink_cpp_source_code #} 153 {% endfilter %}{# format_blink_cpp_source_code #}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698