Skip to content

Commit

Permalink
server now handles requires of common namespaces, still need to clean…
Browse files Browse the repository at this point in the history
… up the global namespace
  • Loading branch information
dnewcome committed May 6, 2010
1 parent e76507f commit e4035be
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server.js
Expand Up @@ -13,6 +13,18 @@ var manualResetEvent : ManualResetEvent = new ManualResetEvent( false );
var workItems = [];

function require( file ) {
// for compiled-in functionality, return existing references.
// TODO: clean up the global namespace, as it is, `http' et al.
// are already visible to the user code
if( file == 'http' ) {
return http;
}
if( file == 'net' ) {
return net;
}
if( file == 'sys' ) {
return sys;
}
print( 'requiring: ' + file );
var sr : StreamReader = new StreamReader( file + '.js' );
var fileContents = sr.ReadToEnd();
Expand All @@ -23,6 +35,10 @@ function require( file ) {
return eval( code, 'unsafe' );
}

// quick hack to add sys.puts();
// TODO: `sys' should be implemented in its own class
var sys = { puts: function( string ){ print( string ); } };

// threadsafe enqueue function
function queueWorkItem( item ) {
print( 'queueWorkItem(): queuing item: ' + item );
Expand Down

0 comments on commit e4035be

Please sign in to comment.