| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 Assertion support. | 6 * @fileoverview Assertion support. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Verify |condition| is truthy and return |condition| if so. | 10 * Verify |condition| is truthy and return |condition| if so. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 * | 47 * |
| 48 * @param {string=} opt_message A message to show when this is hit. | 48 * @param {string=} opt_message A message to show when this is hit. |
| 49 */ | 49 */ |
| 50 function assertNotReached(opt_message) { | 50 function assertNotReached(opt_message) { |
| 51 throw new Error(opt_message || 'Unreachable code hit'); | 51 throw new Error(opt_message || 'Unreachable code hit'); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * @param {*} value The value to check. | 55 * @param {*} value The value to check. |
| 56 * @param {function(new: T, ...)} type A user-defined constructor. | 56 * @param {function(new: T, ...)} type A user-defined constructor. |
| 57 * @param {string=} opt_message A message to show when this is hit. |
| 57 * @return {T} | 58 * @return {T} |
| 58 * @template T | 59 * @template T |
| 59 */ | 60 */ |
| 60 function assertInstanceof(value, type) { | 61 function assertInstanceof(value, type, opt_message) { |
| 61 if (!(value instanceof type)) | 62 if (!(value instanceof type)) { |
| 62 throw new Error(value + ' is not a[n] ' + (type.name || typeof type)); | 63 throw new Error(opt_message || |
| 64 value + ' is not a[n] ' + (type.name || typeof type)); |
| 65 } |
| 63 return value; | 66 return value; |
| 64 } | 67 } |
| OLD | NEW |