OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY! | 5 // This file has been auto-generated by {{code_generator}}. DO NOT MODIFY! |
6 | 6 |
7 #include "config.h" | 7 #include "config.h" |
8 #include "{{header_filename}}" | 8 #include "{{header_filename}}" |
9 | 9 |
10 {% macro assign_and_return_if_hasinstance(member) %} | 10 {% macro assign_and_return_if_hasinstance(member) %} |
11 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { | 11 if (V8{{member.type_name}}::hasInstance(v8Value, isolate)) { |
12 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Loca
l<v8::Object>::Cast(v8Value)); | 12 {{member.cpp_local_type}} cppValue = V8{{member.type_name}}::toImpl(v8::Loca
l<v8::Object>::Cast(v8Value)); |
13 impl.set{{member.type_name}}(cppValue); | 13 impl.set{{member.type_name}}(cppValue); |
14 return; | 14 return true; |
15 } | 15 } |
16 {% endmacro %} | 16 {% endmacro %} |
17 {% for filename in cpp_includes %} | 17 {% for filename in cpp_includes %} |
18 #include "{{filename}}" | 18 #include "{{filename}}" |
19 {% endfor %} | 19 {% endfor %} |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 | 22 |
23 {% for container in containers %} | 23 {% for container in containers %} |
24 {{container.cpp_class}}::{{container.cpp_class}}() | 24 {{container.cpp_class}}::{{container.cpp_class}}() |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 {% endfor %} | 57 {% endfor %} |
58 {% if container.needs_trace %} | 58 {% if container.needs_trace %} |
59 void {{container.cpp_class}}::trace(Visitor* visitor) | 59 void {{container.cpp_class}}::trace(Visitor* visitor) |
60 { | 60 { |
61 {% for member in container.members if member.is_traceable %} | 61 {% for member in container.members if member.is_traceable %} |
62 visitor->trace(m_{{member.cpp_name}}); | 62 visitor->trace(m_{{member.cpp_name}}); |
63 {% endfor %} | 63 {% endfor %} |
64 } | 64 } |
65 | 65 |
66 {% endif %} | 66 {% endif %} |
67 void V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value
> v8Value, {{container.cpp_class}}& impl, ExceptionState& exceptionState) | 67 bool V8{{container.cpp_class}}::toImpl(v8::Isolate* isolate, v8::Local<v8::Value
> v8Value, {{container.cpp_class}}& impl, ExceptionState& exceptionState) |
68 { | 68 { |
69 if (v8Value.IsEmpty()) | 69 if (v8Value.IsEmpty()) |
70 return; | 70 return true; |
71 | 71 |
72 {# The numbers in the following comments refer to the steps described in | 72 {# The numbers in the following comments refer to the steps described in |
73 http://heycam.github.io/webidl/#es-union | 73 http://heycam.github.io/webidl/#es-union |
74 NOTE: Step 1 (null or undefined) is handled in *OrNull::toImpl() | 74 NOTE: Step 1 (null or undefined) is handled in *OrNull::toImpl() |
75 FIXME: Implement all necessary steps #} | 75 FIXME: Implement all necessary steps #} |
76 {# 3. Platform objects (interfaces) #} | 76 {# 3. Platform objects (interfaces) #} |
77 {% for interface in container.interface_types %} | 77 {% for interface in container.interface_types %} |
78 {{assign_and_return_if_hasinstance(interface) | indent}} | 78 {{assign_and_return_if_hasinstance(interface) | indent}} |
79 | 79 |
80 {% endfor %} | 80 {% endfor %} |
(...skipping 11 matching lines...) Expand all Loading... |
92 {% if container.dictionary_type %} | 92 {% if container.dictionary_type %} |
93 {# 12. Dictionaries #} | 93 {# 12. Dictionaries #} |
94 {# 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 |
95 when we implement conversions for Date and RegExp. #} | 95 when we implement conversions for Date and RegExp. #} |
96 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { | 96 if (isUndefinedOrNull(v8Value) || v8Value->IsObject()) { |
97 {% if container.dictionary_type.type_name != 'Dictionary' %} | 97 {% if container.dictionary_type.type_name != 'Dictionary' %} |
98 {{container.dictionary_type.cpp_local_type}} cppValue; | 98 {{container.dictionary_type.cpp_local_type}} cppValue; |
99 {% endif %} | 99 {% endif %} |
100 {{container.dictionary_type.v8_value_to_local_cpp_value}}; | 100 {{container.dictionary_type.v8_value_to_local_cpp_value}}; |
101 impl.set{{container.dictionary_type.type_name}}(cppValue); | 101 impl.set{{container.dictionary_type.type_name}}(cppValue); |
102 return; | 102 return true; |
103 } | 103 } |
104 | 104 |
105 {% endif %} | 105 {% endif %} |
106 {% if container.array_or_sequence_type %} | 106 {% if container.array_or_sequence_type %} |
107 {# 13. Arrays/Sequences #} | 107 {# 13. Arrays/Sequences #} |
108 {# FIXME: This should also check "object but not Date or RegExp". Add checks | 108 {# FIXME: This should also check "object but not Date or RegExp". Add checks |
109 when we implement conversions for Date and RegExp. #} | 109 when we implement conversions for Date and RegExp. #} |
110 {# FIXME: Should check for sequences too, not just Array instances. #} | 110 {# FIXME: Should check for sequences too, not just Array instances. #} |
111 if (v8Value->IsArray()) { | 111 if (v8Value->IsArray()) { |
112 {{container.array_or_sequence_type.v8_value_to_local_cpp_value}}; | 112 {{container.array_or_sequence_type.v8_value_to_local_cpp_value}}; |
113 impl.set{{container.array_or_sequence_type.type_name}}(cppValue); | 113 impl.set{{container.array_or_sequence_type.type_name}}(cppValue); |
114 return; | 114 return true; |
115 } | 115 } |
116 | 116 |
117 {% endif %} | 117 {% endif %} |
118 {# FIXME: In some cases, we can omit boolean and numeric type checks because | 118 {# FIXME: In some cases, we can omit boolean and numeric type checks because |
119 we have fallback conversions. (step 17 and 18) #} | 119 we have fallback conversions. (step 17 and 18) #} |
120 {% if container.boolean_type %} | 120 {% if container.boolean_type %} |
121 {# 14. Boolean #} | 121 {# 14. Boolean #} |
122 if (v8Value->IsBoolean()) { | 122 if (v8Value->IsBoolean()) { |
123 impl.setBoolean(v8Value->ToBoolean()->Value()); | 123 impl.setBoolean(v8Value->ToBoolean()->Value()); |
124 return; | 124 return true; |
125 } | 125 } |
126 | 126 |
127 {% endif %} | 127 {% endif %} |
128 {% if container.numeric_type %} | 128 {% if container.numeric_type %} |
129 {# 15. Number #} | 129 {# 15. Number #} |
130 if (v8Value->IsNumber()) { | 130 if (v8Value->IsNumber()) { |
131 {{container.numeric_type.v8_value_to_local_cpp_value}}; | 131 {{container.numeric_type.v8_value_to_local_cpp_value}}; |
132 impl.set{{container.numeric_type.type_name}}(cppValue); | 132 impl.set{{container.numeric_type.type_name}}(cppValue); |
133 return; | 133 return true; |
134 } | 134 } |
135 | 135 |
136 {% endif %} | 136 {% endif %} |
137 {% if container.string_type %} | 137 {% if container.string_type %} |
138 {# 16. String #} | 138 {# 16. String #} |
139 { | 139 { |
140 {{container.string_type.v8_value_to_local_cpp_value}}; | 140 {{container.string_type.v8_value_to_local_cpp_value}}; |
141 {% if container.string_type.enum_validation_expression %} | 141 {% if container.string_type.enum_validation_expression %} |
142 String string = cppValue; | 142 String string = cppValue; |
143 if (!({{container.string_type.enum_validation_expression}})) { | 143 if (!({{container.string_type.enum_validation_expression}})) { |
144 exceptionState.throwTypeError("'" + string + "' is not a valid enum
value."); | 144 exceptionState.throwTypeError("'" + string + "' is not a valid enum
value."); |
145 return; | 145 return false; |
146 } | 146 } |
147 {% endif %} | 147 {% endif %} |
148 impl.set{{container.string_type.type_name}}(cppValue); | 148 impl.set{{container.string_type.type_name}}(cppValue); |
149 return; | 149 return true; |
150 } | 150 } |
151 | 151 |
152 {# 17. Number (fallback) #} | 152 {# 17. Number (fallback) #} |
153 {% elif container.numeric_type %} | 153 {% elif container.numeric_type %} |
154 { | 154 { |
155 {{container.numeric_type.v8_value_to_local_cpp_value}}; | 155 {{container.numeric_type.v8_value_to_local_cpp_value}}; |
156 impl.set{{container.numeric_type.type_name}}(cppValue); | 156 impl.set{{container.numeric_type.type_name}}(cppValue); |
157 return; | 157 return true; |
158 } | 158 } |
159 | 159 |
160 {# 18. Boolean (fallback) #} | 160 {# 18. Boolean (fallback) #} |
161 {% elif container.boolean_type %} | 161 {% elif container.boolean_type %} |
162 { | 162 { |
163 impl.setBoolean(v8Value->ToBoolean()->Value()); | 163 impl.setBoolean(v8Value->BooleanValue()); |
164 return; | 164 return true; |
165 } | 165 } |
166 | 166 |
167 {% else %} | 167 {% else %} |
168 {# 19. TypeError #} | 168 {# 19. TypeError #} |
169 exceptionState.throwTypeError("The provided value is not of type '{{containe
r.type_string}}'"); | 169 exceptionState.throwTypeError("The provided value is not of type '{{containe
r.type_string}}'"); |
| 170 return false; |
170 {% endif %} | 171 {% endif %} |
171 } | 172 } |
172 | 173 |
173 v8::Local<v8::Value> toV8(const {{container.cpp_class}}& impl, v8::Local<v8::Obj
ect> creationContext, v8::Isolate* isolate) | 174 v8::Local<v8::Value> toV8(const {{container.cpp_class}}& impl, v8::Local<v8::Obj
ect> creationContext, v8::Isolate* isolate) |
174 { | 175 { |
175 switch (impl.m_type) { | 176 switch (impl.m_type) { |
176 case {{container.cpp_class}}::SpecificTypeNone: | 177 case {{container.cpp_class}}::SpecificTypeNone: |
177 {# FIXME: We might want to return undefined in some cases #} | 178 {# FIXME: We might want to return undefined in some cases #} |
178 return v8::Null(isolate); | 179 return v8::Null(isolate); |
179 {% for member in container.members %} | 180 {% for member in container.members %} |
180 case {{container.cpp_class}}::{{member.specific_type_enum}}: | 181 case {{container.cpp_class}}::{{member.specific_type_enum}}: |
181 return {{member.cpp_value_to_v8_value}}; | 182 return {{member.cpp_value_to_v8_value}}; |
182 {% endfor %} | 183 {% endfor %} |
183 default: | 184 default: |
184 ASSERT_NOT_REACHED(); | 185 ASSERT_NOT_REACHED(); |
185 } | 186 } |
186 return v8::Local<v8::Value>(); | 187 return v8::Local<v8::Value>(); |
187 } | 188 } |
188 | 189 |
189 {{container.cpp_class}} NativeValueTraits<{{container.cpp_class}}>::nativeValue(
const v8::Local<v8::Value>& value, v8::Isolate* isolate, ExceptionState& excepti
onState) | 190 {{container.cpp_class}} NativeValueTraits<{{container.cpp_class}}>::nativeValue(
const v8::Local<v8::Value>& value, v8::Isolate* isolate, ExceptionState& excepti
onState) |
190 { | 191 { |
191 {{container.cpp_class}} impl; | 192 {{container.cpp_class}} impl; |
192 V8{{container.cpp_class}}::toImpl(isolate, value, impl, exceptionState); | 193 V8{{container.cpp_class}}::toImpl(isolate, value, impl, exceptionState); |
193 return impl; | 194 return impl; |
194 } | 195 } |
195 | 196 |
196 {% endfor %} | 197 {% endfor %} |
197 } // namespace blink | 198 } // namespace blink |
OLD | NEW |