aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorEugene Kliuchnikov <eustas@google.com>2017-10-09 17:07:34 +0200
committerGitHub <noreply@github.com>2017-10-09 17:07:34 +0200
commit42d78807bb56a336ff6b30d8e9dc14cd1cf8f105 (patch)
tree171473e64230d3b5dda796ec897b6563d0242b91 /js
parent4f8cd4c0f4443d51a9603790a445b06c073b7a4d (diff)
downloadbrotli-42d78807bb56a336ff6b30d8e9dc14cd1cf8f105.zip
brotli-42d78807bb56a336ff6b30d8e9dc14cd1cf8f105.tar.gz
brotli-42d78807bb56a336ff6b30d8e9dc14cd1cf8f105.tar.bz2
Improve Bazel/JNI portability (#611)
* Improve Bazel/JNI portability * Update go and closure bazel addons
Diffstat (limited to 'js')
-rwxr-xr-xjs/BUILD14
-rwxr-xr-xjs/decode.js65
-rwxr-xr-xjs/decode_test.js6
3 files changed, 48 insertions, 37 deletions
diff --git a/js/BUILD b/js/BUILD
index 67088b1..0400c96 100755
--- a/js/BUILD
+++ b/js/BUILD
@@ -10,16 +10,21 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
closure_js_library(
name = "polyfill",
srcs = ["polyfill.js"],
- language = "ECMASCRIPT6_STRICT",
- suppress = ["JSC_MISSING_JSDOC"],
+ suppress = [
+ "JSC_MISSING_JSDOC",
+ "JSC_TYPE_MISMATCH",
+ "JSC_UNKNOWN_EXPR_TYPE",
+ ],
)
# Do NOT use this artifact; it is for test purposes only.
closure_js_library(
name = "decode",
srcs = ["decode.js"],
- language = "ECMASCRIPT6_STRICT",
- suppress = ["JSC_USELESS_BLOCK"],
+ suppress = [
+ "JSC_DUP_VAR_DECLARATION",
+ "JSC_USELESS_BLOCK",
+ ],
deps = [":polyfill"],
)
@@ -28,7 +33,6 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_test")
closure_js_test(
name = "all_tests",
srcs = ["decode_test.js"],
- language = "ECMASCRIPT6_STRICT",
deps = [
":decode",
":polyfill",
diff --git a/js/decode.js b/js/decode.js
index b786d66..864bc63 100755
--- a/js/decode.js
+++ b/js/decode.js
@@ -4,8 +4,8 @@
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
-/** @export */
-var BrotliDecode = (function() {
+/** @return {function(!Int8Array):!Int8Array} */
+function BrotliDecodeClosure() {
"use strict";
/** @type {!Int8Array} */
@@ -61,7 +61,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
* @param {!InputStream} input
- * @return {!void}
+ * @return {void}
*/
function initState(s, input) {
if (s.runningState != 0) {
@@ -80,7 +80,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function close(s) {
if (s.runningState == 0) {
@@ -116,7 +116,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function decodeMetaBlockLength(s) {
if (s.bitOffset >= 16) {
@@ -226,7 +226,7 @@ var BrotliDecode = (function() {
/**
* @param {!Int32Array} v
* @param {!number} index
- * @return {!void}
+ * @return {void}
*/
function moveToFront(v, index) {
var /** !number */ value = v[index];
@@ -238,7 +238,7 @@ var BrotliDecode = (function() {
/**
* @param {!Int8Array} v
* @param {!number} vLen
- * @return {!void}
+ * @return {void}
*/
function inverseMoveToFrontTransform(v, vLen) {
var /** !Int32Array */ mtf = new Int32Array(256);
@@ -258,7 +258,7 @@ var BrotliDecode = (function() {
* @param {!number} numSymbols
* @param {!Int32Array} codeLengths
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function readHuffmanCodeLengths(codeLengthCodeLengths, numSymbols, codeLengths, s) {
var /** !number */ symbol = 0;
@@ -343,7 +343,7 @@ var BrotliDecode = (function() {
* @param {!Int32Array} table
* @param {!number} offset
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function readHuffmanCode(alphabetSize, table, offset, s) {
var /** !number */ ok = 1;
@@ -517,7 +517,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function decodeLiteralBlockSwitch(s) {
s.literalBlockLength = decodeBlockTypeAndLength(s, 0, s.numLiteralBlockTypes);
@@ -531,7 +531,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function decodeCommandBlockSwitch(s) {
s.commandBlockLength = decodeBlockTypeAndLength(s, 1, s.numCommandBlockTypes);
@@ -539,7 +539,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function decodeDistanceBlockSwitch(s) {
s.distanceBlockLength = decodeBlockTypeAndLength(s, 2, s.numDistanceBlockTypes);
@@ -547,7 +547,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function maybeReallocateRingBuffer(s) {
var /** !number */ newSize = s.maxRingBufferSize;
@@ -573,7 +573,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function readNextMetablockHeader(s) {
if (s.inputEnd != 0) {
@@ -626,7 +626,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function readMetablockHuffmanCodesAndContextMaps(s) {
s.numLiteralBlockTypes = decodeVarLenUnsignedByte(s) + 1;
@@ -690,7 +690,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function copyUncompressedData(s) {
var /** !Int8Array */ ringBuffer = s.ringBuffer;
@@ -748,7 +748,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function decompress(s) {
if (s.runningState == 0) {
@@ -1044,7 +1044,7 @@ var BrotliDecode = (function() {
* @param {!Int32Array} transforms
* @param {!string} prefixSuffixSrc
* @param {!string} transformsSrc
- * @return {!void}
+ * @return {void}
*/
function unpackTransforms(prefixSuffix, prefixSuffixHeads, transforms, prefixSuffixSrc, transformsSrc) {
var /** !number */ n = prefixSuffixSrc.length;
@@ -1142,7 +1142,7 @@ var BrotliDecode = (function() {
* @param {!number} step
* @param {!number} end
* @param {!number} item
- * @return {!void}
+ * @return {void}
*/
function replicateValue(table, offset, step, end, item) {
do {
@@ -1174,7 +1174,7 @@ var BrotliDecode = (function() {
* @param {!number} rootBits
* @param {!Int32Array} codeLengths
* @param {!number} codeLengthsSize
- * @return {!void}
+ * @return {void}
*/
function buildHuffmanTable(rootTable, tableOffset, rootBits, codeLengths, codeLengthsSize) {
var /** !number */ key;
@@ -1232,7 +1232,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function doReadMoreInput(s) {
if (s.endOfStreamReached != 0) {
@@ -1261,7 +1261,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
* @param {!number} endOfStream
- * @return {!void}
+ * @return {void}
*/
function checkHealth(s, endOfStream) {
if (s.endOfStreamReached == 0) {
@@ -1298,7 +1298,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function initBitReader(s) {
s.byteBuffer = new Int8Array(4160);
@@ -1311,7 +1311,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function prepare(s) {
if (s.halfOffset > 2030) {
@@ -1325,7 +1325,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function reload(s) {
if (s.bitOffset == 32) {
@@ -1334,7 +1334,7 @@ var BrotliDecode = (function() {
}
/**
* @param {!State} s
- * @return {!void}
+ * @return {void}
*/
function jumpToByteBoundary(s) {
var /** !number */ padding = (32 - s.bitOffset) & 7;
@@ -1361,7 +1361,7 @@ var BrotliDecode = (function() {
* @param {!Int8Array} data
* @param {!number} offset
* @param {!number} length
- * @return {!void}
+ * @return {void}
*/
function copyBytes(s, data, offset, length) {
if ((s.bitOffset & 7) != 0) {
@@ -1412,7 +1412,7 @@ var BrotliDecode = (function() {
/**
* @param {!State} s
* @param {!number} byteLen
- * @return {!void}
+ * @return {void}
*/
function bytesToNibbles(s, byteLen) {
var /** !Int8Array */ byteBuffer = s.byteBuffer;
@@ -1428,7 +1428,7 @@ var BrotliDecode = (function() {
* @param {!Int32Array} lookup
* @param {!string} map
* @param {!string} rle
- * @return {!void}
+ * @return {void}
*/
function unpackLookupTable(lookup, map, rle) {
for (var /** !number */ i = 0; i < 256; ++i) {
@@ -1603,7 +1603,7 @@ var BrotliDecode = (function() {
* @param {!string} data0
* @param {!string} data1
* @param {!string} skipFlip
- * @return {!void}
+ * @return {void}
*/
function unpackDictionaryData(dictionary, data0, data1, skipFlip) {
var /** !number */ n0 = data0.length;
@@ -1708,6 +1708,9 @@ var BrotliDecode = (function() {
}
return decode;
-})();
+}
+
+/** @export */
+var BrotliDecode = BrotliDecodeClosure();
window["BrotliDecode"] = BrotliDecode;
diff --git a/js/decode_test.js b/js/decode_test.js
index 78ee18b..18ebe9d 100755
--- a/js/decode_test.js
+++ b/js/decode_test.js
@@ -2,7 +2,7 @@ goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
/**
- * @param {string} bytes
+ * @param {!Int8Array} bytes
* @return {string}
*/
function bytesToString(bytes) {
@@ -20,6 +20,7 @@ function testBaseDictWord() {
0x1b, 0x03, 0x00, 0x00, 0x00, 0x00, 0x80, 0xe3, 0xb4, 0x0d, 0x00, 0x00,
0x07, 0x5b, 0x26, 0x31, 0x40, 0x02, 0x00, 0xe0, 0x4e, 0x1b, 0x41, 0x02
]);
+ /** @type {!Int8Array} */
var output = BrotliDecode(input);
assertEquals("time", bytesToString(output));
}
@@ -30,6 +31,7 @@ function testBlockCountMessage() {
0x65, 0xe1, 0xfc, 0xfd, 0x22, 0x2c, 0xc4, 0x00, 0x00, 0x38, 0xd8, 0x32,
0x89, 0x01, 0x12, 0x00, 0x00, 0x77, 0xda, 0x04, 0x10, 0x42, 0x00, 0x00, 0x00
]);
+ /** @type {!Int8Array} */
var output = BrotliDecode(input);
assertEquals("aabbaaaaabab", bytesToString(output));
}
@@ -42,6 +44,7 @@ function testCompressedUncompressedShortCompressedSmallWindow() {
0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x4e, 0xdb, 0x00, 0x00, 0x70, 0xb0,
0x65, 0x12, 0x03, 0x24, 0x00, 0x00, 0xee, 0xb4, 0x11, 0x24, 0x00
]);
+ /** @type {!Int8Array} */
var output = BrotliDecode(input);
assertEquals(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
@@ -67,6 +70,7 @@ function testIntactDistanceRingBuffer0() {
0x07, 0x5b, 0x26, 0x31, 0x40, 0x02, 0x00, 0xe0, 0x4e, 0x1b, 0xa1, 0x80,
0x20, 0x00
]);
+ /** @type {!Int8Array} */
var output = BrotliDecode(input);
assertEquals("himselfself", bytesToString(output));
}