This port discusses JavaScript code modules and how they can be used in Firefox 4 add-ons to simplify code and more easily access functionality.
|
|
||
|
This port discusses JavaScript code modules and how they can be used in Firefox 4 add-ons to simplify code and more easily access functionality. This post shows you how to build the two V8 JavaScript shells on Fedora 14 and modify them to support shebang functionality. It also shows you how to modify the samples shell to support command line history. This post shows you how to build the Mozilla TraceMonkey JavaScript shell on Fedora 14. A number of examples are also provided to show you how to load and execute JavaScript scripts using this JavaScript shell. Recently I was working on a fairly complex JavaScript script relating to floating point conversions for a new Web page. After a while I got tired on trying to debug the problem via a Web browser and decided to see if I could find a JavaScript shell, i.e. a standalone Javascript intrepreter just like Ruby’s irb, Python’s interactive prompt or the Korn shell, which could load and run JavaScript scripts from the command line without having to reload a Web page. First, some background on the JavaScript langauge for those who are unfamilar with the details. JavaScript is a complex full-featured weakly typed object- based functional programming language originally developed by Brendan Eich in 1995 while working on the Netscape Navigator browser.  It is most frequently used in client-side web applications but is also used to enable scripting access to embedded objects in other applications. The langauge has been standardized in the ECMA-262 (ECMAScript) specification. The first version of ECMAScript was published in June 1997, and was partially based on JavaScript v1.2. The current version is Edition 3 (Dec 1999) and work is ongoing on the next edition. Formally, Javascript is a dialect of ECMAScript whose langauge specification is controlled by the Mozilla Foundation. There are other dialects including ActionScript which the scripting language used in Adobe Flash. Javascript is still evolving as a language and several versions are in daily use. The current version is JavaScript 1.8. The JavaScript engine in Firefox is written in C. It was orginally called Javascript Reference (JSRef) but nowadays is known as SpiderMonkey. Other Mozilla products also use this engine and it is available to the public under a MPL/GPL/LGPL tri-license. The current version, SpiderMonkey 1.7, conforms to JavaScript 1.8 which is a superset of ECMA-262 Edition 3. It consists of a library (or DLL) containing the JavaScript runtime (compiler, interpreter, decompiler, garbage collector, atom manager and standard classes) engine. This codebase has no dependencies on the rest of the Mozilla codebase. The codebase also contains the routines for a simple user interface which can be linked to the runtime library in order to make a command line shell. You can download the source code for SpiderMonkey 1.7 here. Aternatively you can use wget,curl or ftp to download the tarball. No build script is provided with this version of SpiderMonkey. Here is how I downloaded, built and smoketest’ed the shell. mkdir mozilla cd mozilla wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz tar xzf js-1.7.0.tar.gz cd js/src make -f Makefile.ref If everything compiles |
||
|
Copyright © 2005-2012 Finnbarr P. Murphy. All Rights Reserved. |
||