Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / webui / resources / js / assert.js
index bae2910..7b38398 100644 (file)
@@ -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");
+}