Index: ui/webui/resources/js/assert.js |
diff --git a/ui/webui/resources/js/assert.js b/ui/webui/resources/js/assert.js |
index bae2910705bd3eb77270c46cf7ec1fb6dbac82a0..7b38398ed0175179cfc6efaf510b489a73bbf591 100644 |
--- a/ui/webui/resources/js/assert.js |
+++ b/ui/webui/resources/js/assert.js |
@@ -22,3 +22,28 @@ function assert(condition, opt_message) { |
throw new Error(msg); |
} |
} |
+ |
+/** |
+ * Call this from places in the code that should never be reached. |
+ * |
+ * For example, handling all the values of enum with a switch() like this: |
+ * |
+ * function getValueFromEnum(enum) { |
+ * switch (enum) { |
+ * case ENUM_FIRST_OF_TWO: |
+ * return first |
+ * case ENUM_LAST_OF_TWO: |
+ * return last; |
+ * } |
+ * assertNotReached(); |
+ * return document; |
+ * } |
+ * |
+ * This code should only be hit in the case of serious programmer error or |
+ * unexpected input. |
+ * |
+ * @param {string=} opt_message A message to show when this is hit. |
+ */ |
+function assertNotReached(opt_message) { |
+ throw new Error(opt_message || "Unreachable code hit"); |
+} |