diff --git a/src/Angular.js b/src/Angular.js index a5180712dfa1..3457420ca93a 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -901,7 +901,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 diff --git a/test/AngularSpec.js b/test/AngularSpec.js index ec334690019d..b7e4d821d743 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -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();