Its home is currently http://github.com/oyvindkinsey/jsContract
Code contracts are implemented as a series of statements in the head of each function supporting both pre- and postconditions.
Contract.expectNumber(a,"a is not a number");
Contract.guaranteesString("The result was not a string");
To support postconditions one has to instrument the script (rewrite it) using a call to
, such as
var script = ".......";
var instrumented = Contract.instrument(script);
One can also use the Contract framework to asynchronously load and instrument files using
In the left textbox you will find an example of a class that is set up with code contracts.
When run this code will only execute the
statements, since the return values are not yet availabe.
To see the instrumented code press the button.
To see the regular and instrumented code in action, take a look at test2.html