Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library protocol; | 5 library protocol; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:convert' show JsonDecoder; | 8 import 'dart:convert' show JsonDecoder; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 } else if (datum == 'true') { | 279 } else if (datum == 'true') { |
| 280 return true; | 280 return true; |
| 281 } else if (datum == 'false') { | 281 } else if (datum == 'false') { |
| 282 return false; | 282 return false; |
| 283 } | 283 } |
| 284 throw new RequestFailure(new Response.invalidParameter(request, datum, | 284 throw new RequestFailure(new Response.invalidParameter(request, datum, |
| 285 "be a boolean")); | 285 "be a boolean")); |
| 286 } | 286 } |
| 287 | 287 |
| 288 /** | 288 /** |
| 289 * Validate that the datum is a list, and return a list where each element in | |
| 290 * the datum has been converted using the provided function. | |
| 291 */ | |
| 292 List asList(elementConverter(RequestDatum datum)) { | |
| 293 if (datum is! List) { | |
| 294 throw new RequestFailure(new Response.invalidParameter(request, path, | |
| 295 "be a list")); | |
| 296 } | |
| 297 List list = datum as List; | |
| 298 List result = []; | |
| 299 for (int i = 0; i < list.length; i++) { | |
| 300 result[i] = elementConverter(new RequestDatum(request, "$path.$i", list[i] )); | |
|
scheglov
2014/06/15 18:08:15
Does it work?
Will it automatically increase the "
Brian Wilkerson
2014/06/16 15:05:16
No, it didn't work. If I'd remembered the tests fo
| |
| 301 } | |
| 302 return result; | |
| 303 } | |
| 304 | |
| 305 /** | |
| 289 * Validate that the datum is a string, and return it. | 306 * Validate that the datum is a string, and return it. |
| 290 */ | 307 */ |
| 291 String asString() { | 308 String asString() { |
| 292 if (datum is! String) { | 309 if (datum is! String) { |
| 293 throw new RequestFailure(new Response.invalidParameter(request, path, | 310 throw new RequestFailure(new Response.invalidParameter(request, path, |
| 294 "be a string")); | 311 "be a string")); |
| 295 } | 312 } |
| 296 return datum; | 313 return datum; |
| 297 } | 314 } |
| 298 | 315 |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 /** | 861 /** |
| 845 * The response to be returned as a result of the failure. | 862 * The response to be returned as a result of the failure. |
| 846 */ | 863 */ |
| 847 final Response response; | 864 final Response response; |
| 848 | 865 |
| 849 /** | 866 /** |
| 850 * Initialize a newly created exception to return the given reponse. | 867 * Initialize a newly created exception to return the given reponse. |
| 851 */ | 868 */ |
| 852 RequestFailure(this.response); | 869 RequestFailure(this.response); |
| 853 } | 870 } |
| OLD | NEW |