When you call .writebits(n, size) with size > 31, the operation fails silently. This is because JS casts all numbers to Int32's under-the-hood whenever bitwise operations are invoked, such as the following line in writebits:
bits = this._spill << size | n;