Chromium Code Reviews| 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 |
| 11 * @param {*} condition The condition to test. Note that this may be used to | 11 * @param {*} condition The condition to test. Note that this may be used to |
| 12 * test whether a value is defined or not, and we don't want to force a | 12 * test whether a value is defined or not, and we don't want to force a |
| 13 * cast to Boolean. | 13 * cast to Boolean. |
| 14 * @param {string=} opt_message A message to use in any error. | 14 * @param {string=} opt_message A message to use in any error. |
| 15 */ | 15 */ |
| 16 function assert(condition, opt_message) { | 16 function assert(condition, opt_message) { |
| 17 'use strict'; | 17 'use strict'; |
| 18 if (!condition) { | 18 if (!condition) { |
| 19 var msg = 'Assertion failed'; | 19 var msg = 'Assertion failed'; |
| 20 if (opt_message) | 20 if (opt_message) |
| 21 msg = msg + ': ' + opt_message; | 21 msg = msg + ': ' + opt_message; |
| 22 throw new Error(msg); | 22 throw new Error(msg); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | |
| 26 /** | |
| 27 * Insert a notReached() in cases where control flow should never hit. | |
| 28 * @param {string=} opt_message A message to show when this is hit. | |
| 29 */ | |
| 30 function notReached(opt_message) { | |
|
arv (Not doing code reviews)
2014/07/24 16:44:24
How about assertNotReached instead?
Dan Beam
2014/07/25 01:52:32
hmmm, blink uses ASSERT_NOT_REACHED() while chrome
| |
| 31 throw new Error(opt_message || "Unreachable code hit"); | |
| 32 } | |
| OLD | NEW |