| 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 "{{this_include_header_name}}.h" | 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 member.is_array_buffer_or_view_type %} | 7 {% if member.is_array_buffer_or_view_type %} |
| 8 if (v8Value->Is{{member.type_name}}()) { | 8 if (v8Value->Is{{member.type_name}}()) { |
| 9 {% else %} | 9 {% else %} |
| 10 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { | 10 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 { | 70 { |
| 71 if (v8Value.IsEmpty()) | 71 if (v8Value.IsEmpty()) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 {# The numbers in the following comments refer to the steps described in | 74 {# The numbers in the following comments refer to the steps described in |
| 75 http://heycam.github.io/webidl/#es-union #} | 75 http://heycam.github.io/webidl/#es-union #} |
| 76 {# 1. null or undefined #} | 76 {# 1. null or undefined #} |
| 77 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull
(v8Value)) | 77 if (conversionMode == UnionTypeConversionMode::Nullable && isUndefinedOrNull
(v8Value)) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 {# 3. Platform objects (interfaces) #} | 80 {% if dictionary_type %} |
| 81 {# 3. Dictionaries for null or undefined #} |
| 82 if (isUndefinedOrNull(v8Value)) { |
| 83 {{v8_value_to_local_cpp_value(dictionary_type) | indent(8)}} |
| 84 impl.set{{dictionary_type.type_name}}(cppValue); |
| 85 return; |
| 86 } |
| 87 |
| 88 {% endif %} |
| 89 {# 4. Platform objects (interfaces) #} |
| 81 {% for interface in interface_types %} | 90 {% for interface in interface_types %} |
| 82 {{assign_and_return_if_hasinstance(interface) | indent}} | 91 {{assign_and_return_if_hasinstance(interface) | indent}} |
| 83 | 92 |
| 84 {% endfor %} | 93 {% endfor %} |
| 85 {# 8. ArrayBuffer #} | 94 {# 8. ArrayBuffer #} |
| 86 {% if array_buffer_type %} | 95 {% if array_buffer_type %} |
| 87 {{assign_and_return_if_hasinstance(array_buffer_type) | indent}} | 96 {{assign_and_return_if_hasinstance(array_buffer_type) | indent}} |
| 88 | 97 |
| 89 {% endif %} | 98 {% endif %} |
| 90 {# 9., 10. ArrayBufferView #} | 99 {# 9., 10. ArrayBufferView #} |
| 91 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #} | 100 {# FIXME: Individual typed arrays (e.g. Uint8Array) aren't supported yet. #} |
| 92 {% if array_buffer_view_type %} | 101 {% if array_buffer_view_type %} |
| 93 {{assign_and_return_if_hasinstance(array_buffer_view_type) | indent}} | 102 {{assign_and_return_if_hasinstance(array_buffer_view_type) | indent}} |
| 94 | 103 |
| 95 {% endif %} | 104 {% endif %} |
| 96 {% if dictionary_type %} | 105 {% if array_or_sequence_type %} |
| 97 {# 12. Dictionaries #} | 106 {# 12.1, 12.2. Arrays and Sequences #} |
| 98 {# FIXME: This should also check "object but not Date or RegExp". Add checks | 107 {# FIXME: This should also check "object but not RegExp". Add checks |
| 99 when we implement conversions for Date and RegExp. #} | 108 when we implement conversions for Date and RegExp. #} |
| 100 {# TODO(bashi): The spec doesn't say we should check !IsArray() but otherwis
e | 109 {# TODO(bashi): Should check @@iterator symbol instead. #} |
| 101 we can't distinguish a sequence<T> and a dictionary. | |
| 102 https://github.com/heycam/webidl/issues/123 #} | |
| 103 if (isUndefinedOrNull(v8Value) || (v8Value->IsObject() && !v8Value->IsArray(
))) { | |
| 104 {{v8_value_to_local_cpp_value(dictionary_type) | indent(8)}} | |
| 105 impl.set{{dictionary_type.type_name}}(cppValue); | |
| 106 return; | |
| 107 } | |
| 108 | |
| 109 {% endif %} | |
| 110 {% if array_or_sequence_type %} | |
| 111 {# 13.1, 13.2. Arrays and Sequences #} | |
| 112 {# FIXME: This should also check "object but not Date or RegExp". Add checks | |
| 113 when we implement conversions for Date and RegExp. #} | |
| 114 {# FIXME: Should check for sequences too, not just Array instances. #} | |
| 115 if (v8Value->IsArray()) { | 110 if (v8Value->IsArray()) { |
| 116 {{v8_value_to_local_cpp_value(array_or_sequence_type) | indent(8)}} | 111 {{v8_value_to_local_cpp_value(array_or_sequence_type) | indent(8)}} |
| 117 impl.set{{array_or_sequence_type.type_name}}(cppValue); | 112 impl.set{{array_or_sequence_type.type_name}}(cppValue); |
| 118 return; | 113 return; |
| 119 } | 114 } |
| 120 | 115 |
| 121 {% endif %} | 116 {% endif %} |
| 122 {# TODO(bashi): Support 13.3 Callback interface when we need it #} | 117 {% if dictionary_type %} |
| 123 {# 13.4. Objects #} | 118 {# 12.3. Dictionaries #} |
| 119 if (v8Value->IsObject()) { |
| 120 {{v8_value_to_local_cpp_value(dictionary_type) | indent(8)}} |
| 121 impl.set{{dictionary_type.type_name}}(cppValue); |
| 122 return; |
| 123 } |
| 124 |
| 125 {% endif %} |
| 126 {# TODO(bashi): Support 12.4 Callback interface when we need it #} |
| 127 {# 12.5. Objects #} |
| 124 {% if object_type %} | 128 {% if object_type %} |
| 125 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { | 129 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { |
| 126 {{v8_value_to_local_cpp_value(object_type) | indent(8)}} | 130 {{v8_value_to_local_cpp_value(object_type) | indent(8)}} |
| 127 impl.set{{object_type.type_name}}(cppValue); | 131 impl.set{{object_type.type_name}}(cppValue); |
| 128 return; | 132 return; |
| 129 } | 133 } |
| 130 | 134 |
| 131 {% endif %} | 135 {% endif %} |
| 132 {# FIXME: In some cases, we can omit boolean and numeric type checks because | 136 {# FIXME: In some cases, we can omit boolean and numeric type checks because |
| 133 we have fallback conversions. (step 17 and 18) #} | 137 we have fallback conversions. (step 16 and 17) #} |
| 134 {% if boolean_type %} | 138 {% if boolean_type %} |
| 135 {# 14. Boolean #} | 139 {# 13. Boolean #} |
| 136 if (v8Value->IsBoolean()) { | 140 if (v8Value->IsBoolean()) { |
| 137 impl.setBoolean(v8Value.As<v8::Boolean>()->Value()); | 141 impl.setBoolean(v8Value.As<v8::Boolean>()->Value()); |
| 138 return; | 142 return; |
| 139 } | 143 } |
| 140 | 144 |
| 141 {% endif %} | 145 {% endif %} |
| 142 {% if numeric_type %} | 146 {% if numeric_type %} |
| 143 {# 15. Number #} | 147 {# 14. Number #} |
| 144 if (v8Value->IsNumber()) { | 148 if (v8Value->IsNumber()) { |
| 145 {{v8_value_to_local_cpp_value(numeric_type) | indent(8)}} | 149 {{v8_value_to_local_cpp_value(numeric_type) | indent(8)}} |
| 146 impl.set{{numeric_type.type_name}}(cppValue); | 150 impl.set{{numeric_type.type_name}}(cppValue); |
| 147 return; | 151 return; |
| 148 } | 152 } |
| 149 | 153 |
| 150 {% endif %} | 154 {% endif %} |
| 151 {% if string_type %} | 155 {% if string_type %} |
| 152 {# 16. String #} | 156 {# 15. String #} |
| 153 { | 157 { |
| 154 {{v8_value_to_local_cpp_value(string_type) | indent(8)}} | 158 {{v8_value_to_local_cpp_value(string_type) | indent(8)}} |
| 155 {% if string_type.enum_values %} | 159 {% if string_type.enum_values %} |
| 156 {{declare_enum_validation_variable(string_type.enum_values) | indent(8)}
} | 160 {{declare_enum_validation_variable(string_type.enum_values) | indent(8)}
} |
| 157 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "
{{string_type.type_name}}", exceptionState)) | 161 if (!isValidEnum(cppValue, validValues, WTF_ARRAY_LENGTH(validValues), "
{{string_type.type_name}}", exceptionState)) |
| 158 return; | 162 return; |
| 159 {% endif %} | 163 {% endif %} |
| 160 impl.set{{string_type.type_name}}(cppValue); | 164 impl.set{{string_type.type_name}}(cppValue); |
| 161 return; | 165 return; |
| 162 } | 166 } |
| 163 | 167 |
| 164 {# 17. Number (fallback) #} | 168 {# 16. Number (fallback) #} |
| 165 {% elif numeric_type %} | 169 {% elif numeric_type %} |
| 166 { | 170 { |
| 167 {{v8_value_to_local_cpp_value(numeric_type) | indent(8)}} | 171 {{v8_value_to_local_cpp_value(numeric_type) | indent(8)}} |
| 168 impl.set{{numeric_type.type_name}}(cppValue); | 172 impl.set{{numeric_type.type_name}}(cppValue); |
| 169 return; | 173 return; |
| 170 } | 174 } |
| 171 | 175 |
| 172 {# 18. Boolean (fallback) #} | 176 {# 17. Boolean (fallback) #} |
| 173 {% elif boolean_type %} | 177 {% elif boolean_type %} |
| 174 { | 178 { |
| 175 impl.setBoolean(v8Value->BooleanValue()); | 179 impl.setBoolean(v8Value->BooleanValue()); |
| 176 return; | 180 return; |
| 177 } | 181 } |
| 178 | 182 |
| 179 {% else %} | 183 {% else %} |
| 180 {# 19. TypeError #} | 184 {# 18. TypeError #} |
| 181 exceptionState.throwTypeError("The provided value is not of type '{{type_str
ing}}'"); | 185 exceptionState.throwTypeError("The provided value is not of type '{{type_str
ing}}'"); |
| 182 {% endif %} | 186 {% endif %} |
| 183 } | 187 } |
| 184 | 188 |
| 185 v8::Local<v8::Value> toV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat
ionContext, v8::Isolate* isolate) | 189 v8::Local<v8::Value> toV8(const {{cpp_class}}& impl, v8::Local<v8::Object> creat
ionContext, v8::Isolate* isolate) |
| 186 { | 190 { |
| 187 switch (impl.m_type) { | 191 switch (impl.m_type) { |
| 188 case {{cpp_class}}::SpecificTypeNone: | 192 case {{cpp_class}}::SpecificTypeNone: |
| 189 {# FIXME: We might want to return undefined in some cases #} | 193 {# FIXME: We might want to return undefined in some cases #} |
| 190 return v8::Null(isolate); | 194 return v8::Null(isolate); |
| 191 {% for member in members %} | 195 {% for member in members %} |
| 192 case {{cpp_class}}::{{member.specific_type_enum}}: | 196 case {{cpp_class}}::{{member.specific_type_enum}}: |
| 193 return {{member.cpp_value_to_v8_value}}; | 197 return {{member.cpp_value_to_v8_value}}; |
| 194 {% endfor %} | 198 {% endfor %} |
| 195 default: | 199 default: |
| 196 ASSERT_NOT_REACHED(); | 200 ASSERT_NOT_REACHED(); |
| 197 } | 201 } |
| 198 return v8::Local<v8::Value>(); | 202 return v8::Local<v8::Value>(); |
| 199 } | 203 } |
| 200 | 204 |
| 201 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) | 205 {{cpp_class}} NativeValueTraits<{{cpp_class}}>::nativeValue(v8::Isolate* isolate
, v8::Local<v8::Value> value, ExceptionState& exceptionState) |
| 202 { | 206 { |
| 203 {{cpp_class}} impl; | 207 {{cpp_class}} impl; |
| 204 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::NotNulla
ble, exceptionState); | 208 {{v8_class}}::toImpl(isolate, value, impl, UnionTypeConversionMode::NotNulla
ble, exceptionState); |
| 205 return impl; | 209 return impl; |
| 206 } | 210 } |
| 207 | 211 |
| 208 } // namespace blink | 212 } // namespace blink |
| OLD | NEW |