jmuehlner commented on code in PR #853:
URL: https://github.com/apache/guacamole-client/pull/853#discussion_r1186385515
##########
guacamole-common-js/src/main/webapp/modules/Parser.js:
##########
@@ -22,39 +22,91 @@ var Guacamole = Guacamole || {};
/**
* Simple Guacamole protocol parser that invokes an oninstruction event when
* full instructions are available from data received via receive().
- *
+ *
* @constructor
*/
-Guacamole.Parser = function() {
+Guacamole.Parser = function Parser() {
/**
* Reference to this parser.
+ *
* @private
+ * @type {!Guacamole.Parser}
*/
var parser = this;
/**
* Current buffer of received data. This buffer grows until a full
* element is available. After a full element is available, that element
* is flushed into the element buffer.
- *
+ *
* @private
+ * @type {!string}
*/
- var buffer = "";
+ var buffer = '';
/**
* Buffer of all received, complete elements. After an entire instruction
* is read, this buffer is flushed, and a new instruction begins.
- *
+ *
+ * @private
+ * @type {!string[]}
+ */
+ var elementBuffer = [];
+
+ /**
+ * The character offset within the buffer of the current or most recently
+ * parsed element's terminator. If sufficient characters have not yet been
+ * read via calls to receive(), this may point to an offset well beyond the
+ * end of the buffer. If no characters for an element have yet been read,
+ * this will be -1.
+ *
+ * @private
+ * @type {!number}
+ */
+ var elementEnd = -1;
+
+ /**
+ * The character offset within the buffer of the location that the parser
+ * should start looking for the next element length search or next element
+ * value.
+ *
+ * @private
+ * @type {!number}
+ */
+ var startIndex = 0;
+
+ /**
+ * The declared length of the current element being parsed, in Unicode
+ * codepoints.
+ *
* @private
+ * @type {!number}
*/
- var element_buffer = [];
+ var elementCodepoints = 0;
- // The location of the last element's terminator
- var element_end = -1;
+ /**
+ * The number of parsed characters that must accumulate in the begining of
+ * the parse buffer before processing time is expended to truncate that
+ * buffer and conserve memory.
+ *
+ * @private
+ * @constant
+ * @type {!number}
+ */
+ var BUFFER_TRUNCATION_THRESHOLD = 4096;
Review Comment:
Consider using `const` for constants.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]