mozdev.org

Delphi 

projects:
resources:
<- Back

Bridge Classes: TJSEngine

All script interactivity begins with this component and all of the other bridge classes depend on this one. If your application is multithreaded, you'll create a new instance of TJSEngine for each thread.

Properties
  • Context: PJSContext

    Only advanced users should use this property in their code. A developer can use this value when working with the SpiderMonkey API.
  • Global: TJSObject

    This property grants access to the global scope when interfacing with script. From here, users can create variables, call functions, etc, which are accessible to the global scope.
Methods
  • constructor Create(MaxMemory: Cardinal);

    The one parameter to the constructor is a maximum-memory limit. In other words, the amount of memory used by your JavaScript will never exceed this number. Note that it is not allocated all at once. It is simply the point where SpiderMonkey will forcibly deallocate memory.
  • function Declare(val: Integer; const name: string = ''): TJSInteger;
    function Declare(var val: TJSBaseArray; const name: string = ''): TJSArray;
    function Declare(val: Double; const name: string = ''): TJSDouble;
    function Declare(const val: string; const name: string = ''): TJSString;
    function Declare(val: Boolean; const name: string = ''): TJSBoolean;

    These methods create bridge variables A bridge variable is one that can be modified by both Delphi / Kylix code and script code. Any change made in one will be reflected in the other. of the specified type. Declaring a variable without a name creates an anonymous variableAnonymous variables do not have names, and are only usable as parameters when calling a JavaScript function. Assign the variable a name to use it within script code. (See the Call method of TJSObject.). For all other purposes provide a name for the variable as well.
  • function Evaluate(const code: string; scope: TJSObject): Boolean;

    This method runs the JavaScript in code within the scope of the provided object. If scope is nil, the code will run within the TJSEngine.Global scope. This method returns true if the execution completed successfully.
  • function Evaluate(const code: string): Boolean;

    This method runs the JavaScript in code within the TJSEngine.Global scope. This method returns true if the execution completed successfully.
  • procedure GarbageCollect;

    While garbage collecting works, it is not necessary except under very specific conditions. You shouldn't need to call this method at any time.
  • function IsExceptionRaised: Boolean;

    This is more of a token method. This was only necessary before I added custom error reporters. When an exception is raised, this function will return true. However, the error reporter will get those details long before you think of checking this function.
  • function IsValidCode(const code: String): Boolean;

    Returns true if the JavaScript in code will compile. As far as I know, this method does not perform any error checking.
  • function NewJSObject: TJSObject;

    Creates an empty TJSObject at the global scope. The resulting object does not have a name until you assign one via the Name property. In the meantime it is an anonymous variableAnonymous variables do not have names, and are only usable as parameters when calling a JavaScript function. Assign the variable a name to use it within script code. (See the Call method of TJSObject.).
  • function NewJSObject(const name: string): TJSObject;

    This creates an empty, named TJSObject at the global scope. Properties and methods can be added to this object from either script or Delphi / Kylix.
  • function NewJSObject(const name: string; parent: TJSObject): TJSObject;

    This creates an empty, named TJSObject at the scope specified in parent. Properties and methods can be added to this object from either script or Delphi / Kylix.
  • procedure SetErrorReporter(proc: JSErrorReporter);

    The definition of this method will change by the next release to accept a TJSErrorReporter, which will wrap error notifications in an object. You can find a default error reporter called IntfBridge_ErrorReporter in jsintf_bridge.pas.

The delphi project can be contacted through the mailing list or the member list.
Copyright © 2000-2017. All rights reserved. Terms of Use & Privacy Policy.