Merge pull request #9094 from Snuffleupagus/rm-TypedArray-polyfills

[api-major] Remove the TypedArray polyfills
This commit is contained in:
Tim van der Meij 2017-11-02 22:15:44 +01:00 committed by GitHub
commit 6521d2fd94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 160 deletions

View File

@ -524,7 +524,7 @@ var IndexedCS = (function IndexedCSClosure() {
for (var i = 0; i < length; ++i) {
this.lookup[i] = lookup.charCodeAt(i);
}
} else if (lookup instanceof Uint8Array || lookup instanceof Array) {
} else if (lookup instanceof Uint8Array) {
this.lookup = lookup;
} else {
throw new FormatError(`Unrecognized lookup table: ${lookup}`);

View File

@ -17,6 +17,8 @@
* Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
*/
import { isArrayBuffer, isString } from '../shared/util';
var MurmurHash3_64 = (function MurmurHash3_64Closure(seed) {
// Workaround for missing math precision in JS.
var MASK_HIGH = 0xffff0000;
@ -30,11 +32,11 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure(seed) {
MurmurHash3_64.prototype = {
update: function MurmurHash3_64_update(input) {
var i;
if (typeof input === 'string') {
var data = new Uint8Array(input.length * 2);
var length = 0;
for (i = 0; i < input.length; i++) {
let data, length;
if (isString(input)) {
data = new Uint8Array(input.length * 2);
length = 0;
for (let i = 0, ii = input.length; i < ii; i++) {
var code = input.charCodeAt(i);
if (code <= 0xff) {
data[length++] = code;
@ -43,7 +45,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure(seed) {
data[length++] = code & 0xff;
}
}
} else if (typeof input === 'object' && ('byteLength' in input)) {
} else if (isArrayBuffer(input)) {
data = input;
length = data.byteLength;
} else {
@ -64,7 +66,7 @@ var MurmurHash3_64 = (function MurmurHash3_64Closure(seed) {
var C1_LOW = C1 & MASK_LOW;
var C2_LOW = C2 & MASK_LOW;
for (i = 0; i < blockCounts; i++) {
for (let i = 0; i < blockCounts; i++) {
if (i & 1) {
k1 = dataUint32[i];
k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);

View File

@ -243,7 +243,6 @@ PDFJS.LoopbackPort = LoopbackPort;
PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
PDFJS.PDFWorker = PDFWorker;
PDFJS.hasCanvasTypedArrays = true; // compatibility.js ensures this invariant
PDFJS.CustomStyle = CustomStyle;
PDFJS.LinkTarget = LinkTarget;
PDFJS.addLinkAttributes = addLinkAttributes;

View File

@ -46,157 +46,6 @@ if (typeof PDFJS === 'undefined') {
PDFJS.compatibilityChecked = true;
// Checking if the typed arrays are supported
// Support: iOS<6.0 (subarray), IE<10, Android<4.0
(function checkTypedArrayCompatibility() {
if (typeof Uint8ClampedArray === 'undefined') {
// Support: IE<11
globalScope.Uint8ClampedArray =
require('core-js/fn/typed/uint8-clamped-array');
}
if (typeof Uint8Array !== 'undefined') {
// Support: iOS<6.0
if (typeof Uint8Array.prototype.subarray === 'undefined') {
Uint8Array.prototype.subarray = function subarray(start, end) {
return new Uint8Array(this.slice(start, end));
};
Float32Array.prototype.subarray = function subarray(start, end) {
return new Float32Array(this.slice(start, end));
};
}
// Support: Android<4.1
if (typeof Float64Array === 'undefined') {
globalScope.Float64Array = Float32Array;
}
return;
}
function subarray(start, end) {
return new TypedArray(this.slice(start, end));
}
function setArrayOffset(array, offset) {
if (arguments.length < 2) {
offset = 0;
}
for (var i = 0, n = array.length; i < n; ++i, ++offset) {
this[offset] = array[i] & 0xFF;
}
}
function Uint32ArrayView(buffer, length) {
this.buffer = buffer;
this.byteLength = buffer.length;
this.length = length;
ensureUint32ArrayViewProps(this.length);
}
Uint32ArrayView.prototype = Object.create(null);
var uint32ArrayViewSetters = 0;
function createUint32ArrayProp(index) {
return {
get() {
var buffer = this.buffer, offset = index << 2;
return (buffer[offset] | (buffer[offset + 1] << 8) |
(buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
},
set(value) {
var buffer = this.buffer, offset = index << 2;
buffer[offset] = value & 255;
buffer[offset + 1] = (value >> 8) & 255;
buffer[offset + 2] = (value >> 16) & 255;
buffer[offset + 3] = (value >>> 24) & 255;
},
};
}
function ensureUint32ArrayViewProps(length) {
while (uint32ArrayViewSetters < length) {
Object.defineProperty(Uint32ArrayView.prototype,
uint32ArrayViewSetters,
createUint32ArrayProp(uint32ArrayViewSetters));
uint32ArrayViewSetters++;
}
}
function TypedArray(arg1) {
var result, i, n;
if (typeof arg1 === 'number') {
result = [];
for (i = 0; i < arg1; ++i) {
result[i] = 0;
}
} else if ('slice' in arg1) {
result = arg1.slice(0);
} else {
result = [];
for (i = 0, n = arg1.length; i < n; ++i) {
result[i] = arg1[i];
}
}
result.subarray = subarray;
result.buffer = result;
result.byteLength = result.length;
result.set = setArrayOffset;
if (typeof arg1 === 'object' && arg1.buffer) {
result.buffer = arg1.buffer;
}
return result;
}
globalScope.Uint8Array = TypedArray;
globalScope.Int8Array = TypedArray;
// we don't need support for set, byteLength for 32-bit array
// so we can use the TypedArray as well
globalScope.Int32Array = TypedArray;
globalScope.Uint16Array = TypedArray;
globalScope.Float32Array = TypedArray;
globalScope.Float64Array = TypedArray;
globalScope.Uint32Array = function () {
if (arguments.length === 3) {
// Building view for buffer, offset, and length
if (arguments[1] !== 0) {
throw new Error('offset !== 0 is not supported');
}
return new Uint32ArrayView(arguments[0], arguments[2]);
}
return TypedArray.apply(this, arguments);
};
})();
// window.CanvasPixelArray.buffer/.byteLength
// Support: IE9
(function canvasPixelArrayBuffer() {
if (!hasDOM || !window.CanvasPixelArray) {
return;
}
var cpaProto = window.CanvasPixelArray.prototype;
if ('buffer' in cpaProto) {
return;
}
// Trying to fake CanvasPixelArray as Uint8ClampedArray.
Object.defineProperty(cpaProto, 'buffer', {
get() {
return this;
},
enumerable: false,
configurable: true,
});
Object.defineProperty(cpaProto, 'byteLength', {
get() {
return this.length;
},
enumerable: false,
configurable: true,
});
})();
// URL = URL || webkitURL
// Support: Safari<7, Android 4.2+
(function normalizeURLObject() {