tutorial

This is an old revision of the document!


Tutorial

Here, you can find a small tutorial of AspectScript.

To insert aspects, AspectScript instruments the code. This transformation can make it in two ways. The first is easier, but it is lesser efficient. The second is a little bit more complicated but it is more efficient.

The easy way

This way is ideal when you are learning AspectScript or you are editing and testing the AspectScript code on-the-fly. To use AspectScript, you has to include a JavaScript script in the following way:

<script language="javascript" src="jst.php?url=script.js"> </script>

The jst.php is the PHP file available in AspectScript

The efficient way

The previous solution is a little bit inefficient because AspectScript modifies the JavaScript code every time that the Web page is loaded. You can transform the JavaScript code once and then you include the transformed script. To transform the code, you must execute the code:

cat script.js | js -f 'launcher.js' > newscript.js

In the web page you include the new script

<script language="javascript" src="newscript.js"> </script>

The aspects of AspectScript are pointcut-advices pairs. The pointcuts and advices are JavaScript functions. For instance, if you need to identify all executions of the foo function.

AspectScript.after(AspectScript.Pointcuts.exec(foo), function(jp) {
        alert("foo was executed");
});

You want to learn more about AspectScript, you can read the technical report

  • tutorial.1252939224.txt.gz
  • Last modified: 2009/09/25 16:01
  • (external edit)