THRIFT-2576 Implement Thrift.Protocol.prototype.skip method in JavaScript library
Client: JavaScript
Patch: Hyungsul Kim

This closes #141
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index 8fc7cd2..6cab4fd 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -1299,11 +1299,77 @@
     },
 
     /** 
-     * Method to arbitrarily skip over data (not implemented).
-     * @throws {string} this method is not implemented and always throws.
-     */
+     * Method to arbitrarily skip over data */
     skip: function(type) {
-        throw 'skip not supported yet';
+        var ret, i;
+        switch (type) {
+            case Thrift.Type.STOP:
+                return null;
+
+            case Thrift.Type.BOOL:
+                return this.readBool();
+
+            case Thrift.Type.BYTE:
+                return this.readByte();
+
+            case Thrift.Type.I16:
+                return this.readI16();
+
+            case Thrift.Type.I32:
+                return this.readI32();
+
+            case Thrift.Type.I64:
+                return this.readI64();
+
+            case Thrift.Type.DOUBLE:
+                return this.readDouble();
+
+            case Thrift.Type.STRING:
+                return this.readString();
+
+            case Thrift.Type.STRUCT:
+                this.readStructBegin();
+                while (true) {
+                    ret = this.readFieldBegin();
+                    if (ret.ftype == Thrift.Type.STOP) {
+                        break;
+                    }
+                    this.skip(ret.ftype);
+                    this.readFieldEnd();
+                }
+                this.readStructEnd();
+                return null;
+
+            case Thrift.Type.MAP:
+                ret = this.readMapBegin();
+                for (i = 0; i < ret.size; i++) {
+                    if (i > 0) {
+                        if (this.rstack.length > this.rpos[this.rpos.length - 1] + 1) {
+                            this.rstack.pop();
+                        }
+                    }
+                    this.skip(ret.ktype);
+                    this.skip(ret.vtype);
+                }
+                this.readMapEnd();
+                return null;
+
+            case Thrift.Type.SET:
+                ret = this.readSetBegin();
+                for (i = 0; i < ret.size; i++) {
+                    this.skip(ret.etype);
+                }
+                this.readSetEnd();
+                return null;
+
+            case Thrift.Type.LIST:
+                ret = this.readListBegin();
+                for (i = 0; i < ret.size; i++) {
+                    this.skip(ret.etype);
+                }
+                this.readListEnd();
+                return null;
+        }
     }
 };