Delphi
| projects: | Home Articles JavaScript Bridge |
|---|---|
| resources: | Bugs Mailing List Source Code Sidebar |
Bridge Classes: TJSScript
This class provides methods for easy compilation, execution, serialization, and deserialization of JavaScript code. Methods are also available for loading, saving, and streaming both raw and compiled code. This class provides streaming for compiled code only, however, since streaming the raw JavaScript code is trivial.
Properties
- Code: String
Reads and writes the code contained in the class. This property may be empty, even thoughCompiledistrue. - Compiled: Boolean
When true the class contains an image of the compiled JavaScript inCode.
Methods
- constructor Create; overload;
Creates an empty class with no JavaScript. - constructor Create(const ACode: String); overload;
Automatically populates theCodeproperty with the JavaScript inACode. - constructor Create(const ACode: String; AEngine: TJSEngine); overload;
Automatically populates theCodeproperty, then compiles it using the providedTJSEngineinstance. - procedure Compile(AEngine: TJSEngine);
Compiles the contained JavaScript and setsCompiledtotrue. - procedure Execute(AEngine: TJSEngine); overload;
Executes the JavaScript using the providedTJSEngineinstance in the global scope. - procedure Execute(AEngine: TJSEngine; AScope: TJSObject); overload;
Executes the JavaScript using the providedTJSEngineinstance in the specified scope. - procedure LoadCompiled(const AFile: String; AEngine: TJSEngine);
Loads the precompiled JavaScript code from the specified file. TheCompiledproperty is set totrue, and theCodeproperty is emptied. - procedure LoadCompiledFromStream(AStream: TStream; AEngine: TJSEngine);
Loads the precompiled JavaScript code from the specified stream. TheCompiledproperty is set totrue, and theCodeproperty is emptied. - procedure LoadRaw(const AFile: String);
Loads raw (text) JavaScript from the specified file. TheCompiledproperty is set tofalse. - procedure SaveCompiled(const AFile: String; AEngine: TJSEngine);
Attempts to save the compiled JavaScript to the specified file. If the JavaScript has not yet been compiled, it will attempt to do so. - procedure SaveCompiledToStream(AStream: TStream; AEngine: TJSEngine);
Saves the compiled JavaScript to the specified stream. If the JavaScript has not yet been compiled, it will attempt to do so. - procedure SaveRaw(const AFile: String);
Saves the raw (text) JavaScript to the specified file.