Skip to content

Commit 77286bd

Browse files
committed
Add polyfills for Brotli
1 parent 4ef6bbd commit 77286bd

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ $(DIST_DIR)/lib/libexpat.a: build/lib/expat/configured
7070
emmake make install
7171

7272
build/lib/brotli/js/decode.js: build/lib/brotli/configured
73+
build/lib/brotli/js/polyfill.js: build/lib/brotli/configured
7374
build/lib/brotli/configured: lib/brotli $(wildcard $(BASE_DIR)build/patches/brotli/*.patch)
7475
rm -rf build/lib/brotli
7576
cp -r lib/brotli build/lib/brotli
@@ -325,10 +326,11 @@ dist/js/subtitles-octopus-worker.js: src/subtitles-octopus-worker.bc src/pre-wor
325326
-s WASM=1 \
326327
$(EMCC_COMMON_ARGS)
327328

328-
dist/js/subtitles-octopus-worker-legacy.js: src/subtitles-octopus-worker.bc src/polyfill.js src/pre-worker.js src/SubOctpInterface.js src/post-worker.js build/lib/brotli/js/decode.js
329+
dist/js/subtitles-octopus-worker-legacy.js: src/subtitles-octopus-worker.bc src/polyfill.js src/pre-worker.js src/SubOctpInterface.js src/post-worker.js build/lib/brotli/js/decode.js build/lib/brotli/js/polyfill.js
329330
mkdir -p dist/js
330331
emcc src/subtitles-octopus-worker.bc $(OCTP_DEPS) \
331332
--pre-js src/polyfill.js \
333+
--pre-js build/lib/brotli/js/polyfill.js \
332334
--pre-js src/pre-worker.js \
333335
--pre-js build/lib/brotli/js/decode.js \
334336
--post-js src/SubOctpInterface.js \

src/polyfill.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ if (!String.prototype.includes) {
2222
};
2323
}
2424

25+
if (!ArrayBuffer.isView) {
26+
var typedArrays = [
27+
Int8Array,
28+
Uint8Array,
29+
Uint8ClampedArray,
30+
Int16Array,
31+
Uint16Array,
32+
Int32Array,
33+
Uint32Array,
34+
Float32Array,
35+
Float64Array
36+
];
37+
38+
ArrayBuffer.isView = function (obj) {
39+
return obj && obj.constructor && typedArrays.indexOf(obj.constructor) !== -1;
40+
};
41+
}
42+
43+
if (!Int8Array.prototype.slice) {
44+
Object.defineProperty(Int8Array.prototype, 'slice', {
45+
value: function (begin, end)
46+
{
47+
return new Int8Array(this.subarray(begin, end));
48+
}
49+
});
50+
}
51+
2552
if (!Uint8Array.prototype.slice) {
2653
Object.defineProperty(Uint8Array.prototype, 'slice', {
2754
value: function (begin, end)

0 commit comments

Comments
 (0)