Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(517)

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_h.template

Issue 1734693003: Revert of DevTools: simplify JSONValues API, prepare to the OwnPtr migration. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // This file is generated 1 // This file is generated
2 2
3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be 4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file. 5 // found in the LICENSE file.
6 6
7 #ifndef {{class_name}}_h 7 #ifndef {{class_name}}_h
8 #define {{class_name}}_h 8 #define {{class_name}}_h
9 9
10 #include "platform/JSONValues.h" 10 #include "platform/JSONValues.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 PassRefPtr<JSONValue> toValue(PassOwnPtr<T> param) 106 PassRefPtr<JSONValue> toValue(PassOwnPtr<T> param)
107 { 107 {
108 return param->asValue(); 108 return param->asValue();
109 } 109 }
110 110
111 template<typename T> 111 template<typename T>
112 struct FromValue 112 struct FromValue
113 { 113 {
114 static PassOwnPtr<T> convert(RefPtr<JSONValue> value) 114 static PassOwnPtr<T> convert(RefPtr<JSONValue> value)
115 { 115 {
116 return T::runtimeCast(JSONObject::cast(value.release())); 116 if (!value)
117 return nullptr;
118 RefPtr<JSONObject> object;
119 bool success = value->asObject(&object);
120 ASSERT_UNUSED(success, success);
121 return T::runtimeCast(object.release());
117 } 122 }
118 }; 123 };
119 124
120 template<> 125 template<>
121 struct FromValue<bool> 126 struct FromValue<bool>
122 { 127 {
123 static bool convert(RefPtr<JSONValue> value) 128 static bool convert(RefPtr<JSONValue> value)
124 { 129 {
125 bool result; 130 bool result;
126 bool success = value->asBoolean(&result); 131 bool success = value->asBoolean(&result);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 { 177 {
173 return value.release(); 178 return value.release();
174 } 179 }
175 }; 180 };
176 181
177 template<typename T> 182 template<typename T>
178 struct FromValue<protocol::Array<T>> 183 struct FromValue<protocol::Array<T>>
179 { 184 {
180 static PassOwnPtr<protocol::Array<T>> convert(RefPtr<JSONValue> value) 185 static PassOwnPtr<protocol::Array<T>> convert(RefPtr<JSONValue> value)
181 { 186 {
182 return protocol::Array<T>::runtimeCast(JSONArray::cast(value)); 187 RefPtr<JSONArray> array = value->asArray();
188 ASSERT_UNUSED(array, array);
189 return protocol::Array<T>::runtimeCast(array);
183 } 190 }
184 }; 191 };
185 192
186 template<typename T> 193 template<typename T>
187 class ArrayBase { 194 class ArrayBase {
188 public: 195 public:
189 static PassOwnPtr<Array<T>> create() 196 static PassOwnPtr<Array<T>> create()
190 { 197 {
191 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 198 OwnPtr<Array<T>> result = adoptPtr(new Array<T>());
192 result->m_array = JSONArray::create(); 199 result->m_array = JSONArray::create();
193 return result.release(); 200 return result.release();
194 } 201 }
195 202
196 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONValue> array) 203 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONArray> array)
197 { 204 {
198 if (!array || array->type() != JSONValue::TypeArray) 205 if (!array)
199 return nullptr; 206 return nullptr;
200 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 207 OwnPtr<Array<T>> result = adoptPtr(new Array<T>());
201 result->m_array = JSONArray::cast(array); 208 result->m_array = array;
202 return result.release(); 209 return result.release();
203 } 210 }
204 211
205 void addItem(const T& value) 212 void addItem(const T& value)
206 { 213 {
207 m_array->pushValue(toValue(value)); 214 m_array->pushValue(toValue(value));
208 } 215 }
209 216
210 size_t length() { return m_array->length(); } 217 size_t length() { return m_array->length(); }
211 218
(...skipping 13 matching lines...) Expand all
225 template<typename T> 232 template<typename T>
226 class Array { 233 class Array {
227 public: 234 public:
228 static PassOwnPtr<Array<T>> create() 235 static PassOwnPtr<Array<T>> create()
229 { 236 {
230 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 237 OwnPtr<Array<T>> result = adoptPtr(new Array<T>());
231 result->m_array = JSONArray::create(); 238 result->m_array = JSONArray::create();
232 return result.release(); 239 return result.release();
233 } 240 }
234 241
235 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONValue> array) 242 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONArray> array)
236 { 243 {
237 if (!array || array->type() != JSONValue::TypeArray) 244 if (!array)
238 return nullptr; 245 return nullptr;
239 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 246 OwnPtr<Array<T>> result = adoptPtr(new Array<T>());
240 result->m_array = JSONArray::cast(array); 247 result->m_array = array;
241 return result.release(); 248 return result.release();
242 } 249 }
243 250
244 void addItem(PassOwnPtr<T> value) 251 void addItem(PassOwnPtr<T> value)
245 { 252 {
246 m_array->pushValue(toValue(value)); 253 m_array->pushValue(toValue(value));
247 } 254 }
248 255
249 size_t length() { return m_array->length(); } 256 size_t length() { return m_array->length(); }
250 257
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 {% for domain in api.domains %} 319 {% for domain in api.domains %}
313 320
314 namespace {{domain.domain}} { 321 namespace {{domain.domain}} {
315 {% for type in domain.types %} 322 {% for type in domain.types %}
316 {% if type.type == "object" %} 323 {% if type.type == "object" %}
317 {% set type_def = type_definition(domain.domain + "." + type.id)%} 324 {% set type_def = type_definition(domain.domain + "." + type.id)%}
318 325
319 // {{type.description}} 326 // {{type.description}}
320 class PLATFORM_EXPORT {{type.id}} { 327 class PLATFORM_EXPORT {{type.id}} {
321 public: 328 public:
322 static PassOwnPtr<{{type.id}}> runtimeCast(PassRefPtr<JSONValue> value) 329 static PassOwnPtr<{{type.id}}> runtimeCast(PassRefPtr<JSONObject> object)
323 { 330 {
324 if (!value || value->type() != JSONValue::TypeObject) 331 return adoptPtr(new {{type.id}}(object));
325 return nullptr;
326 return adoptPtr(new {{type.id}}(JSONObject::cast(value)));
327 } 332 }
328 333
329 {{type.id}}() : m_object(JSONObject::create()) { } 334 {{type.id}}() : m_object(JSONObject::create()) { }
330 335
331 ~{{type.id}}() { } 336 ~{{type.id}}() { }
332 {% for property in type.properties %} 337 {% for property in type.properties %}
333 338
334 {% if "enum" in property %} 339 {% if "enum" in property %}
335 struct PLATFORM_EXPORT {{property.name | to_title_case}}Enum { 340 struct PLATFORM_EXPORT {{property.name | to_title_case}}Enum {
336 {% for literal in property.enum %} 341 {% for literal in property.enum %}
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 {% endif %} 454 {% endif %}
450 {% endfor %} 455 {% endfor %}
451 456
452 } // {{domain.domain}} 457 } // {{domain.domain}}
453 {% endfor %} 458 {% endfor %}
454 459
455 } // namespace protocol 460 } // namespace protocol
456 } // namespace blink 461 } // namespace blink
457 462
458 #endif // !defined({{class_name}}_h) 463 #endif // !defined({{class_name}}_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698