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 * Simple common assertion API | 10 * Simple common assertion API |
(...skipping 29 matching lines...) Expand all Loading... | |
40 * } | 40 * } |
41 * | 41 * |
42 * This code should only be hit in the case of serious programmer error or | 42 * This code should only be hit in the case of serious programmer error or |
43 * unexpected input. | 43 * unexpected input. |
44 * | 44 * |
45 * @param {string=} opt_message A message to show when this is hit. | 45 * @param {string=} opt_message A message to show when this is hit. |
46 */ | 46 */ |
47 function assertNotReached(opt_message) { | 47 function assertNotReached(opt_message) { |
48 throw new Error(opt_message || "Unreachable code hit"); | 48 throw new Error(opt_message || "Unreachable code hit"); |
49 } | 49 } |
50 | |
51 /** | |
52 * @param {*} value The value to check. | |
53 * @param {function(new: T, ...)} type A user-defined constructor. | |
54 * @return {!T} | |
55 * @template T | |
56 */ | |
57 function assertInstanceof(value, type) { | |
58 if (!(value instanceof type)) { | |
Dan Beam
2014/08/13 22:20:08
nit: no curlies
Vitaly Pavlenko
2014/08/14 00:01:02
Done.
| |
59 throw new Error('assertInstanceof'); | |
Dan Beam
2014/08/13 22:20:07
throw new Error(value + ' is not a[n] ' + (type.na
Vitaly Pavlenko
2014/08/14 00:01:02
Done.
| |
60 } | |
61 return value; | |
62 } | |
OLD | NEW |