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: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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 "be a map")); | 178 "be a map")); |
| 179 } | 179 } |
| 180 if (!datum.containsKey(key)) { | 180 if (!datum.containsKey(key)) { |
| 181 throw new RequestFailure(new Response.invalidParameter(request, path, | 181 throw new RequestFailure(new Response.invalidParameter(request, path, |
| 182 "contain key '$key'")); | 182 "contain key '$key'")); |
| 183 } | 183 } |
| 184 return new RequestDatum(request, "$path.$key", datum[key]); | 184 return new RequestDatum(request, "$path.$key", datum[key]); |
| 185 } | 185 } |
| 186 | 186 |
| 187 /** | 187 /** |
| 188 * Return `true` if the datum is a Map containing the given [key]. | |
| 189 */ | |
| 190 bool hasKey(String key) { | |
| 191 return datum is Map<String, dynamic> && datum.containsKey(key); | |
|
Paul Berry
2014/05/15 00:30:54
This means that if we receive a datum from the cli
danrubel
2014/05/15 11:48:44
Good suggestion. Done.
| |
| 192 } | |
| 193 | |
| 194 /** | |
| 188 * Validate that the datum is a Map whose keys are strings, and call [f] on | 195 * Validate that the datum is a Map whose keys are strings, and call [f] on |
| 189 * each key/value pair in the map. | 196 * each key/value pair in the map. |
| 190 */ | 197 */ |
| 191 void forEachMap(void f(String key, RequestDatum value)) { | 198 void forEachMap(void f(String key, RequestDatum value)) { |
| 192 if (datum is! Map<String, dynamic>) { | 199 if (datum is! Map<String, dynamic>) { |
| 193 throw new RequestFailure(new Response.invalidParameter(request, path, | 200 throw new RequestFailure(new Response.invalidParameter(request, path, |
| 194 "be a map")); | 201 "be a map")); |
| 195 } | 202 } |
| 196 datum.forEach((String key, dynamic value) { | 203 datum.forEach((String key, dynamic value) { |
| 197 f(key, new RequestDatum(request, "$path.$key", value)); | 204 f(key, new RequestDatum(request, "$path.$key", value)); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 /** | 700 /** |
| 694 * The response to be returned as a result of the failure. | 701 * The response to be returned as a result of the failure. |
| 695 */ | 702 */ |
| 696 final Response response; | 703 final Response response; |
| 697 | 704 |
| 698 /** | 705 /** |
| 699 * Initialize a newly created exception to return the given reponse. | 706 * Initialize a newly created exception to return the given reponse. |
| 700 */ | 707 */ |
| 701 RequestFailure(this.response); | 708 RequestFailure(this.response); |
| 702 } | 709 } |
| OLD | NEW |