Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1645924

Browse files
zhukovgkalpak
authored andcommitted
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
1 parent 6bee655 commit 1645924

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ function copy(source, destination) {
909909
case '[object Uint8ClampedArray]':
910910
case '[object Uint16Array]':
911911
case '[object Uint32Array]':
912-
return new source.constructor(copyElement(source.buffer));
912+
return new source.constructor(copyElement(source.buffer), source.byteOffset, source.length);
913913

914914
case '[object ArrayBuffer]':
915915
//Support: IE10

test/AngularSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,20 @@ describe('angular', function() {
240240
}
241241
});
242242

243+
it("should handle Uint16Array subarray", function() {
244+
if (typeof Uint16Array !== 'undefined') {
245+
var arr = new Uint16Array(4);
246+
arr[1] = 1;
247+
var src = arr.subarray(1, 2);
248+
var dst = copy(src);
249+
expect(dst instanceof Uint16Array).toBeTruthy();
250+
expect(dst.length).toEqual(1);
251+
expect(dst[0]).toEqual(1);
252+
expect(dst).not.toBe(src);
253+
expect(dst.buffer).not.toBe(src.buffer);
254+
}
255+
});
256+
243257
it("should throw an exception if a Uint8Array is the destination", function() {
244258
if (typeof Uint8Array !== 'undefined') {
245259
var src = new Uint8Array();

0 commit comments

Comments
 (0)