| 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:convert' show JsonDecoder; | 7 import 'dart:convert' show JsonDecoder; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Instances of the class [Request] represent a request that was received. | 10 * Instances of the class [Request] represent a request that was received. |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 * Validate that the datum is a boolean (or a string that can be parsed | 230 * Validate that the datum is a boolean (or a string that can be parsed |
| 231 * as a boolean), and return the bool. | 231 * as a boolean), and return the bool. |
| 232 * | 232 * |
| 233 * The value is typically the result of invoking either [getParameter] or | 233 * The value is typically the result of invoking either [getParameter] or |
| 234 * [getRequiredParameter]. | 234 * [getRequiredParameter]. |
| 235 */ | 235 */ |
| 236 bool asBool() { | 236 bool asBool() { |
| 237 if (datum is bool) { | 237 if (datum is bool) { |
| 238 return datum; | 238 return datum; |
| 239 } else if (datum == 'true') { | 239 } else if (datum == 'true') { |
| 240 return datum == 'true'; | 240 return true; |
| 241 } else if (datum == 'false') { | 241 } else if (datum == 'false') { |
| 242 return datum == 'false'; | 242 return false; |
| 243 } | 243 } |
| 244 throw new RequestFailure(new Response.invalidParameter(request, datum, | 244 throw new RequestFailure(new Response.invalidParameter(request, datum, |
| 245 "be a boolean")); | 245 "be a boolean")); |
| 246 } | 246 } |
| 247 | 247 |
| 248 /** | 248 /** |
| 249 * Validate that the datum is a string, and return it. | 249 * Validate that the datum is a string, and return it. |
| 250 */ | 250 */ |
| 251 String asString() { | 251 String asString() { |
| 252 if (datum is! String) { | 252 if (datum is! String) { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 /** | 704 /** |
| 705 * The response to be returned as a result of the failure. | 705 * The response to be returned as a result of the failure. |
| 706 */ | 706 */ |
| 707 final Response response; | 707 final Response response; |
| 708 | 708 |
| 709 /** | 709 /** |
| 710 * Initialize a newly created exception to return the given reponse. | 710 * Initialize a newly created exception to return the given reponse. |
| 711 */ | 711 */ |
| 712 RequestFailure(this.response); | 712 RequestFailure(this.response); |
| 713 } | 713 } |
| OLD | NEW |