Chromium Code Reviews

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

Issue 577303002: IDL: Support [DeprecateAs] and [MeasureAs] on constants (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 {##############################################################################}
2 {% macro constant_getter_callback(constant) %}
3 {% filter conditional(constant.conditional_string) %}
4 static void {{constant.name}}AttributeGetterCallback(v8::Local<v8::String>, cons t v8::PropertyCallbackInfo<v8::Value>& info)
5 {
6 TRACE_EVENT_SET_SAMPLING_STATE("blink", "DOMGetter");
7 {% if constant.deprecate_as %}
8 UseCounter::countDeprecation(callingExecutionContext(info.GetIsolate()), Use Counter::{{constant.deprecate_as}});
9 {% endif %}
10 {% if constant.measure_as %}
11 UseCounter::count(callingExecutionContext(info.GetIsolate()), UseCounter::{{ constant.measure_as}});
12 {% endif %}
13 {% if constant.idl_type in ('Double', 'Float') %}
14 v8SetReturnValue(info, {{constant.value}});
15 {% elif constant.idl_type == 'String' %}
16 v8SetReturnValueString(info, "{{constant.value}}");
17 {% else %}
18 v8SetReturnValueInt(info, {{constant.value}});
19 {% endif %}
20 TRACE_EVENT_SET_SAMPLING_STATE("v8", "V8Execution");
21 }
22 {% endfilter %}
23 {% endmacro %}
24
25
1 {######################################} 26 {######################################}
2 {% macro install_constants() %} 27 {% macro install_constants() %}
3 {% if has_constant_configuration %} 28 {% if constant_configuration_constants %}
4 {# Normal constants #} 29 {# Normal constants #}
5 static const V8DOMConfiguration::ConstantConfiguration {{v8_class}}Constants[] = { 30 static const V8DOMConfiguration::ConstantConfiguration {{v8_class}}Constants[] = {
6 {% for constant in constants if not constant.runtime_enabled_function %} 31 {% for constant in constant_configuration_constants %}
7 {% if constant.idl_type in ('Double', 'Float') %} 32 {% if constant.idl_type in ('Double', 'Float') %}
8 {% set value = '0, %s, 0' % constant.value %} 33 {% set value = '0, %s, 0' % constant.value %}
9 {% elif constant.idl_type == 'String' %} 34 {% elif constant.idl_type == 'String' %}
10 {% set value = '0, 0, %s' % constant.value %} 35 {% set value = '0, 0, "%s"' % constant.value %}
11 {% else %} 36 {% else %}
12 {# 'Short', 'Long' etc. #} 37 {# 'Short', 'Long' etc. #}
13 {% set value = '%s, 0, 0' % constant.value %} 38 {% set value = '%s, 0, 0' % constant.value %}
14 {% endif %} 39 {% endif %}
15 {"{{constant.name}}", {{value}}, V8DOMConfiguration::ConstantType{{constant. idl_type}}}, 40 {"{{constant.name}}", {{value}}, V8DOMConfiguration::ConstantType{{constant. idl_type}}},
16 {% endfor %} 41 {% endfor %}
17 }; 42 };
18 V8DOMConfiguration::installConstants(functionTemplate, prototypeTemplate, {{v8_c lass}}Constants, WTF_ARRAY_LENGTH({{v8_class}}Constants), isolate); 43 V8DOMConfiguration::installConstants(functionTemplate, prototypeTemplate, {{v8_c lass}}Constants, WTF_ARRAY_LENGTH({{v8_class}}Constants), isolate);
19 {% endif %} 44 {% endif %}
20 {# Runtime-enabled constants #} 45 {# Runtime-enabled constants #}
21 {% for constant in constants if constant.runtime_enabled_function %} 46 {% for constant in runtime_enabled_constants %}
22 if ({{constant.runtime_enabled_function}}()) { 47 {% filter runtime_enabled(constant.runtime_enabled_function) %}
23 {% if constant.idl_type in ('Double', 'Float') %} 48 {% if constant.idl_type in ('Double', 'Float') %}
24 {% set value = '0, %s, 0' % constant.value %} 49 {% set value = '0, %s, 0' % constant.value %}
25 {% elif constant.idl_type == 'String' %} 50 {% elif constant.idl_type == 'String' %}
26 {% set value = '0, 0, %s' % constant.value %} 51 {% set value = '0, 0, %s' % constant.value %}
27 {% else %} 52 {% else %}
28 {# 'Short', 'Long' etc. #} 53 {# 'Short', 'Long' etc. #}
29 {% set value = '%s, 0, 0' % constant.value %} 54 {% set value = '%s, 0, 0' % constant.value %}
30 {% endif %} 55 {% endif %}
31 static const V8DOMConfiguration::ConstantConfiguration constantConfiguration = {"{{constant.name}}", {{value}}, V8DOMConfiguration::ConstantType{{constant.i dl_type}}}; 56 static const V8DOMConfiguration::ConstantConfiguration constantConfiguration = { "{{constant.name}}", {{value}}, V8DOMConfiguration::ConstantType{{constant.idl_t ype}}};
32 V8DOMConfiguration::installConstants(functionTemplate, prototypeTemplate, &c onstantConfiguration, 1, isolate); 57 V8DOMConfiguration::installConstants(functionTemplate, prototypeTemplate, &const antConfiguration, 1, isolate);
33 } 58 {% endfilter %}
59 {% endfor %}
60 {# Constants with [DeprecateAs] or [MeasureAs] #}
61 {% for constant in special_getter_constants %}
62 V8DOMConfiguration::installConstant(functionTemplate, prototypeTemplate, "{{cons tant.name}}", {{cpp_class}}V8Internal::{{constant.name}}ConstantGetterCallback, isolate);
34 {% endfor %} 63 {% endfor %}
35 {# Check constants #} 64 {# Check constants #}
36 {% if not do_not_check_constants %} 65 {% if not do_not_check_constants %}
37 {% for constant in constants %} 66 {% for constant in constants %}
38 {% if constant.idl_type not in ('Double', 'Float', 'String') %} 67 {% if constant.idl_type not in ('Double', 'Float', 'String') %}
39 {% set constant_cpp_class = constant.cpp_class or cpp_class %} 68 {% set constant_cpp_class = constant.cpp_class or cpp_class %}
40 COMPILE_ASSERT({{constant.value}} == {{constant_cpp_class}}::{{constant.reflecte d_name}}, TheValueOf{{cpp_class}}_{{constant.reflected_name}}DoesntMatchWithImpl ementation); 69 COMPILE_ASSERT({{constant.value}} == {{constant_cpp_class}}::{{constant.reflecte d_name}}, TheValueOf{{cpp_class}}_{{constant.reflected_name}}DoesntMatchWithImpl ementation);
41 {% endif %} 70 {% endif %}
42 {% endfor %} 71 {% endfor %}
43 {% endif %} 72 {% endif %}
44 {% endmacro %} 73 {% endmacro %}
OLDNEW

Powered by Google App Engine