THRIFT-3627 fix missing basic code style consistency of JavaScript.
Client: js
This closes #858
This closes #1243
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index 3ea57c8..37ba690 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -20,21 +20,21 @@
/*jshint evil:true*/
/**
- * The Thrift namespace houses the Apache Thrift JavaScript library
- * elements providing JavaScript bindings for the Apache Thrift RPC
- * system. End users will typically only directly make use of the
- * Transport (TXHRTransport/TWebSocketTransport) and Protocol
+ * The Thrift namespace houses the Apache Thrift JavaScript library
+ * elements providing JavaScript bindings for the Apache Thrift RPC
+ * system. End users will typically only directly make use of the
+ * Transport (TXHRTransport/TWebSocketTransport) and Protocol
* (TJSONPRotocol/TBinaryProtocol) constructors.
- *
- * Object methods beginning with a __ (e.g. __onOpen()) are internal
+ *
+ * Object methods beginning with a __ (e.g. __onOpen()) are internal
* and should not be called outside of the object's own methods.
- *
+ *
* This library creates one global object: Thrift
* Code in this library must never create additional global identifiers,
* all features must be scoped within the Thrift namespace.
* @namespace
* @example
- * var transport = new Thrift.Transport("http://localhost:8585");
+ * var transport = new Thrift.Transport('http://localhost:8585');
* var protocol = new Thrift.Protocol(transport);
* var client = new MyThriftSvcClient(protocol);
* var result = client.MyMethod();
@@ -55,7 +55,7 @@
* @property {number} VOID - No value (only legal for return types).
* @property {number} BOOL - True/False integer.
* @property {number} BYTE - Signed 8 bit integer.
- * @property {number} I08 - Signed 8 bit integer.
+ * @property {number} I08 - Signed 8 bit integer.
* @property {number} DOUBLE - 64 bit IEEE 854 floating point.
* @property {number} I16 - Signed 16 bit integer.
* @property {number} I32 - Signed 32 bit integer.
@@ -70,23 +70,23 @@
* @property {number} UTF16 - Array of bytes representing a string of UTF16 encoded characters.
*/
Type: {
- 'STOP' : 0,
- 'VOID' : 1,
- 'BOOL' : 2,
- 'BYTE' : 3,
- 'I08' : 3,
- 'DOUBLE' : 4,
- 'I16' : 6,
- 'I32' : 8,
- 'I64' : 10,
- 'STRING' : 11,
- 'UTF7' : 11,
- 'STRUCT' : 12,
- 'MAP' : 13,
- 'SET' : 14,
- 'LIST' : 15,
- 'UTF8' : 16,
- 'UTF16' : 17
+ STOP: 0,
+ VOID: 1,
+ BOOL: 2,
+ BYTE: 3,
+ I08: 3,
+ DOUBLE: 4,
+ I16: 6,
+ I32: 8,
+ I64: 10,
+ STRING: 11,
+ UTF7: 11,
+ STRUCT: 12,
+ MAP: 13,
+ SET: 14,
+ LIST: 15,
+ UTF8: 16,
+ UTF16: 17
},
/**
@@ -98,10 +98,10 @@
* @property {number} ONEWAY - Oneway RPC call from client to server with no response.
*/
MessageType: {
- 'CALL' : 1,
- 'REPLY' : 2,
- 'EXCEPTION' : 3,
- 'ONEWAY' : 4
+ CALL: 1,
+ REPLY: 2,
+ EXCEPTION: 3,
+ ONEWAY: 4
},
/**
@@ -130,7 +130,7 @@
function F() {}
F.prototype = superConstructor.prototype;
constructor.prototype = new F();
- constructor.prototype.name = name || "";
+ constructor.prototype.name = name || '';
}
};
@@ -171,17 +171,17 @@
* @property {number} UNSUPPORTED_CLIENT_TYPE - Unused.
*/
Thrift.TApplicationExceptionType = {
- 'UNKNOWN' : 0,
- 'UNKNOWN_METHOD' : 1,
- 'INVALID_MESSAGE_TYPE' : 2,
- 'WRONG_METHOD_NAME' : 3,
- 'BAD_SEQUENCE_ID' : 4,
- 'MISSING_RESULT' : 5,
- 'INTERNAL_ERROR' : 6,
- 'PROTOCOL_ERROR' : 7,
- 'INVALID_TRANSFORM' : 8,
- 'INVALID_PROTOCOL' : 9,
- 'UNSUPPORTED_CLIENT_TYPE' : 10
+ UNKNOWN: 0,
+ UNKNOWN_METHOD: 1,
+ INVALID_MESSAGE_TYPE: 2,
+ WRONG_METHOD_NAME: 3,
+ BAD_SEQUENCE_ID: 4,
+ MISSING_RESULT: 5,
+ INTERNAL_ERROR: 6,
+ PROTOCOL_ERROR: 7,
+ INVALID_TRANSFORM: 8,
+ INVALID_PROTOCOL: 9,
+ UNSUPPORTED_CLIENT_TYPE: 10
};
/**
@@ -194,7 +194,7 @@
*/
Thrift.TApplicationException = function(message, code) {
this.message = message;
- this.code = typeof code === "number" ? code : 0;
+ this.code = typeof code === 'number' ? code : 0;
};
Thrift.inherits(Thrift.TApplicationException, Thrift.TException, 'TApplicationException');
@@ -298,8 +298,8 @@
* for backward compatibility.
* @constructor
* @param {string} [url] - The URL to connect to.
- * @classdesc The Apache Thrift Transport layer performs byte level I/O
- * between RPC clients and servers. The JavaScript TXHRTransport object
+ * @classdesc The Apache Thrift Transport layer performs byte level I/O
+ * between RPC clients and servers. The JavaScript TXHRTransport object
* uses Http[s]/XHR. Target servers must implement the http[s] transport
* (see: node.js example server_http.js).
* @example
@@ -329,12 +329,12 @@
},
/**
- * Sends the current XRH request if the transport was created with a URL
+ * Sends the current XRH request if the transport was created with a URL
* and the async parameter is false. If the transport was not created with
- * a URL, or the async parameter is True and no callback is provided, or
+ * a URL, or the async parameter is True and no callback is provided, or
* the URL is an empty string, the current send buffer is returned.
* @param {object} async - If true the current send buffer is returned.
- * @param {object} callback - Optional async completion callback
+ * @param {object} callback - Optional async completion callback
* @returns {undefined|string} Nothing or the current send buffer.
* @throws {string} If XHR fails.
*/
@@ -353,9 +353,9 @@
if (callback) {
//Ignore XHR callbacks until the data arrives, then call the
// client's callback
- xreq.onreadystatechange =
+ xreq.onreadystatechange =
(function() {
- var clientCallback = callback;
+ var clientCallback = callback;
return function() {
if (this.readyState == 4 && this.status == 200) {
self.setRecvBuffer(this.responseText);
@@ -459,19 +459,19 @@
* Returns true if the transport is open, XHR always returns true.
* @readonly
* @returns {boolean} Always True.
- */
+ */
isOpen: function() {
return true;
},
/**
* Opens the transport connection, with XHR this is a nop.
- */
+ */
open: function() {},
/**
* Closes the transport connection, with XHR this is a nop.
- */
+ */
close: function() {},
/**
@@ -511,7 +511,7 @@
/**
* Sets the send buffer to buf.
* @param {string} buf - The buffer to send.
- */
+ */
write: function(buf) {
this.send_buf = buf;
},
@@ -520,7 +520,7 @@
* Returns the send buffer.
* @readonly
* @returns {string} The send buffer.
- */
+ */
getSendBuffer: function() {
return this.send_buf;
}
@@ -532,8 +532,8 @@
* Constructor Function for the WebSocket transport.
* @constructor
* @param {string} [url] - The URL to connect to.
- * @classdesc The Apache Thrift Transport layer performs byte level I/O
- * between RPC clients and servers. The JavaScript TWebSocketTransport object
+ * @classdesc The Apache Thrift Transport layer performs byte level I/O
+ * between RPC clients and servers. The JavaScript TWebSocketTransport object
* uses the WebSocket protocol. Target servers must implement WebSocket.
* (see: node.js example server_http.js).
* @example
@@ -556,20 +556,20 @@
},
/**
- * Sends the current WS request and registers callback. The async
- * parameter is ignored (WS flush is always async) and the callback
+ * Sends the current WS request and registers callback. The async
+ * parameter is ignored (WS flush is always async) and the callback
* function parameter is required.
* @param {object} async - Ignored.
* @param {object} callback - The client completion callback.
- * @returns {undefined|string} Nothing (undefined)
+ * @returns {undefined|string} Nothing (undefined)
*/
flush: function(async, callback) {
var self = this;
if (this.isOpen()) {
//Send data and register a callback to invoke the client callback
- this.socket.send(this.send_buf);
+ this.socket.send(this.send_buf);
this.callbacks.push((function() {
- var clientCallback = callback;
+ var clientCallback = callback;
return function(msg) {
self.setRecvBuffer(msg);
clientCallback();
@@ -579,20 +579,20 @@
//Queue the send to go out __onOpen
this.send_pending.push({
buf: this.send_buf,
- cb: callback
+ cb: callback
});
}
},
- __onOpen: function() {
+ __onOpen: function() {
var self = this;
if (this.send_pending.length > 0) {
- //If the user made calls before the connection was fully
+ //If the user made calls before the connection was fully
//open, send them now
this.send_pending.forEach(function(elem) {
this.socket.send(elem.buf);
this.callbacks.push((function() {
- var clientCallback = elem.cb;
+ var clientCallback = elem.cb;
return function(msg) {
self.setRecvBuffer(msg);
clientCallback();
@@ -602,19 +602,19 @@
this.send_pending = [];
}
},
-
- __onClose: function(evt) {
+
+ __onClose: function(evt) {
this.__reset(this.url);
},
-
+
__onMessage: function(evt) {
if (this.callbacks.length) {
this.callbacks.shift()(evt.data);
}
},
-
- __onError: function(evt) {
- console.log("Thrift WebSocket Error: " + evt.toString());
+
+ __onError: function(evt) {
+ console.log('Thrift WebSocket Error: ' + evt.toString());
this.socket.close();
},
@@ -632,15 +632,15 @@
/**
* Returns true if the transport is open
* @readonly
- * @returns {boolean}
- */
+ * @returns {boolean}
+ */
isOpen: function() {
return this.socket && this.socket.readyState == this.socket.OPEN;
},
/**
* Opens the transport connection
- */
+ */
open: function() {
//If OPEN/CONNECTING/CLOSING ignore additional opens
if (this.socket && this.socket.readyState != this.socket.CLOSED) {
@@ -648,15 +648,15 @@
}
//If there is no socket or the socket is closed:
this.socket = new WebSocket(this.url);
- this.socket.onopen = this.__onOpen.bind(this);
- this.socket.onmessage = this.__onMessage.bind(this);
- this.socket.onerror = this.__onError.bind(this);
- this.socket.onclose = this.__onClose.bind(this);
+ this.socket.onopen = this.__onOpen.bind(this);
+ this.socket.onmessage = this.__onMessage.bind(this);
+ this.socket.onerror = this.__onError.bind(this);
+ this.socket.onclose = this.__onClose.bind(this);
},
/**
* Closes the transport connection
- */
+ */
close: function() {
this.socket.close();
},
@@ -698,7 +698,7 @@
/**
* Sets the send buffer to buf.
* @param {string} buf - The buffer to send.
- */
+ */
write: function(buf) {
this.send_buf = buf;
},
@@ -707,7 +707,7 @@
* Returns the send buffer.
* @readonly
* @returns {string} The send buffer.
- */
+ */
getSendBuffer: function() {
return this.send_buf;
}
@@ -718,8 +718,8 @@
* Initializes a Thrift JSON protocol instance.
* @constructor
* @param {Thrift.Transport} transport - The transport to serialize to/from.
- * @classdesc Apache Thrift Protocols perform serialization which enables cross
- * language RPC. The Protocol type is the JavaScript browser implementation
+ * @classdesc Apache Thrift Protocols perform serialization which enables cross
+ * language RPC. The Protocol type is the JavaScript browser implementation
* of the Apache Thrift TJSONProtocol.
* @example
* var protocol = new Thrift.Protocol(transport);
@@ -779,7 +779,7 @@
* Returns the underlying transport.
* @readonly
* @returns {Thrift.Transport} The underlying transport.
- */
+ */
getTransport: function() {
return this.transport;
},
@@ -1021,7 +1021,7 @@
if (ch === '\"') {
escapedString += '\\\"'; // write out as: \"
} else if (ch === '\\') { // a single backslash
- escapedString += '\\\\'; // write out as double backslash
+ escapedString += '\\\\'; // write out as double backslash
} else if (ch === '\b') { // a single backspace: invisible
escapedString += '\\b'; // write out as: \b"
} else if (ch === '\f') { // a single formfeed: invisible
@@ -1063,8 +1063,8 @@
@property {Thrift.MessageType} mtype - The type of message call.
@property {number} rseqid - The sequence number of the message (0 in Thrift RPC).
*/
- /**
- * Deserializes the beginning of a message.
+ /**
+ * Deserializes the beginning of a message.
* @returns {AnonReadMessageBeginReturn}
*/
readMessageBegin: function() {
@@ -1101,11 +1101,11 @@
readMessageEnd: function() {
},
- /**
- * Deserializes the beginning of a struct.
+ /**
+ * Deserializes the beginning of a struct.
* @param {string} [name] - The name of the struct (ignored)
* @returns {object} - An object with an empty string fname property
- */
+ */
readStructBegin: function(name) {
var r = {};
r.fname = '';
@@ -1132,8 +1132,8 @@
@property {Thrift.Type} ftype - The data type of the field.
@property {number} fid - The unique identifier of the field.
*/
- /**
- * Deserializes the beginning of a field.
+ /**
+ * Deserializes the beginning of a field.
* @returns {AnonReadFieldBeginReturn}
*/
readFieldBegin: function() {
@@ -1201,8 +1201,8 @@
@property {Thrift.Type} vtype - The data type of the value.
@property {number} size - The number of elements in the map.
*/
- /**
- * Deserializes the beginning of a map.
+ /**
+ * Deserializes the beginning of a map.
* @returns {AnonReadMapBeginReturn}
*/
readMapBegin: function() {
@@ -1237,8 +1237,8 @@
@property {Thrift.Type} etype - The data type of the element.
@property {number} size - The number of elements in the collection.
*/
- /**
- * Deserializes the beginning of a list.
+ /**
+ * Deserializes the beginning of a list.
* @returns {AnonReadColBeginReturn}
*/
readListBegin: function() {
@@ -1259,8 +1259,8 @@
this.readFieldEnd();
},
- /**
- * Deserializes the beginning of a set.
+ /**
+ * Deserializes the beginning of a set.
* @returns {AnonReadColBeginReturn}
*/
readSetBegin: function(elemType, size) {
@@ -1272,8 +1272,8 @@
return this.readListEnd();
},
- /** Returns an object with a value property set to
- * False unless the next number in the protocol buffer
+ /** Returns an object with a value property set to
+ * False unless the next number in the protocol buffer
* is 1, in which case the value property is True */
readBool: function() {
var r = this.readI32();
@@ -1287,19 +1287,19 @@
return r;
},
- /** Returns the an object with a value property set to the
+ /** Returns the an object with a value property set to the
next value found in the protocol buffer */
readByte: function() {
return this.readI32();
},
- /** Returns the an object with a value property set to the
+ /** Returns the an object with a value property set to the
next value found in the protocol buffer */
readI16: function() {
return this.readI32();
},
- /** Returns the an object with a value property set to the
+ /** Returns the an object with a value property set to the
next value found in the protocol buffer */
readI32: function(f) {
if (f === undefined) {
@@ -1333,26 +1333,26 @@
return r;
},
- /** Returns the an object with a value property set to the
+ /** Returns the an object with a value property set to the
next value found in the protocol buffer */
readI64: function() {
return this.readI32();
},
- /** Returns the an object with a value property set to the
+ /** Returns the an object with a value property set to the
next value found in the protocol buffer */
readDouble: function() {
return this.readI32();
},
- /** Returns the an object with a value property set to the
+ /** Returns the an object with a value property set to the
next value found in the protocol buffer */
readString: function() {
var r = this.readI32();
return r;
},
- /** Returns the an object with a value property set to the
+ /** Returns the an object with a value property set to the
next value found in the protocol buffer */
readBinary: function() {
var r = this.readI32();
@@ -1360,7 +1360,7 @@
return r;
},
- /**
+ /**
* Method to arbitrarily skip over data */
skip: function(type) {
var ret, i;
@@ -1440,23 +1440,23 @@
* Initializes a MutilplexProtocol Implementation as a Wrapper for Thrift.Protocol
* @constructor
*/
-Thrift.MultiplexProtocol = function (srvName, trans, strictRead, strictWrite) {
+Thrift.MultiplexProtocol = function(srvName, trans, strictRead, strictWrite) {
Thrift.Protocol.call(this, trans, strictRead, strictWrite);
this.serviceName = srvName;
};
Thrift.inherits(Thrift.MultiplexProtocol, Thrift.Protocol, 'multiplexProtocol');
/** Override writeMessageBegin method of prototype*/
-Thrift.MultiplexProtocol.prototype.writeMessageBegin = function (name, type, seqid) {
+Thrift.MultiplexProtocol.prototype.writeMessageBegin = function(name, type, seqid) {
if (type === Thrift.MessageType.CALL || type === Thrift.MessageType.ONEWAY) {
- Thrift.Protocol.prototype.writeMessageBegin.call(this, this.serviceName + ":" + name, type, seqid);
+ Thrift.Protocol.prototype.writeMessageBegin.call(this, this.serviceName + ':' + name, type, seqid);
} else {
Thrift.Protocol.prototype.writeMessageBegin.call(this, name, type, seqid);
}
};
-Thrift.Multiplexer = function () {
+Thrift.Multiplexer = function() {
this.seqid = 0;
};
@@ -1471,12 +1471,12 @@
* var protocol = new Thrift.Protocol(transport);
* var client = mp.createClient('AuthService', AuthServiceClient, transport);
*/
-Thrift.Multiplexer.prototype.createClient = function (serviceName, SCl, transport) {
+Thrift.Multiplexer.prototype.createClient = function(serviceName, SCl, transport) {
if (SCl.Client) {
SCl = SCl.Client;
}
var self = this;
- SCl.prototype.new_seqid = function () {
+ SCl.prototype.new_seqid = function() {
self.seqid += 1;
return self.seqid;
};
@@ -1519,7 +1519,7 @@
return result;
};
-copyMap = function(obj, types){
+copyMap = function(obj, types) {
if (!obj) {return obj; }
@@ -1534,8 +1534,8 @@
var Type = type;
var result = {}, val;
- for(var prop in obj) {
- if(obj.hasOwnProperty(prop)) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
val = obj[prop];
if (type === null) {
result[prop] = val;