Rework NodeJS / Javascript consistency 

Client: js

* Re-worked consistency of browser.js and index.js in lib/nodejs

* Wrap non-standard V8 method 'Error.captureStackTrace()'
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index c682605..123f526 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -284,10 +284,9 @@
 
 Thrift.TProtocolException = function TProtocolException(type, message) {
     Error.call(this);
-    if (Error.captureStackTrace) {
+    if (Error.captureStackTrace !== undefined) {
         Error.captureStackTrace(this, this.constructor);
     }
-
     this.name = this.constructor.name;
     this.type = type;
     this.message = message;
diff --git a/lib/nodejs/lib/thrift/browser.js b/lib/nodejs/lib/thrift/browser.js
index ba1ea8c..0b06f0f 100644
--- a/lib/nodejs/lib/thrift/browser.js
+++ b/lib/nodejs/lib/thrift/browser.js
@@ -18,25 +18,32 @@
  */
 exports.Thrift = require('./thrift');
 
-var xhrConnection = require('./xhr_connection');
-exports.XHRConnection = xhrConnection.XHRConnection;
-exports.createXHRConnection = xhrConnection.createXHRConnection;
-exports.createXHRClient = xhrConnection.createXHRClient;
-
 var wsConnection = require('./ws_connection');
 exports.WSConnection = wsConnection.WSConnection;
 exports.createWSConnection = wsConnection.createWSConnection;
 exports.createWSClient = wsConnection.createWSClient;
 
-exports.Multiplexer = require('./multiplexed_protocol').Multiplexer;
+var xhrConnection = require('./xhr_connection');
+exports.XHRConnection = xhrConnection.XHRConnection;
+exports.createXHRConnection = xhrConnection.createXHRConnection;
+exports.createXHRClient = xhrConnection.createXHRClient;
 
-exports.TWebSocketTransport = require('./ws_transport');
-exports.TBufferedTransport = require('./buffered_transport');
-exports.TFramedTransport = require('./framed_transport');
-
-exports.Protocol = exports.TJSONProtocol = require('./json_protocol');
-exports.TBinaryProtocol = require('./binary_protocol');
-exports.TCompactProtocol = require('./compact_protocol');
 
 exports.Int64 = require('node-int64');
 exports.Q = require('q');
+
+var mpxProtocol = require('./multiplexed_protocol');
+exports.Multiplexer = mpxProtocol.Multiplexer;
+
+/*
+ * Export transport and protocol so they can be used outside of a
+ * cassandra/server context
+ */
+exports.TBufferedTransport = require('./buffered_transport');
+exports.TFramedTransport = require('./framed_transport');
+exports.TWebSocketTransport = require('./ws_transport');
+
+exports.Protocol = require('./json_protocol');
+exports.TJSONProtocol = require('./json_protocol');
+exports.TBinaryProtocol = require('./binary_protocol');
+exports.TCompactProtocol = require('./compact_protocol');
diff --git a/lib/nodejs/lib/thrift/header_protocol.js b/lib/nodejs/lib/thrift/header_protocol.js
index a037dc2..8971751 100644
--- a/lib/nodejs/lib/thrift/header_protocol.js
+++ b/lib/nodejs/lib/thrift/header_protocol.js
@@ -29,10 +29,9 @@
 
 function THeaderProtocolError(message) {
   Error.call(this);
-  if (Error.captureStackTrace) {
+  if (Error.captureStackTrace !== undefined) {
     Error.captureStackTrace(this, this.constructor);
   }
-
   this.name = this.constructor.name;
   this.message = message;
 }
diff --git a/lib/nodejs/lib/thrift/header_transport.js b/lib/nodejs/lib/thrift/header_transport.js
index 252a423..ec8624b 100644
--- a/lib/nodejs/lib/thrift/header_transport.js
+++ b/lib/nodejs/lib/thrift/header_transport.js
@@ -24,10 +24,9 @@
 
 function THeaderTransportError(message) {
   Error.call(this);
-  if (Error.captureStackTrace) {
+  if (Error.captureStackTrace !== undefined) {
     Error.captureStackTrace(this, this.constructor);
   }
-
   this.name = this.constructor.name;
   this.message = message;
 }
diff --git a/lib/nodejs/lib/thrift/http_connection.js b/lib/nodejs/lib/thrift/http_connection.js
index 81e6b70..17e0d0c 100644
--- a/lib/nodejs/lib/thrift/http_connection.js
+++ b/lib/nodejs/lib/thrift/http_connection.js
@@ -217,7 +217,7 @@
   var opts = self.nodeOptions;
   opts.headers["Content-length"] = data.length;
   if (!opts.headers["Content-Type"])
-    opts.headers["Content-Type"] = "application/x-thrift";  
+    opts.headers["Content-Type"] = "application/x-thrift";
   var req = (self.https) ?
       https.request(opts, self.responseCallback) :
       http.request(opts, self.responseCallback);
@@ -253,7 +253,7 @@
 
 function THTTPException(response) {
   thrift.TApplicationException.call(this);
-  if (Error.captureStackTrace) {
+  if (Error.captureStackTrace !== undefined) {
     Error.captureStackTrace(this, this.constructor);
   }
 
diff --git a/lib/nodejs/lib/thrift/index.js b/lib/nodejs/lib/thrift/index.js
index 0a2d02b..00f2174 100644
--- a/lib/nodejs/lib/thrift/index.js
+++ b/lib/nodejs/lib/thrift/index.js
@@ -58,18 +58,19 @@
 exports.Int64 = require('node-int64');
 exports.Q = require('q');
 
-var mprocessor = require('./multiplexed_processor');
-var mprotocol = require('./multiplexed_protocol');
-exports.Multiplexer = mprotocol.Multiplexer;
-exports.MultiplexedProcessor = mprocessor.MultiplexedProcessor;
+var mpxProcessor = require('./multiplexed_processor');
+var mpxProtocol = require('./multiplexed_protocol');
+exports.MultiplexedProcessor = mpxProcessor.MultiplexedProcessor;
+exports.Multiplexer = mpxProtocol.Multiplexer;
 
 /*
  * Export transport and protocol so they can be used outside of a
  * cassandra/server context
  */
-exports.TFramedTransport = require('./framed_transport');
 exports.TBufferedTransport = require('./buffered_transport');
-exports.TBinaryProtocol = require('./binary_protocol');
+exports.TFramedTransport = require('./framed_transport');
+
 exports.TJSONProtocol = require('./json_protocol');
+exports.TBinaryProtocol = require('./binary_protocol');
 exports.TCompactProtocol = require('./compact_protocol');
 exports.THeaderProtocol = require('./header_protocol');
diff --git a/lib/nodejs/lib/thrift/input_buffer_underrun_error.js b/lib/nodejs/lib/thrift/input_buffer_underrun_error.js
index 0e33f5a..e424540 100644
--- a/lib/nodejs/lib/thrift/input_buffer_underrun_error.js
+++ b/lib/nodejs/lib/thrift/input_buffer_underrun_error.js
@@ -22,10 +22,9 @@
 
 function InputBufferUnderrunError(message) {
   Error.call(this);
-  if (Error.captureStackTrace) {
+  if (Error.captureStackTrace !== undefined) {
     Error.captureStackTrace(this, this.constructor);
   }
-
   this.name = this.constructor.name;
   this.message = message;
 };
diff --git a/lib/nodejs/lib/thrift/thrift.js b/lib/nodejs/lib/thrift/thrift.js
index 58d4aff..f728eac 100644
--- a/lib/nodejs/lib/thrift/thrift.js
+++ b/lib/nodejs/lib/thrift/thrift.js
@@ -49,7 +49,7 @@
 
 function TException(message) {
   Error.call(this);
-  if (Error.captureStackTrace) {
+  if (Error.captureStackTrace !== undefined) {
     Error.captureStackTrace(this, this.constructor);
   }
 
@@ -76,7 +76,7 @@
 
 function TApplicationException(type, message) {
   TException.call(this);
-  if (Error.captureStackTrace) {
+  if (Error.captureStackTrace !== undefined) {
     Error.captureStackTrace(this, this.constructor);
   }
 
@@ -155,7 +155,7 @@
 
 function TProtocolException(type, message) {
   Error.call(this);
-  if (Error.captureStackTrace) {
+  if (Error.captureStackTrace !== undefined) {
     Error.captureStackTrace(this, this.constructor);
   }