mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix(angular.copy): throw Error if source and destination are identical
Closes #693
This commit is contained in:
parent
0bf611087b
commit
08029c7b72
2 changed files with 9 additions and 0 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue