| {% from 'methods.cpp.tmpl' import runtime_timer_scope_disabled_by_default %} |
| |
| {##############################################################################} |
| {% macro constant_getter_callback(constant) %} |
| void {{v8_class_or_partial}}::{{constant.name}}ConstantGetterCallback(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>& info) { |
| {{ runtime_timer_scope_disabled_by_default(constant.rcs_counter) }} |
| {% if constant.deprecate_as %} |
| Deprecation::CountDeprecation(CurrentExecutionContext(info.GetIsolate()), WebFeature::k{{constant.deprecate_as}}); |
| {% endif %} |
| {% if constant.measure_as %} |
| UseCounter::Count(CurrentExecutionContext(info.GetIsolate()), WebFeature::k{{constant.measure_as('ConstantGetter')}}); |
| {% endif %} |
| {% if constant.idl_type in ('Double', 'Float') %} |
| V8SetReturnValue(info, {{constant.value}}); |
| {% elif constant.idl_type == 'String' %} |
| V8SetReturnValueString(info, "{{constant.value}}"); |
| {% else %} |
| V8SetReturnValueInt(info, {{constant.value}}); |
| {% endif %} |
| } |
| {% endmacro %} |
| |
| |
| {######################################} |
| {% macro install_constants() %} |
| {% if constants | has_constant_configuration %} |
| {# Normal constants #} |
| static constexpr V8DOMConfiguration::ConstantConfiguration {{v8_class}}Constants[] = { |
| {% for constant in constants | has_constant_configuration %} |
| {{constant_configuration(constant)}}, |
| {% endfor %} |
| }; |
| V8DOMConfiguration::InstallConstants( |
| isolate, interfaceTemplate, prototypeTemplate, |
| {{v8_class}}Constants, base::size({{v8_class}}Constants)); |
| {% endif %} |
| {# Constants with [DeprecateAs] or [MeasureAs] #} |
| {% for constant in constants | has_special_getter %} |
| V8DOMConfiguration::InstallConstantWithGetter( |
| isolate, interfaceTemplate, prototypeTemplate, |
| "{{constant.name}}", {{v8_class_or_partial}}::{{constant.name}}ConstantGetterCallback); |
| {% endfor %} |
| {# Check constants #} |
| {% if not do_not_check_constants %} |
| {% for constant in constants %} |
| {% if constant.idl_type not in ('Double', 'Float', 'String') %} |
| {% set constant_cpp_class = constant.cpp_class or cpp_class %} |
| static_assert({{constant.value}} == {{constant_cpp_class}}::{{constant.reflected_name}}, "the value of {{cpp_class}}_{{constant.reflected_name}} does not match with implementation"); |
| {% endif %} |
| {% endfor %} |
| {% endif %} |
| {% endmacro %} |
| |
| |
| {######################################} |
| {%- macro constant_configuration(constant) %} |
| {# Explicitly select the correct overload to populate the union. #} |
| {% if constant.idl_type in ('Double', 'Float') %} |
| {% set value = 'static_cast<double>(%s)' % constant.value %} |
| {% else %} |
| {# 'Short', 'Long' etc. #} |
| {% set value = 'static_cast<int>(%s)' % constant.value %} |
| {% endif %} |
| {"{{constant.name}}", V8DOMConfiguration::kConstantType{{constant.idl_type}}, {{value}}} |
| {%- endmacro %} |