fix(copy): fix handling of typed subarrays
Previously, it would return a copy of the whole original typed array, not its slice. Now, the `byteOffset` and `length` are also preserved. Fixes #14842 Closes #14845
This commit is contained in:
committed by
Georgios Kalpakas
parent
6a219ad8db
commit
6280ec89e3
+1
-1
@@ -908,7 +908,7 @@ function copy(source, destination) {
|
||||
case '[object Uint8ClampedArray]':
|
||||
case '[object Uint16Array]':
|
||||
case '[object Uint32Array]':
|
||||
return new source.constructor(copyElement(source.buffer));
|
||||
return new source.constructor(copyElement(source.buffer), source.byteOffset, source.length);
|
||||
|
||||
case '[object ArrayBuffer]':
|
||||
//Support: IE10
|
||||
|
||||
@@ -240,6 +240,20 @@ describe('angular', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it("should handle Uint16Array subarray", function() {
|
||||
if (typeof Uint16Array !== 'undefined') {
|
||||
var arr = new Uint16Array(4);
|
||||
arr[1] = 1;
|
||||
var src = arr.subarray(1, 2);
|
||||
var dst = copy(src);
|
||||
expect(dst instanceof Uint16Array).toBeTruthy();
|
||||
expect(dst.length).toEqual(1);
|
||||
expect(dst[0]).toEqual(1);
|
||||
expect(dst).not.toBe(src);
|
||||
expect(dst.buffer).not.toBe(src.buffer);
|
||||
}
|
||||
});
|
||||
|
||||
it("should throw an exception if a Uint8Array is the destination", function() {
|
||||
if (typeof Uint8Array !== 'undefined') {
|
||||
var src = new Uint8Array();
|
||||
|
||||
Reference in New Issue
Block a user