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

Side by Side Diff: Source/bindings/templates/interface.cpp

Issue 968573004: [bindings] Support extended attribute '[CallWith=ScriptState ]' for getter/setter/deleter. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@972153002
Patch Set: Patch for landing. Created 5 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
« no previous file with comments | « Source/bindings/scripts/v8_interface.py ('k') | Source/bindings/tests/idls/core/TestObject.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {% extends 'interface_base.cpp' %} 1 {% extends 'interface_base.cpp' %}
2 2
3 3
4 {##############################################################################} 4 {##############################################################################}
5 {% block indexed_property_getter %} 5 {% block indexed_property_getter %}
6 {% if indexed_property_getter and not indexed_property_getter.is_custom %} 6 {% if indexed_property_getter and not indexed_property_getter.is_custom %}
7 {% set getter = indexed_property_getter %} 7 {% set getter = indexed_property_getter %}
8 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo <v8::Value>& info) 8 static void indexedPropertyGetter(uint32_t index, const v8::PropertyCallbackInfo <v8::Value>& info)
9 { 9 {
10 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 10 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
11 {% if getter.is_raises_exception %} 11 {% if getter.is_raises_exception %}
12 ExceptionState exceptionState(ExceptionState::IndexedGetterContext, "{{inter face_name}}", info.Holder(), info.GetIsolate()); 12 ExceptionState exceptionState(ExceptionState::IndexedGetterContext, "{{inter face_name}}", info.Holder(), info.GetIsolate());
13 {% endif %} 13 {% endif %}
14 {% if getter.is_call_with_script_state %}
15 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
16 {% endif %}
14 {% set getter_name = getter.name or 'anonymousIndexedGetter' %} 17 {% set getter_name = getter.name or 'anonymousIndexedGetter' %}
15 {% set getter_arguments = ['index', 'exceptionState'] 18 {% set getter_arguments = ['index'] %}
16 if getter.is_raises_exception else ['index'] %} 19 {% if getter.is_call_with_script_state %}
20 {% set getter_arguments = ['scriptState'] + getter_arguments %}
21 {% endif %}
22 {% if getter.is_raises_exception %}
23 {% set getter_arguments = getter_arguments + ['exceptionState'] %}
24 {% endif %}
17 {{getter.cpp_type}} result = impl->{{getter_name}}({{getter_arguments | join (', ')}}); 25 {{getter.cpp_type}} result = impl->{{getter_name}}({{getter_arguments | join (', ')}});
18 {% if getter.is_raises_exception %} 26 {% if getter.is_raises_exception %}
19 if (exceptionState.throwIfNeeded()) 27 if (exceptionState.throwIfNeeded())
20 return; 28 return;
21 {% endif %} 29 {% endif %}
22 if ({{getter.is_null_expression}}) 30 if ({{getter.is_null_expression}})
23 return; 31 return;
24 {{getter.v8_set_return_value}}; 32 {{getter.v8_set_return_value}};
25 } 33 }
26 34
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 {% endif %} 69 {% endif %}
62 {% if setter.has_type_checking_interface %} 70 {% if setter.has_type_checking_interface %}
63 {# Type checking for interface types (if interface not implemented, throw 71 {# Type checking for interface types (if interface not implemented, throw
64 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} 72 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
65 if (!propertyValue{% if setter.is_nullable %} && !isUndefinedOrNull(v8Value) {% endif %}) { 73 if (!propertyValue{% if setter.is_nullable %} && !isUndefinedOrNull(v8Value) {% endif %}) {
66 exceptionState.throwTypeError("The provided value is not of type '{{sett er.idl_type}}'."); 74 exceptionState.throwTypeError("The provided value is not of type '{{sett er.idl_type}}'.");
67 exceptionState.throwIfNeeded(); 75 exceptionState.throwIfNeeded();
68 return; 76 return;
69 } 77 }
70 {% endif %} 78 {% endif %}
79 {% if setter.is_call_with_script_state %}
80 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
81 {% endif %}
71 {% set setter_name = setter.name or 'anonymousIndexedSetter' %} 82 {% set setter_name = setter.name or 'anonymousIndexedSetter' %}
72 {% set setter_arguments = ['index', 'propertyValue', 'exceptionState'] 83 {% set setter_arguments = ['index', 'propertyValue'] %}
73 if setter.is_raises_exception else ['index', 'propertyValue'] %} 84 {% if setter.is_call_with_script_state %}
85 {% set setter_arguments = ['scriptState'] + setter_arguments %}
86 {% endif %}
87 {% if setter.is_raises_exception %}
88 {% set setter_arguments = setter_arguments + ['exceptionState'] %}
89 {% endif %}
74 bool result = impl->{{setter_name}}({{setter_arguments | join(', ')}}); 90 bool result = impl->{{setter_name}}({{setter_arguments | join(', ')}});
75 {% if setter.is_raises_exception %} 91 {% if setter.is_raises_exception %}
76 if (exceptionState.throwIfNeeded()) 92 if (exceptionState.throwIfNeeded())
77 return; 93 return;
78 {% endif %} 94 {% endif %}
79 if (!result) 95 if (!result)
80 return; 96 return;
81 v8SetReturnValue(info, v8Value); 97 v8SetReturnValue(info, v8Value);
82 } 98 }
83 99
(...skipping 23 matching lines...) Expand all
107 {##############################################################################} 123 {##############################################################################}
108 {% block indexed_property_deleter %} 124 {% block indexed_property_deleter %}
109 {% if indexed_property_deleter and not indexed_property_deleter.is_custom %} 125 {% if indexed_property_deleter and not indexed_property_deleter.is_custom %}
110 {% set deleter = indexed_property_deleter %} 126 {% set deleter = indexed_property_deleter %}
111 static void indexedPropertyDeleter(uint32_t index, const v8::PropertyCallbackInf o<v8::Boolean>& info) 127 static void indexedPropertyDeleter(uint32_t index, const v8::PropertyCallbackInf o<v8::Boolean>& info)
112 { 128 {
113 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 129 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
114 {% if deleter.is_raises_exception %} 130 {% if deleter.is_raises_exception %}
115 ExceptionState exceptionState(ExceptionState::IndexedDeletionContext, "{{int erface_name}}", info.Holder(), info.GetIsolate()); 131 ExceptionState exceptionState(ExceptionState::IndexedDeletionContext, "{{int erface_name}}", info.Holder(), info.GetIsolate());
116 {% endif %} 132 {% endif %}
133 {% if deleter.is_call_with_script_state %}
134 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
135 {% endif %}
117 {% set deleter_name = deleter.name or 'anonymousIndexedDeleter' %} 136 {% set deleter_name = deleter.name or 'anonymousIndexedDeleter' %}
118 {% set deleter_arguments = ['index', 'exceptionState'] 137 {% set deleter_arguments = ['index'] %}
119 if deleter.is_raises_exception else ['index'] %} 138 {% if deleter.is_call_with_script_state %}
139 {% set deleter_arguments = ['scriptState'] + deleter_arguments %}
140 {% endif %}
141 {% if deleter.is_raises_exception %}
142 {% set deleter_arguments = deleter_arguments + ['exceptionState'] %}
143 {% endif %}
120 DeleteResult result = impl->{{deleter_name}}({{deleter_arguments | join(', ' )}}); 144 DeleteResult result = impl->{{deleter_name}}({{deleter_arguments | join(', ' )}});
121 {% if deleter.is_raises_exception %} 145 {% if deleter.is_raises_exception %}
122 if (exceptionState.throwIfNeeded()) 146 if (exceptionState.throwIfNeeded())
123 return; 147 return;
124 {% endif %} 148 {% endif %}
125 if (result != DeleteUnknownProperty) 149 if (result != DeleteUnknownProperty)
126 return v8SetReturnValueBool(info, result == DeleteSuccess); 150 return v8SetReturnValueBool(info, result == DeleteSuccess);
127 } 151 }
128 152
129 {% endif %} 153 {% endif %}
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(nameString).IsEmpty ()) 188 if (!info.Holder()->GetRealNamedPropertyInPrototypeChain(nameString).IsEmpty ())
165 return; 189 return;
166 190
167 {% endif %} 191 {% endif %}
168 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 192 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
169 AtomicString propertyName = toCoreAtomicString(nameString); 193 AtomicString propertyName = toCoreAtomicString(nameString);
170 {% if getter.is_raises_exception %} 194 {% if getter.is_raises_exception %}
171 v8::String::Utf8Value namedProperty(nameString); 195 v8::String::Utf8Value namedProperty(nameString);
172 ExceptionState exceptionState(ExceptionState::GetterContext, *namedProperty, "{{interface_name}}", info.Holder(), info.GetIsolate()); 196 ExceptionState exceptionState(ExceptionState::GetterContext, *namedProperty, "{{interface_name}}", info.Holder(), info.GetIsolate());
173 {% endif %} 197 {% endif %}
198 {% if getter.is_call_with_script_state %}
199 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
200 {% endif %}
174 {% if getter.use_output_parameter_for_result %} 201 {% if getter.use_output_parameter_for_result %}
175 {{getter.cpp_type}} result; 202 {{getter.cpp_type}} result;
176 {{getter.cpp_value}}; 203 {{getter.cpp_value}};
177 {% else %} 204 {% else %}
178 {{getter.cpp_type}} result = {{getter.cpp_value}}; 205 {{getter.cpp_type}} result = {{getter.cpp_value}};
179 {% endif %} 206 {% endif %}
180 {% if getter.is_raises_exception %} 207 {% if getter.is_raises_exception %}
181 if (exceptionState.throwIfNeeded()) 208 if (exceptionState.throwIfNeeded())
182 return; 209 return;
183 {% endif %} 210 {% endif %}
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 {{v8_value_to_local_cpp_value(setter) | indent}} 265 {{v8_value_to_local_cpp_value(setter) | indent}}
239 {% if setter.has_type_checking_interface %} 266 {% if setter.has_type_checking_interface %}
240 {# Type checking for interface types (if interface not implemented, throw 267 {# Type checking for interface types (if interface not implemented, throw
241 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} 268 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #}
242 if (!propertyValue{% if setter.is_nullable %} && !isUndefinedOrNull(v8Value) {% endif %}) { 269 if (!propertyValue{% if setter.is_nullable %} && !isUndefinedOrNull(v8Value) {% endif %}) {
243 exceptionState.throwTypeError("The provided value is not of type '{{sett er.idl_type}}'."); 270 exceptionState.throwTypeError("The provided value is not of type '{{sett er.idl_type}}'.");
244 exceptionState.throwIfNeeded(); 271 exceptionState.throwIfNeeded();
245 return; 272 return;
246 } 273 }
247 {% endif %} 274 {% endif %}
275 {% if setter.is_call_with_script_state %}
276 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
277 {% endif %}
248 {% set setter_name = setter.name or 'anonymousNamedSetter' %} 278 {% set setter_name = setter.name or 'anonymousNamedSetter' %}
249 {% set setter_arguments = 279 {% set setter_arguments = ['propertyName', 'propertyValue'] %}
250 ['propertyName', 'propertyValue', 'exceptionState'] 280 {% if setter.is_call_with_script_state %}
251 if setter.is_raises_exception else 281 {% set setter_arguments = ['scriptState'] + setter_arguments %}
252 ['propertyName', 'propertyValue'] %} 282 {% endif %}
283 {% if setter.is_raises_exception %}
284 {% set setter_arguments = setter_arguments + ['exceptionState'] %}
285 {% endif %}
253 bool result = impl->{{setter_name}}({{setter_arguments | join(', ')}}); 286 bool result = impl->{{setter_name}}({{setter_arguments | join(', ')}});
254 {% if setter.is_raises_exception %} 287 {% if setter.is_raises_exception %}
255 if (exceptionState.throwIfNeeded()) 288 if (exceptionState.throwIfNeeded())
256 return; 289 return;
257 {% endif %} 290 {% endif %}
258 if (!result) 291 if (!result)
259 return; 292 return;
260 v8SetReturnValue(info, v8Value); 293 v8SetReturnValue(info, v8Value);
261 } 294 }
262 295
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 static void namedPropertyDeleter(v8::Local<v8::Name> name, const v8::PropertyCal lbackInfo<v8::Boolean>& info) 368 static void namedPropertyDeleter(v8::Local<v8::Name> name, const v8::PropertyCal lbackInfo<v8::Boolean>& info)
336 { 369 {
337 if (!name->IsString()) 370 if (!name->IsString())
338 return; 371 return;
339 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder()); 372 {{cpp_class}}* impl = {{v8_class}}::toImpl(info.Holder());
340 AtomicString propertyName = toCoreAtomicString(name.As<v8::String>()); 373 AtomicString propertyName = toCoreAtomicString(name.As<v8::String>());
341 {% if deleter.is_raises_exception %} 374 {% if deleter.is_raises_exception %}
342 v8::String::Utf8Value namedProperty(name); 375 v8::String::Utf8Value namedProperty(name);
343 ExceptionState exceptionState(ExceptionState::DeletionContext, *namedPropert y, "{{interface_name}}", info.Holder(), info.GetIsolate()); 376 ExceptionState exceptionState(ExceptionState::DeletionContext, *namedPropert y, "{{interface_name}}", info.Holder(), info.GetIsolate());
344 {% endif %} 377 {% endif %}
378 {% if deleter.is_call_with_script_state %}
379 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
380 {% endif %}
345 {% set deleter_name = deleter.name or 'anonymousNamedDeleter' %} 381 {% set deleter_name = deleter.name or 'anonymousNamedDeleter' %}
346 {% set deleter_arguments = ['propertyName', 'exceptionState'] 382 {% set deleter_arguments = ['propertyName'] %}
347 if deleter.is_raises_exception else ['propertyName'] %} 383 {% if deleter.is_call_with_script_state %}
384 {% set deleter_arguments = ['scriptState'] + deleter_arguments %}
385 {% endif %}
386 {% if deleter.is_raises_exception %}
387 {% set deleter_arguments = deleter_arguments + ['exceptionState'] %}
388 {% endif %}
348 DeleteResult result = impl->{{deleter_name}}({{deleter_arguments | join(', ' )}}); 389 DeleteResult result = impl->{{deleter_name}}({{deleter_arguments | join(', ' )}});
349 {% if deleter.is_raises_exception %} 390 {% if deleter.is_raises_exception %}
350 if (exceptionState.throwIfNeeded()) 391 if (exceptionState.throwIfNeeded())
351 return; 392 return;
352 {% endif %} 393 {% endif %}
353 if (result != DeleteUnknownProperty) 394 if (result != DeleteUnknownProperty)
354 return v8SetReturnValueBool(info, result == DeleteSuccess); 395 return v8SetReturnValueBool(info, result == DeleteSuccess);
355 } 396 }
356 397
357 {% endif %} 398 {% endif %}
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 } 1030 }
990 1031
991 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %} 1032 {% for method in methods if method.overloads and method.overloads.has_partial_ov erloads %}
992 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&)) 1033 void {{v8_class}}::register{{method.name | blink_capitalize}}MethodForPartialInt erface(void (*method)(const v8::FunctionCallbackInfo<v8::Value>&))
993 { 1034 {
994 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method; 1035 {{cpp_class}}V8Internal::{{method.name}}MethodForPartialInterface = method;
995 } 1036 }
996 {% endfor %} 1037 {% endfor %}
997 {% endif %} 1038 {% endif %}
998 {% endblock %} 1039 {% endblock %}
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_interface.py ('k') | Source/bindings/tests/idls/core/TestObject.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698