From f43c226c67ab64ee056615567e51f976c7637127 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 30 Nov 2011 14:06:04 -0500 Subject: fix(copy,equals): prevent browser crashes with Scope or Window Scope and Window instances are special and when copied can crash browser. For this reason it makes sense to compare them only by identity. --- test/AngularSpec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/AngularSpec.js') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index 53f62f00..1cb6af5e 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -57,6 +57,14 @@ describe('angular', function() { expect(copy(123)).toEqual(123); expect(copy([{key:null}])).toEqual([{key:null}]); }); + + it('should throw an exception if a Scope is being copied', inject(function($rootScope) { + expect(function() { copy($rootScope.$new()); }).toThrow("Can't copy Window or Scope"); + })); + + it('should throw an exception if a Window is being copied', function() { + expect(function() { copy(window); }).toThrow("Can't copy Window or Scope"); + }); }); describe('equals', function() { @@ -114,6 +122,22 @@ describe('angular', function() { it('should treat two NaNs as equal', function() { expect(equals(NaN, NaN)).toBe(true); }); + + it('should compare Scope instances only by identity', inject(function($rootScope) { + var scope1 = $rootScope.$new(), + scope2 = $rootScope.$new(); + + expect(equals(scope1, scope1)).toBe(true); + expect(equals(scope1, scope2)).toBe(false); + expect(equals($rootScope, scope1)).toBe(false); + expect(equals(undefined, scope1)).toBe(false); + })); + + it('should compare Window instances only by identity', function() { + expect(equals(window, window)).toBe(true); + expect(equals(window, window.parent)).toBe(false); + expect(equals(window, undefined)).toBe(false); + }); }); describe('size', function() { -- cgit v1.2.3