| OLD | NEW |
| (Empty) | |
| 1 {##############################################################################} |
| 2 {% macro attribute_getter(cpp_class, attribute) %} |
| 3 static void {{static_attribute_name(attribute, 'Getter')}}(Dart_NativeArguments
args) |
| 4 { |
| 5 {% if attribute.idl_type == "EventHandler" %} |
| 6 {# TODO(terry): Need to fix properly. #} |
| 7 // FIXME: proper implementation. |
| 8 DART_UNIMPLEMENTED(); |
| 9 {% else %} |
| 10 {% if attribute.is_getter_raises_exception or attribute.is_call_with_execution
_context or attribute.is_call_with_script_state %} |
| 11 Dart_Handle exception = 0; |
| 12 {% endif %} |
| 13 { |
| 14 {% if attribute.is_call_with_execution_context %} |
| 15 ExecutionContext* context = DartUtilities::scriptExecutionContext(); |
| 16 if (!context) { |
| 17 exception = Dart_NewStringFromCString("Failed to retrieve a context"
); |
| 18 goto fail; |
| 19 } |
| 20 |
| 21 {% endif %} |
| 22 {% if attribute.is_call_with_script_state %} |
| 23 ScriptState* state = DartUtilities::currentScriptState(); |
| 24 if (!state) { |
| 25 exception = Dart_NewStringFromCString("Failed to retrieve a script state")
; |
| 26 goto fail; |
| 27 } |
| 28 {% endif %} |
| 29 {% if attribute.dart_set_return_value and not attribute.is_static %} |
| 30 {{cpp_class}}* receiver = DartDOMWrapper::receiver< {{cpp_class}} >(args
); |
| 31 {% else %} |
| 32 // FIXME: Need receiver setup too. |
| 33 {% endif %} |
| 34 {% if attribute.reflect_only %} |
| 35 {{generate_reflects(attribute) | indent(8)}} |
| 36 {% endif %} |
| 37 {{callback_return(attribute)|indent(8)}} |
| 38 return; |
| 39 } |
| 40 {% if attribute.is_getter_raises_exception or attribute.is_call_with_execution
_context or attribute.is_call_with_script_state %} |
| 41 |
| 42 fail: |
| 43 Dart_ThrowException(exception); |
| 44 ASSERT_NOT_REACHED(); |
| 45 {% endif %} |
| 46 {% endif %} |
| 47 } |
| 48 {% endmacro %} |
| 49 |
| 50 |
| 51 {##############################################################################} |
| 52 {% macro callback_return(attribute) %} |
| 53 {% if attribute.dart_set_return_value %} |
| 54 {% if attribute.is_nullable %} |
| 55 bool isNull = false; |
| 56 {% endif %} |
| 57 {% if attribute.is_getter_raises_exception or |
| 58 attribute.is_nullable %} |
| 59 DartExceptionState es; |
| 60 {% endif %} |
| 61 {% if attribute.cached_attribute_validation_method or |
| 62 attribute.is_getter_raises_exception or |
| 63 attribute.is_nullable or |
| 64 attribute.idl_type == 'EventHandler' %} |
| 65 {% if attribute.cpp_type == 'DartStringAdapter' %} |
| 66 {% set native_type = 'String' %} |
| 67 {% else %} |
| 68 {% set native_type = attribute.cpp_type %} |
| 69 {% endif %} |
| 70 {# TODO(vsm): We still need to generate checks for cache attributes. #} |
| 71 {{native_type}} {{attribute.cpp_value}} = {{attribute.cpp_value_original}}; |
| 72 {% endif %} |
| 73 {% if attribute.is_nullable %} |
| 74 if (isNull) |
| 75 return; |
| 76 {% endif %} |
| 77 {% if attribute.is_getter_raises_exception %} |
| 78 if (es.hadException()) { |
| 79 exception = es.toDart(args, {{attribute.auto_scope}}); |
| 80 goto fail; |
| 81 } |
| 82 {% endif %} |
| 83 {{attribute.dart_set_return_value}}; |
| 84 {% else %} |
| 85 // FIXME: Need to convert this properly. |
| 86 DART_UNIMPLEMENTED(); |
| 87 {% endif %} |
| 88 {% endmacro %} |
| 89 |
| 90 |
| 91 {##############################################################################} |
| 92 {% macro attribute_setter(cpp_class, attribute) %} |
| 93 static void {{static_attribute_name(attribute, 'Setter')}}(Dart_NativeArguments
args) |
| 94 { |
| 95 {% if attribute.idl_type == "EventHandler" or not attribute.cpp_setter %} |
| 96 {# TODO(terry): Need to fix properly. #} |
| 97 // FIXME: proper implementation. |
| 98 DART_UNIMPLEMENTED(); |
| 99 {% else %} |
| 100 Dart_Handle exception = 0; |
| 101 { |
| 102 {{cpp_class}}* receiver = DartDOMWrapper::receiver< {{cpp_class}} >(args
); |
| 103 {% if attribute.is_custom_element_callbacks %} |
| 104 CustomElementCallbackDispatcher::CallbackDeliveryScope deliveryScope; |
| 105 {% endif %} |
| 106 {% set attribute_name = attribute.name if not attribute.put_forwards else 'value
' %} |
| 107 |
| 108 {{attribute.local_cpp_type}} {{attribute.setter_lvalue}} = {{attribute.d
art_value_to_local_cpp_value}}; |
| 109 if (exception) |
| 110 goto fail; |
| 111 {% if attribute.is_call_with_execution_context or |
| 112 attribute.is_setter_call_with_execution_context %} |
| 113 |
| 114 ExecutionContext* context = DartUtilities::scriptExecutionContext(); |
| 115 if (!context) { |
| 116 exception = Dart_NewStringFromCString("Failed to retrieve a context"
); |
| 117 goto fail; |
| 118 } |
| 119 |
| 120 {% endif %} |
| 121 |
| 122 {% if attribute.is_call_with_script_state %} |
| 123 ScriptState* state = DartUtilities::currentScriptState(); |
| 124 if (!state) { |
| 125 exception = Dart_NewStringFromCString("Failed to retrieve a script s
tate"); |
| 126 goto fail; |
| 127 } |
| 128 {% endif %} |
| 129 {% if attribute.is_setter_raises_exception %} |
| 130 DartExceptionState es; |
| 131 {% endif %} |
| 132 {{attribute.cpp_setter}}; |
| 133 {% if attribute.is_setter_raises_exception %} |
| 134 if (es.hadException()) { |
| 135 exception = es.toDart(args, {{attribute.auto_scope}}); |
| 136 goto fail; |
| 137 } |
| 138 {% endif %} |
| 139 return; |
| 140 } |
| 141 |
| 142 fail: |
| 143 Dart_ThrowException(exception); |
| 144 ASSERT_NOT_REACHED(); |
| 145 {% endif %} |
| 146 } |
| 147 {% endmacro %} |
| 148 |
| 149 |
| 150 {######################################} |
| 151 {% macro generate_reflects(attribute) %} |
| 152 {% set reflect_only_values = attribute.reflect_only %} |
| 153 {% set reflect_missing = attribute.reflect_missing %} |
| 154 {% set reflect_invalid = attribute.reflect_invalid %} |
| 155 {% set reflect_empty = attribute.reflect_empty %} |
| 156 {% if attribute.cpp_type == 'DartStringAdapter' %} |
| 157 {% set native_type = 'String' %} |
| 158 {% else %} |
| 159 {% set native_type = attribute.cpp_type %} |
| 160 {% endif %} |
| 161 {{native_type}} result = {{attribute.cpp_value_original}}; |
| 162 |
| 163 {# Attribute is limited to only known values: check that the attribute value is |
| 164 one of those. If not, set it to the empty string. |
| 165 http://www.whatwg.org/specs/web-apps/current-work/#limited-to-only-known-valu
es #} |
| 166 {% if reflect_empty %} |
| 167 if (result.isNull()) { |
| 168 {% if reflect_missing %} |
| 169 result = "{{reflect_missing}}"; |
| 170 {% else %} |
| 171 ; |
| 172 {% endif %} |
| 173 } else if (result.isEmpty()) { |
| 174 result = "{{reflect_empty}}"; |
| 175 {% else %} |
| 176 if (result.isEmpty()) { |
| 177 {# FIXME: should use [ReflectEmpty] instead; need to change IDL files #} |
| 178 {% if reflect_missing %} |
| 179 result = "{{reflect_missing}}"; |
| 180 {% else %} |
| 181 ; |
| 182 {% endif %} |
| 183 {% endif %} |
| 184 {% for value in reflect_only_values %} |
| 185 } else if (equalIgnoringCase(result, "{{value}}")) { |
| 186 result = "{{value}}"; |
| 187 {% endfor %} |
| 188 } else { |
| 189 result = "{{reflect_invalid}}"; |
| 190 } |
| 191 |
| 192 {% endmacro %} |
| 193 |
| 194 |
| 195 {##############################################################################} |
| 196 {% macro static_attribute_name(attribute, setter_or_getter) -%} |
| 197 {{attribute.name}}{{setter_or_getter}} |
| 198 {%- endmacro -%} |
| 199 |
| 200 |
| 201 {##############################################################################} |
| 202 {% macro generate_attribute_resolver_body(dart_class, class_name, attribute) %} |
| 203 {% if not attribute.is_getter_suppressed %} |
| 204 if (argumentCount == 1 && name == "{{attribute.native_entry_getter.resolver_stri
ng}}") { |
| 205 *autoSetupScope = {{attribute.auto_scope}}; |
| 206 return {{dart_class}}Internal::{{static_attribute_name(attribute, 'Getter')}
}; |
| 207 } |
| 208 {% endif %} |
| 209 {# FIXME Disabling PutForwards for now #} |
| 210 {# {% if not attribute.is_read_only or attribute.put_forwards %} #} |
| 211 {% if not attribute.is_read_only and not attribute.is_setter_suppressed %} |
| 212 if (argumentCount == 2 && name == "{{attribute.native_entry_setter.resolver_stri
ng}}") { |
| 213 *autoSetupScope = {{attribute.auto_scope}}; |
| 214 return {{dart_class}}Internal::{{static_attribute_name(attribute, 'Setter')}
}; |
| 215 } |
| 216 {% endif %} |
| 217 {% endmacro %} |
| 218 |
| 219 {##############################################################################} |
| 220 {% macro generate_attribute_symbolizer_body(dart_class, class_name, attribute) %
} |
| 221 {% if not attribute.is_getter_suppressed %} |
| 222 if (nf == {{dart_class}}Internal::{{static_attribute_name(attribute, 'Getter')}}
) { |
| 223 return reinterpret_cast<const uint8_t*>("{{attribute.native_entry_getter.res
olver_string}}"); |
| 224 } |
| 225 {% endif %} |
| 226 {% if not attribute.is_read_only and not attribute.is_setter_suppressed %} |
| 227 if (nf == {{dart_class}}Internal::{{static_attribute_name(attribute, 'Setter')}}
) { |
| 228 return reinterpret_cast<const uint8_t*>("{{attribute.native_entry_setter.res
olver_string}}"); |
| 229 } |
| 230 {% endif %} |
| 231 {% endmacro %} |
| OLD | NEW |