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 * @fileoverview | 6 * @fileoverview |
7 * A module that contains basic utility components and methods for the | 7 * A module that contains basic utility components and methods for the |
8 * chromoting project | 8 * chromoting project |
9 * | 9 * |
10 */ | 10 */ |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 */ | 105 */ |
106 base.values = function(dict) { | 106 base.values = function(dict) { |
107 return Object.keys(dict).map( | 107 return Object.keys(dict).map( |
108 /** @param {string} key */ | 108 /** @param {string} key */ |
109 function(key) { | 109 function(key) { |
110 return dict[key]; | 110 return dict[key]; |
111 }); | 111 }); |
112 }; | 112 }; |
113 | 113 |
114 /** | 114 /** |
| 115 * @param {*} value |
| 116 * @return {*} a recursive copy of |value| or null if |value| is not copyable |
| 117 * (e.g. undefined, NaN). |
| 118 */ |
| 119 base.deepCopy = function (value) { |
| 120 try { |
| 121 return JSON.parse(JSON.stringify(value)); |
| 122 } catch (e) {} |
| 123 return null; |
| 124 }; |
| 125 |
| 126 /** |
115 * @type {boolean|undefined} | 127 * @type {boolean|undefined} |
116 * @private | 128 * @private |
117 */ | 129 */ |
118 base.isAppsV2_ = undefined; | 130 base.isAppsV2_ = undefined; |
119 | 131 |
120 /** | 132 /** |
121 * @return {boolean} True if this is a v2 app; false if it is a legacy app. | 133 * @return {boolean} True if this is a v2 app; false if it is a legacy app. |
122 */ | 134 */ |
123 base.isAppsV2 = function() { | 135 base.isAppsV2 = function() { |
124 if (base.isAppsV2_ === undefined) { | 136 if (base.isAppsV2_ === undefined) { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 * @return {Object|undefined} The decoded object, or undefined if the string | 473 * @return {Object|undefined} The decoded object, or undefined if the string |
462 * cannot be parsed. | 474 * cannot be parsed. |
463 */ | 475 */ |
464 base.jsonParseSafe = function(jsonString) { | 476 base.jsonParseSafe = function(jsonString) { |
465 try { | 477 try { |
466 return /** @type {Object} */ (JSON.parse(jsonString)); | 478 return /** @type {Object} */ (JSON.parse(jsonString)); |
467 } catch (err) { | 479 } catch (err) { |
468 return undefined; | 480 return undefined; |
469 } | 481 } |
470 } | 482 } |
OLD | NEW |