couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [48/50] git commit: updated refs/heads/1894-feature-experimental-nodejs-couchjs to 532100c
Date Thu, 03 Oct 2013 15:47:46 GMT
applied formatting for constancy


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/0902e8c5
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/0902e8c5
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/0902e8c5

Branch: refs/heads/1894-feature-experimental-nodejs-couchjs
Commit: 0902e8c5e8f7e66eecfacbdb266422d51f8cafc3
Parents: 2d7da55
Author: Sven Lito <me@svenlito.com>
Authored: Thu Oct 3 09:23:07 2013 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Thu Oct 3 17:45:38 2013 +0200

----------------------------------------------------------------------
 src/couchjs-node/cli.js             |  96 +++++++++++--------
 src/couchjs-node/console.js         |  73 +++++++-------
 src/couchjs-node/couchdb.js         |  20 ++--
 src/couchjs-node/couchjs.js         | 133 ++++++++++++++------------
 src/couchjs-node/inspector.js       | 111 +++++++++++----------
 src/couchjs-node/package.json       |  68 +++++++------
 src/couchjs-node/sandbox.js         |  23 +++--
 src/couchjs-node/stream.js          | 106 +++++++++++----------
 src/couchjs-node/test/experiment.js | 159 ++++++++++++++++---------------
 src/couchjs-node/xml.js             |   9 +-
 10 files changed, 441 insertions(+), 357 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/cli.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/cli.js b/src/couchjs-node/cli.js
index 8b7abef..065951f 100755
--- a/src/couchjs-node/cli.js
+++ b/src/couchjs-node/cli.js
@@ -12,64 +12,80 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-var fs = require('fs')
-var util = require('util')
-var Fiber = require('fibers')
-var optimist = require('optimist')
-var child_process = require('child_process')
+var fs = require('fs');
+var util = require('util');
+var Fiber = require('fibers');
+var optimist = require('optimist');
+var child_process = require('child_process');
 
-var couchjs = require('./couchjs')
-var package_json = require('./package.json')
-var LineStream = require('./stream')
-var inspector = require('./inspector')
-var log = require('./console').log
+var couchjs = require('./couchjs');
+var package_json = require('./package.json');
+var LineStream = require('./stream');
+var inspector = require('./inspector');
+var log = require('./console').log;
 
 
 var opts = optimist.boolean(['h', 'V', 'H'])
-                   .describe({ 'h': 'display a short help message and exit'
-                             , 'V': 'display version information and exit'
-                             , 'H': 'enable couchjs cURL bindings (not implemented)'
+                   .describe({ 'h': 'display a short help message and exit',
+                             'V': 'display version information and exit',
+                             'H': 'enable couchjs cURL bindings (not implemented)'
                              })
-                   .usage('$0 <path to main.js>')
+                   .usage('$0 <path to main.js>');
 
 
 function main() {
-  var main_js = opts.argv._[0]
-  if(!main_js)
-    return console.error(opts.help())
 
-  log('couchjs/%s %s: %s', package_json.version, process.pid, main_js)
-  if(process.env.COUCHJS_DEBUG_PORT)
-    inspector(+process.env.COUCHJS_DEBUG_PORT)
+  'use strict';
+
+  var main_js = opts.argv._[0];
+
+  if (!main_js) {
+    return console.error(opts.help());
+  }
+
+  log('couchjs/%s %s: %s', package_json.version, process.pid, main_js);
+
+  if (process.env.COUCHJS_DEBUG_PORT) {
+    inspector(+process.env.COUCHJS_DEBUG_PORT);
+  }
 
   fs.readFile(main_js, 'utf8', function(er, body) {
-    if(er)
-      throw er
+    if (er) {
+      throw er;
+    }
+
+    var stdin = new LineStream.v2();
 
-    var stdin = new LineStream.v2
     stdin.on('readable', function() {
-      var buf = stdin.read()
-      if(buf)
-        couchjs.stdin(buf)
-    })
+      var buf = stdin.read();
+
+      if (buf) {
+        couchjs.stdin(buf);
+      }
+    });
+
     stdin.on('end', function() {
-      log('Terminate; connection to parent closed')
-      process.exit(0)
-    })
+      log('Terminate; connection to parent closed');
+      process.exit(0);
+    });
 
-    process.stdin.setEncoding('utf8')
-    process.stdin.pipe(stdin)
+    process.stdin.setEncoding('utf8');
+    process.stdin.pipe(stdin);
 
-    var main_func = Function(['print', 'readline', 'evalcx', 'gc', 'quit'], body)
+    var main_func = Function(['print', 'readline', 'evalcx', 'gc', 'quit'], body);
 
-    log('Call main')
-    Fiber(function() { main_func(couchjs.print, couchjs.readline, couchjs.evalcx, couchjs.gc)
}).run()
-  })
+    log('Call main');
+
+    new Fiber(function() {
+      main_func(couchjs.print, couchjs.readline, couchjs.evalcx, couchjs.gc);
+    }).run();
+  });
 
   process.on('uncaughtException', function(er) {
-    log('Error:\n%s', er.stack)
-  })
+    log('Error:\n%s', er.stack);
+  });
 }
 
-if(require.main === module)
-  main()
+if (require.main === module) {
+  main();
+}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/console.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/console.js b/src/couchjs-node/console.js
index 67cc32d..0fda066 100644
--- a/src/couchjs-node/console.js
+++ b/src/couchjs-node/console.js
@@ -10,54 +10,57 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-var fs = require('fs')
-var util = require('util')
+var fs = require('fs');
+var util = require('util');
 
+var noop = function() {};
 
-module.exports = {}
-module.exports.log = noop
-module.exports.debug = noop
-module.exports.info = noop
-module.exports.warn = noop
-module.exports.error = noop
+module.exports = {};
+module.exports.log = noop;
+module.exports.debug = noop;
+module.exports.info = noop;
+module.exports.warn = noop;
+module.exports.error = noop;
 
-var LOG_PATH = '/tmp/couchjs.log'
-  , stat = null
-  , LOG = null
+var LOG_PATH = '/tmp/couchjs.log';
+var stat = null;
+var LOG = null;
 
 try {
-  stat = fs.statSync(LOG_PATH)
+  stat = fs.statSync(LOG_PATH);
 } catch(er) {}
 
-if(stat) {
-  LOG = fs.createWriteStream(LOG_PATH, {'flags':'a'})
+if (stat) {
+  LOG = fs.createWriteStream(LOG_PATH, {
+    'flags':'a'
+  });
 
-  module.exports.log = log
-  module.exports.debug = log
-  module.exports.info = log
-  module.exports.warn = log
-  module.exports.error = log
+  var log = function () {
+    var str = util.format.apply(this, arguments);
+    LOG.write(str + '\n');
+  };
 
-  process.on('exit', function() {
-    module.exports.log('Exit %d', process.pid)
-  })
+  var on_err = function (er) {
+    module.exports.error('Uncaught error:\n%s', er.stack || er.message || JSON.stringify(er))
 
-  process.on('uncaughtException', on_err)
-}
+    if (er.stack) {
+      er = ['fatal', 'unknown_error', er.stack];
+    }
 
-function log() {
-  var str = util.format.apply(this, arguments)
-  LOG.write(str + '\n')
-}
+    process.stdout.write(JSON.stringify(er) + '\n');
+    process.exit(1);
+  };
 
-function on_err(er) {
-  module.exports.error('Uncaught error:\n%s', er.stack || er.message || JSON.stringify(er))
+  module.exports.log = log;
+  module.exports.debug = log;
+  module.exports.info = log;
+  module.exports.warn = log;
+  module.exports.error = log;
 
-  if(er.stack)
-    er = ['fatal', 'unknown_error', er.stack]
+  process.on('exit', function() {
+    module.exports.log('Exit %d', process.pid);
+  });
 
-  process.stdout.write(JSON.stringify(er) + '\n')
-  process.exit(1)
+  process.on('uncaughtException', on_err);
 }
 
-function noop() {}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/couchdb.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchdb.js b/src/couchjs-node/couchdb.js
index 46b23b0..d420540 100755
--- a/src/couchjs-node/couchdb.js
+++ b/src/couchjs-node/couchdb.js
@@ -10,18 +10,20 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-module.exports = handler
 
-var http = require('http')
+var http = require('http');
 
 function handler(req, res) {
-  res.writeHead(200)
-  res.end('Hello: ' + req.url + '\n')
+  res.writeHead(200);
+  res.end('Hello: ' + req.url + '\n');
 }
 
-if(require.main === module) {
-  var http = require('http')
-  var server = http.createServer(handler)
-  server.listen(3000)
-  console.log('Listening on :3000')
+if (require.main === module) {
+  var http = require('http');
+  var server = http.createServer(handler);
+
+  server.listen(3000);
+  console.log('Listening on :3000');
 }
+
+module.exports = handler;

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/couchjs.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/couchjs.js b/src/couchjs-node/couchjs.js
index b633f6f..7b12dc3 100644
--- a/src/couchjs-node/couchjs.js
+++ b/src/couchjs-node/couchjs.js
@@ -10,105 +10,120 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-module.exports = { 'print'   : print
-                 , 'readline': readline
-                 , 'stdin'   : stdin
-                 , 'evalcx'  : evalcx
-                 , 'quit'    : quit
-                 , 'gc'      : gc
-                 }
+module.exports = {
+  'print': print,
+  'readline': readline,
+  'stdin': stdin,
+  'evalcx': evalcx,
+  'quit': quit,
+  'gc': gc
+};
 
 
-var vm = require('vm')
-var Fiber = require('fibers')
+var vm = require('vm');
+var Fiber = require('fibers');
 
-var XML = require('./xml')
-var log = require('./console').log
+var XML = require('./xml');
+var log = require('./console').log;
 
-var INPUT = {'queue':[], 'waiting':null}
+var INPUT = {
+  'queue':[],
+  'waiting':null
+};
 
-Error.prototype.toSource = Error.prototype.toSource || toSource
-Error.prototype.toString = Error.prototype.toString || toSource
-Function.prototype.toSource = Function.prototype.toSource || toSource
-Function.prototype.toString = Function.prototype.toString || toSource
+Error.prototype.toSource = Error.prototype.toSource || toSource;
+Error.prototype.toString = Error.prototype.toString || toSource;
+Function.prototype.toSource = Function.prototype.toSource || toSource;
+Function.prototype.toString = Function.prototype.toString || toSource;
 
 
 function print(line) {
-  log('STDOUT %s: %s', process.pid, line)
-  process.stdout.write(line + '\n')
+  log('STDOUT %s: %s', process.pid, line);
+  process.stdout.write(line + '\n');
 
   try {
-    line = JSON.parse(line)
-  } catch(er) { return }
+    line = JSON.parse(line);
+  } catch(er) {
+    return;
+  }
 
-  if(line[0] == 'log')
-    log('LOG: %s', line[1])
+  if (line[0] === 'log') {
+    log('LOG: %s', line[1]);
+  }
 }
 
-function stdin(line) {
-  log('STDIN %s: %s', process.pid, line.trim())
-  if(INPUT.waiting)
-    INPUT.waiting.run(line)
-  else
-    INPUT.queue.push(line)
+function stdin (line) {
+  log('STDIN %s: %s', process.pid, line.trim());
+
+  if (INPUT.waiting) {
+    INPUT.waiting.run(line);
+  } else {
+    INPUT.queue.push(line);
+  }
 }
 
-function readline() {
-  var line = INPUT.queue.shift()
-  if(line)
-    return line
+function readline () {
+  var line = INPUT.queue.shift();
+
+  if (line) {
+    return line;
+  }
 
-  INPUT.waiting = Fiber.current
-  line = Fiber.yield()
-  INPUT.waiting = null
+  INPUT.waiting = Fiber.current;
+  line = Fiber.yield();
+  INPUT.waiting = null;
 
-  return line
+  return line;
 }
 
 
-function evalcx(source, sandbox) {
-  sandbox = sandbox || {}
+function evalcx (source, sandbox) {
+  sandbox = sandbox || {};
   //log('evalcx in %j: %j', Object.keys(sandbox), source)
 
-  if(source == '')
-    return sandbox
+  if (source == '') {
+    return sandbox;
+  }
 
   // source might be "function(doc) { emit(doc._id, 1) }"
-  source = source.replace(/;+$/, '')
+  source = source.replace(/;+$/, '');
 
-  sandbox.XML = sandbox.XML || XML
-  source = '(' + source + ')'
+  sandbox.XML = sandbox.XML || XML;
+  source = '(' + source + ')';
 
   try {
-    var id = Math.floor(Math.random() * 1000*1000)
-    var filename = '_couchdb:' + id + '.js'
-    var script = vm.createScript(source, filename)
-    var func = script.runInNewContext(sandbox)
+    var id = Math.floor(Math.random() * 1000*1000);
+    var filename = '_couchdb:' + id + '.js';
+    var script = vm.createScript(source, filename);
+    var func = script.runInNewContext(sandbox);
   } catch (er) {
-    log('Error making code: %s', er.stack)
-    return sandbox
+    log('Error making code: %s', er.stack);
+    return sandbox;
   }
 
-  return func
+  return func;
 }
 
 function quit(code) {
-  code = code || 1
-  if(code < 0)
-    code = -code
+  code = code || 1;
+  if (code < 0) {
+    code = -code;
+  }
 
-  process.exit(code)
+  process.exit(code);
 }
 
 function gc() { }
 
 
 function toSource() {
-  if(typeof this == 'function')
-    return '' + this
+  if (typeof this == 'function') {
+    return '' + this;
+  }
 
-  if(this instanceof Error)
-    return this.stack
+  if (this instanceof Error) {
+    return this.stack;
+  }
 
-  return util.inspect(this)
+  return util.inspect(this);
 }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/inspector.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/inspector.js b/src/couchjs-node/inspector.js
index 2b75c3b..343770f 100755
--- a/src/couchjs-node/inspector.js
+++ b/src/couchjs-node/inspector.js
@@ -12,77 +12,92 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-module.exports = start
+module.exports = start;
 
-if(require.main === module)
-  main()
+if (require.main === module) {
+  main();
+}
+
+
+var fs = require('fs');
+var util = require('util');
+var child_process = require('child_process');
+var log = require('./console').log;
 
+function start (debugPort) {
 
-var fs = require('fs')
-var util = require('util')
-var child_process = require('child_process')
+  if (!debugPort || typeof debugPort !== 'number') {
+    throw new Error('Need a listen debugPort');
+  }
 
-var log = require('./console').log
+  var webPort = debugPort + 1;
 
-function start(debugPort) {
-  if(!debugPort || typeof debugPort != 'number')
-    throw new Error('Need a listen debugPort')
-  var webPort = debugPort + 1
+  var cmd = __filename;
+  var args = [debugPort, webPort];
+  var opts = {
+    'cwd': __dirname,
+    'stdio': 'pipe',
+    'detached': false
+  };
 
-  var cmd = __filename
-  var args = [debugPort, webPort]
-  var opts =
-    { 'cwd': __dirname
-    , 'stdio': 'pipe'
-    , 'detached': false
-    }
+  log('Start inspector: %s %j %j', cmd, args, opts);
 
-  log('Start inspector: %s %j %j', cmd, args, opts)
-  var inspector = child_process.spawn(cmd, args, opts)
-  watch_inspector(inspector)
+  var inspector = child_process.spawn(cmd, args, opts);
 
-  log('Enable remote debug pid=%d port=%d', process.pid, debugPort)
-  process.debugPort = debugPort
-  process.kill(process.pid, 'SIGUSR1')
+  watch_inspector(inspector);
+
+  log('Enable remote debug pid=%d port=%d', process.pid, debugPort);
+
+  process.debugPort = debugPort;
+  process.kill(process.pid, 'SIGUSR1');
 }
 
 function watch_inspector(child) {
+
   child.stderr.on('data', function(body) {
-    log('Inspector STDERR: %s', body)
-  })
+    log('Inspector STDERR: %s', body);
+  });
+
   child.stdout.on('data', function(body) {
-    log('Inspector STDOUT: %s', body)
-  })
+    log('Inspector STDOUT: %s', body);
+  });
 
   child.on('exit', function(code, signal) {
-    log('Inspector exited %d signal=%j', code, signal)
-    process.exit(code)
-  })
+    log('Inspector exited %d signal=%j', code, signal);
+    process.exit(code);
+  });
 
   process.on('exit', function() {
-    log('Kill inspector upon exit: %d', child.pid)
-    process.kill(child.pid, 'SIGTERM')
-  })
-}
+    log('Kill inspector upon exit: %d', child.pid);
+    process.kill(child.pid, 'SIGTERM');
+  });
 
+}
 
 function main() {
-  var debugPort = +process.argv[2]
-  var webPort = +process.argv[3]
+  var debugPort = +process.argv[2];
+  var webPort = +process.argv[3];
 
-  if(!debugPort || !webPort)
-    throw new Error('Bad arguments: need debugPort and webPort')
+  if (!debugPort || !webPort) {
+    throw new Error('Bad arguments: need debugPort and webPort');
+  }
+
+  console.log('Start inspector debugPort=%j webPort=%j', debugPort, webPort);
+
+  var DebugServer = require('node-inspector/lib/debug-server');
+  var server = new DebugServer();
 
-  console.log('Start inspector debugPort=%j webPort=%j', debugPort, webPort)
-  var DebugServer = require('node-inspector/lib/debug-server')
-  var server = new DebugServer
   server.on('close', function() {
-    console.log('Server closed')
-    process.exit(0)
-  })
+    console.log('Server closed');
+    process.exit(0);
+  });
+
+  server.start({
+    'webPort':webPort,
+    'debugPort':debugPort
+  });
 
-  server.start({'webPort':webPort, 'debugPort':debugPort})
   process.on('uncaughtException', function(er) {
-    console.log('Error:\n%s', er.stack)
-  })
+    console.log('Error:\n%s', er.stack);
+  });
 }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/package.json
----------------------------------------------------------------------
diff --git a/src/couchjs-node/package.json b/src/couchjs-node/package.json
index 5e8ade0..445f3b9 100644
--- a/src/couchjs-node/package.json
+++ b/src/couchjs-node/package.json
@@ -1,30 +1,40 @@
-{ "name": "couchjs"
-, "description": "Drop-in replacement for CouchDB JavaScript view server"
-, "keywords": [ "couchdb", "couchjs" ]
-, "version": "0.3.2"
-, "author": "Jason Smith <jhs@iriscouch.com> (http://www.iriscouch.com)"
-, "repository": { "type":"git", "url":"https://github.com/iriscouch/couchjs" }
-
-, "engines": { "node": ">= 0.8" }
-, "main": "./couchjs.js"
-, "bin": {"couchjs-node":"./cli.js"}
-
-, "couchdb": { "main":"./couchdb.js"
-             , "vhosts": ["127.0.0.1.xip.io"]
-             }
-
-, "bundledDependencies": ["node-inspector"]
-
-, "dependencies": { "optimist": "~0.3.4"
-                  , "async"   : "~0.2.5"
-                  , "mkdirp"  : "~0.3.4"
-                  , "fibers"  : "~1.0.0"
-                  , "request" : "~2.9.203"
-                  , "pushover": "~1.2.1"
-                  , "defaultable": "~0.7.2"
-                  , "node-inspector": "git://github.com/iriscouch/node-inspector#couchjs"
-                  }
-
-, "devDependencies": { "tap": "~0.2.5"
-                     }
+{
+  "name": "couchjs",
+  "description": "Drop-in replacement for CouchDB JavaScript view server",
+  "keywords": [ "couchdb", "couchjs" ],
+  "version": "0.3.2",
+  "author": "Jason Smith <jhs@iriscouch.com> (http://www.iriscouch.com)",
+  "repository": {
+    "type":"git",
+    "url":"https://github.com/iriscouch/couchjs"
+  },
+  "engines": {
+    "node": ">= 0.8"
+  },
+  "main": "./couchjs.js",
+  "bin": {
+    "couchjs-node":"./cli.js"
+  },
+  "couchdb": {
+    "main":"./couchdb.js",
+    "vhosts": [
+      "127.0.0.1.xip.io"
+    ]
+  },
+  "bundledDependencies": [
+    "node-inspector"
+  ],
+  "dependencies": {
+    "optimist": "~0.3.4",
+    "async"   : "~0.2.5",
+    "mkdirp"  : "~0.3.4",
+    "fibers"  : "~1.0.0",
+    "request" : "~2.9.203",
+    "pushover": "~1.2.1",
+    "defaultable": "~0.7.2",
+    "node-inspector": "git://github.com/iriscouch/node-inspector#couchjs"
+  },
+  "devDependencies": {
+    "tap": "~0.2.5"
+  }
 }

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/sandbox.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/sandbox.js b/src/couchjs-node/sandbox.js
index cfdff18..5c18ef4 100644
--- a/src/couchjs-node/sandbox.js
+++ b/src/couchjs-node/sandbox.js
@@ -1,21 +1,28 @@
 // from https://github.com/KlausTrainer/sandbox.js
 exports.runInSandbox = function(src, ctx, whitelist) {
-  var vm = require('vm'),
-    sandbox;
+  var vm = require('vm');
+  var sandbox;
 
   if (ctx && ctx.require) {
+
     whitelist = whitelist || [];
-    var insecureRequire = ctx.require,
-      module = require("module"),
-      oldModulePrototype = module.prototype;
+
+    var insecureRequire = ctx.require;
+    var module = require('module');
+    var oldModulePrototype = module.prototype;
 
     var secureRequire = function(moduleName) {
-      if (whitelist.indexOf(moduleName) == -1) {
+
+      if (whitelist.indexOf(moduleName) === -1) {
         module.prototype = oldModulePrototype;
+
         throw new Error("'" + moduleName + "' is not whitelisted");
+
       } else {
         var requiredModule = insecureRequire(moduleName);
+
         module.prototype = oldModulePrototype;
+
         return requiredModule;
       }
     };
@@ -31,10 +38,10 @@ exports.runInSandbox = function(src, ctx, whitelist) {
     ctx.require = secureRequire;
     sandbox = Object.freeze(vm.createContext(ctx));
     ctx.require = insecureRequire;
+
   } else {
     sandbox = Object.freeze(vm.createContext(ctx || {}));
   }
 
-  return vm.createScript('(function() {"use strict"; return ('
-                         + src + ')()}())').runInContext(sandbox);
+  return vm.createScript('(function() {"use strict"; return (' + src + ')()}())').runInContext(sandbox);
 };

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/stream.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/stream.js b/src/couchjs-node/stream.js
index ad6bcab..d0c192c 100644
--- a/src/couchjs-node/stream.js
+++ b/src/couchjs-node/stream.js
@@ -12,94 +12,100 @@
 
 // Text line stream
 
-module.exports = LineStream
-module.exports.v2 = LineStream2
+module.exports = LineStream;
+module.exports.v2 = LineStream2;
 
-var stream = require('stream')
-var util = require('util')
+var stream = require('stream');
+var util = require('util');
 
 
-util.inherits(LineStream2, stream.Transform)
+util.inherits(LineStream2, stream.Transform);
+
 function LineStream2 () {
-  if(! (this instanceof LineStream2))
-    return new LineStream2
 
-  stream.Transform.call(this)
-  this.setEncoding('utf8')
+  if (!(this instanceof LineStream2)) {
+    return new LineStream2();
+  }
+
+  stream.Transform.call(this);
+  this.setEncoding('utf8');
 }
 
 LineStream2.prototype._transform = function(message, encoding, done) {
-  var self = this
+  var self = this;
 
-  message = message.toString(encoding)
-  var lines = message.split(/\n/)
+  message = message.toString(encoding);
+  var lines = message.split(/\n/);
 
   // If the data ends in "\n" this will be ""; otherwise the final partial line.
-  var remainder = lines.pop()
-  if(remainder)
-    this.unshift(remainder)
+  var remainder = lines.pop();
+  if (remainder) {
+    this.unshift(remainder);
+  }
 
   lines.forEach(function(line) {
-    self.push(line)
-  })
+    self.push(line);
+  });
 
-  done()
-}
+  done();
+};
+
+util.inherits(LineStream, stream);
 
-util.inherits(LineStream, stream)
 function LineStream () {
-  var self = this
-  stream.call(self)
+  var self = this;
+  stream.call(self);
 
-  self.readable = true
-  self.writable = true
+  self.readable = true;
+  self.writable = true;
 
-  self.buffer = ''
-  self.downstream = null
+  self.buffer = '';
+  self.downstream = null;
 
   self.on('pipe', function(upstream) {
     upstream.on('end', function(data, encoding) {
-      self.emit('end', data, encoding)
-    })
-  })
+      self.emit('end', data, encoding);
+    });
+  });
 }
 
 
 LineStream.prototype.write = function(data, encoding) {
-  var self = this
+  var self = this;
 
-  data = data || ''
-  if(typeof data != 'string')
-    return self.error(new Error('Data was not a string: ' + util.inspect(data)))
+  data = data || '';
+  if (typeof data !== 'string') {
+    return self.error(new Error('Data was not a string: ' + util.inspect(data)));
+  }
 
-  self.buffer += data
-  var lines = self.buffer.split(/\n/)
-  self.buffer = lines.pop() // If the data ended in "\n" this will be ""; otherwise the final
partial line.
+  self.buffer += data;
+  var lines = self.buffer.split(/\n/);
+  self.buffer = lines.pop(); // If the data ended in "\n" this will be ""; otherwise the
final partial line.
 
   lines.forEach(function(line) {
-    self.emit('data', line)
-  })
-}
+    self.emit('data', line);
+  });
+};
 
 
 LineStream.prototype.end = function(data, encoding) {
-  var self = this
+  var self = this;
 
-  self.is_ending = true
-  self.writable = false
+  self.is_ending = true;
+  self.writable = false;
 
   // Always call write, even with no data, so it can fire the "end" event.
-  self.write(data)
-}
+  self.write(data);
+};
 
 
 LineStream.prototype.error = function(er) {
-  var self = this
+  var self = this;
 
-  self.readable = false
-  self.writable = false
-  self.emit('error', er)
+  self.readable = false;
+  self.writable = false;
+  self.emit('error', er);
 
   // The write() method sometimes returns this value, so if there was an error, make write()
return false.
-  return false
-}
+  return false;
+};

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/test/experiment.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/test/experiment.js b/src/couchjs-node/test/experiment.js
index 094ac1d..fedf6d0 100644
--- a/src/couchjs-node/test/experiment.js
+++ b/src/couchjs-node/test/experiment.js
@@ -10,108 +10,117 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-var vm = require('vm')
-var util = require('util')
+var vm = require('vm');
+var util = require('util');
 
-var STATE = 'wait'
-  , v = 'vm'
+var STATE = 'wait';
+var v = 'vm';
 
 function main() {
-  process.debugPort = 5859
-  process.kill(process.pid, 'SIGUSR1')
+  process.debugPort = 5859;
+  process.kill(process.pid, 'SIGUSR1');
 
-  setTimeout(function() { stuff(0) }, 1000)
+  setTimeout(function() {
+    stuff(0);
+  }, 1000);
 }
 
 function stuff(count) {
-  console.log('Doing stuff: %d', count)
-  //debugger
-  STATE = 'vm'
-  console.log('More stuff: %d', count)
-  if(STATE == 'done')
-    console.log('Done')
-  else if(STATE == 'code')
-    setTimeout(code, 1000)
-  else if(STATE == 'eval')
-    test_eval()
-  else if(STATE == 'vm')
-    test_vm()
-  else if(STATE == 'wait')
-    setTimeout(function() { stuff(count+1) }, 1000)
-  else
-    throw new Error('Unknown state: ' + STATE)
+
+  console.log('Doing stuff: %d', count);
+  STATE = 'vm';
+  console.log('More stuff: %d', count);
+
+  if (STATE === 'done') {
+    console.log('Done');
+  } else if (STATE === 'code') {
+    setTimeout(code, 1000);
+  } else if(STATE === 'eval') {
+    test_eval();
+  } else if(STATE === 'vm') {
+    test_vm();
+  } else if(STATE === 'wait') {
+    setTimeout(function() {
+      stuff(count+1);
+    }, 1000);
+  } else {
+    throw new Error('Unknown state: ' + STATE);
+  }
 }
 
 function code() {
-  var code =
-    [ 'var foo = "in the code"'
-    , 'console.log("This is some code")'
-    , 'debugger'
-    , 'console.log("foo = " + foo)'
-    ].join('\n')
-
-  var runner = Function([], code)
-  console.log('Run runner in 1s')
+  var code = [
+    'var foo = "in the code"',
+    'console.log("This is some code")',
+    'debugger',
+    'console.log("foo = " + foo)'
+    ].join('\n');
+
+  var runner = Function([], code);
+
+  console.log('Run runner in 1s');
+
   setTimeout(run_runner, 1000)
 
   function run_runner() {
-    console.log('About to run runner')
-    debugger
-    runner()
-    console.log('Runner done')
+    console.log('About to run runner');
+    debugger;
+    runner();
+    console.log('Runner done');
   }
 }
 
 function test_eval() {
-  console.log('Test eval in 1s')
-  setTimeout(run_eval, 1000)
+  console.log('Test eval in 1s');
+  setTimeout(run_eval, 1000);
 
-  var code =
-    [ 'var foo = "in eval"'
-    , 'console.log("This is eval")'
-    , 'debugger'
-    , 'console.log("foo = " + foo)'
-    ].join('\n')
+  var code = [
+    'var foo = "in eval"',
+    'console.log("This is eval")',
+    'debugger',
+    'console.log("foo = " + foo)'
+    ].join('\n');
 
   function run_eval() {
-    console.log('Run eval now')
-    debugger
-    eval(code)
+    console.log('Run eval now');
+    debugger;
+    eval(code);
   }
 }
 
 function test_vm() {
-  console.log('Test vm')
-
-  var code =
-    [ 'var i = 10'
-    , 'setTimeout(hello, 1000)'
-    , ''
-    , 'function hello() {'
-    , '  debugger'
-    , '  console.log("Hello: " + i)'
-    , '  if(--i)'
-    , '    setTimeout(hello, 1000)'
-    , '}'
-    ].join('\n')
-
-  console.log('Run vm now')
-  var filename = '_couchdb:code.js'
-
-  var sandbox = {}
-    , ok = ['console', 'setTimeout']
+  console.log('Test vm');
+
+  var code = [
+    'var i = 10',
+    'setTimeout(hello, 1000)',
+    '',
+    'function hello() {',
+    '  debugger',
+    '  console.log("Hello: " + i)',
+    '  if(--i)',
+    '    setTimeout(hello, 1000)',
+    '}'
+  ].join('\n');
+
+  console.log('Run vm now');
+  var filename = '_couchdb:code.js';
+
+  var sandbox = {};
+  var ok = ['console', 'setTimeout'];
 
   ok.forEach(function(key) {
-    sandbox[key] = global[key]
-  })
+    sandbox[key] = global[key];
+  });
 
-  var ctx = vm.createContext(sandbox)
-  var script = vm.createScript(code, filename)
+  var ctx = vm.createContext(sandbox);
+  var script = vm.createScript(code, filename);
 
-  var r = script.runInNewContext(sandbox)
-  console.log('Result:\n%s', util.inspect(r, false, 10))
-  return r
+  var r = script.runInNewContext(sandbox);
+  console.log('Result:\n%s', util.inspect(r, false, 10));
+  return r;
 }
 
-if(require.main === module)
-  main()
+if (require.main === module) {
+  main();
+}

http://git-wip-us.apache.org/repos/asf/couchdb/blob/0902e8c5/src/couchjs-node/xml.js
----------------------------------------------------------------------
diff --git a/src/couchjs-node/xml.js b/src/couchjs-node/xml.js
index efd3a8f..b64d221 100644
--- a/src/couchjs-node/xml.js
+++ b/src/couchjs-node/xml.js
@@ -10,12 +10,13 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-module.exports = XML
 
 function XML () {
-  this.foo = 'bar'
+  this.foo = 'bar';
 }
 
 XML.prototype.toXMLString = function() {
-  return '<xml>\n  <title>test</title>\n</xml>'
-}
+  return '<xml>\n  <title>test</title>\n</xml>';
+};
+
+module.exports = XML;


Mime
View raw message