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

Commit

Permalink
fix(angular.copy): throw Error if source and destination are identical
Browse files Browse the repository at this point in the history
Closes #693
  • Loading branch information
dmanek authored and IgorMinar committed Jan 6, 2012
1 parent 0bf6110 commit 08029c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 08029c7

Please sign in to comment.