My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

Jslibs is a standalone JavaScript development runtime environment for using JavaScript as a general-purpose scripting language.

jslibs uses SpiderMonkey library that is Gecko's JavaScript engine (SpiderMonkey is used in various Mozilla products, including Firefox). The latest version of jslibs uses the new TraceMonkey/JaegerMonkey library with tracing/method JIT enabled.

jslibs provides a set of native modules that contains various general purpose classes and functions.

Some of these modules are simple wrappers for familiar libraries such as: zlib, SQLite, FastCGI, NSPR (Netscape Portable Runtime) , ODE (Open Dynamics Engine) , libpng, libjpeg, librsvg, SDL, libiconv, OpenGL, OpenAL, ogg vorbis, libTomCrypt, libffi (Foreign function interface) , ...

Other modules provide tools for enhancing JavaScript programming : Print(), Load(), Exec(), Seal(), Expand(), Buffer class, Blob class, Sandbox class, ...

The jslibs distribution comes with a small standalone command line access program (jshost) that can be used to run JavaScript files. Note that the modules are quite independent from jshost and can be used in any project that embeds SpiderMonkey. A Windows binary (without console) is also available (jswinhost).

jslibs is available under GNU GPL 2.0 license. You can access the source code through the Subversion repository using the 'Source' tab.

Project documentation is available in the 'Wiki' tab. In this section, you can find modules and classes API.

If you would like to report a defect or request an enhancement, click the 'Issues' tab and read the existing issues. If no existing issue is relevant, you may enter a new one. You can also use the discussion group to propose new features.

Feel free to ask any question or make any comments on this project in the discussion group or the mailing list.

You can contact me at soubok+jslibs@gmail.com or leave a comment.

  • 2011.01.04 - Code optimization (speed and size).
  • 2010.12.31 - Fix Win32 compilation.
  • 2010.12.19 - Removing memory leaks.
  • 2010.10.27 - Update to JaegerMonkey engine (huge work).
  • 2010.10.19 - Working on Linux64 port.
  • 2010.03.21 - Adding OpenGL Vertex and Pixel Shaders support (GLSL).
  • 2010.03.15 - 3rd video
  • 2010.03.13 - 2nd video
  • 2010.03.11 - 1st video
  • 2010.02.24 - drawing arabesques using OpenGL (jsgraphics+jssdl)
  • 2010.02.16 - Working on 3D text drawing through OGLFT library.
  • 2010.02.11 - Buzz
  • 2010.01.10 - Working on a cross-module non-blocking system that allow to wait for I/O, SDL, task, videoInput, systray, endSignal and timeouts events from a single function. eg. ProcessEvents(IOEvents(descList), systray.Events(), EndSignalEvents(), TimeoutEvents(100) );
  • 2010.01.04 - new code snippet: "A minimalist HTTP server" see below. (thanks to Phil Rhodes)
  • 2009.12.09 - NEW DEVSNAPSHOT release available here.
  • 2009.12.07 - New project logo. Thanks a lot to Stéphanie Bentz.
  • 2009.11.25 - Linux: support installed shared libraries (using waf, the flexible build system). see defails
  • 2009.11.24 - Add UTF8/UTF16 scripts encoding support.
  • 2009.11.14 - Add ActiveX/COM support to jswinshell module.
  • 2009.10.26 - Checking for memory leaks.
  • 2009.10.23 - Linux32 compilation works again.
  • 2009.10.21 - Fixing Linux32 compilation.
  • 2009.10.19 - Updating libraries: SQLite-3.6.18, NSPR-4.8
  • 2009.10.13 - Trunk is unstable and does not compile on Linux, please use the last stable version of jslibs (see below).
  • 2009.10.03 - Great performance gain using threaded memory release + google's tcmalloc library.
  • 2009.09.28 - Working on threaded memory release.
  • 2009.09.22 - Updating the JavaScript engine to the latest version of TraceMonkey.
  • 2009.09.05 - New module: jsvideoinput (video capture for Windows).
  • 2009.09.02 - testing openCV to manage real-time video input devices with jslibs.
  • 2009.05.31 - NEW RELEASE jslibs version 0.95 r2572 has been release (release notes)
  • 2009.05.21 - Update TraceMonkey and SQLite to the latest version.
  • 2009.05.15 - working on Linux 64bit compilation.
  • 2009.05.13 - all memory leaks are fixed.
  • 2009.05.11 - fixing memory leaks.
  • 2009.05.09 - jslibs "testing" revision has been updated to r2434.
  • 2009.05.03 - bug fixing and stabilization.
  • . . .

SVN revision status

  • stable (last release + doc in sync): 2572 (May 31, 2009)
  • testing (compile + QA pass on Win & Linux 32bit): 3040 (Dec 9, 2009)
  • unstable (may crash): HEAD
(use svn checkout --revision #### http://jslibs.googlecode.com/svn/trunk/ ./jslibs or svn update --revision ####)

Some code snippets

Capture an image from a webcam (module jsvideoinput)

LoadModule('jsio');
LoadModule('jsimage');
LoadModule('jsvideoinput'); 

var vi = new VideoInput('QuickCam', 800, 600, 30); // 800x600 at 30fps
var img = vi.GetImage();
new File('myImage.png').content = EncodePngImage(img);

Create a JavaScript thread (module jstask)

LoadModule('jsstd');
LoadModule('jstask');

function MyTask( request ) {

 for ( var i = 0; i < 200000; i++); // working...
 return 'r#' + request;
}

var myTask = new Task(MyTask);

for ( var i = 0; i < 10; i++ )
 myTask.Request(i);

while ( !myTask.idle )
 Print( myTask.Response(), ', ' );

Create a PNG from SVG (modules jsimage, jssvg, jsio)

LoadModule('jsio');
LoadModule('jsimage');
LoadModule('jssvg');

var svgSource = <svg width="100%" height="100%">
 <rect x="0" y="0" width="100" height="100" fill="#FF4422" />
 <circle cx="50" cy="50" r="25" stroke="black" stroke-width="5" fill="none"/>
</svg>

var svg = new SVG();
svg.Write(svgSource);
svgimage = svg.RenderImage();
new File('myImage.png').content = EncodePngImage( svgimage );

Display the content of a file (module jsio)

Print( new File('test.txt').content );

Compress a string (module jsz)

var compressedText = new Z(Z.DEFLATE)('This text will be compressed', true);

Call MessageBoxA in User32.dll (module jsffi / jsni)

function Alert( text, caption ) {

 var ret = new NativeData().PU32.Alloc();
 new NativeModule('C:\\WINDOWS\\SYSTEM32\\User32').Proc('MessageBoxA')( ret, DWORD( 0 ), SZ(text), SZ( caption || 'Alert' ), DWORD( 1 ) );
 return ret[0];
}

One-line database query (module jssqlite)

var myDatabaseVersion = new Database('myDatabase').Exec('PRAGMA user_version');

Non-blocking sockets (module jsio)

var soc = new Socket();
soc.Connect( 'localhost', 8080 );
soc.writable = function(s) {

 delete soc.writable;
 s.Write('GET\r\n');
}
soc.readable = function(s) {

 Print( s.Read() );
}
while(!endSignal)
 Poll([soc],100);

Encrypt data using blowfish (module jscrypt)

var rnd = new Prng('yarrow');
rnd.AutoEntropy(128);

var key = new Hash('sha256')('this is a secret key');
var IV = rnd(Crypt.BlockLength('blowfish'));

var crypt = new Crypt( 'ctr', 'blowfish', key, IV );
var plainText = 'secret string';
var cipherData = crypt.Encrypt(plainText);

Draw "Hello world" in hello.png (module jsfont)

var f = new Font('arial.ttf');
f.size = 100;
var img = f.Draw('Hello world');
var file = new File('hello.png');
file.content = EncodePngImage(img);

Ogg Vorbis player (module jsaudio + jssound)

LoadModule('jsio');
LoadModule('jsstd');
LoadModule('jssound');
LoadModule('jsaudio');

var decoder = new OggVorbisDecoder(new File('41_30secOgg-q0.ogg').Open(File.RDONLY));

Oal.Open();
var src = Oal.GenSource();

var pcm, decodeSize = 512;
while ( (pcm = decoder.Read(decodeSize)) && !endSignal ) {

	Oal.SourceQueueBuffers(src, Oal.Buffer(pcm));
	if ( Oal.GetSourceInteger(src, Oal.SOURCE_STATE) == Oal.INITIAL )
		Oal.PlaySource(src);
	decodeSize = pcm.frames * 2;
}

var totalTime = decoder.frames/decoder.rate;
var currentTimeOffset = Oal.GetSourceReal(src, Oal.SEC_OFFSET);
for ( i = 0; !endSignal && i < totalTime - currentTimeOffset; i++ )
	Sleep(1000);

Oal.Close();

Use Open Dynamics Engine (module jsode)

var world = new World();
world.gravity = [0,0,-0.81];

var body1 = new Body(world);
var geo1 = new GeomBox();
geo1.body = body1;


var body2 = new Body(world);
var geo2 = new GeomBox();
geo2.body = body2;

var joint = new JointHinge(world);

joint.body1 = body1;
joint.body2 = body2;
joint.anchor = [4,4,0];
joint.axis = [1,0,0];
joint.loStop = 1;
joint.hiStop = 1.5;

body1.linearVel = [0,0,19];
body1.angularVel = [1,1,0];
...

Load a jpeg image (module jsimage)

var texture = new Jpeg(new File('R0010235.JPG').Open(File.RDONLY)).Load().Trim([10,10,20,20]);
Print( texture.width+'x'+texture.height+'x'+texture.channels, '\n' );

A configurable systray shortcut launcher (module jswinshell)

LoadModule('jsstd');
LoadModule('jswinshell');

var s = new Systray();
s.icon = new Icon( 0 );
s.menu = { add:'Add', exit:'Exit', s1:{ separator:true } };
s.onmousedown = s.PopupMenu;

s.oncommand = function( id, button ) {

	switch ( id ) {
		case 'exit':
			return true;
		case 'add':
			var fileName = FileOpenDialog( 'executable files|*.exe;*.com;*.cmd;*.bat|all files|*.*' );
			if ( !fileName )
				return;
			s.menu[fileName] = { 
				icon: ExtractIcon( fileName ), 
				text: fileName.substr( fileName.lastIndexOf( '\\' ) + 1 )
			};
			break;
		default:
			if ( button == 1 ) // left-click to run.
				CreateProcess( id );
			else // right-click to remove.
				if ( MessageBox( 'Remove item: ' + id + '? ', 'Question', MB_YESNO) == IDYES )
					delete s.menu[id];
		}
}

do { Sleep(100) } while ( !s.ProcessEvents() );

A server-side script using E4X with the FastCGI module (module jsfastcgi)

Write( "Content-type: text/html\r\n\r\n" );

function CGIVariableList() {

	var fcgiParams = GetParam();
	var list = <ul/>;
	for ( var k in fcgiParams )
		list += <li><b>{k} = </b><pre>{fcgiParams[k]}</pre></li>;
	return list;
}

Write(
<html>
	<head>
		<title>teswt</title>
	</head>
	<body>
		<H1>HELLO WORLD</H1>
		<p>CGI/1.1 variables:</p> {CGIVariableList()}
	</body>
</html>
);

A minimalist HTTP server (modules jsstd, jsio)

LoadModule('jsstd');
LoadModule('jsio');

const CRLF = '\r\n';
var descList = [];
var serv = new Socket(Socket.TCP);
serv.Bind(8081);
serv.Listen();
descList.push(serv);

function Respond() {

  this.httpHeader += this.Read();
  if ( this.httpHeader.indexOf(CRLF+CRLF) == -1 )
    return;

  Print('Received: \n' + this.httpHeader + '\n');
  descList.splice(descList.indexOf(this), 1);

  var writeOp = this.Write(
    'HTTP/1.0 200 OK' + CRLF +
    'Content-Type: text/html; charset=utf-8' + CRLF +
    'Cache-Control: no-cache, must-revalidate' + CRLF +
    'Pragma: no-cache' + CRLF + CRLF +
    '<html><body>Hello from <a href="http://jslibs.googlecode.com/">jslibs</a> at ' + new Date() + '</body></html>' );
  this.Close();
};

serv.readable = function () {

  var desc = this.Accept();
  desc.httpHeader = '';
  desc.readable = Respond;
  descList.push(desc);
}

Print('HTTP server minimal example. Point a web browser at http://localhost:8081. CTRL+C to exit\n');

while ( !endSignal )
 Poll(descList, 50);



Leave a comment.







|| visitors since 2007.01.24

Powered by Google Project Hosting