Permalink
Browse files

Made sure that LongBits ctor is always called with unsigned 32 bits +…

… static codegen compat., fixes #690
  • Loading branch information...
dcodeIO committed Feb 28, 2017
1 parent cbd4c62 commit 88eb7a603a21643d5012a374c7d246f4c27620f3

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +8 Bytes (100%) dist/light/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +1 Byte (100%) dist/minimal/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +2 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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 {
@@ -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);
@@ -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)
@@ -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);
@@ -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) {
@@ -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;
}
/**

0 comments on commit 88eb7a6

Please sign in to comment.