Skip to content

Commit

Permalink
Fix check for Long in readVarint64
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jun 5, 2014
1 parent 57f7e7b commit 885186b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bytebuffer",
"version": "3.0.0-RC1",
"version": "3.0.0-RC2",
"author": "Daniel Wirtz <[email protected]>",
"description": "A full-featured ByteBuffer implementation using typed arrays.",
"main": "ByteBuffer.js",
Expand Down
4 changes: 2 additions & 2 deletions dist/ByteBufferAB.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
* @const
* @expose
*/
ByteBuffer.VERSION = "3.0.0-RC1";
ByteBuffer.VERSION = "3.0.0-RC2";

/**
* Little endian constant that can be used instead of its boolean value. Evaluates to `true`.
Expand Down Expand Up @@ -1352,7 +1352,7 @@
*/
ByteBuffer.prototype.readVarint64ZigZag = function(offset) {
var val = this.readVarint64(offset);
if (typeof val === 'object')
if (val && val['value'] instanceof Long)
val["value"] = ByteBuffer.zigZagDecode64(val["value"]);
else
val = ByteBuffer.zigZagDecode64(val);
Expand Down
8 changes: 4 additions & 4 deletions dist/ByteBufferAB.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/ByteBufferAB.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/ByteBufferAB.min.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ByteBufferNB.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ module.exports = (function() {
* @const
* @expose
*/
ByteBuffer.VERSION = "3.0.0-RC1";
ByteBuffer.VERSION = "3.0.0-RC2";

/**
* Little endian constant that can be used instead of its boolean value. Evaluates to `true`.
Expand Down Expand Up @@ -1508,7 +1508,7 @@ module.exports = (function() {
*/
ByteBuffer.prototype.readVarint64ZigZag = function(offset) {
var val = this.readVarint64(offset);
if (typeof val === 'object')
if (val && val['value'] instanceof Long)
val["value"] = ByteBuffer.zigZagDecode64(val["value"]);
else
val = ByteBuffer.zigZagDecode64(val);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bytebuffer",
"version": "3.0.0-RC1",
"version": "3.0.0-RC2",
"author": "Daniel Wirtz <[email protected]>",
"description": "The swiss army knife for binary data in JavaScript.",
"main": "ByteBuffer.js",
Expand Down
2 changes: 1 addition & 1 deletion src/types/varints/varint64.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ if (Long) {
*/
ByteBuffer.prototype.readVarint64ZigZag = function(offset) {
var val = this.readVarint64(offset);
if (typeof val === 'object')
if (val && val['value'] instanceof Long)
val["value"] = ByteBuffer.zigZagDecode64(val["value"]);
else
val = ByteBuffer.zigZagDecode64(val);
Expand Down
30 changes: 16 additions & 14 deletions tests/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,21 +513,23 @@ function makeSuite(ByteBuffer) {
};

var types = [
// name | alias | size | input | output | BE representation
["Int8" , "Byte" , 1 , 0xFE , -2 , "fe" ],
["Uint8" , null , 1 , -2 , 0xFE , "fe" ],
["Int16" , "Short" , 2 , 0xFFFE , -2 , "fffe" ],
["Uint16" , null , 2 , -2 , 0xFFFE , "fffe" ],
["Int32" , "Int" , 4 , 0xFFFFFFFE , -2 , "fffffffe" ],
["Uint32" , null , 4 , -2 , 0xFFFFFFFE , "fffffffe" ],
["Float32" , "Float" , 4 , 0.5 , 0.5 , "3f000000" ],
["Float64" , "Double", 8 , 0.1 , 0.1 , "3fb999999999999a" ],
["Int64" , "Long" , 8 , new Long(0xFFFFFFFE, 0xFFFFFFFF, true) , new Long(0xFFFFFFFE, 0xFFFFFFFF, false) , "fffffffffffffffe" ],
["Uint64" , null , 8 , new Long(0xFFFFFFFE, 0xFFFFFFFF, false) , new Long(0xFFFFFFFE, 0xFFFFFFFF, true) , "fffffffffffffffe" ],
// name | alias | size | input | output | BE representation
["Int8" , "Byte" , 1 , 0xFE , -2 , "fe" ],
["Uint8" , null , 1 , -2 , 0xFE , "fe" ],
["Int16" , "Short" , 2 , 0xFFFE , -2 , "fffe" ],
["Uint16" , null , 2 , -2 , 0xFFFE , "fffe" ],
["Int32" , "Int" , 4 , 0xFFFFFFFE , -2 , "fffffffe" ],
["Uint32" , null , 4 , -2 , 0xFFFFFFFE , "fffffffe" ],
["Float32" , "Float" , 4 , 0.5 , 0.5 , "3f000000" ],
["Float64" , "Double", 8 , 0.1 , 0.1 , "3fb999999999999a" ],
["Int64" , "Long" , 8 , new Long(0xFFFFFFFE, 0xFFFFFFFF, true) , new Long(0xFFFFFFFE, 0xFFFFFFFF, false) , "fffffffffffffffe" ],
["Uint64" , null , 8 , new Long(0xFFFFFFFE, 0xFFFFFFFF, false) , new Long(0xFFFFFFFE, 0xFFFFFFFF, true) , "fffffffffffffffe" ],

// name | alias | size | input | output | representation
["Varint32", null , 5 , 0xFFFFFFFE , -2 , "feffffff0f" ],
["Varint64", null , 10 , new Long(0xFFFFFFFE, 0xFFFFFFFF, true) , new Long(0xFFFFFFFE, 0xFFFFFFFF, false) , "feffffffffffffffff01"]
// name | alias | size | input | output | representation
["Varint32" , null , 5 , 0xFFFFFFFE , -2 , "feffffff0f" ],
["Varint32ZigZag", null , 1 , -1 , -1 , "01" ],
["Varint64" , null , 10 , new Long(0xFFFFFFFE, 0xFFFFFFFF, true) , new Long(0xFFFFFFFE, 0xFFFFFFFF, false) , "feffffffffffffffff01"],
["Varint64ZigZag", null , 1 , Long.fromNumber(-1) , Long.fromNumber(-1) , "01" ]
];

suite.types = {};
Expand Down

0 comments on commit 885186b

Please sign in to comment.