OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 * Inherit the prototype methods from one constructor into another. | 6 * Inherit the prototype methods from one constructor into another. |
7 */ | 7 */ |
8 function inherits(childCtor, parentCtor) { | 8 function inherits(childCtor, parentCtor) { |
9 function tempCtor() {}; | 9 function tempCtor() {}; |
10 tempCtor.prototype = parentCtor.prototype; | 10 tempCtor.prototype = parentCtor.prototype; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 function getKeyWithValue(map, value) { | 99 function getKeyWithValue(map, value) { |
100 for (key in map) { | 100 for (key in map) { |
101 if (map[key] == value) | 101 if (map[key] == value) |
102 return key; | 102 return key; |
103 } | 103 } |
104 return '?'; | 104 return '?'; |
105 } | 105 } |
106 | 106 |
107 /** | 107 /** |
| 108 * Looks up |key| in |map|, and returns the resulting entry, if there is one. |
| 109 * Otherwise, returns |key|. Intended primarily for use with incomplete |
| 110 * tables, and for reasonable behavior with system enumerations that may be |
| 111 * extended in the future. |
| 112 */ |
| 113 function tryGetValueWithKey(map, key) { |
| 114 if (key in map) |
| 115 return map[key]; |
| 116 return key; |
| 117 } |
| 118 |
| 119 /** |
108 * Builds a string by repeating |str| |count| times. | 120 * Builds a string by repeating |str| |count| times. |
109 */ | 121 */ |
110 function makeRepeatedString(str, count) { | 122 function makeRepeatedString(str, count) { |
111 var out = []; | 123 var out = []; |
112 for (var i = 0; i < count; ++i) | 124 for (var i = 0; i < count; ++i) |
113 out.push(str); | 125 out.push(str); |
114 return out.join(''); | 126 return out.join(''); |
115 } | 127 } |
116 | 128 |
117 /** | 129 /** |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 out.push(paddingStr); | 225 out.push(paddingStr); |
214 } | 226 } |
215 } | 227 } |
216 } | 228 } |
217 out.push('\n'); | 229 out.push('\n'); |
218 } | 230 } |
219 | 231 |
220 return out.join(''); | 232 return out.join(''); |
221 }; | 233 }; |
222 | 234 |
OLD | NEW |