From aa052ce3996748f4f75e1722ce4a48cae99dc0a4 Mon Sep 17 00:00:00 2001 From: Dhruv Manek Date: Sun, 18 Dec 2011 18:33:25 -0800 Subject: [PATCH] fix(angular): fix to check if source and destination are equivalent in angular.copy Closes #693 --- src/Angular.js | 1 + test/AngularSpec.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/Angular.js b/src/Angular.js index 2a9fb5560edb..c14c6ea0928a 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -597,6 +597,7 @@ function copy(source, destination){ } } } else { + if (source === destination) throw Error("Can't copy equivalent objects or arrays"); if (isArray(source)) { while(destination.length) { destination.pop(); diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 1cb6af5e8796..709972407ac2 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -65,6 +65,14 @@ describe('angular', function() { it('should throw an exception if a Window is being copied', function() { expect(function() { copy(window); }).toThrow("Can't copy Window or Scope"); }); + + it('should throw an exception when source and destination are equivalent', function() { + var src, dst; + src = dst = {key: 'value'}; + expect(function() { copy(src, dst); }).toThrow("Can't copy equivalent objects or arrays"); + src = dst = [2, 4]; + expect(function() { copy(src, dst); }).toThrow("Can't copy equivalent objects or arrays"); + }); }); describe('equals', function() {