Skip to content

Commit 3ff6090

Browse files
authored
Merge pull request #146 from dibenede/commonjs-tests
Re-enable advanced optimizations and add binary/ tests for CommonJS
2 parents e34549d + bed436a commit 3ff6090

20 files changed

+493
-82
lines changed

binary/arith.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,19 @@ goog.provide('jspb.arith.UInt64');
4949
* @param {number} lo The low 32 bits.
5050
* @param {number} hi The high 32 bits.
5151
* @constructor
52+
* @export
5253
*/
5354
jspb.arith.UInt64 = function(lo, hi) {
5455
/**
5556
* The low 32 bits.
56-
* @public {number}
57+
* @type {number}
58+
* @export
5759
*/
5860
this.lo = lo;
5961
/**
6062
* The high 32 bits.
61-
* @public {number}
63+
* @type {number}
64+
* @export
6265
*/
6366
this.hi = hi;
6467
};
@@ -69,6 +72,7 @@ jspb.arith.UInt64 = function(lo, hi) {
6972
* less, +1 if the first is greater, or 0 if both are equal.
7073
* @param {!jspb.arith.UInt64} other
7174
* @return {number}
75+
* @export
7276
*/
7377
jspb.arith.UInt64.prototype.cmp = function(other) {
7478
if (this.hi < other.hi || (this.hi == other.hi && this.lo < other.lo)) {
@@ -84,6 +88,7 @@ jspb.arith.UInt64.prototype.cmp = function(other) {
8488
/**
8589
* Right-shift this number by one bit.
8690
* @return {!jspb.arith.UInt64}
91+
* @export
8792
*/
8893
jspb.arith.UInt64.prototype.rightShift = function() {
8994
var hi = this.hi >>> 1;
@@ -95,6 +100,7 @@ jspb.arith.UInt64.prototype.rightShift = function() {
95100
/**
96101
* Left-shift this number by one bit.
97102
* @return {!jspb.arith.UInt64}
103+
* @export
98104
*/
99105
jspb.arith.UInt64.prototype.leftShift = function() {
100106
var lo = this.lo << 1;
@@ -106,6 +112,7 @@ jspb.arith.UInt64.prototype.leftShift = function() {
106112
/**
107113
* Test the MSB.
108114
* @return {boolean}
115+
* @export
109116
*/
110117
jspb.arith.UInt64.prototype.msb = function() {
111118
return !!(this.hi & 0x80000000);
@@ -115,6 +122,7 @@ jspb.arith.UInt64.prototype.msb = function() {
115122
/**
116123
* Test the LSB.
117124
* @return {boolean}
125+
* @export
118126
*/
119127
jspb.arith.UInt64.prototype.lsb = function() {
120128
return !!(this.lo & 1);
@@ -124,6 +132,7 @@ jspb.arith.UInt64.prototype.lsb = function() {
124132
/**
125133
* Test whether this number is zero.
126134
* @return {boolean}
135+
* @export
127136
*/
128137
jspb.arith.UInt64.prototype.zero = function() {
129138
return this.lo == 0 && this.hi == 0;
@@ -134,6 +143,7 @@ jspb.arith.UInt64.prototype.zero = function() {
134143
* Add two 64-bit numbers to produce a 64-bit number.
135144
* @param {!jspb.arith.UInt64} other
136145
* @return {!jspb.arith.UInt64}
146+
* @export
137147
*/
138148
jspb.arith.UInt64.prototype.add = function(other) {
139149
var lo = ((this.lo + other.lo) & 0xffffffff) >>> 0;
@@ -148,6 +158,7 @@ jspb.arith.UInt64.prototype.add = function(other) {
148158
* Subtract two 64-bit numbers to produce a 64-bit number.
149159
* @param {!jspb.arith.UInt64} other
150160
* @return {!jspb.arith.UInt64}
161+
* @export
151162
*/
152163
jspb.arith.UInt64.prototype.sub = function(other) {
153164
var lo = ((this.lo - other.lo) & 0xffffffff) >>> 0;
@@ -163,6 +174,7 @@ jspb.arith.UInt64.prototype.sub = function(other) {
163174
* @param {number} a The first integer: must be in [0, 2^32-1).
164175
* @param {number} b The second integer: must be in [0, 2^32-1).
165176
* @return {!jspb.arith.UInt64}
177+
* @export
166178
*/
167179
jspb.arith.UInt64.mul32x32 = function(a, b) {
168180
// Directly multiplying two 32-bit numbers may produce up to 64 bits of
@@ -204,6 +216,7 @@ jspb.arith.UInt64.mul32x32 = function(a, b) {
204216
* truncate the top 32 bits.
205217
* @param {number} a The multiplier.
206218
* @return {!jspb.arith.UInt64}
219+
* @export
207220
*/
208221
jspb.arith.UInt64.prototype.mul = function(a) {
209222
// Produce two parts: at bits 0-63, and 32-95.
@@ -223,6 +236,7 @@ jspb.arith.UInt64.prototype.mul = function(a) {
223236
* @param {number} _divisor
224237
* @return {Array<jspb.arith.UInt64>} array of [quotient, remainder],
225238
* unless divisor is 0, in which case an empty array is returned.
239+
* @export
226240
*/
227241
jspb.arith.UInt64.prototype.div = function(_divisor) {
228242
if (_divisor == 0) {
@@ -264,6 +278,7 @@ jspb.arith.UInt64.prototype.div = function(_divisor) {
264278
* Convert a 64-bit number to a string.
265279
* @return {string}
266280
* @override
281+
* @export
267282
*/
268283
jspb.arith.UInt64.prototype.toString = function() {
269284
var result = '';
@@ -285,6 +300,7 @@ jspb.arith.UInt64.prototype.toString = function() {
285300
* Parse a string into a 64-bit number. Returns `null` on a parse error.
286301
* @param {string} s
287302
* @return {?jspb.arith.UInt64}
303+
* @export
288304
*/
289305
jspb.arith.UInt64.fromString = function(s) {
290306
var result = new jspb.arith.UInt64(0, 0);
@@ -305,6 +321,7 @@ jspb.arith.UInt64.fromString = function(s) {
305321
/**
306322
* Make a copy of the uint64.
307323
* @return {!jspb.arith.UInt64}
324+
* @export
308325
*/
309326
jspb.arith.UInt64.prototype.clone = function() {
310327
return new jspb.arith.UInt64(this.lo, this.hi);
@@ -324,16 +341,19 @@ jspb.arith.UInt64.prototype.clone = function() {
324341
* @param {number} lo The low 32 bits.
325342
* @param {number} hi The high 32 bits.
326343
* @constructor
344+
* @export
327345
*/
328346
jspb.arith.Int64 = function(lo, hi) {
329347
/**
330348
* The low 32 bits.
331-
* @public {number}
349+
* @type {number}
350+
* @export
332351
*/
333352
this.lo = lo;
334353
/**
335354
* The high 32 bits.
336-
* @public {number}
355+
* @type {number}
356+
* @export
337357
*/
338358
this.hi = hi;
339359
};
@@ -343,6 +363,7 @@ jspb.arith.Int64 = function(lo, hi) {
343363
* Add two 64-bit numbers to produce a 64-bit number.
344364
* @param {!jspb.arith.Int64} other
345365
* @return {!jspb.arith.Int64}
366+
* @export
346367
*/
347368
jspb.arith.Int64.prototype.add = function(other) {
348369
var lo = ((this.lo + other.lo) & 0xffffffff) >>> 0;
@@ -357,6 +378,7 @@ jspb.arith.Int64.prototype.add = function(other) {
357378
* Subtract two 64-bit numbers to produce a 64-bit number.
358379
* @param {!jspb.arith.Int64} other
359380
* @return {!jspb.arith.Int64}
381+
* @export
360382
*/
361383
jspb.arith.Int64.prototype.sub = function(other) {
362384
var lo = ((this.lo - other.lo) & 0xffffffff) >>> 0;
@@ -370,6 +392,7 @@ jspb.arith.Int64.prototype.sub = function(other) {
370392
/**
371393
* Make a copy of the int64.
372394
* @return {!jspb.arith.Int64}
395+
* @export
373396
*/
374397
jspb.arith.Int64.prototype.clone = function() {
375398
return new jspb.arith.Int64(this.lo, this.hi);
@@ -380,6 +403,7 @@ jspb.arith.Int64.prototype.clone = function() {
380403
* Convert a 64-bit number to a string.
381404
* @return {string}
382405
* @override
406+
* @export
383407
*/
384408
jspb.arith.Int64.prototype.toString = function() {
385409
// If the number is negative, find its twos-complement inverse.
@@ -396,6 +420,7 @@ jspb.arith.Int64.prototype.toString = function() {
396420
* Parse a string into a 64-bit number. Returns `null` on a parse error.
397421
* @param {string} s
398422
* @return {?jspb.arith.Int64}
423+
* @export
399424
*/
400425
jspb.arith.Int64.fromString = function(s) {
401426
var hasNegative = (s.length > 0 && s[0] == '-');

0 commit comments

Comments
 (0)