Class Index | File Index

Classes


Class com.jiffeegames.Checks

This class defines some checking routines that help with error handling. These are class static routines, so there is no need to ever create a "Checks" object. The normal way to use these routines is:

com.jiffeegames.Checks.validate(arguments);
...
com.jiffeegames.Checks.error(arguments, 'ABCNNN', 'message');
It is really important to use these methods, and to provide good explanatory messages, because JIFFEE is intended for use by novices who don't have a clue about programming or about JavaScript. Without clear and specific diagnostics, they won't stand a chance of getting their games to work correctly. In order for these to work optimally, you must give all functions, even "anonymous" ones, a good name, e.g.
Wizard.prototype.shazam = function shazam(arg1, arg2, ..., argN) {
  var checks = com.jiffeegames.Checks;
  checks.validate(arguments);
  ...
  if (today() === 'tuesday') {
      checks.error(arguments,
                   'WIZ007',
                   'Magic spells are not allowed on Tuesdays.');
    }
  ...
  };
In the rest of JIFFEE we stick to a convention of packaging things as objects and passing them to constructors of other objects. This use of dependency injection makes it easier to test and isolate problems. This pseudo-class deliberately violates that convention, because following it would lead to chicken-and-egg problems if a Checks argument to a constructor was missing.
Defined in: jiffee-checks.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
A dummy constructor, so that jsdoc can figure out that this is a class.
Method Summary
Method Attributes Method Name and Description
<static>  
com.jiffeegames.Checks.error(parentArgs, code, msg)
Throw an error with a formatted diagnostic message.
<static>  
com.jiffeegames.Checks.formatErrorInHTML(e)
Format an error message for HTML.
<static>  
com.jiffeegames.Checks.initOnly(parentArgs, started)
Verify that the function is called only during the init phase.
<static>  
com.jiffeegames.Checks.runningOnly(parentArgs, started)
Verify that the function is called only during the running phase.
<static>  
com.jiffeegames.Checks.validate(parentArgs)
Verify that the number of arguments provided matches the number expected by the function definition.
Class Detail
com.jiffeegames.Checks()
A dummy constructor, so that jsdoc can figure out that this is a class.
Method Detail
<static> {void} com.jiffeegames.Checks.error(parentArgs, code, msg)
Throw an error with a formatted diagnostic message.
Parameters:
{Arguments} parentArgs
The "arguments" taken directly from the calling function. This is used to create a nicely formatted error message which includes the name and all arguments of the calling function.
{String} code
An arbitrary code which will be set as the "jiffeeCode" property of the thrown error. This can then be used by unit tests to verify that the correct error-checking was executed.
{String} msg
An explanatory message. This will be included as part of the "message" property of the the thrown error.
Throws:
Error with a jiffeeCode and a nicely formatted message.
Returns:
Never returns (always throws).

<static> {void} com.jiffeegames.Checks.formatErrorInHTML(e)
Format an error message for HTML. This is intended for use at the very top-level, where all errors are caught and displayed to the user.
Parameters:
{Error} e
- The error object to be interpreted.

<static> {void} com.jiffeegames.Checks.initOnly(parentArgs, started)
Verify that the function is called only during the init phase.
Parameters:
parentArgs
started
Throws:
Error with a jiffeeCode, if the phase is wrong.

<static> {void} com.jiffeegames.Checks.runningOnly(parentArgs, started)
Verify that the function is called only during the running phase.
Parameters:
parentArgs
started
Throws:
Error with a jiffeeCode, if the phase is wrong.

<static> {void} com.jiffeegames.Checks.validate(parentArgs)
Verify that the number of arguments provided matches the number expected by the function definition. This checks only the number of arguments; if you need to check types you must do that with separate "if" statements.
Parameters:
{Arguments} parentArgs
- The "arguments" taken directly from the calling function, and passed on to "error" to allow nice formatting of diagnostic messages.
Throws:
Error with a jiffeeCode, if the number of arguments is wrong.

Documentation generated by JsDoc Toolkit 2.3.2 on Sun Jul 25 2010 13:49:30 GMT-0700 (PDT)