From 976983960d69cb8aac8327880b0f3c1ef28ff81f Mon Sep 17 00:00:00 2001 From: isaacs Date: Wed, 10 Mar 2010 00:17:15 -0800 Subject: [PATCH 01/14] More ini parser features. Update the ini parser to support some more whitespace cases, turn lines without an equal sign into a "flag" that's just true if set, and support comments. --- lib/ini.js | 17 ++++++++++------- test/fixtures/fixture.ini | 10 +++++++++- test/simple/test-ini.js | 25 ++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/ini.js b/lib/ini.js index 6a1b18daa86..bc1938733b4 100644 --- a/lib/ini.js +++ b/lib/ini.js @@ -1,22 +1,25 @@ exports.parse = function(d) { - var trim = function(str) { return str.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); } var ini = {'-':{}}; var section = '-'; var lines = d.split('\n'); for (var i=0; i Date: Thu, 11 Mar 2010 10:27:20 -0800 Subject: [PATCH 02/14] Adjust process.compile documentation --- doc/api.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api.txt b/doc/api.txt index c745bc8716d..b4e35ab9b66 100644 --- a/doc/api.txt +++ b/doc/api.txt @@ -154,9 +154,9 @@ Send a signal to a process. +pid+ is the process id and +signal+ is the signal to send; for example, "SIGINT" or "SIGUSR1". See kill(2) for more information. -+process.compile(source, scriptOrigin)+:: -Just like +eval()+ except that you can specify a +scriptOrigin+ for better -error reporting. ++process.compile(code, scriptOrigin)+:: +Similar to +eval()+ except that you can specify a +scriptOrigin+ for better +error reporting and the +code+ cannot see the local scope. +process.mixin([deep], target, object1, [objectN])+ :: Extend one object with one or more others, returning the modified object. From 6d9227b79a65c1d5df8e0ffb86c8a7fb1efe7884 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 11 Mar 2010 12:37:32 -0800 Subject: [PATCH 03/14] Make relative ref to sys in fs module. --- lib/fs.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 22d4afb4430..28e52bd293d 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1,7 +1,5 @@ -var - sys = require('sys'), - events = require('events'), - fs = require('fs'); +var sys = require('./sys'), + events = require('events'); exports.Stats = process.Stats; @@ -660,4 +658,4 @@ var FileWriteStream = exports.FileWriteStream = function(path, options) { flush(); }; -sys.inherits(FileWriteStream, events.EventEmitter); \ No newline at end of file +sys.inherits(FileWriteStream, events.EventEmitter); From c93bab141c0ebf119cd9f47d43c1e865c14e1620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Lal?= Date: Thu, 11 Mar 2010 22:15:32 +0100 Subject: [PATCH 04/14] Add --system option to configure, so make uses V8, EV, UDNS system libraries and headers. --- wscript | 77 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/wscript b/wscript index a8793d78761..f8ccfcd7c39 100644 --- a/wscript +++ b/wscript @@ -32,6 +32,12 @@ def set_options(opt): , help='Build with -lefence for debugging [Default: False]' , dest='efence' ) + opt.add_option( '--system' + , action='store_true' + , default=False + , help='Build using system libraries and headers (like a debian build) [Default: False]' + , dest='system' + ) def mkdir_p(dir): if not os.path.exists (dir): @@ -106,6 +112,7 @@ def configure(conf): if not conf.env.CC: conf.fatal('c compiler not found') conf.env["USE_DEBUG"] = Options.options.debug + conf.env["USE_SYSTEM"] = Options.options.system conf.check(lib='dl', uselib_store='DL') if not sys.platform.startswith("sunos"): @@ -145,12 +152,19 @@ def configure(conf): conf.fatal("Cannot find nsl library") conf.sub_config('deps/libeio') - conf.sub_config('deps/libev') - - if sys.platform.startswith("sunos"): - conf_subproject(conf, 'deps/udns', 'LIBS="-lsocket -lnsl" ./configure') + if not Options.options.system: + conf.sub_config('deps/libev') + if sys.platform.startswith("sunos"): + conf_subproject(conf, 'deps/udns', 'LIBS="-lsocket -lnsl" ./configure') + else: + conf_subproject(conf, 'deps/udns', './configure') else: - conf_subproject(conf, 'deps/udns', './configure') + if not conf.check(lib='v8', uselib_store='V8'): + conf.fatal("Cannot find V8") + if not conf.check(lib='ev', uselib_store='EV'): + conf.fatal("Cannot find libev") + if conf.check(lib='udns', uselib_store='UDNS'): + conf.fatal("Cannot find udns") conf.define("HAVE_CONFIG_H", 1) @@ -278,15 +292,22 @@ def build_v8(bld): bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/*.h') def build(bld): - bld.add_subdirs('deps/libeio deps/libev') + if not bld.env["USE_SYSTEM"]: + bld.add_subdirs('deps/libeio deps/libev') + build_udns(bld) + build_v8(bld) + else: + bld.add_subdirs('deps/libeio') + - build_udns(bld) - build_v8(bld) ### evcom evcom = bld.new_task_gen("cc") evcom.source = "deps/evcom/evcom.c" - evcom.includes = "deps/evcom/ deps/libev/" + if not bld.env["USE_SYSTEM"]: + evcom.includes = "deps/evcom/ deps/libev/" + else: + evcom.includes = "deps/evcom/" evcom.name = "evcom" evcom.target = "evcom" evcom.uselib = "GPGERROR GNUTLS" @@ -357,19 +378,31 @@ def build(bld): src/node_timer.cc src/node_idle_watcher.cc """ - node.includes = """ - src/ - deps/v8/include - deps/libev - deps/udns - deps/libeio - deps/evcom - deps/http_parser - deps/coupling - """ - node.add_objects = 'ev eio evcom http_parser coupling' - node.uselib_local = '' - node.uselib = 'GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL' + if not bld.env["USE_SYSTEM"]: + node.includes = """ + src/ + deps/v8/include + deps/libev + deps/udns + deps/libeio + deps/evcom + deps/http_parser + deps/coupling + """ + node.add_objects = 'ev eio evcom http_parser coupling' + node.uselib_local = '' + node.uselib = 'GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL' + else: + node.includes = """ + src/ + deps/libeio + deps/evcom + deps/http_parser + deps/coupling + """ + node.add_objects = 'eio evcom http_parser coupling' + node.uselib_local = 'eio' + node.uselib = 'EV GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL' node.install_path = '${PREFIX}/lib' node.install_path = '${PREFIX}/bin' From ff2457754ce355caf2ba22210cbe42cbd412cdca Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 11 Mar 2010 14:31:51 -0800 Subject: [PATCH 05/14] Upgrade libeio --- deps/libeio/Changes | 2 ++ deps/libeio/eio.c | 46 +++++++++++++++++++++++++++++++++++-------- deps/libeio/eio.h | 18 ++++++++++++----- deps/libeio/libeio.m4 | 4 ++-- 4 files changed, 55 insertions(+), 15 deletions(-) diff --git a/deps/libeio/Changes b/deps/libeio/Changes index 78a34594be9..7cba947ea55 100644 --- a/deps/libeio/Changes +++ b/deps/libeio/Changes @@ -18,7 +18,9 @@ TODO: maybe add mincore support? available on at least darwin, solaris, linux, f - "outbundled" from IO::AIO. - eio_set_max_polltime did not properly convert time to ticks. - tentatively support darwin in sendfile. + - fix freebsd/darwin sendfile. - also use sendfile emulation for ENOTSUP and EOPNOTSUPP error codes. - add OS-independent EIO_MT_* and EIO_MS_* flag enums. + - add eio_statvfs/eio_fstatvfs. diff --git a/deps/libeio/eio.c b/deps/libeio/eio.c index 7d54ca97c9e..937c066a845 100644 --- a/deps/libeio/eio.c +++ b/deps/libeio/eio.c @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -82,7 +83,7 @@ # include /* POSIX_SOURCE is useless on bsd's, and XOPEN_SOURCE is unreliable there, too */ -# if __freebsd || defined __NetBSD__ || defined __OpenBSD__ +# if __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ # define _DIRENT_HAVE_D_TYPE /* sigh */ # define D_INO(de) (de)->d_fileno # define D_NAMLEN(de) (de)->d_namlen @@ -108,7 +109,7 @@ #if HAVE_SENDFILE # if __linux # include -# elif __freebsd || defined __APPLE__ +# elif __FreeBSD__ || defined __APPLE__ # include # include # elif __hpux @@ -138,6 +139,11 @@ # define NAME_MAX 4096 #endif +/* used for readlink etc. */ +#ifndef PATH_MAX +# define PATH_MAX 4096 +#endif + /* buffer size for various temporary buffers */ #define EIO_BUFSIZE 65536 @@ -911,7 +917,7 @@ eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) # if __linux res = sendfile (ofd, ifd, &offset, count); -# elif __freebsd +# elif __FreeBSD__ /* * Of course, the freebsd sendfile is a dire hack with no thoughts * wasted on making it similar to other I/O functions. @@ -920,8 +926,16 @@ eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) off_t sbytes; res = sendfile (ifd, ofd, offset, count, 0, &sbytes, 0); - if (res < 0 && sbytes) - /* maybe only on EAGAIN: as usual, the manpage leaves you guessing */ + #if 0 /* according to the manpage, this is correct, but broken behaviour */ + /* freebsd' sendfile will return 0 on success */ + /* freebsd 8 documents it as only setting *sbytes on EINTR and EAGAIN, but */ + /* not on e.g. EIO or EPIPE - sounds broken */ + if ((res < 0 && (errno == EAGAIN || errno == EINTR) && sbytes) || res == 0) + res = sbytes; + #endif + + /* according to source inspection, this is correct, and useful behaviour */ + if (sbytes) res = sbytes; } @@ -931,7 +945,8 @@ eio__sendfile (int ofd, int ifd, off_t offset, size_t count, etp_worker *self) off_t sbytes = count; res = sendfile (ifd, ofd, offset, &sbytes, 0, 0); - if (res < 0 && errno == EAGAIN && sbytes) + /* according to the manpage, sbytes is always valid */ + if (sbytes) res = sbytes; } @@ -1577,6 +1592,11 @@ static void eio_execute (etp_worker *self, eio_req *req) case EIO_FSTAT: ALLOC (sizeof (EIO_STRUCT_STAT)); req->result = fstat (req->int1, (EIO_STRUCT_STAT *)req->ptr2); break; + case EIO_STATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = statvfs (req->ptr1, (EIO_STRUCT_STATVFS *)req->ptr2); break; + case EIO_FSTATVFS: ALLOC (sizeof (EIO_STRUCT_STATVFS)); + req->result = fstatvfs (req->int1, (EIO_STRUCT_STATVFS *)req->ptr2); break; + case EIO_CHOWN: req->result = chown (req->ptr1, req->int2, req->int3); break; case EIO_FCHOWN: req->result = fchown (req->int1, req->int2, req->int3); break; case EIO_CHMOD: req->result = chmod (req->ptr1, (mode_t)req->int2); break; @@ -1595,8 +1615,8 @@ static void eio_execute (etp_worker *self, eio_req *req) case EIO_SYMLINK: req->result = symlink (req->ptr1, req->ptr2); break; case EIO_MKNOD: req->result = mknod (req->ptr1, (mode_t)req->int2, (dev_t)req->int3); break; - case EIO_READLINK: ALLOC (NAME_MAX); - req->result = readlink (req->ptr1, req->ptr2, NAME_MAX); break; + case EIO_READLINK: ALLOC (PATH_MAX); + req->result = readlink (req->ptr1, req->ptr2, PATH_MAX); break; case EIO_SYNC: req->result = 0; sync (); break; case EIO_FSYNC: req->result = fsync (req->int1); break; @@ -1733,6 +1753,11 @@ eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data) REQ (EIO_FSTAT); req->int1 = fd; SEND; } +eio_req *eio_fstatvfs (int fd, int pri, eio_cb cb, void *data) +{ + REQ (EIO_FSTATVFS); req->int1 = fd; SEND; +} + eio_req *eio_futime (int fd, double atime, double mtime, int pri, eio_cb cb, void *data) { REQ (EIO_FUTIME); req->int1 = fd; req->nv1 = atime; req->nv2 = mtime; SEND; @@ -1814,6 +1839,11 @@ eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data) return eio__1path (EIO_LSTAT, path, pri, cb, data); } +eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data) +{ + return eio__1path (EIO_STATVFS, path, pri, cb, data); +} + eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data) { return eio__1path (EIO_UNLINK, path, pri, cb, data); diff --git a/deps/libeio/eio.h b/deps/libeio/eio.h index 2008d8579b2..1a5dc3d3f9e 100644 --- a/deps/libeio/eio.h +++ b/deps/libeio/eio.h @@ -60,6 +60,10 @@ typedef int (*eio_cb)(eio_req *req); # define EIO_STRUCT_STAT struct stat #endif +#ifndef EIO_STRUCT_STATVFS +# define EIO_STRUCT_STATVFS struct statvfs +#endif + /* for readdir */ /* eio_readdir flags */ @@ -133,6 +137,7 @@ enum { EIO_READ, EIO_WRITE, EIO_READAHEAD, EIO_SENDFILE, EIO_STAT, EIO_LSTAT, EIO_FSTAT, + EIO_STATVFS, EIO_FSTATVFS, EIO_TRUNCATE, EIO_FTRUNCATE, EIO_UTIME, EIO_FUTIME, EIO_CHMOD, EIO_FCHMOD, @@ -239,6 +244,7 @@ eio_req *eio_readahead (int fd, off_t offset, size_t length, int pri, eio_cb cb, eio_req *eio_read (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); eio_req *eio_write (int fd, void *buf, size_t length, off_t offset, int pri, eio_cb cb, void *data); eio_req *eio_fstat (int fd, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_fstatvfs (int fd, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ eio_req *eio_futime (int fd, eio_tstamp atime, eio_tstamp mtime, int pri, eio_cb cb, void *data); eio_req *eio_ftruncate (int fd, off_t offset, int pri, eio_cb cb, void *data); eio_req *eio_fchmod (int fd, mode_t mode, int pri, eio_cb cb, void *data); @@ -257,6 +263,7 @@ eio_req *eio_unlink (const char *path, int pri, eio_cb cb, void *data); eio_req *eio_readlink (const char *path, int pri, eio_cb cb, void *data); /* result=ptr2 allocated dynamically */ eio_req *eio_stat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ eio_req *eio_lstat (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ +eio_req *eio_statvfs (const char *path, int pri, eio_cb cb, void *data); /* stat buffer=ptr2 allocated dynamically */ eio_req *eio_mknod (const char *path, mode_t mode, dev_t dev, int pri, eio_cb cb, void *data); eio_req *eio_link (const char *path, const char *new_path, int pri, eio_cb cb, void *data); eio_req *eio_symlink (const char *path, const char *new_path, int pri, eio_cb cb, void *data); @@ -277,13 +284,14 @@ void eio_grp_cancel (eio_req *grp); /* cancels all sub requests but not the g /* request api */ /* true if the request was cancelled, useful in the invoke callback */ -#define EIO_CANCELLED(req) ((req)->flags & EIO_FLAG_CANCELLED) +#define EIO_CANCELLED(req) ((req)->flags & EIO_FLAG_CANCELLED) -#define EIO_RESULT(req) ((req)->result) +#define EIO_RESULT(req) ((req)->result) /* returns a pointer to the result buffer allocated by eio */ -#define EIO_BUF(req) ((req)->ptr2) -#define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) -#define EIO_PATH(req) ((char *)(req)->ptr1) +#define EIO_BUF(req) ((req)->ptr2) +#define EIO_STAT_BUF(req) ((EIO_STRUCT_STAT *)EIO_BUF(req)) +#define EIO_STATVFS_BUF(req) ((EIO_STRUCT_STATVFS *)EIO_BUF(req)) +#define EIO_PATH(req) ((char *)(req)->ptr1) /* submit a request for execution */ void eio_submit (eio_req *req); diff --git a/deps/libeio/libeio.m4 b/deps/libeio/libeio.m4 index e80e008174d..0a737d36d7e 100644 --- a/deps/libeio/libeio.m4 +++ b/deps/libeio/libeio.m4 @@ -64,7 +64,7 @@ AC_CACHE_CHECK(for sendfile, ac_cv_sendfile, [AC_LINK_IFELSE([ # include #if __linux # include -#elif __freebsd || defined __APPLE__ +#elif __FreeBSD__ || defined __APPLE__ # include # include #elif __hpux @@ -80,7 +80,7 @@ int main(void) ssize_t res; #if __linux res = sendfile (fd, fd, offset, count); -#elif __freebsd +#elif __FreeBSD__ res = sendfile (fd, fd, offset, count, 0, &offset, 0); #elif __hpux res = sendfile (fd, fd, offset, count, 0, 0); From 6bd11f147ab6277a672f8e36e707306752d93538 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 11 Mar 2010 14:32:10 -0800 Subject: [PATCH 06/14] Fix undefined reference in fs.js --- lib/fs.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/fs.js b/lib/fs.js index 28e52bd293d..f9eae9bd39a 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1,6 +1,8 @@ var sys = require('./sys'), events = require('events'); +var fs = exports; + exports.Stats = process.Stats; process.Stats.prototype._checkModeProperty = function (property) { From 0c17067d873f807b1280d5e922f44da3abc4c328 Mon Sep 17 00:00:00 2001 From: Tim-Smart Date: Mon, 8 Mar 2010 17:35:39 +1300 Subject: [PATCH 07/14] Add require.registerExtension --- src/node.js | 78 +++++++++++++++++++++++++----- test/fixtures/registerExt.test | 1 + test/fixtures/registerExt2.test | 1 + test/simple/test-module-loading.js | 18 +++++++ 4 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/registerExt.test create mode 100644 test/fixtures/registerExt2.test diff --git a/src/node.js b/src/node.js index 0398ba261fb..bbaa684f186 100644 --- a/src/node.js +++ b/src/node.js @@ -45,6 +45,7 @@ node.dns.createConnection = removed("node.dns.createConnection() has moved. Use // Module var internalModuleCache = {}; +var extensionCache = {}; function Module (id, parent) { this.id = id; @@ -481,6 +482,12 @@ function findModulePath (id, dirs, callback) { path.join(dir, id, "index.addon") ]; + var ext; + for (ext in extensionCache) { + locations.push(path.join(dir, id + ext)); + locations.push(path.join(dir, id, 'index' + ext)); + } + function searchLocations () { var location = locations.shift(); if (!location) { @@ -515,8 +522,13 @@ function resolveModulePath(request, parent) { var id, paths; if (request.charAt(0) == "." && (request.charAt(1) == "/" || request.charAt(1) == ".")) { // Relative request + var exts = ['js', 'node'], ext; + for (ext in extensionCache) { + exts.push(ext.slice(1)); + } + var parentIdPath = path.dirname(parent.id + - (path.basename(parent.filename).match(/^index\.(js|addon)$/) ? "/" : "")); + (path.basename(parent.filename).match(new RegExp('^index\\.(' + exts.join('|') + ')$')) ? "/" : "")); id = path.join(parentIdPath, request); // debug("RELATIVE: requested:"+request+" set ID to: "+id+" from "+parent.id+"("+parentIdPath+")"); paths = [path.dirname(parent.filename)]; @@ -584,6 +596,32 @@ function loadModule (request, parent, callback) { }; +// This function allows the user to register file extensions to custom +// Javascript 'compilers'. It accepts 2 arguments, where ext is a file +// extension as a string. E.g. '.coffee' for coffee-script files. compiler +// is the second argument, which is a function that gets called then the +// specified file extension is found. The compiler is passed a single +// argument, which is, the file contents, which need to be compiled. +// +// The function needs to return the compiled source, or an non-string +// variable that will get attached directly to the module exports. Example: +// +// require.registerExtension('.coffee', function(content) { +// return doCompileMagic(content); +// }); +function registerExtension(ext, compiler) { + if ('string' !== typeof ext && false === /\.\w+$/.test(ext)) { + throw new Error('require.registerExtension: First argument not a valid extension string.'); + } + + if ('function' !== typeof compiler) { + throw new Error('require.registerExtension: Second argument not a valid compiler function.'); + } + + extensionCache[ext] = compiler; +} + + Module.prototype.loadSync = function (filename) { debug("loadSync " + JSON.stringify(filename) + " for module " + JSON.stringify(this.id)); @@ -649,6 +687,12 @@ Module.prototype._loadContent = function (content, filename) { // remove shebang content = content.replace(/^\#\!.*/, ''); + // Compile content if needed + var ext = path.extname(filename); + if (extensionCache[ext]) { + content = extensionCache[ext](content); + } + function requireAsync (url, cb) { loadModule(url, self, cb); } @@ -660,19 +704,27 @@ Module.prototype._loadContent = function (content, filename) { require.paths = process.paths; require.async = requireAsync; require.main = process.mainModule; - // create wrapper function - var wrapper = "(function (exports, require, module, __filename, __dirname) { " - + content - + "\n});"; + require.registerExtension = registerExtension; - try { - var compiledWrapper = process.compile(wrapper, filename); - var dirName = path.dirname(filename); - if (filename === process.argv[1]) - process.checkBreak(); - compiledWrapper.apply(self.exports, [self.exports, require, self, filename, dirName]); - } catch (e) { - return e; + + if ('string' === typeof content) { + // create wrapper function + var wrapper = "(function (exports, require, module, __filename, __dirname) { " + + content + + "\n});"; + + try { + var compiledWrapper = process.compile(wrapper, filename); + var dirName = path.dirname(filename); + if (filename === process.argv[1]) { + process.checkBreak(); + } + compiledWrapper.apply(self.exports, [self.exports, require, self, filename, dirName]); + } catch (e) { + return e; + } + } else { + self.exports = content; } }; diff --git a/test/fixtures/registerExt.test b/test/fixtures/registerExt.test new file mode 100644 index 00000000000..d08e5b1d02a --- /dev/null +++ b/test/fixtures/registerExt.test @@ -0,0 +1 @@ +this is custom source diff --git a/test/fixtures/registerExt2.test b/test/fixtures/registerExt2.test new file mode 100644 index 00000000000..94544f1d0f4 --- /dev/null +++ b/test/fixtures/registerExt2.test @@ -0,0 +1 @@ +This is for the object return test diff --git a/test/simple/test-module-loading.js b/test/simple/test-module-loading.js index 0d99c25a907..0011e136190 100644 --- a/test/simple/test-module-loading.js +++ b/test/simple/test-module-loading.js @@ -63,6 +63,24 @@ require.async('../fixtures/a', function (err, a) { assert.equal("A", a.A()); }); +debug('load custom file types with registerExtension'); +require.registerExtension('.test', function(content) { + assert.equal("this is custom source\n", content); + + return content.replace("this is custom source", "exports.test = 'passed'"); +}); + +assert.equal(require('../fixtures/registerExt').test, "passed"); + +debug('load custom file types that return non-strings'); +require.registerExtension('.test', function(content) { + return { + custom: 'passed' + }; +}); + +assert.equal(require('../fixtures/registerExt2').custom, 'passed'); + process.addListener("exit", function () { assert.equal(true, a.A instanceof Function); assert.equal("A done", a.A()); From dd857f9fdfa9bb2dcd71500173bd203aa2dd588b Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 11 Mar 2010 22:03:55 -0800 Subject: [PATCH 08/14] .addon -> .node How'd that get in there? --- src/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.js b/src/node.js index bbaa684f186..ccd1b5679f4 100644 --- a/src/node.js +++ b/src/node.js @@ -479,7 +479,7 @@ function findModulePath (id, dirs, callback) { path.join(dir, id + ".js"), path.join(dir, id + ".node"), path.join(dir, id, "index.js"), - path.join(dir, id, "index.addon") + path.join(dir, id, "index.node") ]; var ext; From c96b7e5ca05b7ca3b34b45deb01ac0498cb201c6 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 11 Mar 2010 22:05:09 -0800 Subject: [PATCH 09/14] Missing EOL semicolons --- src/node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node.js b/src/node.js index ccd1b5679f4..f55ad3c543e 100644 --- a/src/node.js +++ b/src/node.js @@ -502,7 +502,7 @@ function findModulePath (id, dirs, callback) { } else { return searchLocations(); } - }) + }); // if sync } else { @@ -815,4 +815,4 @@ process.loop(); process.emit("exit"); -}) +}); From 116dfb87403af2f08d163dd8bf39f2ffaf7a4754 Mon Sep 17 00:00:00 2001 From: Vanilla Hsu Date: Fri, 12 Mar 2010 12:05:47 +0800 Subject: [PATCH 10/14] 1: sync wscript with libeio.m4 2: try to enable macosx's sendfile. --- deps/libeio/wscript | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deps/libeio/wscript b/deps/libeio/wscript index 2c49f71f28b..e6146ec7f1b 100644 --- a/deps/libeio/wscript +++ b/deps/libeio/wscript @@ -67,7 +67,7 @@ def configure(conf): # include #if __linux # include - #elif __freebsd + #elif __FreeBSD__ || defined(__APPLE__) # include # include #elif __hpux @@ -83,8 +83,10 @@ def configure(conf): ssize_t res; #if __linux res = sendfile (fd, fd, offset, count); - #elif __freebsd + #elif __FreeBSD__ res = sendfile (fd, fd, offset, count, 0, &offset, 0); + #elif __APPLE__ + res = sendfile (fd, fd, offset, &offset, 0, 0); #elif __hpux res = sendfile (fd, fd, offset, count, 0, 0); #endif From b13081691e27f6cc62628d0fc38b1a9f5e290bc5 Mon Sep 17 00:00:00 2001 From: Vanilla Hsu Date: Fri, 12 Mar 2010 15:14:54 +0800 Subject: [PATCH 11/14] use getpagesize() to get PAGE_SIZE on FreeBSD. --- src/node.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index b7fad3055eb..5e8f752f865 100644 --- a/src/node.cc +++ b/src/node.cc @@ -597,6 +597,7 @@ int getmem(size_t *rss, size_t *vsize) { struct kinfo_proc *kinfo = NULL; pid_t pid; int nprocs; + size_t page_size = getpagesize(); pid = getpid(); @@ -606,7 +607,7 @@ int getmem(size_t *rss, size_t *vsize) { kinfo = kvm_getprocs(kd, KERN_PROC_PID, pid, &nprocs); if (kinfo == NULL) goto error; - *rss = kinfo->ki_rssize * PAGE_SIZE; + *rss = kinfo->ki_rssize * page_size; *vsize = kinfo->ki_size; kvm_close(kd); From 6ec2f877c201ad238d44506a27fd26fc5518f891 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 11 Mar 2010 23:50:41 -0800 Subject: [PATCH 12/14] Depreciation -> Deprecation --- src/node.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node.cc b/src/node.cc index 5e8f752f865..25f249fa7b2 100644 --- a/src/node.cc +++ b/src/node.cc @@ -420,7 +420,7 @@ static Handle Loop(const Arguments& args) { } static Handle Unloop(const Arguments& args) { - fprintf(stderr, "Node.js Depreciation: Don't use process.unloop(). It will be removed soon.\n"); + fprintf(stderr, "Deprecation: Don't use process.unloop(). It will be removed soon.\n"); HandleScope scope; int how = EVUNLOOP_ONE; if (args[0]->IsString()) { From ae10a483834d2870073b5513badc5b7003bcdade Mon Sep 17 00:00:00 2001 From: Tim-Smart Date: Fri, 12 Mar 2010 21:36:00 +1300 Subject: [PATCH 13/14] Initial implementation of process.evalcx --- src/node.cc | 48 +++++++++++++++++++++++++++++++++++++ test/simple/test-eval-cx.js | 27 +++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 test/simple/test-eval-cx.js diff --git a/src/node.cc b/src/node.cc index 25f249fa7b2..8cb5e64ed8e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -846,6 +846,53 @@ Handle DLOpen(const v8::Arguments& args) { return Undefined(); } +// evalcx(code, sandbox={}) +// Executes code in a new context +Handle EvalCX(const Arguments& args) { + HandleScope scope; + + Local code = args[0]->ToString(); + Local sandbox = args.Length() > 1 ? args[1]->ToObject() + : Object::New(); + // Create the new context + Persistent context = Context::New(); + + // Copy objects from global context, to our brand new context + Handle keys = sandbox->GetPropertyNames(); + + int i; + for (i = 0; i < keys->Length(); i++) { + Handle key = keys->Get(Integer::New(i))->ToString(); + Handle value = sandbox->Get(key); + context->Global()->Set(key, value->ToObject()->Clone()); + } + + // Enter and compile script + context->Enter(); + + // Catch errors + TryCatch try_catch; + + Local