Skip to content

Commit 576870c

Browse files
committed
Ensure that printDebugs works in Chrome, fixes #7
1 parent dd75744 commit 576870c

12 files changed

+15241
-86
lines changed

ByteBuffer.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @license ByteBuffer.js (c) 2013 Daniel Wirtz <[email protected]>
1919
* Released under the Apache License, Version 2.0
2020
* see: https://github.com/dcodeIO/ByteBuffer.js for details
21-
*/
21+
*/ //
2222
(function(global) {
2323
"use strict";
2424

@@ -29,7 +29,7 @@
2929
/**
3030
* @param {Function=} Long
3131
* @returns {Function}
32-
* @private
32+
* @inner
3333
*/
3434
function loadByteBuffer(Long) {
3535

@@ -45,12 +45,11 @@
4545

4646
/**
4747
* Constructs a new ByteBuffer.
48-
* @exports ByteBuffer
4948
* @class A full-featured ByteBuffer implementation in JavaScript using typed arrays.
49+
* @exports ByteBuffer
5050
* @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}.
5151
* @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big
5252
* endian.
53-
* @constructor
5453
* @expose
5554
*/
5655
var ByteBuffer = function(capacity, littleEndian) {
@@ -111,7 +110,7 @@
111110
* @const
112111
* @expose
113112
*/
114-
ByteBuffer.VERSION = "2.0.1";
113+
ByteBuffer.VERSION = "2.0.2";
115114

116115
/**
117116
* Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required.
@@ -138,13 +137,13 @@
138137
ByteBuffer.BIG_ENDIAN = false;
139138

140139
/**
141-
* Long class for int64 support. May be undefined if the Long class has not been loaded and int64 support is
140+
* Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is
142141
* not available.
143-
* @type {Long|undefined}
142+
* @type {?Long}
144143
* @const
145144
* @expose
146145
*/
147-
ByteBuffer.Long = Long;
146+
ByteBuffer.Long = Long || null;
148147

149148
/**
150149
* Allocates a new ByteBuffer.
@@ -162,7 +161,7 @@
162161
* Converts a node.js <= 0.8 Buffer to an ArrayBuffer.
163162
* @param {!Buffer} b Buffer to convert
164163
* @returns {?ArrayBuffer} Converted buffer
165-
* @private
164+
* @inner
166165
*/
167166
function b2ab(b) {
168167
var ab = new ArrayBuffer(b.length),
@@ -1118,7 +1117,7 @@
11181117
/**
11191118
* Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf.
11201119
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted.
1121-
* @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read
1120+
* @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read
11221121
* and the actual number of bytes read.
11231122
* @throws {Error} If it's not a valid varint
11241123
* @expose
@@ -1143,28 +1142,28 @@
11431142
/**
11441143
* @type {number}
11451144
* @const
1146-
* @private
1145+
* @inner
11471146
*/
11481147
var TWO_PWR_7_DBL = 1 << 7;
11491148

11501149
/**
11511150
* @type {number}
11521151
* @const
1153-
* @private
1152+
* @inner
11541153
*/
11551154
var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL;
11561155

11571156
/**
11581157
* @type {number}
11591158
* @const
1160-
* @private
1159+
* @inner
11611160
*/
11621161
var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL;
11631162

11641163
/**
11651164
* @type {number}
11661165
* @const
1167-
* @private
1166+
* @inner
11681167
*/
11691168
var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL;
11701169

@@ -1265,7 +1264,7 @@
12651264
/**
12661265
* Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf.
12671266
* @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted.
1268-
* @returns {Long|{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read.
1267+
* @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read.
12691268
* @throws {Error} If it's not a valid varint
12701269
* @expose
12711270
*/
@@ -1593,11 +1592,12 @@
15931592

15941593
/**
15951594
* Base64 alphabet.
1596-
* @type{string}
1595+
* @type {string}
15971596
* @const
1598-
* @private
1599-
*/ // FIXME: CC inlines this, which is not so smart regarding script size. Any ideas?
1597+
* @inner
1598+
*/
16001599
var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
1600+
// FIXME: CC inlines this, which is not so smart regarding script size. Any ideas?
16011601

16021602
/**
16031603
* Encodes a ByteBuffer's contents to a base64 string.
@@ -2036,7 +2036,7 @@
20362036
* @expose
20372037
*/
20382038
ByteBuffer.prototype.printDebug = function(out) {
2039-
if (typeof out !== 'function') out = console.log;
2039+
if (typeof out !== 'function') out = console.log.bind(console);
20402040
out(
20412041
(this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+
20422042
"-------------------------------------------------------------------\n"+

ByteBuffer.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ByteBuffer.min.map

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

ByteBuffer.noexpose.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @license ByteBuffer.js (c) 2013 Daniel Wirtz <[email protected]>
1919
* Released under the Apache License, Version 2.0
2020
* see: https://github.com/dcodeIO/ByteBuffer.js for details
21-
*/
21+
*/ //
2222
(function(global) {
2323
"use strict";
2424

@@ -29,7 +29,7 @@
2929
/**
3030
* @param {Function=} Long
3131
* @returns {Function}
32-
* @private
32+
* @inner
3333
*/
3434
function loadByteBuffer(Long) {
3535

@@ -45,12 +45,11 @@
4545

4646
/**
4747
* Constructs a new ByteBuffer.
48-
* @exports ByteBuffer
4948
* @class A full-featured ByteBuffer implementation in JavaScript using typed arrays.
49+
* @exports ByteBuffer
5050
* @param {number=} capacity Initial capacity. Defaults to {@link ByteBuffer.DEFAULT_CAPACITY}.
5151
* @param {boolean=} littleEndian `true` to use little endian multi byte values, defaults to `false` for big
5252
* endian.
53-
* @constructor
5453
*/
5554
var ByteBuffer = function(capacity, littleEndian) {
5655

@@ -103,7 +102,7 @@
103102
* @type {string}
104103
* @const
105104
*/
106-
ByteBuffer.VERSION = "2.0.1";
105+
ByteBuffer.VERSION = "2.0.2";
107106

108107
/**
109108
* Default buffer capacity of `16`. The ByteBuffer will be automatically resized by a factor of 2 if required.
@@ -127,12 +126,12 @@
127126
ByteBuffer.BIG_ENDIAN = false;
128127

129128
/**
130-
* Long class for int64 support. May be undefined if the Long class has not been loaded and int64 support is
129+
* Long class for int64 support. May be `null` if the Long class has not been loaded and int64 support is
131130
* not available.
132-
* @type {Long|undefined}
131+
* @type {?Long}
133132
* @const
134133
*/
135-
ByteBuffer.Long = Long;
134+
ByteBuffer.Long = Long || null;
136135

137136
/**
138137
* Allocates a new ByteBuffer.
@@ -149,7 +148,7 @@
149148
* Converts a node.js <= 0.8 Buffer to an ArrayBuffer.
150149
* @param {!Buffer} b Buffer to convert
151150
* @returns {?ArrayBuffer} Converted buffer
152-
* @private
151+
* @inner
153152
*/
154153
function b2ab(b) {
155154
var ab = new ArrayBuffer(b.length),
@@ -1051,7 +1050,7 @@
10511050
/**
10521051
* Reads a zigzag encoded 32bit base 128 variable-length integer as used in protobuf.
10531052
* @param {number=} offset Offset to read from. Will use and advance {@link ByteBuffer#offset} if omitted.
1054-
* @returns {number|{value: number, length: number}} The value read if offset is omitted, else the value read
1053+
* @returns {number|!{value: number, length: number}} The value read if offset is omitted, else the value read
10551054
* and the actual number of bytes read.
10561055
* @throws {Error} If it's not a valid varint
10571056
*/
@@ -1074,28 +1073,28 @@
10741073
/**
10751074
* @type {number}
10761075
* @const
1077-
* @private
1076+
* @inner
10781077
*/
10791078
var TWO_PWR_7_DBL = 1 << 7;
10801079

10811080
/**
10821081
* @type {number}
10831082
* @const
1084-
* @private
1083+
* @inner
10851084
*/
10861085
var TWO_PWR_14_DBL = TWO_PWR_7_DBL * TWO_PWR_7_DBL;
10871086

10881087
/**
10891088
* @type {number}
10901089
* @const
1091-
* @private
1090+
* @inner
10921091
*/
10931092
var TWO_PWR_21_DBL = TWO_PWR_7_DBL * TWO_PWR_14_DBL;
10941093

10951094
/**
10961095
* @type {number}
10971096
* @const
1098-
* @private
1097+
* @inner
10991098
*/
11001099
var TWO_PWR_28_DBL = TWO_PWR_14_DBL * TWO_PWR_14_DBL;
11011100

@@ -1193,7 +1192,7 @@
11931192
/**
11941193
* Reads a zigzag encoded 64bit base 128 variable-length integer as used in protobuf.
11951194
* @param {number=} offset Offset to read from. Defaults to {@link ByteBuffer#offset} which will be modified only if omitted.
1196-
* @returns {Long|{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read.
1195+
* @returns {Long|!{value: Long, length: number}} The value read if offset is omitted, else the value read and the actual number of bytes read.
11971196
* @throws {Error} If it's not a valid varint
11981197
*/
11991198
ByteBuffer.prototype.readZigZagVarint64 = function(offset) {
@@ -1507,11 +1506,12 @@
15071506

15081507
/**
15091508
* Base64 alphabet.
1510-
* @type{string}
1509+
* @type {string}
15111510
* @const
1512-
* @private
1513-
*/ // FIXME: CC inlines this, which is not so smart regarding script size. Any ideas?
1511+
* @inner
1512+
*/
15141513
var B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
1514+
// FIXME: CC inlines this, which is not so smart regarding script size. Any ideas?
15151515

15161516
/**
15171517
* Encodes a ByteBuffer's contents to a base64 string.
@@ -1934,7 +1934,7 @@
19341934
* @param {function(string)=} out Output function to call, defaults to console.log
19351935
*/
19361936
ByteBuffer.prototype.printDebug = function(out) {
1937-
if (typeof out !== 'function') out = console.log;
1937+
if (typeof out !== 'function') out = console.log.bind(console);
19381938
out(
19391939
(this.array != null ? "ByteBuffer(offset="+this.offset+",markedOffset="+this.markedOffset+",length="+this.length+",capacity="+this.array.byteLength+")" : "ByteBuffer(DESTROYED)")+"\n"+
19401940
"-------------------------------------------------------------------\n"+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ What can it do?
1919
* Relative and absolute zero-copy operations
2020
* Manual and automatic resizing (efficiently doubles capacity)
2121
* Chaining of all operations that do not return a specific value
22-
* Slicing, appending, prepending, flip, reset, etc.
22+
* Slicing, appending, prepending, reversing, flip, mark, reset, etc.
2323

2424
And much more...
2525

0 commit comments

Comments
 (0)