Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 if (!(object instanceof Object)) | 136 if (!(object instanceof Object)) |
| 137 return object; | 137 return object; |
| 138 var copy = {}; | 138 var copy = {}; |
| 139 for (var key in object) { | 139 for (var key in object) { |
| 140 copy[key] = object[key]; | 140 copy[key] = object[key]; |
| 141 } | 141 } |
| 142 return copy; | 142 return copy; |
| 143 } | 143 } |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * Helper to make sure singleton classes are not instantiated more than once. | |
| 147 */ | |
| 148 function assertFirstConstructorCall(ctor) { | |
|
eroman
2011/08/03 20:46:54
I added this as an extra bonus, since weird things
mmenke
2011/08/03 20:50:36
Good idea.
| |
| 149 // This is the variable which is set by cr.addSingletonGetter(). | |
| 150 if (ctor.hasCreateFirstInstance_) { | |
| 151 throw Error('The class ' + ctor.name + ' is a singleton, and should ' + | |
| 152 'only be accessed using ' + ctor.name + '.getInstance().'); | |
| 153 } | |
| 154 ctor.hasCreateFirstInstance_ = true; | |
| 155 } | |
| 156 | |
| 157 /** | |
| 146 * TablePrinter is a helper to format a table as ascii art or an HTML table. | 158 * TablePrinter is a helper to format a table as ascii art or an HTML table. |
| 147 * | 159 * |
| 148 * Usage: call addRow() and addCell() repeatedly to specify the data. | 160 * Usage: call addRow() and addCell() repeatedly to specify the data. |
| 149 * | 161 * |
| 150 * addHeaderCell() can optionally be called to specify header cells for a | 162 * addHeaderCell() can optionally be called to specify header cells for a |
| 151 * single header row. The header row appears at the top of an HTML formatted | 163 * single header row. The header row appears at the top of an HTML formatted |
| 152 * table, and uses thead and th tags. In ascii tables, the header is separated | 164 * table, and uses thead and th tags. In ascii tables, the header is separated |
| 153 * from the table body by a partial row of dashes. | 165 * from the table body by a partial row of dashes. |
| 154 * | 166 * |
| 155 * setTitle() can optionally be used to set a title that is displayed before | 167 * setTitle() can optionally be used to set a title that is displayed before |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 linkNode.href = cell.link; | 379 linkNode.href = cell.link; |
| 368 } else { | 380 } else { |
| 369 addTextNode(tableCell, cell.text); | 381 addTextNode(tableCell, cell.text); |
| 370 } | 382 } |
| 371 } | 383 } |
| 372 } | 384 } |
| 373 } | 385 } |
| 374 return table; | 386 return table; |
| 375 }; | 387 }; |
| 376 | 388 |
| OLD | NEW |