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

Side by Side Diff: third_party/WebKit/Source/bindings/templates/attributes.cpp.tmpl

Issue 2446213002: [Bindings] [Reformat] Reformat template files (Closed)
Patch Set: Rebase (Split out Callbackfunctions) Created 4 years, 1 month 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/templates/callback_function.cpp.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %} 1 {% from 'utilities.cpp.tmpl' import declare_enum_validation_variable, v8_value_t o_local_cpp_value %}
2 2
3 {##############################################################################} 3 {##############################################################################}
4 {% macro attribute_getter(attribute, world_suffix) %} 4 {% macro attribute_getter(attribute, world_suffix) %}
5 static void {{attribute.name}}AttributeGetter{{world_suffix}}( 5 static void {{attribute.name}}AttributeGetter{{world_suffix}}(
6 {%- if attribute.is_data_type_property %} 6 {%- if attribute.is_data_type_property %}
7 const v8::PropertyCallbackInfo<v8::Value>& info 7 const v8::PropertyCallbackInfo<v8::Value>& info
8 {%- else %} 8 {%- else %}
9 const v8::FunctionCallbackInfo<v8::Value>& info 9 const v8::FunctionCallbackInfo<v8::Value>& info
10 {%- endif %}) 10 {%- endif %}) {
11 {% filter format_remove_duplicates([ 11 {% filter format_remove_duplicates(['ExceptionState exceptionState']) %}
12 'ExceptionState exceptionState']) %} 12 {% set define_exception_state -%}
13 { 13 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::GetterContext , "{{interface_name}}", "{{attribute.name}}");
14 {% set define_exception_state -%} 14 {%- endset %}
15 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::GetterConte xt, "{{interface_name}}", "{{attribute.name}}");
16 {%- endset %}
17 15
18 {% if attribute.is_lenient_this %} 16 {% if attribute.is_lenient_this %}
19 // [LenientThis] 17 // [LenientThis]
20 // Make sure that info.Holder() really points to an instance if [LenientThis ]. 18 // Make sure that info.Holder() really points to an instance if [LenientThis].
21 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) 19 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate()))
22 return; // Return silently because of [LenientThis]. 20 return; // Return silently because of [LenientThis].
23 {% endif %} 21 {% endif %}
24 22
25 {% if not attribute.is_static %} 23 {% if not attribute.is_static %}
26 v8::Local<v8::Object> holder = info.Holder(); 24 v8::Local<v8::Object> holder = info.Holder();
27 {% endif %} 25 {% endif %}
28 26
29 {% if attribute.is_save_same_object %} 27 {% if attribute.is_save_same_object %}
30 // [SaveSameObject] 28 // [SaveSameObject]
31 {% set same_object_private_key = interface_name + attribute.name[0]|capitali ze + attribute.name[1:] %} 29 {% set same_object_private_key = interface_name + attribute.name[0]|capitalize + attribute.name[1:] %}
32 // If you see a compile error that 30 // If you see a compile error that
33 // V8PrivateProperty::getSameObject{{same_object_private_key}} 31 // V8PrivateProperty::getSameObject{{same_object_private_key}}
34 // is not defined, then you need to register your attribute at 32 // is not defined, then you need to register your attribute at
35 // V8_PRIVATE_PROPERTY_FOR_EACH defined in V8PrivateProperty.h as 33 // V8_PRIVATE_PROPERTY_FOR_EACH defined in V8PrivateProperty.h as
36 // X(SameObject, {{same_object_private_key}}) 34 // X(SameObject, {{same_object_private_key}})
37 auto privateSameObject = V8PrivateProperty::getSameObject{{same_object_priva te_key}}(info.GetIsolate()); 35 auto privateSameObject = V8PrivateProperty::getSameObject{{same_object_private _key}}(info.GetIsolate());
38 { 36 {
39 v8::Local<v8::Value> v8Value = privateSameObject.get(info.GetIsolate()-> GetCurrentContext(), holder); 37 v8::Local<v8::Value> v8Value = privateSameObject.get(info.GetIsolate()->GetC urrentContext(), holder);
40 if (!v8Value.IsEmpty()) { 38 if (!v8Value.IsEmpty()) {
41 v8SetReturnValue(info, v8Value); 39 v8SetReturnValue(info, v8Value);
42 return; 40 return;
43 }
44 } 41 }
45 {% endif %} 42 }
43 {% endif %}
46 44
47 {% if not attribute.is_static %} 45 {% if not attribute.is_static %}
48 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 46 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
49 {% endif %} 47 {% endif %}
50 48
51 {% if attribute.cached_attribute_validation_method %} 49 {% if attribute.cached_attribute_validation_method %}
52 // [CachedAttribute] 50 // [CachedAttribute]
53 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}"); 51 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{attr ibute.name}}");
54 if (!impl->{{attribute.cached_attribute_validation_method}}()) { 52 if (!impl->{{attribute.cached_attribute_validation_method}}()) {
55 v8::Local<v8::Value> v8Value = V8HiddenValue::getHiddenValue(ScriptState ::forFunctionObject(info), holder, propertyName); 53 v8::Local<v8::Value> v8Value = V8HiddenValue::getHiddenValue(ScriptState::fo rFunctionObject(info), holder, propertyName);
56 if (!v8Value.IsEmpty() && !v8Value->IsUndefined()) { 54 if (!v8Value.IsEmpty() && !v8Value->IsUndefined()) {
57 v8SetReturnValue(info, v8Value); 55 v8SetReturnValue(info, v8Value);
58 return; 56 return;
59 }
60 } 57 }
61 {% endif %} 58 }
59 {% endif %}
62 60
63 {% if attribute.is_check_security_for_receiver and 61 {% if attribute.is_check_security_for_receiver and not attribute.is_data_type_ property %}
64 not attribute.is_data_type_property %} 62 // Perform a security check for the receiver object.
65 // Perform a security check for the receiver object. 63 {{define_exception_state}}
66 {{define_exception_state}} 64 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, exceptionState)) {
67 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), impl, exceptionState)) { 65 v8SetReturnValueNull(info);
68 v8SetReturnValueNull(info); 66 return;
69 return; 67 }
70 } 68 {% endif %}
71 {% endif %}
72 69
73 {% if attribute.is_check_security_for_return_value %} 70 {% if attribute.is_check_security_for_return_value %}
74 // Perform a security check for the returned object. 71 // Perform a security check for the returned object.
75 {{define_exception_state}} 72 {{define_exception_state}}
76 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), {{attribute.cpp_value}}, exceptionState)) { 73 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), {{attribute.cpp_value}}, exceptionState)) {
77 v8SetReturnValueNull(info); 74 v8SetReturnValueNull(info);
78 return; 75 return;
79 } 76 }
80 {% endif %} 77 {% endif %}
81 78
82 {% if attribute.is_call_with_execution_context %} 79 {% if attribute.is_call_with_execution_context %}
83 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate ()); 80 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate() );
84 {% endif %} 81 {% endif %}
85 {% if attribute.is_call_with_script_state %} 82 {% if attribute.is_call_with_script_state %}
86 {% if attribute.is_static %} 83 {% if attribute.is_static %}
87 ScriptState* scriptState = ScriptState::forFunctionObject(info); 84 ScriptState* scriptState = ScriptState::forFunctionObject(info);
88 {% else %} 85 {% else %}
89 ScriptState* scriptState = ScriptState::forReceiverObject(info); 86 ScriptState* scriptState = ScriptState::forReceiverObject(info);
90 {% endif %} 87 {% endif %}
91 {% endif %} 88 {% endif %}
92 {% if attribute.is_getter_raises_exception %} 89 {% if attribute.is_getter_raises_exception %}
93 {{define_exception_state}} 90 {{define_exception_state}}
94 {% endif %} 91 {% endif %}
95 {% if attribute.is_explicit_nullable %} 92 {% if attribute.is_explicit_nullable %}
96 bool isNull = false; 93 bool isNull = false;
97 {% endif %} 94 {% endif %}
98 95
99 {% if attribute.is_implemented_in_private_script %} 96 {% if attribute.is_implemented_in_private_script %}
100 {{attribute.cpp_type}} result{{attribute.cpp_type_initializer}}; 97 {{attribute.cpp_type}} result{{attribute.cpp_type_initializer}};
101 if (!{{attribute.cpp_value_original}}) 98 if (!{{attribute.cpp_value_original}})
102 return; 99 return;
103 {% elif attribute.cpp_value_original %} 100 {% elif attribute.cpp_value_original %}
104 {{attribute.cpp_type}} {{attribute.cpp_value}}({{attribute.cpp_value_origina l}}); 101 {{attribute.cpp_type}} {{attribute.cpp_value}}({{attribute.cpp_value_original} });
105 {% endif %} 102 {% endif %}
106 103
107 {% if attribute.use_output_parameter_for_result %} 104 {% if attribute.use_output_parameter_for_result %}
108 {{attribute.cpp_type}} result; 105 {{attribute.cpp_type}} result;
109 {{attribute.cpp_value}}; 106 {{attribute.cpp_value}};
110 {% endif %} 107 {% endif %}
111 108
112 {% if attribute.is_getter_raises_exception %} 109 {% if attribute.is_getter_raises_exception %}
113 if (UNLIKELY(exceptionState.hadException())) 110 if (UNLIKELY(exceptionState.hadException()))
114 return; 111 return;
115 {% endif %} 112 {% endif %}
116 113
117 {% if attribute.reflect_only %} 114 {% if attribute.reflect_only %}
118 {{release_only_check(attribute.reflect_only, attribute.reflect_missing, 115 {{release_only_check(attribute.reflect_only, attribute.reflect_missing,
119 attribute.reflect_invalid, attribute.reflect_empty, 116 attribute.reflect_invalid, attribute.reflect_empty,
120 attribute.cpp_value) 117 attribute.cpp_value)
121 | indent}} 118 | indent(2)}}
122 {% endif %} 119 {% endif %}
123 120
124 {% if attribute.cached_attribute_validation_method %} 121 {% if attribute.cached_attribute_validation_method %}
125 // [CachedAttribute] 122 // [CachedAttribute]
126 v8::Local<v8::Value> v8Value({{attribute.cpp_value_to_v8_value}}); 123 v8::Local<v8::Value> v8Value({{attribute.cpp_value_to_v8_value}});
127 V8HiddenValue::setHiddenValue(ScriptState::forFunctionObject(info), holder, propertyName, v8Value); 124 V8HiddenValue::setHiddenValue(ScriptState::forFunctionObject(info), holder, pr opertyName, v8Value);
128 {% endif %} 125 {% endif %}
129 126
130 {% if attribute.is_explicit_nullable %} 127 {% if attribute.is_explicit_nullable %}
131 if (isNull) { 128 if (isNull) {
132 v8SetReturnValueNull(info); 129 v8SetReturnValueNull(info);
133 return; 130 return;
134 } 131 }
135 {% endif %} 132 {% endif %}
136 133
137 {% if attribute.is_keep_alive_for_gc %} 134 {% if attribute.is_keep_alive_for_gc %}
138 // Keep the wrapper object for the return value alive as long as |this| 135 // Keep the wrapper object for the return value alive as long as |this|
139 // object is alive in order to save creation time of the wrapper object. 136 // object is alive in order to save creation time of the wrapper object.
140 if ({{attribute.cpp_value}} && DOMDataStore::setReturnValue{{world_suffix}}( info.GetReturnValue(), {{attribute.cpp_value}})) 137 if ({{attribute.cpp_value}} && DOMDataStore::setReturnValue{{world_suffix}}(in fo.GetReturnValue(), {{attribute.cpp_value}}))
141 return; 138 return;
142 v8::Local<v8::Value> v8Value(toV8({{attribute.cpp_value}}, holder, info.GetI solate())); 139 v8::Local<v8::Value> v8Value(toV8({{attribute.cpp_value}}, holder, info.GetIso late()));
143 const char kKeepAliveKey[] = "KeepAlive#{{interface_name}}#{{attribute.name} }"; 140 const char kKeepAliveKey[] = "KeepAlive#{{interface_name}}#{{attribute.name}}" ;
144 V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), holde r, v8AtomicString(info.GetIsolate(), StringView(kKeepAliveKey, sizeof kKeepAlive Key)), v8Value); 141 V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), holder, v8AtomicString(info.GetIsolate(), StringView(kKeepAliveKey, sizeof kKeepAliveKe y)), v8Value);
145 {% endif %} 142 {% endif %}
146 143
147 {% if world_suffix %} 144 {% if world_suffix %}
148 {{attribute.v8_set_return_value_for_main_world}}; 145 {{attribute.v8_set_return_value_for_main_world}};
149 {% else %} 146 {% else %}
150 {{attribute.v8_set_return_value}}; 147 {{attribute.v8_set_return_value}};
151 {% endif %} 148 {% endif %}
152 149
153 {% if attribute.is_save_same_object %} 150 {% if attribute.is_save_same_object %}
154 // [SaveSameObject] 151 // [SaveSameObject]
155 privateSameObject.set(info.GetIsolate()->GetCurrentContext(), holder, info.G etReturnValue().Get()); 152 privateSameObject.set(info.GetIsolate()->GetCurrentContext(), holder, info.Get ReturnValue().Get());
156 {% endif %} 153 {% endif %}
154 {% endfilter %}{# format_remove_duplicates #}
157 } 155 }
158 {% endfilter %}{# format_remove_duplicates #}
159 {% endmacro %} 156 {% endmacro %}
160 157
161 158
162 {######################################} 159 {######################################}
163 {% macro release_only_check(reflect_only_values, reflect_missing, 160 {% macro release_only_check(reflect_only_values, reflect_missing,
164 reflect_invalid, reflect_empty, cpp_value) %} 161 reflect_invalid, reflect_empty, cpp_value) %}
165 {# Attribute is limited to only known values: check that the attribute value is 162 {# Attribute is limited to only known values: check that the attribute value is
166 one of those. If not, set it to the empty string. 163 one of those. If not, set it to the empty string.
167 http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known-valu es #} 164 http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known-valu es #}
168 {% if reflect_empty %} 165 {% if reflect_empty %}
169 if ({{cpp_value}}.isNull()) { 166 if ({{cpp_value}}.isNull()) {
170 {% if reflect_missing %} 167 {% if reflect_missing %}
171 {{cpp_value}} = "{{reflect_missing}}"; 168 {{cpp_value}} = "{{reflect_missing}}";
172 {% else %} 169 {% else %}
173 ; 170 ;
174 {% endif %} 171 {% endif %}
175 } else if ({{cpp_value}}.isEmpty()) { 172 } else if ({{cpp_value}}.isEmpty()) {
176 {{cpp_value}} = "{{reflect_empty}}"; 173 {{cpp_value}} = "{{reflect_empty}}";
177 {% else %} 174 {% else %}
178 if ({{cpp_value}}.isEmpty()) { 175 if ({{cpp_value}}.isEmpty()) {
179 {# FIXME: should use [ReflectEmpty] instead; need to change IDL files #} 176 {# FIXME: should use [ReflectEmpty] instead; need to change IDL files #}
180 {% if reflect_missing %} 177 {% if reflect_missing %}
181 {{cpp_value}} = "{{reflect_missing}}"; 178 {{cpp_value}} = "{{reflect_missing}}";
182 {% else %} 179 {% else %}
183 ; 180 ;
184 {% endif %} 181 {% endif %}
185 {% endif %} 182 {% endif %}
186 {% for value in reflect_only_values %} 183 {% for value in reflect_only_values %}
187 } else if (equalIgnoringASCIICase({{cpp_value}}, "{{value}}")) { 184 } else if (equalIgnoringASCIICase({{cpp_value}}, "{{value}}")) {
188 {{cpp_value}} = "{{value}}"; 185 {{cpp_value}} = "{{value}}";
189 {% endfor %} 186 {% endfor %}
190 } else { 187 } else {
191 {{cpp_value}} = "{{reflect_invalid}}"; 188 {{cpp_value}} = "{{reflect_invalid}}";
192 } 189 }
193 {% endmacro %} 190 {% endmacro %}
194 191
195 192
196 {##############################################################################} 193 {##############################################################################}
197 {% macro attribute_getter_callback(attribute, world_suffix) %} 194 {% macro attribute_getter_callback(attribute, world_suffix) %}
198 void {{attribute.name}}AttributeGetterCallback{{world_suffix}}( 195 void {{attribute.name}}AttributeGetterCallback{{world_suffix}}(
199 {%- if attribute.is_data_type_property %} 196 {%- if attribute.is_data_type_property %}
200 v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info 197 v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info
201 {%- else %} 198 {%- else %}
202 const v8::FunctionCallbackInfo<v8::Value>& info 199 const v8::FunctionCallbackInfo<v8::Value>& info
203 {%- endif %}) 200 {%- endif %}) {
204 { 201 {% if attribute.deprecate_as %}
205 {% if attribute.deprecate_as %} 202 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentExec utionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
206 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx ecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}}); 203 {% endif %}
207 {% endif %}
208 204
209 {% if attribute.measure_as %} 205 {% if attribute.measure_as %}
210 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte xt(info.GetIsolate()), UseCounter::{{attribute.measure_as('AttributeGetter')}}); 206 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionContext (info.GetIsolate()), UseCounter::{{attribute.measure_as('AttributeGetter')}});
211 {% endif %} 207 {% endif %}
212 208
213 {% if world_suffix in attribute.activity_logging_world_list_for_getter %} 209 {% if world_suffix in attribute.activity_logging_world_list_for_getter %}
214 {% if attribute.is_static %} 210 {% if attribute.is_static %}
215 ScriptState* scriptState = ScriptState::forFunctionObject(info); 211 ScriptState* scriptState = ScriptState::forFunctionObject(info);
216 {% else %} 212 {% else %}
217 ScriptState* scriptState = ScriptState::forReceiverObject(info); 213 ScriptState* scriptState = ScriptState::forReceiverObject(info);
218 {% endif %} 214 {% endif %}
219 V8PerContextData* contextData = scriptState->perContextData(); 215 V8PerContextData* contextData = scriptState->perContextData();
220 if ( 216 if (
221 {%- if attribute.activity_logging_world_check -%} 217 {%- if attribute.activity_logging_world_check -%}
222 scriptState->world().isIsolatedWorld() && {# one space at the end #} 218 scriptState->world().isIsolatedWorld() && {# one space at the end #}
223 {%- endif -%} 219 {%- endif -%}
224 contextData && contextData->activityLogger()) { 220 contextData && contextData->activityLogger()) {
225 contextData->activityLogger()->logGetter("{{interface_name}}.{{attribute .name}}"); 221 contextData->activityLogger()->logGetter("{{interface_name}}.{{attribute.nam e}}");
226 } 222 }
227 {% endif %} 223 {% endif %}
228 224
229 {% if attribute.has_custom_getter %} 225 {% if attribute.has_custom_getter %}
230 {{v8_class}}::{{attribute.name}}AttributeGetterCustom(info); 226 {{v8_class}}::{{attribute.name}}AttributeGetterCustom(info);
231 {% else %} 227 {% else %}
232 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeGetter{{world _suffix}}(info); 228 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeGetter{{world_s uffix}}(info);
233 {% endif %} 229 {% endif %}
234 } 230 }
235 {% endmacro %} 231 {% endmacro %}
236 232
237 233
238 {##############################################################################} 234 {##############################################################################}
239 {% macro constructor_getter_callback(attribute, world_suffix) %} 235 {% macro constructor_getter_callback(attribute, world_suffix) %}
240 void {{attribute.name}}ConstructorGetterCallback{{world_suffix}}(v8::Local<v8::N ame> property, const v8::PropertyCallbackInfo<v8::Value>& info) 236 void {{attribute.name}}ConstructorGetterCallback{{world_suffix}}(v8::Local<v8::N ame> property, const v8::PropertyCallbackInfo<v8::Value>& info) {
241 { 237 {% if attribute.deprecate_as %}
242 {% if attribute.deprecate_as %} 238 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentExec utionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
243 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx ecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}}); 239 {% endif %}
244 {% endif %}
245 240
246 {% if attribute.measure_as %} 241 {% if attribute.measure_as %}
247 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte xt(info.GetIsolate()), UseCounter::{{attribute.measure_as('ConstructorGetter')}} ); 242 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionContext (info.GetIsolate()), UseCounter::{{attribute.measure_as('ConstructorGetter')}});
248 {% endif %} 243 {% endif %}
249 244
250 v8ConstructorAttributeGetter(property, info); 245 v8ConstructorAttributeGetter(property, info);
251 } 246 }
252 {% endmacro %} 247 {% endmacro %}
253 248
254 249
255 {##############################################################################} 250 {##############################################################################}
256 {% macro attribute_setter(attribute, world_suffix) %} 251 {% macro attribute_setter(attribute, world_suffix) %}
257 static void {{attribute.name}}AttributeSetter{{world_suffix}}( 252 static void {{attribute.name}}AttributeSetter{{world_suffix}}(
258 {%- if attribute.is_data_type_property %} 253 {%- if attribute.is_data_type_property %}
259 v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info 254 v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInfo<void>& info
260 {%- else %} 255 {%- else %}
261 v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info 256 v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info
262 {%- endif %}) 257 {%- endif %}) {
263 {% filter format_remove_duplicates([ 258 {% filter format_remove_duplicates(['ExceptionState exceptionState']) %}
264 'ExceptionState exceptionState']) %} 259 {% set define_exception_state -%}
265 { 260 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::SetterContext , "{{interface_name}}", "{{attribute.name}}");
266 {% set define_exception_state -%} 261 {%- endset %}
267 ExceptionState exceptionState(info.GetIsolate(), ExceptionState::SetterConte xt, "{{interface_name}}", "{{attribute.name}}");
268 {%- endset %}
269 262
270 {% if attribute.is_lenient_this %} 263 {% if attribute.is_lenient_this %}
271 // [LenientThis] 264 // [LenientThis]
272 // Make sure that info.Holder() really points to an instance if [LenientThis ]. 265 // Make sure that info.Holder() really points to an instance if [LenientThis].
273 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate())) 266 if (!{{v8_class}}::hasInstance(info.Holder(), info.GetIsolate()))
274 return; // Return silently because of [LenientThis]. 267 return; // Return silently because of [LenientThis].
275 {% endif %} 268 {% endif %}
276 269
277 {% if not attribute.is_static and 270 {% if not attribute.is_static and not attribute.is_replaceable %}
278 not attribute.is_replaceable %} 271 v8::Local<v8::Object> holder = info.Holder();
279 v8::Local<v8::Object> holder = info.Holder(); 272 {% if attribute.is_put_forwards %}
280 {% if attribute.is_put_forwards %} 273 {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder);
281 {{cpp_class}}* proxyImpl = {{v8_class}}::toImpl(holder); 274 {{attribute.cpp_type}} impl = WTF::getPtr(proxyImpl->{{attribute.name}}());
282 {{attribute.cpp_type}} impl = WTF::getPtr(proxyImpl->{{attribute.name}}()); 275 if (!impl)
283 if (!impl) 276 return;
284 return; 277 {% else %}
285 {% else %} 278 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder);
286 {{cpp_class}}* impl = {{v8_class}}::toImpl(holder); 279 {% endif %}
287 {% endif %} 280 {% endif %}
288 {% endif %}
289 281
290 {% if attribute.is_check_security_for_receiver and 282 {% if attribute.is_check_security_for_receiver and not attribute.is_data_type_ property %}
291 not attribute.is_data_type_property %} 283 // Perform a security check for the receiver object.
292 // Perform a security check for the receiver object. 284 {{define_exception_state}}
293 {{define_exception_state}} 285 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate()), impl, exceptionState)) {
294 if (!BindingSecurity::shouldAllowAccessTo(currentDOMWindow(info.GetIsolate() ), impl, exceptionState)) { 286 v8SetReturnValue(info, v8Value);
295 v8SetReturnValue(info, v8Value); 287 return;
296 return; 288 }
297 } 289 {% endif %}
298 {% endif %}
299 290
300 {% if attribute.is_check_security_for_return_value %} 291 {% if attribute.is_check_security_for_return_value %}
301 #error Attribute setter with the security check for the return value is not supp orted. Since the return value is the given value to be set, it\'s meaningless t o perform the security check for the return value. 292 #error Attribute setter with the security check for the return value is not supp orted. Since the return value is the given value to be set, it\'s meaningless t o perform the security check for the return value.
302 {% endif %} 293 {% endif %}
303 294
304 {% if attribute.is_custom_element_callbacks or 295 {% if attribute.is_custom_element_callbacks or
305 (attribute.is_reflect and 296 (attribute.is_reflect and not (attribute.idl_type == 'DOMString' and is_ node)) %}
306 not (attribute.idl_type == 'DOMString' and is_node)) %} 297 // Skip on compact node DOMString getters.
307 // Skip on compact node DOMString getters. 298 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
308 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 299 {% endif %}
309 {% endif %}
310 300
311 {% if attribute.has_setter_exception_state %} 301 {% if attribute.has_setter_exception_state %}
312 {{define_exception_state}} 302 {{define_exception_state}}
313 {% endif %} 303 {% endif %}
314 304
315 // Prepare the value to be set. 305 // Prepare the value to be set.
316 {% if attribute.idl_type == 'EventHandler' %} 306 {% if attribute.idl_type == 'EventHandler' %}
317 {% if not is_node %} 307 {% if not is_node %}
318 moveEventListenerToNewWrapper(info.GetIsolate(), holder, {{attribute.event_h andler_getter_expression}}, v8Value, {{v8_class}}::eventListenerCacheIndex); 308 moveEventListenerToNewWrapper(info.GetIsolate(), holder, {{attribute.event_han dler_getter_expression}}, v8Value, {{v8_class}}::eventListenerCacheIndex);
319 {% endif %} 309 {% endif %}
320 {% else %}{# not EventHandler #} 310 {% else %}{# not EventHandler #}
321 {{v8_value_to_local_cpp_value(attribute) | indent}} 311 {{v8_value_to_local_cpp_value(attribute) | indent(2)}}
322 {% endif %} 312 {% endif %}
323 313
324 {% if attribute.has_type_checking_interface %} 314 {% if attribute.has_type_checking_interface %}
325 // Type check per: http://heycam.github.io/webidl/#es-interface 315 // Type check per: http://heycam.github.io/webidl/#es-interface
326 if (!cppValue{% if attribute.is_nullable %} && !isUndefinedOrNull(v8Value){% endif %}) { 316 if (!cppValue{% if attribute.is_nullable %} && !isUndefinedOrNull(v8Value){% e ndif %}) {
327 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); 317 exceptionState.throwTypeError("The provided value is not of type '{{attribut e.idl_type}}'.");
328 return; 318 return;
329 } 319 }
330 {% endif %} 320 {% endif %}
331 321
332 {% if attribute.enum_values %} 322 {% if attribute.enum_values %}
333 // Type check per: http://heycam.github.io/webidl/#dfn-attribute-setter 323 // Type check per: http://heycam.github.io/webidl/#dfn-attribute-setter
334 // Returns undefined without setting the value if the value is invalid. 324 // Returns undefined without setting the value if the value is invalid.
335 TrackExceptionState trackExceptionState; 325 TrackExceptionState trackExceptionState;
336 {{declare_enum_validation_variable(attribute.enum_values) | indent}} 326 {{declare_enum_validation_variable(attribute.enum_values) | indent(2)}}
337 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "{{at tribute.enum_type}}", trackExceptionState)) { 327 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "{{attr ibute.enum_type}}", trackExceptionState)) {
338 currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMes sage::create(JSMessageSource, WarningMessageLevel, trackExceptionState.message() )); 328 currentExecutionContext(info.GetIsolate())->addConsoleMessage(ConsoleMessage ::create(JSMessageSource, WarningMessageLevel, trackExceptionState.message()));
339 return; 329 return;
340 } 330 }
341 {% endif %} 331 {% endif %}
342 332
343 {% if attribute.is_call_with_execution_context or 333 {% if attribute.is_call_with_execution_context or attribute.is_setter_call_wit h_execution_context %}
344 attribute.is_setter_call_with_execution_context %} 334 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate() );
345 ExecutionContext* executionContext = currentExecutionContext(info.GetIsolate ()); 335 {% endif %}
346 {% endif %}
347 336
348 {% if attribute.is_call_with_script_state %} 337 {% if attribute.is_call_with_script_state %}
349 {% if attribute.is_static %} 338 {% if attribute.is_static %}
350 ScriptState* scriptState = ScriptState::forFunctionObject(info); 339 ScriptState* scriptState = ScriptState::forFunctionObject(info);
351 {% else %} 340 {% else %}
352 ScriptState* scriptState = ScriptState::forReceiverObject(info); 341 ScriptState* scriptState = ScriptState::forReceiverObject(info);
353 {% endif %} 342 {% endif %}
354 {% endif %} 343 {% endif %}
355 344
356 {% if attribute.is_replaceable %} 345 {% if attribute.is_replaceable %}
357 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{at tribute.name}}"); 346 v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{attr ibute.name}}");
358 {% endif %} 347 {% endif %}
359 {{attribute.cpp_setter}}; 348 {{attribute.cpp_setter}};
360 349
361 {% if attribute.cached_attribute_validation_method %} 350 {% if attribute.cached_attribute_validation_method %}
362 // [CachedAttribute] 351 // [CachedAttribute]
363 // Invalidate the cached value. 352 // Invalidate the cached value.
364 V8HiddenValue::deleteHiddenValue(ScriptState::forFunctionObject(info), holde r, v8AtomicString(info.GetIsolate(), "{{attribute.name}}")); 353 V8HiddenValue::deleteHiddenValue(ScriptState::forFunctionObject(info), holder, v8AtomicString(info.GetIsolate(), "{{attribute.name}}"));
365 {% endif %} 354 {% endif %}
366 } 355 }
367 {% endfilter %}{# format_remove_duplicates #} 356 {% endfilter %}{# format_remove_duplicates #}
368 {% endmacro %} 357 {% endmacro %}
369 358
370 359
371 {##############################################################################} 360 {##############################################################################}
372 {% macro attribute_setter_callback(attribute, world_suffix) %} 361 {% macro attribute_setter_callback(attribute, world_suffix) %}
373 void {{attribute.name}}AttributeSetterCallback{{world_suffix}}( 362 void {{attribute.name}}AttributeSetterCallback{{world_suffix}}(
374 {%- if attribute.is_data_type_property %} 363 {%- if attribute.is_data_type_property %}
375 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf o<void>& info 364 v8::Local<v8::Name>, v8::Local<v8::Value> v8Value, const v8::PropertyCallbackInf o<void>& info
376 {%- else %} 365 {%- else %}
377 const v8::FunctionCallbackInfo<v8::Value>& info 366 const v8::FunctionCallbackInfo<v8::Value>& info
378 {%- endif %}) 367 {%- endif %}) {
379 { 368 {% if not attribute.is_data_type_property %}
380 {% if not attribute.is_data_type_property %} 369 v8::Local<v8::Value> v8Value = info[0];
381 v8::Local<v8::Value> v8Value = info[0]; 370 {% endif %}
382 {% endif %}
383 371
384 {% if attribute.deprecate_as %} 372 {% if attribute.deprecate_as %}
385 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentEx ecutionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}}); 373 Deprecation::countDeprecationIfNotPrivateScript(info.GetIsolate(), currentExec utionContext(info.GetIsolate()), UseCounter::{{attribute.deprecate_as}});
386 {% endif %} 374 {% endif %}
387 375
388 {% if attribute.measure_as %} 376 {% if attribute.measure_as %}
389 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionConte xt(info.GetIsolate()), UseCounter::{{attribute.measure_as('AttributeSetter')}}); 377 UseCounter::countIfNotPrivateScript(info.GetIsolate(), currentExecutionContext (info.GetIsolate()), UseCounter::{{attribute.measure_as('AttributeSetter')}});
390 {% endif %} 378 {% endif %}
391 379
392 {% if world_suffix in attribute.activity_logging_world_list_for_setter %} 380 {% if world_suffix in attribute.activity_logging_world_list_for_setter %}
393 {% if attribute.is_static %} 381 {% if attribute.is_static %}
394 ScriptState* scriptState = ScriptState::forFunctionObject(info); 382 ScriptState* scriptState = ScriptState::forFunctionObject(info);
395 {% else %} 383 {% else %}
396 ScriptState* scriptState = ScriptState::forReceiverObject(info); 384 ScriptState* scriptState = ScriptState::forReceiverObject(info);
397 {% endif %} 385 {% endif %}
398 V8PerContextData* contextData = scriptState->perContextData(); 386 V8PerContextData* contextData = scriptState->perContextData();
399 if ( 387 if (
400 {%- if attribute.activity_logging_world_check -%} 388 {%- if attribute.activity_logging_world_check -%}
401 scriptState->world().isIsolatedWorld() && {# one space at the end #} 389 scriptState->world().isIsolatedWorld() && {# one space at the end #}
402 {%- endif -%} 390 {%- endif -%}
403 contextData && contextData->activityLogger()) { 391 contextData && contextData->activityLogger()) {
404 contextData->activityLogger()->logSetter("{{interface_name}}.{{attribute .name}}", v8Value); 392 contextData->activityLogger()->logSetter("{{interface_name}}.{{attribute.nam e}}", v8Value);
405 } 393 }
406 {% endif %} 394 {% endif %}
407 395
408 {% if attribute.is_ce_reactions %} 396 {% if attribute.is_ce_reactions %}
409 CEReactionsScope ceReactionsScope; 397 CEReactionsScope ceReactionsScope;
410 {% endif %} 398 {% endif %}
411 399
412 {% if attribute.is_custom_element_callbacks or attribute.is_reflect %} 400 {% if attribute.is_custom_element_callbacks or attribute.is_reflect %}
413 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope; 401 V0CustomElementProcessingStack::CallbackDeliveryScope deliveryScope;
414 {% endif %} 402 {% endif %}
415 403
416 {% if attribute.has_custom_setter %} 404 {% if attribute.has_custom_setter %}
417 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(v8Value, info); 405 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(v8Value, info);
418 {% else %} 406 {% else %}
419 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter{{world _suffix}}(v8Value, info); 407 {{cpp_class_or_partial}}V8Internal::{{attribute.name}}AttributeSetter{{world_s uffix}}(v8Value, info);
420 {% endif %} 408 {% endif %}
421 } 409 }
422 {% endmacro %} 410 {% endmacro %}
423 411
424 412
425 {##############################################################################} 413 {##############################################################################}
426 {% macro attribute_getter_implemented_in_private_script(attribute) %} 414 {% macro attribute_getter_implemented_in_private_script(attribute) %}
427 bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.cpp_type}}* result) 415 bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeGetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.cpp_type}}* result) {
428 { 416 if (!frame)
429 if (!frame) 417 return false;
430 return false; 418 v8::HandleScope handleScope(toIsolate(frame));
431 v8::HandleScope handleScope(toIsolate(frame)); 419 ScriptForbiddenScope::AllowUserAgentScript script;
432 ScriptForbiddenScope::AllowUserAgentScript script; 420 ScriptState* scriptState = ScriptState::forWorld(frame, DOMWrapperWorld::priva teScriptIsolatedWorld());
433 ScriptState* scriptState = ScriptState::forWorld(frame, DOMWrapperWorld::pri vateScriptIsolatedWorld()); 421 if (!scriptState)
434 if (!scriptState) 422 return false;
435 return false; 423 ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
436 ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame); 424 if (!scriptStateInUserScript)
437 if (!scriptStateInUserScript) 425 return false;
438 return false;
439 426
440 ScriptState::Scope scope(scriptState); 427 ScriptState::Scope scope(scriptState);
441 v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Globa l(), scriptState->isolate()); 428 v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global( ), scriptState->isolate());
442 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate() ); 429 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.name }}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
443 v8::Local<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(sc riptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holde r); 430 v8::Local<v8::Value> v8Value = PrivateScriptRunner::runDOMAttributeGetter(scri ptState, scriptStateInUserScript, "{{cpp_class}}", "{{attribute.name}}", holder) ;
444 if (v8Value.IsEmpty()) 431 if (v8Value.IsEmpty())
445 return false; 432 return false;
446 {{v8_value_to_local_cpp_value(attribute.private_script_v8_value_to_local_cpp _value) | indent}} 433 {{v8_value_to_local_cpp_value(attribute.private_script_v8_value_to_local_cpp_v alue) | indent(2)}}
447 RELEASE_ASSERT(!exceptionState.hadException()); 434 CHECK(!exceptionState.hadException());
448 *result = cppValue; 435 *result = cppValue;
449 return true; 436 return true;
450 } 437 }
451 {% endmacro %} 438 {% endmacro %}
452 439
453 440
454 {% macro attribute_setter_implemented_in_private_script(attribute) %} 441 {% macro attribute_setter_implemented_in_private_script(attribute) %}
455 bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.argument_cpp_type}} cppValue) 442 bool {{v8_class}}::PrivateScript::{{attribute.name}}AttributeSetter(LocalFrame* frame, {{cpp_class}}* holderImpl, {{attribute.argument_cpp_type}} cppValue) {
456 { 443 if (!frame)
457 if (!frame) 444 return false;
458 return false; 445 v8::HandleScope handleScope(toIsolate(frame));
459 v8::HandleScope handleScope(toIsolate(frame)); 446 ScriptForbiddenScope::AllowUserAgentScript script;
460 ScriptForbiddenScope::AllowUserAgentScript script; 447 ScriptState* scriptState = ScriptState::forWorld(frame, DOMWrapperWorld::priva teScriptIsolatedWorld());
461 ScriptState* scriptState = ScriptState::forWorld(frame, DOMWrapperWorld::pri vateScriptIsolatedWorld()); 448 if (!scriptState)
462 if (!scriptState) 449 return false;
463 return false; 450 ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame);
464 ScriptState* scriptStateInUserScript = ScriptState::forMainWorld(frame); 451 if (!scriptStateInUserScript)
465 if (!scriptStateInUserScript) 452 return false;
466 return false;
467 453
468 ScriptState::Scope scope(scriptState); 454 ScriptState::Scope scope(scriptState);
469 v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Globa l(), scriptState->isolate()); 455 v8::Local<v8::Value> holder = toV8(holderImpl, scriptState->context()->Global( ), scriptState->isolate());
470 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate() ); 456 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.name }}", "{{cpp_class}}", scriptState->context()->Global(), scriptState->isolate());
471 return PrivateScriptRunner::runDOMAttributeSetter(scriptState, scriptStateIn UserScript, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_s cript_cpp_value_to_v8_value}}); 457 return PrivateScriptRunner::runDOMAttributeSetter(scriptState, scriptStateInUs erScript, "{{cpp_class}}", "{{attribute.name}}", holder, {{attribute.private_scr ipt_cpp_value_to_v8_value}});
472 } 458 }
473 {% endmacro %} 459 {% endmacro %}
474 460
475 461
476 {##############################################################################} 462 {##############################################################################}
477 {% macro attribute_configuration(attribute) %} 463 {% macro attribute_configuration(attribute) %}
478 {% from 'utilities.cpp.tmpl' import property_location %} 464 {% from 'utilities.cpp.tmpl' import property_location %}
479 {% if attribute.constructor_type %} 465 {% if attribute.constructor_type %}
480 {% set getter_callback = 466 {% set getter_callback =
481 '%sV8Internal::%sConstructorGetterCallback' % (cpp_class_or_partial, attr ibute.name) 467 '%sV8Internal::%sConstructorGetterCallback' % (cpp_class_or_partial, attr ibute.name)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 setter_callback_for_main_world, 507 setter_callback_for_main_world,
522 wrapper_type_info, 508 wrapper_type_info,
523 access_control, 509 access_control,
524 property_attribute, 510 property_attribute,
525 only_exposed_to_private_script, 511 only_exposed_to_private_script,
526 property_location(attribute), 512 property_location(attribute),
527 holder_check, 513 holder_check,
528 ] %} 514 ] %}
529 {{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}} 515 {{'{'}}{{attribute_configuration_list | join(', ')}}{{'}'}}
530 {%- endmacro %} 516 {%- endmacro %}
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/templates/callback_function.cpp.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698