Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 {##############################################################################} | 1 {##############################################################################} |
| 2 {% macro attribute_getter(attribute, world_suffix) %} | 2 {% macro attribute_getter(attribute, world_suffix) %} |
| 3 {% filter conditional(attribute.conditional_string) %} | 3 {% filter conditional(attribute.conditional_string) %} |
| 4 static void {{attribute.name}}AttributeGetter{{world_suffix}}( | 4 static void {{attribute.name}}AttributeGetter{{world_suffix}}( |
| 5 {%- if attribute.is_expose_js_accessors %} | 5 {%- if attribute.is_expose_js_accessors %} |
| 6 const v8::FunctionCallbackInfo<v8::Value>& info | 6 const v8::FunctionCallbackInfo<v8::Value>& info |
| 7 {%- else %} | 7 {%- else %} |
| 8 const v8::PropertyCallbackInfo<v8::Value>& info | 8 const v8::PropertyCallbackInfo<v8::Value>& info |
| 9 {%- endif %}) | 9 {%- endif %}) |
| 10 { | 10 { |
| 11 {% if attribute.is_reflect and not attribute.is_url and | 11 {% if attribute.is_reflect and not attribute.is_url and |
| 12 attribute.idl_type == 'DOMString' and is_node %} | 12 attribute.idl_type == 'DOMString' and is_node %} |
| 13 {% set cpp_class, v8_class = 'Element', 'V8Element' %} | 13 {% set cpp_class, v8_class = 'Element', 'V8Element' %} |
| 14 {% endif %} | 14 {% endif %} |
| 15 {# impl #} | 15 {# isolate #} |
| 16 {# FIXME: use a local variable for holder more often and simplify below #} | 16 {% if attribute.cached_attribute_validation_method or |
| 17 {% if attribute.is_unforgeable or | 17 attribute.is_call_with_execution_context or |
| 18 interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} | 18 attribute.is_check_security_for_node or |
| 19 {% if interface_name == 'Window' %} | 19 attribute.is_getter_raises_exception or |
| 20 v8::Handle<v8::Object> holder = info.Holder(); | 20 attribute.is_keep_alive_for_gc %} |
|
haraken
2014/03/27 04:40:36
I'm not sure if this improves the IDL compiler. It
Nils Barth (inactive)
2014/03/27 05:19:46
Got it; revised CL to only have |holder|.
| |
| 21 {% else %}{# perform lookup first #} | 21 v8::Isolate* isolate = info.GetIsolate(); |
| 22 {% endif %} | |
| 23 {# holder #} | |
| 24 {% if attribute.is_unforgeable and interface_name != 'Window' %} | |
| 25 {# perform lookup first #} | |
| 22 {# FIXME: can we remove this lookup? #} | 26 {# FIXME: can we remove this lookup? #} |
| 23 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i nfo.This(), info.GetIsolate()); | 27 v8::Handle<v8::Object> holder = {{v8_class}}::findInstanceInPrototypeChain(i nfo.This(), info.GetIsolate()); |
| 24 if (holder.IsEmpty()) | 28 if (holder.IsEmpty()) |
| 25 return; | 29 return; |
| 26 {% endif %}{# Window #} | 30 {% elif not attribute.is_static %} |
| 31 v8::Handle<v8::Object> holder = info.Holder(); | |
| 32 {% endif %} | |
| 33 {# impl #} | |
| 34 {% if attribute.cached_attribute_validation_method %} | |
| 35 v8::Handle<v8::String> propertyName = v8AtomicString(isolate, "{{attribute.n ame}}"); | |
| 27 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); | 36 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); |
| 28 {% elif attribute.cached_attribute_validation_method %} | |
| 29 v8::Handle<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "{{a ttribute.name}}"); | |
| 30 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | |
| 31 if (!impl->{{attribute.cached_attribute_validation_method}}()) { | 37 if (!impl->{{attribute.cached_attribute_validation_method}}()) { |
| 32 v8::Handle<v8::Value> jsValue = V8HiddenValue::getHiddenValue(info.GetIs olate(), info.Holder(), propertyName); | 38 v8::Handle<v8::Value> jsValue = V8HiddenValue::getHiddenValue(isolate, h older, propertyName); |
| 33 if (!jsValue.IsEmpty()) { | 39 if (!jsValue.IsEmpty()) { |
| 34 v8SetReturnValue(info, jsValue); | 40 v8SetReturnValue(info, jsValue); |
| 35 return; | 41 return; |
| 36 } | 42 } |
| 37 } | 43 } |
| 38 {% elif not (attribute.is_static or attribute.is_unforgeable) %} | 44 {% elif not attribute.is_static %} |
| 39 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 45 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); |
| 40 {% endif %} | 46 {% endif %} |
| 41 {% if attribute.is_implemented_by and not attribute.is_static %} | 47 {% if attribute.is_implemented_by and not attribute.is_static %} |
| 42 ASSERT(impl); | 48 ASSERT(impl); |
| 43 {% endif %} | 49 {% endif %} |
| 44 {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} | 50 {% if interface_name == 'Window' and attribute.idl_type == 'EventHandler' %} |
| 45 if (!impl->document()) | 51 if (!impl->document()) |
| 46 return; | 52 return; |
| 47 {% endif %} | 53 {% endif %} |
| 48 {# Local variables #} | 54 {# Local variables #} |
| 49 {% if attribute.is_call_with_execution_context %} | 55 {% if attribute.is_call_with_execution_context %} |
| 50 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; | 56 ExecutionContext* scriptContext = currentExecutionContext(isolate); |
| 51 {% endif %} | 57 {% endif %} |
| 52 {% if attribute.is_check_security_for_node or | 58 {% if attribute.is_check_security_for_node or |
| 53 attribute.is_getter_raises_exception %} | 59 attribute.is_getter_raises_exception %} |
| 54 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 60 ExceptionState exceptionState(ExceptionState::GetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, isolate); |
| 55 {% endif %} | 61 {% endif %} |
| 56 {% if attribute.is_nullable %} | 62 {% if attribute.is_nullable %} |
| 57 bool isNull = false; | 63 bool isNull = false; |
| 58 {% endif %} | 64 {% endif %} |
| 59 {# FIXME: consider always using a local variable for value #} | 65 {# FIXME: consider always using a local variable for value #} |
| 60 {% if attribute.cached_attribute_validation_method or | 66 {% if attribute.cached_attribute_validation_method or |
| 61 attribute.is_getter_raises_exception or | 67 attribute.is_getter_raises_exception or |
| 62 attribute.is_nullable or | 68 attribute.is_nullable or |
| 63 attribute.reflect_only or | 69 attribute.reflect_only or |
| 64 attribute.idl_type == 'EventHandler' %} | 70 attribute.idl_type == 'EventHandler' %} |
| 65 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; | 71 {{attribute.cpp_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_origi nal}}; |
| 66 {% endif %} | 72 {% endif %} |
| 67 {# Checks #} | 73 {# Checks #} |
| 68 {% if attribute.is_getter_raises_exception %} | 74 {% if attribute.is_getter_raises_exception %} |
| 69 if (UNLIKELY(exceptionState.throwIfNeeded())) | 75 if (UNLIKELY(exceptionState.throwIfNeeded())) |
| 70 return; | 76 return; |
| 71 {% endif %} | 77 {% endif %} |
| 72 {% if attribute.is_check_security_for_node %} | 78 {% if attribute.is_check_security_for_node %} |
| 73 {# FIXME: use a local variable to not call getter twice #} | 79 {# FIXME: use a local variable to not call getter twice #} |
| 74 if (!BindingSecurity::shouldAllowAccessToNode(info.GetIsolate(), {{attribute .cpp_value}}, exceptionState)) { | 80 if (!BindingSecurity::shouldAllowAccessToNode(isolate, {{attribute.cpp_value }}, exceptionState)) { |
| 75 v8SetReturnValueNull(info); | 81 v8SetReturnValueNull(info); |
| 76 exceptionState.throwIfNeeded(); | 82 exceptionState.throwIfNeeded(); |
| 77 return; | 83 return; |
| 78 } | 84 } |
| 79 {% endif %} | 85 {% endif %} |
| 80 {% if attribute.reflect_only %} | 86 {% if attribute.reflect_only %} |
| 81 {{release_only_check(attribute.reflect_only, attribute.reflect_missing, | 87 {{release_only_check(attribute.reflect_only, attribute.reflect_missing, |
| 82 attribute.reflect_invalid, attribute.reflect_empty) | 88 attribute.reflect_invalid, attribute.reflect_empty) |
| 83 | indent}} | 89 | indent}} |
| 84 {% endif %} | 90 {% endif %} |
| 85 {% if attribute.is_nullable %} | 91 {% if attribute.is_nullable %} |
| 86 if (isNull) { | 92 if (isNull) { |
| 87 v8SetReturnValueNull(info); | 93 v8SetReturnValueNull(info); |
| 88 return; | 94 return; |
| 89 } | 95 } |
| 90 {% endif %} | 96 {% endif %} |
| 91 {% if attribute.cached_attribute_validation_method %} | 97 {% if attribute.cached_attribute_validation_method %} |
| 92 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), propertyName , {{attribute.cpp_value}}.v8Value()); | 98 V8HiddenValue::setHiddenValue(isolate, holder, propertyName, {{attribute.cpp _value}}.v8Value()); |
| 93 {% endif %} | 99 {% endif %} |
| 94 {# v8SetReturnValue #} | 100 {# v8SetReturnValue #} |
| 95 {% if attribute.is_keep_alive_for_gc %} | 101 {% if attribute.is_keep_alive_for_gc %} |
| 96 {# FIXME: merge local variable assignment with above #} | 102 {# FIXME: merge local variable assignment with above #} |
| 97 {{attribute.cpp_type}} result({{attribute.cpp_value}}); | 103 {{attribute.cpp_type}} result({{attribute.cpp_value}}); |
| 98 if (result && DOMDataStore::setReturnValueFromWrapper{{world_suffix}}<{{attr ibute.v8_type}}>(info.GetReturnValue(), result.get())) | 104 if (result && DOMDataStore::setReturnValueFromWrapper{{world_suffix}}<{{attr ibute.v8_type}}>(info.GetReturnValue(), result.get())) |
| 99 return; | 105 return; |
| 100 v8::Handle<v8::Value> wrapper = toV8(result.get(), info.Holder(), info.GetIs olate()); | 106 v8::Handle<v8::Value> wrapper = toV8(result.get(), holder, isolate); |
| 101 if (!wrapper.IsEmpty()) { | 107 if (!wrapper.IsEmpty()) { |
| 102 V8HiddenValue::setHiddenValue(info.GetIsolate(), info.Holder(), v8Atomic String(info.GetIsolate(), "{{attribute.name}}"), wrapper); | 108 V8HiddenValue::setHiddenValue(isolate, holder, v8AtomicString(info.GetIs olate(), "{{attribute.name}}"), wrapper); |
| 103 {{attribute.v8_set_return_value}}; | 109 {{attribute.v8_set_return_value}}; |
| 104 } | 110 } |
| 105 {% elif world_suffix %} | 111 {% elif world_suffix %} |
| 106 {{attribute.v8_set_return_value_for_main_world}}; | 112 {{attribute.v8_set_return_value_for_main_world}}; |
| 107 {% else %} | 113 {% else %} |
| 108 {{attribute.v8_set_return_value}}; | 114 {{attribute.v8_set_return_value}}; |
| 109 {% endif %} | 115 {% endif %} |
| 110 } | 116 } |
| 111 {% endfilter %} | 117 {% endfilter %} |
| 112 {% endmacro %} | 118 {% endmacro %} |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 {%- if attribute.is_expose_js_accessors %} | 211 {%- if attribute.is_expose_js_accessors %} |
| 206 v8::Local<v8::Value> jsValue, const v8::FunctionCallbackInfo<v8::Value>& info | 212 v8::Local<v8::Value> jsValue, const v8::FunctionCallbackInfo<v8::Value>& info |
| 207 {%- else %} | 213 {%- else %} |
| 208 v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info | 214 v8::Local<v8::Value> jsValue, const v8::PropertyCallbackInfo<void>& info |
| 209 {%- endif %}) | 215 {%- endif %}) |
| 210 { | 216 { |
| 211 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' and | 217 {% if attribute.is_reflect and attribute.idl_type == 'DOMString' and |
| 212 is_node %} | 218 is_node %} |
| 213 {% set cpp_class, v8_class = 'Element', 'V8Element' %} | 219 {% set cpp_class, v8_class = 'Element', 'V8Element' %} |
| 214 {% endif %} | 220 {% endif %} |
| 221 {# Local variables #} | |
| 222 {% if attribute.cached_attribute_validation_method or | |
| 223 attribute.has_setter_exception_state or | |
| 224 attribute.has_strict_type_checking or | |
| 225 attribute.is_call_with_execution_context or | |
| 226 attribute.is_setter_call_with_execution_context or | |
| 227 (attribute.idl_type == 'EventHandler' and not is_node) %} | |
|
haraken
2014/03/27 04:40:36
Ditto.
| |
| 228 v8::Isolate* isolate = info.GetIsolate(); | |
| 229 {% endif %} | |
| 230 {% if not attribute.is_static %} | |
| 231 v8::Handle<v8::Object> holder = info.Holder(); | |
| 232 {% endif %} | |
| 215 {% if attribute.has_setter_exception_state %} | 233 {% if attribute.has_setter_exception_state %} |
| 216 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", info.Holder(), info.GetIsolate()); | 234 ExceptionState exceptionState(ExceptionState::SetterContext, "{{attribute.na me}}", "{{interface_name}}", holder, isolate); |
| 217 {% endif %} | 235 {% endif %} |
| 236 {# Type checking #} | |
| 218 {% if attribute.has_strict_type_checking %} | 237 {% if attribute.has_strict_type_checking %} |
| 219 {# Type checking for interface types (if interface not implemented, throw | 238 {# Type checking for interface types (if interface not implemented, throw |
| 220 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} | 239 TypeError), per http://www.w3.org/TR/WebIDL/#es-interface #} |
| 221 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, info.GetIsolate())) { | 240 if (!isUndefinedOrNull(jsValue) && !V8{{attribute.idl_type}}::hasInstance(js Value, isolate)) { |
| 222 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); | 241 exceptionState.throwTypeError("The provided value is not of type '{{attr ibute.idl_type}}'."); |
| 223 exceptionState.throwIfNeeded(); | 242 exceptionState.throwIfNeeded(); |
| 224 return; | 243 return; |
| 225 } | 244 } |
| 226 {% endif %} | 245 {% endif %} |
| 227 {# impl #} | 246 {# impl #} |
| 228 {% if attribute.put_forwards %} | 247 {% if attribute.put_forwards %} |
| 229 {{cpp_class}}* proxyImpl = {{v8_class}}::toNative(info.Holder()); | 248 {{cpp_class}}* proxyImpl = {{v8_class}}::toNative(holder); |
| 230 {{attribute.ref_ptr}}<{{attribute.idl_type}}> impl = WTF::getPtr(proxyImpl-> {{attribute.name}}()); | 249 {{attribute.ref_ptr}}<{{attribute.idl_type}}> impl = WTF::getPtr(proxyImpl-> {{attribute.name}}()); |
| 231 if (!impl) | 250 if (!impl) |
| 232 return; | 251 return; |
| 233 {% elif not attribute.is_static %} | 252 {% elif not attribute.is_static %} |
| 234 {{cpp_class}}* impl = {{v8_class}}::toNative(info.Holder()); | 253 {{cpp_class}}* impl = {{v8_class}}::toNative(holder); |
| 235 {% endif %} | 254 {% endif %} |
| 236 {% if attribute.is_implemented_by and not attribute.is_static %} | 255 {% if attribute.is_implemented_by and not attribute.is_static %} |
| 237 ASSERT(impl); | 256 ASSERT(impl); |
| 238 {% endif %} | 257 {% endif %} |
| 239 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} | 258 {% if attribute.idl_type == 'EventHandler' and interface_name == 'Window' %} |
| 240 if (!impl->document()) | 259 if (!impl->document()) |
| 241 return; | 260 return; |
| 242 {% endif %} | 261 {% endif %} |
| 243 {# Convert JS value to C++ value #} | 262 {# Convert JS value to C++ value #} |
| 244 {% if attribute.idl_type != 'EventHandler' %} | 263 {% if attribute.idl_type != 'EventHandler' %} |
| 245 {{attribute.v8_value_to_local_cpp_value}}; | 264 {{attribute.v8_value_to_local_cpp_value}}; |
| 246 {% elif not is_node %}{# EventHandler hack #} | 265 {% elif not is_node %}{# EventHandler hack #} |
| 247 moveEventListenerToNewWrapper(info.Holder(), {{attribute.event_handler_gette r_expression}}, jsValue, {{v8_class}}::eventListenerCacheIndex, info.GetIsolate( )); | 266 moveEventListenerToNewWrapper(holder, {{attribute.event_handler_getter_expre ssion}}, jsValue, {{v8_class}}::eventListenerCacheIndex, isolate); |
| 248 {% endif %} | 267 {% endif %} |
| 249 {% if attribute.enum_validation_expression %} | 268 {% if attribute.enum_validation_expression %} |
| 250 {# Setter ignores invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enum s #} | 269 {# Setter ignores invalid enum values: http://www.w3.org/TR/WebIDL/#idl-enum s #} |
| 251 String string = cppValue; | 270 String string = cppValue; |
| 252 if (!({{attribute.enum_validation_expression}})) | 271 if (!({{attribute.enum_validation_expression}})) |
| 253 return; | 272 return; |
| 254 {% endif %} | 273 {% endif %} |
| 255 {# Pre-set context #} | 274 {# Pre-set context #} |
| 256 {% if attribute.is_custom_element_callbacks or | 275 {% if attribute.is_custom_element_callbacks or |
| 257 (attribute.is_reflect and | 276 (attribute.is_reflect and |
| 258 not(attribute.idl_type == 'DOMString' and is_node)) %} | 277 not(attribute.idl_type == 'DOMString' and is_node)) %} |
| 259 {# Skip on compact node DOMString getters #} | 278 {# Skip on compact node DOMString getters #} |
| 260 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; | 279 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 261 {% endif %} | 280 {% endif %} |
| 262 {% if attribute.is_call_with_execution_context or | 281 {% if attribute.is_call_with_execution_context or |
| 263 attribute.is_setter_call_with_execution_context %} | 282 attribute.is_setter_call_with_execution_context %} |
| 264 ExecutionContext* scriptContext = currentExecutionContext(info.GetIsolate()) ; | 283 ExecutionContext* scriptContext = currentExecutionContext(isolate); |
| 265 {% endif %} | 284 {% endif %} |
| 266 {# Set #} | 285 {# Set #} |
| 267 {{attribute.cpp_setter}}; | 286 {{attribute.cpp_setter}}; |
| 268 {# Post-set #} | 287 {# Post-set #} |
| 269 {% if attribute.is_setter_raises_exception %} | 288 {% if attribute.is_setter_raises_exception %} |
| 270 exceptionState.throwIfNeeded(); | 289 exceptionState.throwIfNeeded(); |
| 271 {% endif %} | 290 {% endif %} |
| 272 {% if attribute.cached_attribute_validation_method %} | 291 {% if attribute.cached_attribute_validation_method %} |
| 273 V8HiddenValue::deleteHiddenValue(info.GetIsolate(), info.Holder(), v8AtomicS tring(info.GetIsolate(), "{{attribute.name}}")); // Invalidate the cached value. | 292 V8HiddenValue::deleteHiddenValue(isolate, holder, v8AtomicString(info.GetIso late(), "{{attribute.name}}")); // Invalidate the cached value. |
| 274 {% endif %} | 293 {% endif %} |
| 275 } | 294 } |
| 276 {% endfilter %} | 295 {% endfilter %} |
| 277 {% endmacro %} | 296 {% endmacro %} |
| 278 | 297 |
| 279 | 298 |
| 280 {##############################################################################} | 299 {##############################################################################} |
| 281 {% macro attribute_setter_callback(attribute, world_suffix) %} | 300 {% macro attribute_setter_callback(attribute, world_suffix) %} |
| 282 {% filter conditional(attribute.conditional_string) %} | 301 {% filter conditional(attribute.conditional_string) %} |
| 283 static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}( | 302 static void {{attribute.name}}AttributeSetterCallback{{world_suffix}}( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 309 {% endif %} | 328 {% endif %} |
| 310 {% if attribute.has_custom_setter %} | 329 {% if attribute.has_custom_setter %} |
| 311 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); | 330 {{v8_class}}::{{attribute.name}}AttributeSetterCustom(jsValue, info); |
| 312 {% else %} | 331 {% else %} |
| 313 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); | 332 {{cpp_class}}V8Internal::{{attribute.name}}AttributeSetter{{world_suffix}}(j sValue, info); |
| 314 {% endif %} | 333 {% endif %} |
| 315 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); | 334 TRACE_EVENT_SET_SAMPLING_STATE("V8", "V8Execution"); |
| 316 } | 335 } |
| 317 {% endfilter %} | 336 {% endfilter %} |
| 318 {% endmacro %} | 337 {% endmacro %} |
| OLD | NEW |