diff --git a/src/core/murmurhash3.js b/src/core/murmurhash3.js index c2e716330..929dd3ab7 100644 --- a/src/core/murmurhash3.js +++ b/src/core/murmurhash3.js @@ -19,6 +19,7 @@ * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz. */ +/* globals Uint32ArrayView */ 'use strict'; @@ -35,6 +36,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) { MurmurHash3_64.prototype = { update: function MurmurHash3_64_update(input) { + var useUint32ArrayView = false; if (typeof input == 'string') { var data = new Uint8Array(input.length * 2); var length = 0; @@ -48,18 +50,25 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) { data[length++] = code & 0xff; } } - } else { - if (!(input instanceof Uint8Array)) { - throw new Error('Wrong data format in MurmurHash3_64_update. ' + - 'Input must be a string or Uint8Array'); - } + } else if (input instanceof Uint8Array) { data = input; length = data.length; + } else if (typeof input === 'object' && ('length' in input)) { + // processing regular arrays as well, e.g. for IE9 + data = input; + length = data.length; + useUint32ArrayView = true; + } else { + throw new Error('Wrong data format in MurmurHash3_64_update. ' + + 'Input must be a string or array.'); } var blockCounts = length >> 2; var tailLength = length - blockCounts * 4; - var dataUint32 = new Uint32Array(data.buffer, 0, blockCounts); + // we don't care about endianness here + var dataUint32 = useUint32ArrayView ? + new Uint32ArrayView(data, blockCounts) : + new Uint32Array(data.buffer, 0, blockCounts); var k1 = 0; var k2 = 0; var h1 = this.h1; diff --git a/src/shared/util.js b/src/shared/util.js index efa578e11..01e7fbff3 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -465,10 +465,10 @@ Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', { var Uint32ArrayView = (function Uint32ArrayViewClosure() { - function Uint32ArrayView(buffer) { + function Uint32ArrayView(buffer, length) { this.buffer = buffer; this.byteLength = buffer.length; - this.length = (this.byteLength >> 2); + this.length = length === undefined ? (this.byteLength >> 2) : length; ensureUint32ArrayViewProps(this.length); } Uint32ArrayView.prototype = Object.create(null);