Skip to content

Commit

Permalink
Made sure that LongBits ctor is always called with unsigned 32 bits +…
Browse files Browse the repository at this point in the history
… static codegen compat., fixes #690
  • Loading branch information
dcodeIO committed Feb 28, 2017
1 parent cbd4c62 commit 88eb7a6
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 52 deletions.
21 changes: 12 additions & 9 deletions dist/light/protobuf.js

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

2 changes: 1 addition & 1 deletion dist/light/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/light/protobuf.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions dist/minimal/protobuf.js

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

2 changes: 1 addition & 1 deletion dist/minimal/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/minimal/protobuf.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions dist/protobuf.js

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

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2033,8 +2033,8 @@ export namespace util {
* @classdesc Helper class for working with the low and high bits of a 64 bit value.
* @memberof util
* @constructor
* @param {number} lo Low bits
* @param {number} hi High bits
* @param {number} lo Low bits, unsigned
* @param {number} hi High bits, unsigned
*/
class LongBits {

Expand All @@ -2043,8 +2043,8 @@ export namespace util {
* @classdesc Helper class for working with the low and high bits of a 64 bit value.
* @memberof util
* @constructor
* @param {number} lo Low bits
* @param {number} hi High bits
* @param {number} lo Low bits, unsigned
* @param {number} hi High bits, unsigned
*/
constructor(lo: number, hi: number);

Expand Down
4 changes: 2 additions & 2 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
("else if(typeof d%s===\"number\")", prop)
("m%s=d%s", prop, prop)
("else if(typeof d%s===\"object\")", prop)
("m%s=new util.LongBits(d%s.low,d%s.high).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : "");
("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : "");
break;
case "bytes": gen
("if(typeof d%s===\"string\")", prop)
Expand Down Expand Up @@ -172,7 +172,7 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
("if(typeof m%s===\"number\")", prop)
("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)
("else") // Long-like
("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low,m%s.high).toNumber(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop);
("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop);
break;
case "bytes": gen
("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s", prop, prop, prop, prop, prop);
Expand Down
2 changes: 1 addition & 1 deletion src/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Reader.prototype.sint32 = function read_sint32() {

function readLongVarint() {
// tends to deopt with local vars for octet etc.
var bits = new LongBits(0 >>> 0, 0 >>> 0);
var bits = new LongBits(0, 0);
var i = 0;
if (this.len - this.pos > 4) { // fast route (lo)
for (; i < 4; ++i) {
Expand Down
13 changes: 8 additions & 5 deletions src/util/longbits.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ var util = require("../util/minimal");
* @classdesc Helper class for working with the low and high bits of a 64 bit value.
* @memberof util
* @constructor
* @param {number} lo Low bits
* @param {number} hi High bits
* @param {number} lo Low bits, unsigned
* @param {number} hi High bits, unsigned
*/
function LongBits(lo, hi) { // make sure to always call this with unsigned 32bits for proper optimization
function LongBits(lo, hi) {

// note that the casts below are theoretically unnecessary as of today, but older statically
// generated converter code might still call the ctor with signed 32bits. kept for compat.

/**
* Low bits.
* @type {number}
*/
this.lo = lo;
this.lo = lo >>> 0;

/**
* High bits.
* @type {number}
*/
this.hi = hi;
this.hi = hi >>> 0;
}

/**
Expand Down

0 comments on commit 88eb7a6

Please sign in to comment.