Namespace goog.asserts

code »

Classes

goog.asserts.AssertionError
Error object for failed assertions.
Show:

Global Functions

code »goog.asserts.assert ( condition, opt_message, var_args )*

Checks if the condition evaluates to true if goog.asserts.ENABLE_ASSERTS is true.

Parameters
condition: *
The condition to check.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Returns
The value of the condition.
Throws
goog.asserts.AssertionError
When the condition evaluates to false.
code »goog.asserts.assertArray ( value, opt_message, var_args )!Array

Checks if the value is an Array if goog.asserts.ENABLE_ASSERTS is true.

Parameters
value: *
The value to check.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Returns
The value, guaranteed to be a non-null array.
Throws
goog.asserts.AssertionError
When the value is not an array.
code »goog.asserts.assertBoolean ( value, opt_message, var_args )boolean

Checks if the value is a boolean if goog.asserts.ENABLE_ASSERTS is true.

Parameters
value: *
The value to check.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Returns
The value, guaranteed to be a boolean when asserts are enabled.
Throws
goog.asserts.AssertionError
When the value is not a boolean.
code »goog.asserts.assertFunction ( value, opt_message, var_args )!Function

Checks if the value is a function if goog.asserts.ENABLE_ASSERTS is true.

Parameters
value: *
The value to check.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Returns
The value, guaranteed to be a function when asserts enabled.
Throws
goog.asserts.AssertionError
When the value is not a function.
code »<T> goog.asserts.assertInstanceof ( value, type, opt_message, var_args )!T

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.

Parameters
value: *
The value to check.
type: function(new: T, ...)
A user-defined constructor.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Throws
goog.asserts.AssertionError
When the value is not an instance of type.
code »goog.asserts.assertNumber ( value, opt_message, var_args )number

Checks if the value is a number if goog.asserts.ENABLE_ASSERTS is true.

Parameters
value: *
The value to check.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Returns
The value, guaranteed to be a number when asserts enabled.
Throws
goog.asserts.AssertionError
When the value is not a number.
code »goog.asserts.assertObject ( value, opt_message, var_args )!Object

Checks if the value is an Object if goog.asserts.ENABLE_ASSERTS is true.

Parameters
value: *
The value to check.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Returns
The value, guaranteed to be a non-null object.
Throws
goog.asserts.AssertionError
When the value is not an object.
code »goog.asserts.assertString ( value, opt_message, var_args )string

Checks if the value is a string if goog.asserts.ENABLE_ASSERTS is true.

Parameters
value: *
The value to check.
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Returns
The value, guaranteed to be a string when asserts enabled.
Throws
goog.asserts.AssertionError
When the value is not a string.
code »goog.asserts.doAssertFailure_ ( defaultMessage, defaultArgs, givenMessage, givenArgs )

Throws an exception with the given message and "Assertion failed" prefixed onto it.

Parameters
defaultMessage: string
The message to use if givenMessage is empty.
defaultArgs: Array
The substitution arguments for defaultMessage.
givenMessage: (string|undefined)
Message supplied by the caller.
givenArgs: Array
The substitution arguments for givenMessage.
Throws
goog.asserts.AssertionError
When the value is not a number.
code »goog.asserts.fail ( opt_message, var_args )

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:

  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.
  }
 
Parameters
opt_message: string=
Error message in case of failure.
var_args: ...*
The items to substitute into the failure message.
Throws
goog.asserts.AssertionError
Failure.

Compiler Constants