Add JSDoc to helper functions and reformat while true.

This commit is contained in:
Jarmo van Lenthe 2017-11-12 22:20:16 -05:00
parent 50a32e90d9
commit 29047c2481
1 changed files with 24 additions and 1 deletions

View File

@ -26,7 +26,16 @@ const PhpSerialization = {
* @returns {string} * @returns {string}
*/ */
PhpDeserialize: function (input, args) { PhpDeserialize: function (input, args) {
/**
* Recursive method for deserializing.
* @returns {*}
*/
function handleInput() { function handleInput() {
/**
* Read `length` characters from the input, shifting them out the input.
* @param length
* @returns {string}
*/
function read(length) { function read(length) {
let result = ""; let result = "";
for (let idx = 0; idx < length; idx++) { for (let idx = 0; idx < length; idx++) {
@ -39,9 +48,14 @@ const PhpSerialization = {
return result; return result;
} }
/**
* Read characters from the input until `until` is found.
* @param until
* @returns {string}
*/
function readUntil(until) { function readUntil(until) {
let result = ""; let result = "";
while (true) { for(;;) {
let char = read(1); let char = read(1);
if (char === until) { if (char === until) {
break; break;
@ -53,6 +67,11 @@ const PhpSerialization = {
} }
/**
* Read characters from the input that must be equal to `expect`
* @param expect
* @returns {string}
*/
function expect(expect) { function expect(expect) {
let result = read(expect.length); let result = read(expect.length);
if (result !== expect) { if (result !== expect) {
@ -61,6 +80,10 @@ const PhpSerialization = {
return result; return result;
} }
/**
* Helper function to handle deserialized arrays.
* @returns {Array}
*/
function handleArray() { function handleArray() {
let items = parseInt(readUntil(":"), 10) * 2; let items = parseInt(readUntil(":"), 10) * 2;
expect("{"); expect("{");