mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
245 lines
8.8 KiB
Plaintext
245 lines
8.8 KiB
Plaintext
{% extends 'interface_base_cpp.template' %}
|
|
|
|
|
|
{# TODO(terry): Implement setter and deleter too #}
|
|
|
|
|
|
{##############################################################################}
|
|
{% block named_property_getter %}
|
|
{% if named_property_getter and not named_property_getter.is_custom %}
|
|
static void namedPropertyGetter(Dart_NativeArguments args)
|
|
{
|
|
{{cpp_class}}* /* FIXME(vsm): Remove this. */ ALLOW_UNUSED receiver = GetReceiver<{{cpp_class}}>(args);
|
|
Dart_Handle exception = nullptr;
|
|
{
|
|
{% if named_property_getter.is_raises_exception %}
|
|
ExceptionState es;
|
|
{% endif %}
|
|
|
|
String name = DartConverter<String>::FromArguments(args, 1, exception);
|
|
if (exception)
|
|
goto fail;
|
|
{{named_property_getter.cpp_type}} result = {{named_property_getter.cpp_value}};
|
|
if (!result)
|
|
return;
|
|
{{named_property_getter.dart_set_return_value}};
|
|
return;
|
|
}
|
|
|
|
fail:
|
|
Dart_ThrowException(exception);
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block named_property_setter %}
|
|
{% if named_property_setter and not named_property_setter.is_custom %}
|
|
static void namedPropertySetter(Dart_NativeArguments args)
|
|
{
|
|
{{cpp_class}}* /* FIXME(vsm): Remove this. */ ALLOW_UNUSED receiver = GetReceiver<{{cpp_class}}>(args);
|
|
Dart_Handle exception = nullptr;
|
|
{
|
|
{% if named_property_setter.is_raises_exception %}
|
|
ExceptionState es;
|
|
{% endif %}
|
|
|
|
String name = DartConverter<String>::FromArguments(args, 1, exception);
|
|
if (exception)
|
|
goto fail;
|
|
String value = DartConverter<String>::FromArgumentsWithNullCheck(args, 2, exception);
|
|
if (exception)
|
|
goto fail;
|
|
{{named_property_setter.cpp_value}};
|
|
return;
|
|
}
|
|
|
|
fail:
|
|
Dart_ThrowException(exception);
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block indexed_property_getter %}
|
|
{% if indexed_property_getter and not indexed_property_getter.is_custom %}
|
|
{% set getter = indexed_property_getter %}
|
|
static void indexedPropertyGetter(Dart_NativeArguments args)
|
|
{
|
|
{{cpp_class}}* /* FIXME(vsm): Remove this. */ ALLOW_UNUSED receiver = GetReceiver<{{cpp_class}}>(args);
|
|
Dart_Handle exception = nullptr;
|
|
{
|
|
{% if indexed_property_getter.is_raises_exception %}
|
|
ExceptionState es;
|
|
{% endif %}
|
|
|
|
{# TODO(terry): Assume index is unsigned long, which all currently are. #}
|
|
unsigned index = DartConverter<unsigned>::FromArguments(args, 1, exception);
|
|
if (exception)
|
|
goto fail;
|
|
{{indexed_property_getter.cpp_type}} result = {{indexed_property_getter.cpp_value}};
|
|
if (!result)
|
|
return;
|
|
{{indexed_property_getter.dart_set_return_value}};
|
|
|
|
return;
|
|
}
|
|
|
|
fail:
|
|
Dart_ThrowException(exception);
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
|
|
{% endif %}
|
|
{# TODO(terry): Should handle custom index getter - none today. #}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block indexed_property_getter_resolver %}
|
|
{# TODO(terry): Support all indexed and named properties today only indexed getter is supported. #}
|
|
{# Resolver indexed properties #}
|
|
{% if indexed_property_getter and not indexed_property_getter.is_custom %}
|
|
{% for native_entry in indexed_property_getter.native_entries %}
|
|
{% set resolver_string = native_entry.resolver_string %}
|
|
if (argumentCount == 2 && name == "{{resolver_string}}") {
|
|
*autoSetupScope = true;
|
|
return {{dart_class}}Internal::indexedPropertyGetter;
|
|
}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block named_property_getter_resolver %}
|
|
{# Resolver named properties #}
|
|
{% if named_property_getter and not named_property_getter.is_custom %}
|
|
{% for native_entry in named_property_getter.native_entries %}
|
|
{% set resolver_string = native_entry.resolver_string %}
|
|
if (argumentCount == 2 && (name == "{{resolver_string}}")) {
|
|
*autoSetupScope = true;
|
|
return {{dart_class}}Internal::namedPropertyGetter;
|
|
}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block named_property_setter_resolver %}
|
|
{# Resolver named properties #}
|
|
{% if named_property_setter and not named_property_setter.is_custom %}
|
|
{% for native_entry in named_property_setter.native_entries %}
|
|
{% set resolver_string = native_entry.resolver_string %}
|
|
if (argumentCount == 3 && (name == "{{resolver_string}}")) {
|
|
*autoSetupScope = true;
|
|
return {{dart_class}}Internal::namedPropertySetter;
|
|
}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block generate_symbolizer_indexed_property_getter %}
|
|
{% if indexed_property_getter and not indexed_property_getter.is_custom %}
|
|
{% for native_entry in indexed_property_getter.native_entries %}
|
|
{% set resolver_string = native_entry.resolver_string %}
|
|
if (native_function == {{dart_class}}Internal::indexedPropertyGetter) {
|
|
return reinterpret_cast<const uint8_t*>("{{resolver_string}}");
|
|
}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block generate_symbolizer_named_property_getter %}
|
|
{% if named_property_getter %}
|
|
{% for native_entry in named_property_getter.native_entries %}
|
|
{% set resolver_string = native_entry.resolver_string %}
|
|
if (native_function == {{dart_class}}Internal::namedPropertyGetter) {
|
|
return reinterpret_cast<const uint8_t*>("{{resolver_string}}");
|
|
}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
{% block generate_symbolizer_named_property_setter %}
|
|
{% if named_property_setter %}
|
|
{% for native_entry in named_property_setter.native_entries %}
|
|
{% set resolver_string = native_entry.resolver_string %}
|
|
if (native_function == {{dart_class}}Internal::namedPropertySetter) {
|
|
return reinterpret_cast<const uint8_t*>("{{resolver_string}}");
|
|
}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
{##############################################################################}
|
|
|
|
{% from 'methods_cpp.template' import static_method_name with context %}
|
|
|
|
{##############################################################################}
|
|
{% block overloaded_constructor %}
|
|
{% if constructor_overloads %}
|
|
static void constructorCallbackDispatcher(Dart_NativeArguments args)
|
|
{
|
|
Dart_Handle exception = nullptr;
|
|
const int argOffset = 0;
|
|
int argCount = Dart_GetNativeArgumentCount(args) + argOffset;
|
|
{# 2. Initialize argcount to be min(maxarg, n). #}
|
|
switch (std::min({{constructor_overloads.maxarg}}, argCount)) {
|
|
{# 3. Remove from S all entries whose type list is not of length argcount. #}
|
|
{% for length, tests_constructors in constructor_overloads.length_tests_methods %}
|
|
case {{length}}:
|
|
{# Then resolve by testing argument #}
|
|
{% for test, constructor in tests_constructors %}
|
|
{# 10. If i = d, then: #}
|
|
if ({{test}}) {
|
|
{% if constructor.is_custom %}
|
|
{{static_method_name(constructor.name)}}(args);
|
|
{% else %}
|
|
{{static_method_name(constructor.name, constructor.overload_index)}}(args);
|
|
{% endif %}
|
|
return;
|
|
}
|
|
{% endfor %}
|
|
break;
|
|
{% endfor %}
|
|
default:
|
|
{# Invalid arity, throw error #}
|
|
{# Report full list of valid arities if gaps and above minimum #}
|
|
{% if constructor_overloads.valid_arities %}
|
|
if (argCount >= {{overloads.minarg}}) {
|
|
const String message = "Wrong arity, expected one of {{constructor_overloads.valid_arities}}";
|
|
// TODO(dart): exception = DartUtilities::coreArgumentErrorException(message);
|
|
goto fail;
|
|
}
|
|
{% endif %}
|
|
{# Otherwise just report "not enough arguments" #}
|
|
{
|
|
const String message = "Not enough arguments (at least {{constructor_overloads.minarg}} required)";
|
|
// TODO(dart): exception = DartUtilities::coreArgumentErrorException(message);
|
|
goto fail;
|
|
}
|
|
return;
|
|
}
|
|
{# No match, throw error #}
|
|
{
|
|
const String message = "No matching constructor signature.";
|
|
// TODO(dart): exception = DartUtilities::coreArgumentErrorException(message);
|
|
goto fail;
|
|
}
|
|
return;
|
|
fail:
|
|
Dart_ThrowException(exception);
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
{% endif %}
|
|
{% endblock %}
|
|
|
|
|
|
{##############################################################################}
|