Index: ui/webui/resources/js/assert.js |
diff --git a/ui/webui/resources/js/assert.js b/ui/webui/resources/js/assert.js |
index 7b38398ed0175179cfc6efaf510b489a73bbf591..563b12ec4bfe63b4dc6815e8d1c5cb706581aaf4 100644 |
--- a/ui/webui/resources/js/assert.js |
+++ b/ui/webui/resources/js/assert.js |
@@ -47,3 +47,16 @@ function assert(condition, opt_message) { |
function assertNotReached(opt_message) { |
throw new Error(opt_message || "Unreachable code hit"); |
} |
+ |
+/** |
+ * @param {*} value The value to check. |
+ * @param {function(new: T, ...)} type A user-defined constructor. |
+ * @return {!T} |
+ * @template T |
+ */ |
+function assertInstanceof(value, type) { |
+ if (!(value instanceof type)) { |
Dan Beam
2014/08/13 22:20:08
nit: no curlies
Vitaly Pavlenko
2014/08/14 00:01:02
Done.
|
+ 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.
|
+ } |
+ return value; |
+} |