Bridge Classes: TJSEngine

All scripting interactivity begins with this component. 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.
  • Debugger: TJSDebugger Provides access to the instance of TJSDebugger being used for debugging, if any. This property is nil if no debugger has been set.
  • 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 of the specified type. Declaring a variable without a name creates an anonymous variable. 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.
  • function Execute(script: PJSScript): Boolean; Only advanced developers should use this method. It executes precompiled scripts, returning the success result.
  • procedure GarbageCollect; While GC'ing 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 variable.
  • 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 SetDebugger(dbg: TJSDebugger); Sets a custom TJSDebugger instance to use for debugging javascript with the given TJSEngine instance.
  • 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.
  • procedure StartDebugger; Creates an internal TJSDebugger instance to use for debugging javascript with the given TJSEngine instance.