aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJisi Liu <jisi.liu@gmail.com>2017-07-18 16:26:16 -0700
committerJisi Liu <jisi.liu@gmail.com>2017-07-18 16:26:16 -0700
commit3af881c7e2db0553207876acbdb91c6e77974e44 (patch)
tree35e2a96cce802d4235bd29afa396e28ead892fa2 /js
parent86975301f1876ce1934612777b8ca6c76520f5cc (diff)
parent942a29cecd36f2a4b22fdd2179635cd548e6bd27 (diff)
downloadprotobuf-3af881c7e2db0553207876acbdb91c6e77974e44.tar.gz
protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.tar.bz2
protobuf-3af881c7e2db0553207876acbdb91c6e77974e44.zip
Merge master into 3.4.x
Diffstat (limited to 'js')
-rw-r--r--js/README.md10
-rw-r--r--js/binary/decoder.js2
-rw-r--r--js/binary/utils.js2
-rw-r--r--js/binary/utils_test.js24
4 files changed, 23 insertions, 15 deletions
diff --git a/js/README.md b/js/README.md
index f4184621..24386dc7 100644
--- a/js/README.md
+++ b/js/README.md
@@ -19,7 +19,9 @@ resolve imports at compile time.
To use Protocol Buffers with JavaScript, you need two main components:
1. The protobuf runtime library. You can install this with
- `npm install google-protobuf`, or use the files in this directory.
+ `npm install google-protobuf`, or use the files in this directory.
+ If npm is not being used, as of 3.3.0, the files needed are located in binary subdirectory;
+ arith.js, constants.js, decoder.js, encoder.js, map.js, message.js, reader.js, utils.js, writer.js
2. The Protocol Compiler `protoc`. This translates `.proto` files
into `.js` files. The compiler is not currently available via
npm, but you can download a pre-built binary
@@ -93,6 +95,12 @@ statements like:
var message = proto.my.package.MyMessage();
+If unfamiliar with Closure or it's compiler, consider reviewing Closure documentation
+https://developers.google.com/closure/library/docs/tutorial
+https://developers.google.com/closure/library/docs/closurebuilder
+https://developers.google.com/closure/library/docs/depswriter
+At a high level, closurebuilder.py can walk dependencies, and compile your code, and all dependencies for Protobuf into a single .js file. Using depsbuilder.py to generate a dependency file can also be considered for non-production dev environments.
+
CommonJS imports
----------------
diff --git a/js/binary/decoder.js b/js/binary/decoder.js
index ad9cb01b..6db28e7c 100644
--- a/js/binary/decoder.js
+++ b/js/binary/decoder.js
@@ -994,7 +994,7 @@ jspb.BinaryDecoder.prototype.readString = function(length) {
codeUnits.length = 0;
}
}
- result += String.fromCharCode.apply(null, codeUnits);
+ result += goog.crypt.byteArrayToString(codeUnits);
this.cursor_ = cursor;
return result;
};
diff --git a/js/binary/utils.js b/js/binary/utils.js
index 25131b06..58f11b54 100644
--- a/js/binary/utils.js
+++ b/js/binary/utils.js
@@ -613,7 +613,7 @@ jspb.utils.decimalStringToHash64 = function(dec) {
muladd(1, 1);
}
- return String.fromCharCode.apply(null, resultBytes);
+ return goog.crypt.byteArrayToString(resultBytes);
};
diff --git a/js/binary/utils_test.js b/js/binary/utils_test.js
index d27e5ea2..0a2f4f0a 100644
--- a/js/binary/utils_test.js
+++ b/js/binary/utils_test.js
@@ -205,31 +205,31 @@ describe('binaryUtilsTest', function() {
var convert = jspb.utils.decimalStringToHash64;
result = convert('0');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result);
result = convert('-1');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
result = convert('18446744073709551615');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
result = convert('9223372036854775808');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result);
result = convert('-9223372036854775808');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80]), result);
result = convert('123456789123456789');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0x15, 0x5F, 0xD0, 0xAC, 0x4B, 0x9B, 0xB6, 0x01]), result);
result = convert('-123456789123456789');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0xEB, 0xA0, 0x2F, 0x53, 0xB4, 0x64, 0x49, 0xFE]), result);
});
@@ -259,21 +259,21 @@ describe('binaryUtilsTest', function() {
var convert = jspb.utils.hexStringToHash64;
result = convert('0x0000000000000000');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]), result);
result = convert('0xffffffffffffffff');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]), result);
// Hex string is big-endian, hash string is little-endian.
result = convert('0x123456789ABCDEF0');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]), result);
// Capitalization should not matter.
result = convert('0x0000abcdefABCDEF');
- assertEquals(String.fromCharCode.apply(null,
+ assertEquals(goog.crypt.byteArrayToString(
[0xEF, 0xCD, 0xAB, 0xEF, 0xCD, 0xAB, 0x00, 0x00]), result);
});
@@ -643,7 +643,7 @@ describe('binaryUtilsTest', function() {
var sourceBytes = new Uint8Array(sourceData);
var sourceBuffer = sourceBytes.buffer;
var sourceBase64 = goog.crypt.base64.encodeByteArray(sourceData);
- var sourceString = String.fromCharCode.apply(null, sourceData);
+ var sourceString = goog.crypt.byteArrayToString(sourceData);
function check(result) {
assertEquals(Uint8Array, result.constructor);