|
1 | 1 | "use strict";
|
2 | 2 | var util = exports;
|
3 | 3 |
|
4 |
| -util.asPromise = require("@protobufjs/aspromise"); |
5 |
| -util.base64 = require("@protobufjs/base64"); |
| 4 | +// used to return a Promise where callback is omitted |
| 5 | +util.asPromise = require("@protobufjs/aspromise"); |
| 6 | + |
| 7 | +// converts to / from base64 encoded strings |
| 8 | +util.base64 = require("@protobufjs/base64"); |
| 9 | + |
| 10 | +// base class of rpc.Service |
6 | 11 | util.EventEmitter = require("@protobufjs/eventemitter");
|
7 |
| -util.inquire = require("@protobufjs/inquire"); |
8 |
| -util.utf8 = require("@protobufjs/utf8"); |
9 |
| -util.pool = require("@protobufjs/pool"); |
10 | 12 |
|
11 |
| -util.LongBits = require("./longbits"); |
| 13 | +// requires modules optionally and hides the call from bundlers |
| 14 | +util.inquire = require("@protobufjs/inquire"); |
| 15 | + |
| 16 | +// convert to / from utf8 encoded strings |
| 17 | +util.utf8 = require("@protobufjs/utf8"); |
| 18 | + |
| 19 | +// provides a node-like buffer pool in the browser |
| 20 | +util.pool = require("@protobufjs/pool"); |
| 21 | + |
| 22 | +// utility to work with the low and high bits of a 64 bit value |
| 23 | +util.LongBits = require("./longbits"); |
12 | 24 |
|
13 | 25 | /**
|
14 | 26 | * An immuable empty array.
|
15 | 27 | * @memberof util
|
16 | 28 | * @type {Array.<*>}
|
17 | 29 | */
|
18 |
| -util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; |
| 30 | +util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes |
19 | 31 |
|
20 | 32 | /**
|
21 | 33 | * An immutable empty object.
|
22 | 34 | * @type {Object}
|
23 | 35 | */
|
24 |
| -util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; |
| 36 | +util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes |
25 | 37 |
|
26 | 38 | /**
|
27 | 39 | * Whether running within node or not.
|
@@ -73,8 +85,23 @@ util.Buffer = (function() {
|
73 | 85 | }
|
74 | 86 | })();
|
75 | 87 |
|
76 |
| -// Aliases where supported, otherwise polyfills |
| 88 | +/** |
| 89 | + * Internal alias of or polyfull for Buffer.from. |
| 90 | + * @type {?function} |
| 91 | + * @param {string|number[]} value Value |
| 92 | + * @param {string} [encoding] Encoding if value is a string |
| 93 | + * @returns {Uint8Array} |
| 94 | + * @private |
| 95 | + */ |
77 | 96 | util._Buffer_from = null;
|
| 97 | + |
| 98 | +/** |
| 99 | + * Internal alias of or polyfill for Buffer.allocUnsafe. |
| 100 | + * @type {?function} |
| 101 | + * @param {number} size Buffer size |
| 102 | + * @returns {Uint8Array} |
| 103 | + * @private |
| 104 | + */ |
78 | 105 | util._Buffer_allocUnsafe = null;
|
79 | 106 |
|
80 | 107 | /**
|
@@ -230,7 +257,7 @@ util._configure = function() {
|
230 | 257 | util._Buffer_from = util._Buffer_allocUnsafe = null;
|
231 | 258 | return;
|
232 | 259 | }
|
233 |
| - // node 4.2.0 - 4.4.7 support makes it impossible to just polyfill these. |
| 260 | + // because node 4.x buffers are incompatible & immutable |
234 | 261 | // see: https://github.com/dcodeIO/protobuf.js/pull/665
|
235 | 262 | util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
|
236 | 263 | /* istanbul ignore next */
|
|
0 commit comments