mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 10:15:37 +02:00
[api-major] Remove the TypedArray polyfills
This commit is contained in:
parent
b46443f0c1
commit
2dbd3f2603
4 changed files with 10 additions and 160 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue