You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
17 KiB

<!DOCTYPE html><meta charset="UTF-8"><meta http-equiv="Content-Language" content="en" /><title>goog.asserts</title><link href="dossier.css" rel="stylesheet" type="text/css"><div id="main-wrapper"><input type="checkbox" id="sidenav-toggle" /><main><header><h1>Namespace goog.asserts</h1><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l36">code &raquo;</a></header><section></section><section><h2>Classes</h2><div class="type-summary"><table><tbody><tr><td><dl><dt><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a><dd>Error object for failed assertions.</dl></table></div></section><div id="visibility-controls"><b>Show:</b><label for="show-public"><span><input type="checkbox" id="show-public" checked/></span>Public</label><label for="show-protected"><span><input type="checkbox" id="show-protected"/></span>Protected</label><label for="show-private"><span><input type="checkbox" id="show-private"/></span>Private</label></div><section id="static-functions"><h2>Global Functions</h2><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l118">code &raquo;</a><code class="type">&lt;T&gt;</code> <span class="member"><a name="goog.asserts.assert">goog.asserts.assert</a> <span class="args">( condition, opt_message, var_args )</span> &rArr; <code class="type">T</code></span></div><p>Checks if the condition evaluates to true if goog.asserts.ENABLE_ASSERTS is
true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>condition: <code class="type">T</code><dd>The condition to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value of the condition.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the condition evaluates to false.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l235">code &raquo;</a><span class="member"><a name="goog.asserts.assertArray">goog.asserts.assertArray</a> <span class="args">( value, opt_message, var_args )</span> &rArr; <code class="type">!<a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code></span></div><p>Checks if the value is an Array if goog.asserts.ENABLE_ASSERTS is true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value, guaranteed to be a non-null array.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not an array.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l254">code &raquo;</a><span class="member"><a name="goog.asserts.assertBoolean">goog.asserts.assertBoolean</a> <span class="args">( value, opt_message, var_args )</span> &rArr; <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div><p>Checks if the value is a boolean if goog.asserts.ENABLE_ASSERTS is true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value, guaranteed to be a boolean when asserts are
enabled.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not a boolean.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l273">code &raquo;</a><span class="member"><a name="goog.asserts.assertElement">goog.asserts.assertElement</a> <span class="args">( value, opt_message, var_args )</span> &rArr; <code class="type">!<a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#ID-745549614">Element</a></code></span></div><p>Checks if the value is a DOM Element if goog.asserts.ENABLE_ASSERTS is true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value, likely to be a DOM Element when asserts are
enabled.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not a boolean.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l199">code &raquo;</a><span class="member"><a name="goog.asserts.assertFunction">goog.asserts.assertFunction</a> <span class="args">( value, opt_message, var_args )</span> &rArr; <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">Function</a></code></span></div><p>Checks if the value is a function if goog.asserts.ENABLE_ASSERTS is true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value, guaranteed to be a function when asserts
enabled.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not a function.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l299">code &raquo;</a><code class="type">&lt;T&gt;</code> <span class="member"><a name="goog.asserts.assertInstanceof">goog.asserts.assertInstanceof</a> <span class="args">( value, type, opt_message, var_args )</span> &rArr; <code class="type">!T</code></span></div><p>Checks if the value is an instance of the user-defined type if
goog.asserts.ENABLE_ASSERTS is true.
The compiler may tighten the type returned by this function.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>type: <code class="type">function(new: T, ...)</code><dd>A user-defined constructor.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not an instance of
type.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l162">code &raquo;</a><span class="member"><a name="goog.asserts.assertNumber">goog.asserts.assertNumber</a> <span class="args">( value, opt_message, var_args )</span> &rArr; <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code></span></div><p>Checks if the value is a number if goog.asserts.ENABLE_ASSERTS is true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value, guaranteed to be a number when asserts enabled.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not a number.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l217">code &raquo;</a><span class="member"><a name="goog.asserts.assertObject">goog.asserts.assertObject</a> <span class="args">( value, opt_message, var_args )</span> &rArr; <code class="type">!<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a></code></span></div><p>Checks if the value is an Object if goog.asserts.ENABLE_ASSERTS is true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value, guaranteed to be a non-null object.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not an object.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l312">code &raquo;</a><span class="member"><a name="goog.asserts.assertObjectPrototypeIsIntact">goog.asserts.assertObjectPrototypeIsIntact</a> <span class="args">( )</span></span></div><p>Checks that no enumerable keys are present in Object.prototype. Such keys
would break most code that use <code >for (var ... in ...)</code> loops.</summary></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l180">code &raquo;</a><span class="member"><a name="goog.asserts.assertString">goog.asserts.assertString</a> <span class="args">( value, opt_message, var_args )</span> &rArr; <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code></span></div><p>Checks if the value is a string if goog.asserts.ENABLE_ASSERTS is true.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>value: <code class="type">*</code><dd>The value to check.<dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Returns<tr><td><dl>The value, guaranteed to be a string when asserts enabled.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not a string.</dl></table></div></details></div></div><div class="wrap-details private"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l90">code &raquo;</a><span class="member"><a name="goog.asserts.doAssertFailure_">goog.asserts.doAssertFailure_</a> <span class="args">( defaultMessage, defaultArgs, givenMessage, givenArgs )</span></span></div><p>Throws an exception with the given message and "Assertion failed" prefixed
onto it.</summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>defaultMessage: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><dd>The message to use if givenMessage is empty.<dt>defaultArgs: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code><dd>The substitution arguments for defaultMessage.<dt>givenMessage: <code class="type">(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>|<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Undefined">undefined</a>)</code><dd>Message supplied by the caller.<dt>givenArgs: <code class="type"><a href="http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array">Array</a></code><dd>The substitution arguments for givenMessage.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>When the value is not a number.</dl></table></div></details></div></div><div class="wrap-details public"><div><details class="function"><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l145">code &raquo;</a><span class="member"><a name="goog.asserts.fail">goog.asserts.fail</a> <span class="args">( opt_message, var_args )</span></span></div><p>Fails if goog.asserts.ENABLE_ASSERTS is true. This function is useful in case
when we want to add a check in the unreachable area like switch-case
statement:
<pre>
switch(type) {
case FOO: doSomething(); break;
case BAR: doSomethingElse(); break;
default: goog.assert.fail('Unrecognized type: ' + type);
// We have only 2 types - "default:" section is unreachable code.
}
</pre></summary><div class="info"><table><tbody><tr><th>Parameters<tr><td><dl><dt>opt_message: <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>=</code><dd>Error message in case of failure.<dt>var_args: <code class="type">...*</code><dd>The items to substitute into the failure message.</dl><tr><th>Throws<tr><td><dl><dt><code class="type"><a href="class_goog_asserts_AssertionError.html">goog.asserts.AssertionError</a></code><dd>Failure.</dl></table></div></details></div></div></section><section id="compiler-constants"><h2>Compiler Constants</h2><div class="wrap-details public"><div><details><summary><div><a class="source" href="source/lib/goog/asserts/asserts.js.src.html#l47">code &raquo;</a><span class="member"><a name="goog.asserts.ENABLE_ASSERTS">goog.asserts.ENABLE_ASSERTS</a> : <code class="type"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">boolean</a></code></span></div></summary></details></div></div></section></main><nav id="topnav"><div><div id="menubutton"><label for="sidenav-toggle">Menu</label></div><form id="searchbox"><div><input type="search" placeholder="Search" tabindex="1"></div></form></div></nav><nav id="sidenav"><input type="checkbox" id="sidenav-types-ctrl" /><input type="checkbox" id="sidenav-files-ctrl" /><input type="checkbox" id="sidenav-modules-ctrl" /><a id="sidenav-overview"><div><h4>Overview</h4></div></a><div id="sidenav-types"><label for="sidenav-types-ctrl"><h4>Types</h4></label><i>No data</i></div><div id="sidenav-modules"><label for="sidenav-modules-ctrl"><h4>Modules</h4></label><i>No data</i></div><div id="sidenav-files"><label for="sidenav-files-ctrl"><h4>Files</h4></label><i>No data</i></div><a href="license.html"><div><h4>License</h4></div></a></nav><div id="push-footer"></div></div><footer><a href="https://github.com/jleyba/js-dossier">Generated by dossier</a></footer><script src="types.js"></script><script src="dossier.js"></script>