|
About
PurposeJavaScript has always been considered as a second-rate language in spite of its powerful features. These features like exceptions, closures, garbage collection, generator, ..., can make JavaScript an efficient and modern general-purpose scripting language like python and ruby. The main issue is that there are no or only few ways to execute JavaScript code outside the web browser. jslibs is based on Spidermonkey, the mozilla's JavaScript engine. Usually SpiderMonkey is used to enable scripting capabilities of existing projects but not for a standalone development environment. jslibs is composed of a set of general-purpose libraries and a host to execute JavaScript source files. The aim of jslibs is to be simple to use, fast, safe and lightweight. ModulesIn jslibs a module is the name given to a dynamically linked library (.dll or .so) that content a set of related classes an functions. A module can be a simple wrapper to an existing library. Modules are loaded using the LoadModule() function witch is the only function that is provided by the script host (jshost and jswinhost). jslibs modules
Wrappers to third party libraries
By default, modules are loaded in the global namespace, however, it is possible to load a module in a custom namespace: Load a module in the global namespace (default): LoadModule('jssqlite');
...
var db = new Database('myDatabase');Load a module in a custom namespace: var sqlite = {}; // create the namespace
LoadModule.apply(sqlite, 'jssqlite'); // load the module inside the namespace
...
var db = new sqlite.Database('myDatabase');Standard moduleSpiderMonkey is only a language library, and, for example, it does not provide any standard input or output access. To display something on the screen, at least a Print function is needed. jsstd module provide a minimal set of basic programing functions like Print(), Expand(), Seal(), ... . Another important basic function is Exec() that allows you to load (compile and execute) other scripts. The Exec() function saves the compiled version of the script to the disk, to speeds up following loads of the same script. The format used to store the compiled script version is XDR (External Data Representation XDR IETF standard) Simplicity of useUsing these libraries is very simple and the modules can be load at run-time, this allows a good modularity of the code. Each module is loaded only once even if you call LoadModule several times with the same argument. Deflate a string using zlib: LoadModule('jsz');
deflatedText = new Z(Z.DEFLATE)('This text will be deflated', true);Query the version of a sqlite database file: LoadModule('jssalite');
myDatabaseVersion = new Database('myDatabase').Exec('PRAGMA user_version');Server-Side scriptingOne interesting feature of jslibs is its server-side scripting capability. Using jshost as a FastCGI program allow server-side applications development. see the page HOWTO for further information. ConfigurationEach module can use the global configuration object (configuration) to get some informations about the execution environment. This object is optional an neither module nor host should rely on it. Safe modeInternaly, jslibs supports two execution modes: safe mode and unsafe mode. This mode is transmitted to other modules using the configuration object. Modules can use this information to make more tests and assertions in its code. The safe mode is like a run-time debug mode. Standard output and errorThe global configuration object also stores two javascript functions to write, output messages and error messages. By default, jshost bind these functions do stdout and stderr, and jswinhost do not define them. These functions can be overrided by redefining them. eg. LoadModule('jswinshell');
_configuration.stderr = MessageBox;
LoadModule('jsstd');Global objectThe global namespace object is also defined with 'global' Using jslibs in a third-party application(TBD) supported platformsCurrently, the supported platforms are Windows and Linux, and MacOSX soon. Licensejslibs is an open-source project under the GNU GPL2 license. External Links
|