diff --git a/src/Angular.js b/src/Angular.js index 48c31ea1a0b9..e7b109da1d31 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1031,6 +1031,24 @@ function copy(source, destination, maxDepth) { case '[object Blob]': return new source.constructor([source], {type: source.type}); + case '[object Map]': + // If we're in this case we know the environment supports Map + /* eslint-disable no-undef */ + var copiedMap = new Map(); + /* eslint-enable */ + source.forEach(function(value, key) { + copiedMap.set(key, value); + }); + return copiedMap; + case '[object Set]': + // If we're in this case we know the environment supports Set + /* eslint-disable no-undef */ + var copiedSet = new Set(); + /* eslint-enable */ + source.forEach(function(value) { + copiedSet.add(value); + }); + return copiedSet; } if (isFunction(source.cloneNode)) { diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 9aaa2f5b8f83..0d7a78ff0eef 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -3,7 +3,7 @@ // Lots of typed array globals are used in this file and ESLint is // not smart enough to understand the `typeof !== 'undefined'` guards. /* globals Blob, Uint8ClampedArray, Uint16Array, Uint32Array, Int8Array, Int16Array, Int32Array, -Float32Array, Float64Array, */ +Float32Array, Float64Array, Map, Set */ describe('angular', function() { var element, document; @@ -249,6 +249,30 @@ describe('angular', function() { } }); + it('should handle Map objects', function() { + if (typeof Map !== 'undefined') { + var src = new Map(); + src.set('foo', 'bar'); + var dst = copy(src); + expect(dst).not.toBe(src); + expect(dst.size).toBe(1); + expect(dst instanceof Map).toBeTruthy(); + expect(dst.get('foo')).toBe('bar'); + } + }); + + it('should handle Set objects', function() { + if (typeof Set !== 'undefined') { + var src = new Set(); + src.add('foo'); + var dst = copy(src); + expect(dst).not.toBe(src); + expect(dst.size).toBe(1); + expect(dst instanceof Set).toBeTruthy(); + expect(dst.has('foo')).toBeTruthy(); + } + }); + it('should handle Uint16Array subarray', function() { if (typeof Uint16Array !== 'undefined') { var arr = new Uint16Array(4);