Code — Copy and Paste AJS_HP
Quick Access to the Code for the AJS_HP Object
T
he JavaScript code that defines the AJS_HP object can be acquired in structured and minified forms by downloading the zip file that is available through the AspectJS Download page on this site.
However, some developers may be unable or unwilling to perform such downloads, therefore this page offers an alternative, wherein the code can be acquired simply by performing a click-drag operation across the listing below, before copying and pasting the selection into a file within an editor.
Developers who desire a minified version should either pass the code below through a minifier such as JSMin, or should download the zip file. See the Download page for a discussion of obfuscation (scrunching) and compression issues.
Note that the point size of the listing below is deliberately small in order to allow the reader to gain an overall impression of the structure of the code, and in order to make it a little easier to mark out with a click-drag of the mouse. Exception object message-strings are laid out on a single line for each in order to facilitate comparison between the contents of different messages.
AJS_HP v1.0 Source
 /*

 == AspectJS - AJS_HP V1.0 ======================================================

 Copyright (c) 2007 Dodeca Technologies Ltd.

 Designed and developed by Richard Vaughan.

 For API documentation visit: http://www.aspectjs.com/API_00.htm
 For a tutorial visit:        http://www.aspectjs.com/Tutorial_00.htm

 Permission is granted hereby and free of charge, to any person obtaining a copy
 of this software and associated applications-programming-interface (API) documentation
 (the 'Software'), to deal in the Software without restriction including, and without
 limitation, the rights to use, copy, modify, merge, publish, distribute, sub-license,
 and/or sell copies of the Software, and to permit persons to whom the Software is
 furnished to do the same, subject to the following three conditions:

 1) The Software is provided 'as is', without warranty of any kind, express or
    implied, and including, but not limited to, the warranties of merchantability,
    fitness for a particular purpose, and non-infringement. In no event shall the
    authors or copyright holders be liable for any claim, damages or other
    liability; whether in an action of contract, tort or otherwise, arising from,
    out of, or in connection with the Software, its use, or any other dealings in
    the Software.

 2) This license does not extend to any tutorial documentation provided by Dodeca
    Technologies Ltd, and the sole copyright to such documentation resides with
    that company.

 3) The Software will not be used with malicious intent.

 ================================================================================*/

 var AJS_HP =
    {
    NullFunc          : function () {                  },
    ReturnZero        : function () { return 0;        },
    ReturnNull        : function () { return null;     },

    ReturnInfinity    : function () { return Infinity; },
    ReturnFalse       : function () { return false;    },

    NullFuncCallTotal : 0,                                  // Is not used, and is present here only to preserve symmetry with AJS

    //--------------------------------------------------------------------------------

    AddPrefix : function (IntercepteeOwner, Interceptee, PrefixFunc, PrefixArg, ExecMax)
       {
       if (this !== AJS_HP)                                       { throw new Error ("AJS_HP.AddPrefix - 'this' reference does not refer to the AJS_HP object; do not invoke AJS_HP methods using 'apply' or 'call'"); }
       if (IntercepteeOwner[Interceptee].IsAspectJS_HP_Intercept) { throw new Error ("AJS_HP.AddPrefix - Function is already intercepted by AJS_HP, use AJS to apply additional affixes"); }
       if (IntercepteeOwner[Interceptee].IsAspectJSIntercept)     { throw new Error ("AJS_HP.AddPrefix - Function is already intercepted by AJS, use that object to apply additional affixes"); }

       var DecrExecMax = AJS_HP.NullFunc;

       var DecrFunc    = function ()
          {
          ExecMax--;
          if (ExecMax === 0) { Prefix.Remove (); }
          };

       if ((ExecMax)
       &&   ExecMax < Infinity) { DecrExecMax = DecrFunc; }

       // - ---------------------------------------------

       var Prefix =
          {
          GetPrev           : function () { return this; },
          GetNext           : function () { return this; },

          AddBefore         : function () { return this; },
          AddAfter          : function () { return this; },

          Promote           : AJS_HP.ReturnFalse,
          Demote            : AJS_HP.ReturnFalse,

          Remove            : function ()
             {
             if (this !== Prefix) { throw new Error ("(AJS_HP) Affix.AddAfter - 'this' reference does not refer to the Affix object on which it should have been called; do not invoke AJS_HP Affix-methods using 'apply' or 'call'. Client-code call point: "); }

             IntercepteeOwner[Interceptee] = IntercepteeRef;

             this.Remove            = AJS_HP.NullFunc;

             this.GetExecsRemaining =
             this.SetExecMax        = AJS_HP.ReturnZero;

             },

          GetExecsRemaining : function () { return ExecMax; },
          SetExecMax        : function (NewExecMax)
             {
             var OldExecMax = ExecMax;

             ExecMax = NewExecMax;

             if (ExecMax === Infinity) { DecrExecMax = AJS_HP.NullFunc; }
             else                      { DecrExecMax = DecrFunc;        }

             return OldExecMax;

             }

          };

       // - ---------------------------------------------

       function Proxy ()
          {
          try       { PrefixFunc.call (this, PrefixArg, undefined, arguments); }
          catch (E) { }

          DecrExecMax ();

          var Result = IntercepteeRef.apply (this, arguments);

          return Result;

          }

       var IntercepteeRef = IntercepteeOwner[Interceptee];

       IntercepteeOwner[Interceptee] = Proxy;
       Proxy.IsAspectJS_HP_Intercept = true;

       return Prefix;

       },


    // - -----------------------------------------------------------------------------------------------------------------------

    AddSuffix : function (IntercepteeOwner, Interceptee, SuffixFunc, SuffixArg, ExecMax)
       {
       if (this !== AJS_HP)                                       { throw new Error ("AJS_HP.AddSuffix - 'this' reference does not refer to the AJS_HP object; do not invoke AJS_HP methods using 'apply' or 'call'"); }
       if (IntercepteeOwner[Interceptee].IsAspectJS_HP_Intercept) { throw new Error ("AJS_HP.AddSuffix - Function is already intercepted by AJS_HP, use AJS to apply additional affixes"); }
       if (IntercepteeOwner[Interceptee].IsAspectJSIntercept)     { throw new Error ("AJS_HP.AddSuffix - Function is already intercepted by AJS, use that object to apply additional affixes"); }

       var DecrExecMax = AJS_HP.NullFunc;

       var DecrFunc    = function ()
          {
          ExecMax--;
          if (ExecMax === 0) { Suffix.Remove (); }
          };

       if ((ExecMax)
       &&   ExecMax < Infinity) { DecrExecMax = DecrFunc; }


       //--------------------------------------------------------------------------------

       var Suffix =
          {
          GetPrev           : function () { return this; },
          GetNext           : function () { return this; },

          AddBefore         : function () { return this; },
          AddAfter          : function () { return this; },

          Promote           : AJS_HP.ReturnFalse,
          Demote            : AJS_HP.ReturnFalse,

          Remove            : function ()
             {
             if (this !== Suffix) { throw new Error ("(AJS_HP) Affix.AddAfter - 'this' reference does not refer to the Affix object on which it should have been called; do not invoke AJS_HP Affix-object methods using 'apply' or 'call'. Client-code call point: "); }

             IntercepteeOwner[Interceptee] = IntercepteeRef;

             this.Execute_          =
             this.Remove            = AJS_HP.NullFunc;

             this.GetExecsRemaining =
             this.SetExecMax        = AJS_HP.ReturnZero;

             },

          GetExecsRemaining : function () { return ExecMax; },
          SetExecMax        : function (NewExecMax)
             {
             var OldExecMax = ExecMax;

             ExecMax = NewExecMax;

             if (ExecMax === Infinity) { DecrExecMax = AJS_HP.NullFunc; }
             else                      { DecrExecMax = DecrFunc;        }

             return OldExecMax;

             },

          Execute_          : function (IResult)
             {
             try       { SuffixFunc.call (this, SuffixArg, undefined, arguments, IResult); }
             catch (E) { }

             DecrExecMax ();

             }

          };

       //--------------------------------------------------------------------------------

       function Proxy ()
          {
          var Result = IntercepteeRef.apply (this, arguments);

          Suffix.Execute_.call (this, Result);

          return Result;

          }

      var IntercepteeRef = IntercepteeOwner[Interceptee];

      IntercepteeOwner[Interceptee] = Proxy;
      Proxy.IsAspectJS_HP_Intercept = true;

      return Suffix;

      },


    // - -----------------------------------------------------------------------------------------------------------------------

    AddWrapper : function (IntercepteeOwner, Interceptee, PrefixFunc, PrefixArg, PrefixExecMax,
                                                          SuffixFunc, SuffixArg, SuffixExecMax)
       {
       if (this !== AJS_HP)                                       { throw new Error ("AJS_HP.AddWrapper - 'this' reference does not refer to the AJS_HP object; do not invoke AJS_HP methods using 'apply' or 'call'"); }
       if (IntercepteeOwner[Interceptee].IsAspectJS_HP_Intercept) { throw new Error ("AJS_HP.AddWrapper - Function is already intercepted by AJS_HP, use AJS to apply additional affixes"); }
       if (IntercepteeOwner[Interceptee].IsAspectJSIntercept)     { throw new Error ("AJS_HP.AddWrapper - Function is already intercepted by AJS, use that object to apply additional affixes"); }

       function RemovePrefix ()
          {
          Wrapper.Prefix.Remove            = AJS_HP.NullFunc;

          Wrapper.Prefix.GetExecsRemaining =
          Wrapper.Prefix.SetExecMax        = AJS_HP.ReturnZero;

          if (DecrExecMax_Suffix == AJS_HP.NullFunc) { IntercepteeOwner[Interceptee] = IntercepteeRef;    }
          else                                       { PrefixFunc = DecrExecMax_Prefix = AJS_HP.NullFunc; }

          }

       function RemoveSuffix ()
          {
          Wrapper.Suffix.Execute_          =
          Wrapper.Suffix.Remove            = AJS_HP.NullFunc;

          Wrapper.Suffix.GetExecsRemaining =
          Wrapper.Suffix.SetExecMax        = AJS_HP.ReturnZero;

          if (DecrExecMax_Prefix == AJS_HP.NullFunc) { IntercepteeOwner[Interceptee]   = IntercepteeRef;  }
          else                                       { SuffixFunc = DecrExecMax_Suffix = AJS_HP.NullFunc; }

          }

       var DecrExecMax_Prefix = AJS_HP.NullFunc;
       var DecrExecMax_Suffix = AJS_HP.NullFunc;

       var DecrFunc_Prefix    = function ()
          {
          PrefixExecMax--;
          if (PrefixExecMax === 0) { RemovePrefix (); }
          };

       var DecrFunc_Suffix    = function ()
          {
          SuffixExecMax--;
          if (SuffixExecMax === 0) { RemoveSuffix (); }
          };

       if ((PrefixExecMax) && PrefixExecMax < Infinity) { DecrExecMax_Prefix = DecrFunc_Prefix; }
       if ((SuffixExecMax) && SuffixExecMax < Infinity) { DecrExecMax_Suffix = DecrFunc_Suffix; }


       //--------------------------------------------------------------------------------

       var Wrapper =
          {
          Prefix :
             {
             GetPrev           : function () { return this; },
             GetNext           : function () { return this; },

             AddBefore         : function () { return this; },
             AddAfter          : function () { return this; },

             Promote           : AJS_HP.ReturnFalse,
             Demote            : AJS_HP.ReturnFalse,

             Remove            : RemovePrefix,

             GetExecsRemaining : function () { return PrefixExecMax; },
             SetExecMax        : function (NewExecMax)
                {
                var OldExecMax = PrefixExecMax;

                PrefixExecMax = NewExecMax;

                if (PrefixExecMax === Infinity) { DecrExecMax_Prefix = AJS_HP.NullFunc; }
                else                            { DecrExecMax_Prefix = DecrFunc_Prefix; }

                return OldExecMax;

                }

             },

          // - ---------------------------------------------

          Suffix :
             {
             GetPrev           : function () { return this; },
             GetNext           : function () { return this; },

             AddBefore         : function () { return this; },
             AddAfter          : function () { return this; },

             Promote           : AJS_HP.ReturnFalse,
             Demote            : AJS_HP.ReturnFalse,

             Remove            : RemoveSuffix,

             GetExecsRemaining : function () { return SuffixExecMax; },
             SetExecMax        : function (NewExecMax)
                {
                var OldExecMax = SuffixExecMax;

                SuffixExecMax = NewExecMax;

                if (SuffixExecMax === Infinity) { DecrExecMax_Suffix = AJS_HP.NullFunc; }
                else                            { DecrExecMax_Suffix = DecrFunc_Suffix; }

                return OldExecMax;

                },

             Execute_          : function (IResult)
                {
                try       { SuffixFunc.call (this, SuffixArg, undefined, arguments, IResult); }
                catch (E) { }

                DecrExecMax_Suffix ();

                }

             },

          // - ---------------------------------------------

          Promote    : AJS_HP.ReturnFalse,
          Demote     : AJS_HP.ReturnFalse,

          Remove     : function ()
             {
             Wrapper.Prefix.Remove ();
             Wrapper.Suffix.Remove ();

             return this;

             },

          SetExecMax : function (NewExecMax_Prefix, NewExecMax_Suffix)
             {
             Wrapper.Prefix.SetExecMax (NewExecMax_Prefix);
             Wrapper.Suffix.SetExecMax (NewExecMax_Suffix);
             }

          };


       //--------------------------------------------------------------------------------

       function Proxy ()
          {
          try       { PrefixFunc.call (this, PrefixArg, undefined, arguments, undefined); }
          catch (E) { }

          DecrExecMax_Prefix ();

          var Result = IntercepteeRef.apply (this, arguments);

          Wrapper.Suffix.Execute_.call (this, Result);

          return Result;

          }

       var IntercepteeRef = IntercepteeOwner[Interceptee];

       IntercepteeOwner[Interceptee] = Proxy;
       Proxy.IsAspectJS_HP_Intercept = true;

       return Wrapper;

       },


    // - -----------------------------------------------------------------------------------------------------------------------

    AddSymmetricWrapper : function (IntercepteeOwner, Interceptee, WrapperFunc, WrapperArg, ExecMax)
       {
       if (this !== AJS_HP)                                       { throw new Error ("AJS_HP.AddSymmetricWrapper - 'this' reference does not refer to the AJS_HP object; do not invoke AJS_HP methods using 'apply' or 'call'"); }
       if (IntercepteeOwner[Interceptee].IsAspectJS_HP_Intercept) { throw new Error ("AJS_HP.AddSymmetricWrapper - Function is already intercepted by AJS_HP, use AJS to apply additional affixes"); }
       if (IntercepteeOwner[Interceptee].IsAspectJSIntercept)     { throw new Error ("AJS_HP.AddSymmetricWrapper - Function is already intercepted by AJS, use that object to apply additional affixes"); }

       var PrefixFunc         = WrapperFunc;
       var SuffixFunc         = WrapperFunc;

       var PrefixExecMax      = ExecMax;
       var SuffixExecMax      = ExecMax;

       function RemovePrefix ()
          {
          Wrapper.Prefix.Remove            = AJS_HP.NullFunc;

          Wrapper.Prefix.GetExecsRemaining =
          Wrapper.Prefix.SetExecMax        = AJS_HP.ReturnZero;

          if (DecrExecMax_Suffix == AJS_HP.NullFunc) { IntercepteeOwner[Interceptee]   = IntercepteeRef;  }
          else                                       { PrefixFunc = DecrExecMax_Prefix = AJS_HP.NullFunc; }

          }

       function RemoveSuffix ()
          {
          Wrapper.Suffix.Execute_          =
          Wrapper.Suffix.Remove            = AJS_HP.NullFunc;

          Wrapper.Suffix.GetExecsRemaining =
          Wrapper.Suffix.SetExecMax        = AJS_HP.ReturnZero;

          if (DecrExecMax_Prefix == AJS_HP.NullFunc) { IntercepteeOwner[Interceptee]   = IntercepteeRef;  }
          else                                       { SuffixFunc = DecrExecMax_Suffix = AJS_HP.NullFunc; }

          }

       var DecrExecMax_Prefix = AJS_HP.NullFunc;
       var DecrExecMax_Suffix = AJS_HP.NullFunc;

       var DecrFunc_Prefix    = function ()
             {
             PrefixExecMax--;
             if (PrefixExecMax === 0) { RemovePrefix (); }
             };

       var DecrFunc_Suffix    = function ()
             {
             SuffixExecMax--;
             if (SuffixExecMax === 0) { RemoveSuffix (); }
             };

       if ((PrefixExecMax) && PrefixExecMax < Infinity) { DecrExecMax_Prefix = DecrFunc_Prefix; }
       if ((SuffixExecMax) && SuffixExecMax < Infinity) { DecrExecMax_Suffix = DecrFunc_Suffix; }


       //--------------------------------------------------------------------------------

       var Wrapper =
          {
          Prefix :
             {
             GetPrev           : function () { return this; },
             GetNext           : function () { return this; },

             AddBefore         : function () { return this; },
             AddAfter          : function () { return this; },

             Promote           : AJS_HP.ReturnFalse,
             Demote            : AJS_HP.ReturnFalse,

             Remove            : RemovePrefix,

             GetExecsRemaining : function () { return PrefixExecMax; },
             SetExecMax        : function (NewExecMax)
                {
                var OldExecMax = PrefixExecMax;

                PrefixExecMax = NewExecMax;

                if (PrefixExecMax === Infinity) { DecrExecMax_Prefix = AJS_HP.NullFunc; }
                else                            { DecrExecMax_Prefix = DecrFunc_Prefix; }

                return OldExecMax;

                }

             },

          Suffix :
             {
             GetPrev           : function () { return this; },
             GetNext           : function () { return this; },

             AddBefore         : function () { return this; },
             AddAfter          : function () { return this; },

             Promote           : AJS_HP.ReturnFalse,
             Demote            : AJS_HP.ReturnFalse,

             Remove            : RemoveSuffix,

             GetExecsRemaining : function () { return SuffixExecMax; },
             SetExecMax        : function (NewExecMax)
                {
                var OldExecMax = SuffixExecMax;

                SuffixExecMax = NewExecMax;

                if (SuffixExecMax === Infinity) { DecrExecMax_Suffix = AJS_HP.NullFunc; }
                else                            { DecrExecMax_Suffix = DecrFunc_Suffix; }

                return OldExecMax;

                },

             Execute_ : function (IResult)
                {
                try       { SuffixFunc.call (this, WrapperArg, undefined, arguments, IResult); }
                catch (E) { }

                DecrExecMax_Suffix ();

                }

             },

          // - ---------------------------------------------

          Promote    : AJS_HP.ReturnFalse,
          Demote     : AJS_HP.ReturnFalse,

          Remove     : function ()
             {
             Wrapper.Prefix.Remove ();
             Wrapper.Suffix.Remove ();

             return this;

             },

          SetExecMax : function (NewExecMax_Prefix, NewExecMax_Suffix)
             {
             Wrapper.Prefix.SetExecMax (NewExecMax_Prefix);
             Wrapper.Suffix.SetExecMax (NewExecMax_Suffix);
             }

          };


       //--------------------------------------------------------------------------------

       function Proxy ()
          {
          try       { PrefixFunc.call (this, WrapperArg, undefined, arguments); }
          catch (E) { }

          DecrExecMax_Prefix ();

          var Result = IntercepteeRef.apply (this, arguments);

          Wrapper.Suffix.Execute_.call (this, Result);

          return Result;

          }

       var IntercepteeRef = IntercepteeOwner[Interceptee];

       IntercepteeOwner[Interceptee] = Proxy;
       Proxy.IsAspectJS_HP_Intercept = true;

       return Wrapper;

       }

    };
            
Copyright © Dodeca Technologies Ltd 2007