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 /** | 5 /** |
6 * Get the |key| attribute in the given |dict| and verify that it is an | 6 * Get the |key| attribute in the given |dict| and verify that it is an |
7 * array value. | 7 * array value. |
8 * | 8 * |
9 * If the attribute is not an array, then an exception will be thrown unless | 9 * If the attribute is not an array, then an exception will be thrown unless |
10 * a default value is specified in |opt_default|. | 10 * a default value is specified in |opt_default|. |
(...skipping 23 matching lines...) Expand all Loading... |
34 * If the attribute is not a boolean, then an exception will be thrown unless | 34 * If the attribute is not a boolean, then an exception will be thrown unless |
35 * a default value is specified in |opt_default|. | 35 * a default value is specified in |opt_default|. |
36 * | 36 * |
37 * @param {Object.<string,*>} dict The dictionary containing the |key| | 37 * @param {Object.<string,*>} dict The dictionary containing the |key| |
38 * @param {string} key The key to typecheck in the |dict|. | 38 * @param {string} key The key to typecheck in the |dict|. |
39 * @param {boolean=} opt_default The value to return if the key is not a bool. | 39 * @param {boolean=} opt_default The value to return if the key is not a bool. |
40 * @return {boolean} The |key| attribute value as a boolean. | 40 * @return {boolean} The |key| attribute value as a boolean. |
41 */ | 41 */ |
42 function getBooleanAttr(dict, key, opt_default) { | 42 function getBooleanAttr(dict, key, opt_default) { |
43 var value = /** @type {boolean} */ (dict[key]); | 43 var value = /** @type {boolean} */ (dict[key]); |
44 if (typeof value != 'boolean') { | 44 if (value == 'true' || value == 'false') { |
| 45 return (value == 'true'); |
| 46 } |
| 47 if (typeof value !== 'boolean') { |
45 if (opt_default === undefined) { | 48 if (opt_default === undefined) { |
46 throw 'Invalid data type for ' + key + | 49 throw 'Invalid data type for ' + key + |
47 ' (expected: boolean, actual: ' + typeof value + ')'; | 50 ' (expected: boolean, actual: ' + typeof value + ')'; |
48 } else { | 51 } else { |
49 return opt_default; | 52 return opt_default; |
50 } | 53 } |
51 } | 54 } |
52 return value; | 55 return value; |
53 } | 56 } |
54 | 57 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 * @param {string} jsonString The JSON string to parse. | 139 * @param {string} jsonString The JSON string to parse. |
137 * @return {Object} The JSON object created from the |jsonString|. | 140 * @return {Object} The JSON object created from the |jsonString|. |
138 */ | 141 */ |
139 function getJsonObjectFromString(jsonString) { | 142 function getJsonObjectFromString(jsonString) { |
140 var value = base.jsonParseSafe(jsonString); | 143 var value = base.jsonParseSafe(jsonString); |
141 if (typeof value != 'object') { | 144 if (typeof value != 'object') { |
142 throw 'Invalid data type (expected: Object, actual: ' + typeof value + ')'; | 145 throw 'Invalid data type (expected: Object, actual: ' + typeof value + ')'; |
143 } | 146 } |
144 return value; | 147 return value; |
145 } | 148 } |
OLD | NEW |