| OLD | NEW |
| 1 {% from 'utilities.cpp' import declare_enum_validation_variable %} | 1 {% from 'utilities.cpp' import declare_enum_validation_variable %} |
| 2 {% include 'copyright_block.txt' %} | 2 {% include 'copyright_block.txt' %} |
| 3 #include "{{header_filename}}" | 3 #include "{{this_include_header_name}}.h" |
| 4 | 4 |
| 5 {% from 'utilities.cpp' import v8_value_to_local_cpp_value %} | 5 {% from 'utilities.cpp' import v8_value_to_local_cpp_value %} |
| 6 {% macro assign_and_return_if_hasinstance(member) %} | 6 {% macro assign_and_return_if_hasinstance(member) %} |
| 7 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { | 7 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { |
| 8 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Loca
l<v8::Object>::Cast(v8Value)); | 8 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Loca
l<v8::Object>::Cast(v8Value)); |
| 9 impl.set{{member.type_name}}(cppValue); | 9 impl.set{{member.type_name}}(cppValue); |
| 10 return; | 10 return; |
| 11 } | 11 } |
| 12 {% endmacro %} | 12 {% endmacro %} |
| 13 {% for filename in cpp_includes %} | 13 {% for filename in cpp_includes %} |
| 14 #include "{{filename}}" | 14 #include "{{filename}}" |
| 15 {% endfor %} | 15 {% endfor %} |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 {% for container in containers %} | 19 {{cpp_class}}::{{cpp_class}}() |
| 20 {{container.cpp_class}}::{{container.cpp_class}}() | |
| 21 : m_type(SpecificTypeNone) | 20 : m_type(SpecificTypeNone) |
| 22 { | 21 { |
| 23 } | 22 } |
| 24 | 23 |
| 25 {% for member in container.members %} | 24 {% for member in members %} |
| 26 {{member.rvalue_cpp_type}} {{container.cpp_class}}::getAs{{member.type_name}}()
const | 25 {{member.rvalue_cpp_type}} {{cpp_class}}::getAs{{member.type_name}}() const |
| 27 { | 26 { |
| 28 ASSERT(is{{member.type_name}}()); | 27 ASSERT(is{{member.type_name}}()); |
| 29 return m_{{member.cpp_name}}; | 28 return m_{{member.cpp_name}}; |
| 30 } | 29 } |
| 31 | 30 |
| 32 void {{container.cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}}
value) | 31 void {{cpp_class}}::set{{member.type_name}}({{member.rvalue_cpp_type}} value) |
| 33 { | 32 { |
| 34 ASSERT(isNull()); | 33 ASSERT(isNull()); |
| 35 {% if member.enum_values %} | 34 {% if member.enum_values %} |
| 36 NonThrowableExceptionState exceptionState; | 35 NonThrowableExceptionState exceptionState; |
| 37 {{declare_enum_validation_variable(member.enum_values) | indent}} | 36 {{declare_enum_validation_variable(member.enum_values) | indent}} |
| 38 if (!isValidEnum(value, validValues, WTF_ARRAY_LENGTH(validValues), "{{membe
r.type_name}}", exceptionState)) { | 37 if (!isValidEnum(value, validValues, WTF_ARRAY_LENGTH(validValues), "{{membe
r.type_name}}", exceptionState)) { |
| 39 ASSERT_NOT_REACHED(); | 38 ASSERT_NOT_REACHED(); |
| 40 return; | 39 return; |
| 41 } | 40 } |
| 42 {% endif %} | 41 {% endif %} |
| 43 m_{{member.cpp_name}} = value; | 42 m_{{member.cpp_name}} = value; |
| 44 m_type = {{member.specific_type_enum}}; | 43 m_type = {{member.specific_type_enum}}; |
| 45 } | 44 } |
| 46 | 45 |
| 47 {{container.cpp_class}} {{container.cpp_class}}::from{{member.type_name}}({{memb
er.rvalue_cpp_type}} value) | 46 {{cpp_class}} {{cpp_class}}::from{{member.type_name}}({{member.rvalue_cpp_type}}
value) |
| 48 { | 47 { |
| 49 {{container.cpp_class}} container; | 48 {{cpp_class}} container; |
| 50 container.set{{member.type_name}}(value); | 49 container.set{{member.type_name}}(value); |
| 51 return container; | 50 return container; |
| 52 } | 51 } |
| 53 | 52 |
| 54 {% endfor %} | 53 {% endfor %} |
| 55 {{container.cpp_class}}::{{container.cpp_class}}(const {{container.cpp_class}}&)
= default; | 54 {{cpp_class}}::{{cpp_class}}(const {{cpp_class}}&) = default; |
| 56 {{container.cpp_class}}::~{{container.cpp_class}}() = default; | 55 {{cpp_class}}::~{{cpp_class}}() = default; |
| 57 {{container.cpp_class}}& {{container.cpp_class}}::operator=(const {{container.cp
p_class}}&) = default; | 56 {{cpp_class}}& {{cpp_class}}::operator=(const {{cpp_class}}&) = default; |
| 58 | 57 |
| 59 DEFINE_TRACE({{container.cpp_class}}) | 58 DEFINE_TRACE({{cpp_class}}) |
| 60 { | 59 { |
| 61 {% for member in container.members if member.is_traceable %} | 60 {% for member in members if member.is_traceable %} |
| 62 visitor->trace(m_{{member.cpp_name}}); | 61 visitor->trace(m_{{member.cpp_name}}); |
| 63 {% endfor %} | 62 {% endfor %} |
| 64 } | 63 } |
| 65 | 64 |
| 66 void V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value
> v8Value, {{container.cpp_class}}& impl, UnionTypeConversionMode conversionMode
, ExceptionState& exceptionState) | 65 void {{v8_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value> v8Value, {{
cpp_class}}& impl, UnionTypeConversionMode conversionMode, ExceptionState& excep
tionState) |
| 67 { | 66 { |
| 68 if (v8Value.IsEmpty()) | 67 if (v8Value.IsEmpty()) |
| 69 return; | 68 return; |
| 70 | 69 |
| 71 {# The numbers in the following comments refer to the steps described in | 70 {# The numbers in the following comments refer to the steps described in |
| 72 http://heycam.github.io/webidl/#es-union #} | 71 http://heycam.github.io/webidl/#es-union #} |
| 73 {# 1. null or undefined #} | 72 {# 1. null or undefined #} |
| 74 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull
(v8Value)) | 73 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull
(v8Value)) |
| 75 return; | 74 return; |
| 76 | 75 |
| 77 {# 3. Platform objects (interfaces) #} | 76 {# 3. Platform objects (interfaces) #} |
| 78 {% for interface in container.interface_types %} | 77 {% for interface in interface_types %} |
| 79 {{assign_and_return_if_hasinstance(interface) | indent}} | 78 {{assign_and_return_if_hasinstance(interface) | indent}} |
| 80 | 79 |
| 81 {% endfor %} | 80 {% endfor %} |
| 82 {# 8. ArrayBuffer #} | 81 {# 8. ArrayBuffer #} |
| 83 {% if container.array_buffer_type %} | 82 {% if array_buffer_type %} |
| 84 {{assign_and_return_if_hasinstance(container.array_buffer_type) | indent}} | 83 {{assign_and_return_if_hasinstance(array_buffer_type) | indent}} |
| 85 | 84 |
| 86 {% endif %} | 85 {% endif %} |
| 87 {# 9., 10. ArrayBufferView #} | 86 {# 9., 10. ArrayBufferView #} |
| 88 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #} | 87 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #} |
| 89 {% if container.array_buffer_view_type %} | 88 {% if array_buffer_view_type %} |
| 90 {{assign_and_return_if_hasinstance(container.array_buffer_view_type) | inden
t}} | 89 {{assign_and_return_if_hasinstance(array_buffer_view_type) | indent}} |
| 91 | 90 |
| 92 {% endif %} | 91 {% endif %} |
| 93 {% if container.dictionary_type %} | 92 {% if dictionary_type %} |
| 94 {# 12. Dictionaries #} | 93 {# 12. Dictionaries #} |
| 95 {# FIXME: This should also check "object but not Date or RegExp". Add checks | 94 {# FIXME: This should also check "object but not Date or RegExp". Add checks |
| 96 when we implement conversions for Date and RegExp. #} | 95 when we implement conversions for Date and RegExp. #} |
| 97 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { | 96 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { |
| 98 {{v8_value_to_local_cpp_value(container.dictionary_type) | indent(8)}} | 97 {{v8_value_to_local_cpp_value(dictionary_type) | indent(8)}} |
| 99 impl.set{{container.dictionary_type.type_name}}(cppValue); | 98 impl.set{{dictionary_type.type_name}}(cppValue); |
| 100 return; | 99 return; |
| 101 } | 100 } |
| 102 | 101 |
| 103 {% endif %} | 102 {% endif %} |
| 104 {% if container.array_or_sequence_type %} | 103 {% if array_or_sequence_type %} |
| 105 {# 13.1, 13.2. Arrays and Sequences #} | 104 {# 13.1, 13.2. Arrays and Sequences #} |
| 106 {# FIXME: This should also check "object but not Date or RegExp". Add checks | 105 {# FIXME: This should also check "object but not Date or RegExp". Add checks |
| 107 when we implement conversions for Date and RegExp. #} | 106 when we implement conversions for Date and RegExp. #} |
| 108 {# FIXME: Should check for sequences too, not just Array instances. #} | 107 {# FIXME: Should check for sequences too, not just Array instances. #} |
| 109 if (v8Value->IsArray()) { | 108 if (v8Value->IsArray()) { |
| 110 {{v8_value_to_local_cpp_value(container.array_or_sequence_type) | indent
(8)}} | 109 {{v8_value_to_local_cpp_value(array_or_sequence_type) | indent(8)}} |
| 111 impl.set{{container.array_or_sequence_type.type_name}}(cppValue); | 110 impl.set{{array_or_sequence_type.type_name}}(cppValue); |
| 112 return; | 111 return; |
| 113 } | 112 } |
| 114 | 113 |
| 115 {% endif %} | 114 {% endif %} |
| 116 {# TODO(bashi): Support 13.3 Callback interface when we need it #} | 115 {# TODO(bashi): Support 13.3 Callback interface when we need it #} |
| 117 {# 13.4. Objects #} | 116 {# 13.4. Objects #} |
| 118 {% if container.object_type %} | 117 {% if object_type %} |
| 119 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { | 118 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { |
| 120 {{v8_value_to_local_cpp_value(container.object_type) | indent(8)}} | 119 {{v8_value_to_local_cpp_value(object_type) | indent(8)}} |
| 121 impl.set{{container.object_type.type_name}}(cppValue); | 120 impl.set{{object_type.type_name}}(cppValue); |
| 122 return; | 121 return; |
| 123 } | 122 } |
| 124 | 123 |
| 125 {% endif %} | 124 {% endif %} |
| 126 {# FIXME: In some cases, we can omit boolean and numeric type checks because | 125 {# FIXME: In some cases, we can omit boolean and numeric type checks because |
| 127 we have fallback conversions. (step 17 and 18) #} | 126 we have fallback conversions. (step 17 and 18) #} |
| 128 {% if container.boolean_type %} | 127 {% if boolean_type %} |
| 129 {# 14. Boolean #} | 128 {# 14. Boolean #} |
| 130 if (v8Value->IsBoolean()) { | 129 if (v8Value->IsBoolean()) { |
| 131 impl.setBoolean(v8Value.As<v8::Boolean>()->Value()); | 130 impl.setBoolean(v8Value.As<v8::Boolean>()->Value()); |
| 132 return; | 131 return; |
| 133 } | 132 } |
| 134 | 133 |
| 135 {% endif %} | 134 {% endif %} |
| 136 {% if container.numeric_type %} | 135 {% if numeric_type %} |
| 137 {# 15. Number #} | 136 {# 15. Number #} |
| 138 if (v8Value->IsNumber()) { | 137 if (v8Value->IsNumber()) { |
| 139 {{v8_value_to_local_cpp_value(container.numeric_type) | indent(8)}} | 138 {{v8_value_to_local_cpp_value(numeric_type) | indent(8)}} |
| 140 impl.set{{container.numeric_type.type_name}}(cppValue); | 139 impl.set{{numeric_type.type_name}}(cppValue); |
| 141 return; | 140 return; |
| 142 } | 141 } |
| 143 | 142 |
| 144 {% endif %} | 143 {% endif %} |
| 145 {% if container.string_type %} | 144 {% if string_type %} |
| 146 {# 16. String #} | 145 {# 16. String #} |
| 147 { | 146 { |
| 148 {{v8_value_to_local_cpp_value(container.string_type) | indent(8)}} | 147 {{v8_value_to_local_cpp_value(string_type) | indent(8)}} |
| 149 {% if container.string_type.enum_values %} | 148 {% if string_type.enum_values %} |
| 150 {{declare_enum_validation_variable(container.string_type.enum_values) |
indent(8)}} | 149 {{declare_enum_validation_variable(string_type.enum_values) | indent(8)}
} |
| 151 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "
{{container.string_type.type_name}}", exceptionState)) | 150 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "
{{string_type.type_name}}", exceptionState)) |
| 152 return; | 151 return; |
| 153 {% endif %} | 152 {% endif %} |
| 154 impl.set{{container.string_type.type_name}}(cppValue); | 153 impl.set{{string_type.type_name}}(cppValue); |
| 155 return; | 154 return; |
| 156 } | 155 } |
| 157 | 156 |
| 158 {# 17. Number (fallback) #} | 157 {# 17. Number (fallback) #} |
| 159 {% elif container.numeric_type %} | 158 {% elif numeric_type %} |
| 160 { | 159 { |
| 161 {{v8_value_to_local_cpp_value(container.numeric_type) | indent(8)}} | 160 {{v8_value_to_local_cpp_value(numeric_type) | indent(8)}} |
| 162 impl.set{{container.numeric_type.type_name}}(cppValue); | 161 impl.set{{numeric_type.type_name}}(cppValue); |
| 163 return; | 162 return; |
| 164 } | 163 } |
| 165 | 164 |
| 166 {# 18. Boolean (fallback) #} | 165 {# 18. Boolean (fallback) #} |
| 167 {% elif container.boolean_type %} | 166 {% elif boolean_type %} |
| 168 { | 167 { |
| 169 impl.setBoolean(v8Value->BooleanValue()); | 168 impl.setBoolean(v8Value->BooleanValue()); |
| 170 return; | 169 return; |
| 171 } | 170 } |
| 172 | 171 |
| 173 {% else %} | 172 {% else %} |
| 174 {# 19. TypeError #} | 173 {# 19. TypeError #} |
| 175 exceptionState.throwTypeError("The provided value is not of type '{{containe
r.type_string}}'"); | 174 exceptionState.throwTypeError("The provided value is not of type '{{type_str
ing}}'"); |
| 176 {% endif %} | 175 {% endif %} |
| 177 } | 176 } |
| 178 | 177 |
| 179 v8::Local<v8::Value> toV8(const {{container.cpp_class}}& impl, v8::Local<v8::Obj
ect> creationContext, v8::Isolate* isolate) | 178 v8::Local<v8::Value> toV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat
ionContext, v8::Isolate* isolate) |
| 180 { | 179 { |
| 181 switch (impl.m_type) { | 180 switch (impl.m_type) { |
| 182 case {{container.cpp_class}}::SpecificTypeNone: | 181 case {{cpp_class}}::SpecificTypeNone: |
| 183 {# FIXME: We might want to return undefined in some cases #} | 182 {# FIXME: We might want to return undefined in some cases #} |
| 184 return v8::Null(isolate); | 183 return v8::Null(isolate); |
| 185 {% for member in container.members %} | 184 {% for member in members %} |
| 186 case {{container.cpp_class}}::{{member.specific_type_enum}}: | 185 case {{cpp_class}}::{{member.specific_type_enum}}: |
| 187 return {{member.cpp_value_to_v8_value}}; | 186 return {{member.cpp_value_to_v8_value}}; |
| 188 {% endfor %} | 187 {% endfor %} |
| 189 default: | 188 default: |
| 190 ASSERT_NOT_REACHED(); | 189 ASSERT_NOT_REACHED(); |
| 191 } | 190 } |
| 192 return v8::Local<v8::Value>(); | 191 return v8::Local<v8::Value>(); |
| 193 } | 192 } |
| 194 | 193 |
| 195 {{container.cpp_class}} NativeValueTraits<{{container.cpp_class}}>::nativeValue(
v8::Isolate* isolate, v8::Local<v8::Value> value, ExceptionState& exceptionState
) | 194 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) |
| 196 { | 195 { |
| 197 {{container.cpp_class}} impl; | 196 {{cpp_class}} impl; |
| 198 V8{{container.cpp_class}}::toImpl(isolate, value, impl, UnionTypeConversionM
ode::NotNullable, exceptionState); | 197 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::NotNulla
ble, exceptionState); |
| 199 return impl; | 198 return impl; |
| 200 } | 199 } |
| 201 | 200 |
| 202 {% endfor %} | |
| 203 } // namespace blink | 201 } // namespace blink |
| OLD | NEW |