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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 * @param {*} value The value to check. | 58 * @param {*} value The value to check. |
59 * @param {function(new: T, ...)} type A user-defined constructor. | 59 * @param {function(new: T, ...)} type A user-defined constructor. |
60 * @param {string=} opt_message A message to show when this is hit. | 60 * @param {string=} opt_message A message to show when this is hit. |
61 * @return {T} | 61 * @return {T} |
62 * @template T | 62 * @template T |
63 */ | 63 */ |
64 function assertInstanceof(value, type, opt_message) { | 64 function assertInstanceof(value, type, opt_message) { |
65 // We don't use assert immediately here so that we avoid constructing an error | 65 // We don't use assert immediately here so that we avoid constructing an error |
66 // message if we don't have to. | 66 // message if we don't have to. |
67 if (!(value instanceof type)) { | 67 if (!(value instanceof type)) { |
68 assertNotReached(opt_message || 'Value ' + value + | 68 assertNotReached( |
69 ' is not a[n] ' + (type.name || typeof type)); | 69 opt_message || |
| 70 'Value ' + value + ' is not a[n] ' + (type.name || typeof type)); |
70 } | 71 } |
71 return value; | 72 return value; |
72 } | 73 } |
OLD | NEW |