11'use strict' ;
22
33
4- function calcCacheSize ( ) {
5- var size = 0 ;
6- for ( var key in jqLite . cache ) { size ++ ; }
7- return size ;
8- }
9-
104describe ( '$compile' , function ( ) {
115 function isUnknownElement ( el ) {
126 return ! ! el . toString ( ) . match ( / U n k n o w n / ) ;
@@ -334,26 +328,26 @@ describe('$compile', function() {
334328 element = jqLite ( '<div><div></div></div>' ) ;
335329 $compile ( element . contents ( ) ) ( $rootScope ) ;
336330 element . empty ( ) ;
337- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
331+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
338332
339333 // Next with non-empty text nodes at the top level
340334 // (in this case the compiler will wrap them in a <span>)
341335 element = jqLite ( '<div>xxx</div>' ) ;
342336 $compile ( element . contents ( ) ) ( $rootScope ) ;
343337 element . empty ( ) ;
344- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
338+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
345339
346340 // Next with comment nodes at the top level
347341 element = jqLite ( '<div><!-- comment --></div>' ) ;
348342 $compile ( element . contents ( ) ) ( $rootScope ) ;
349343 element . empty ( ) ;
350- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
344+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
351345
352346 // Finally with empty text nodes at the top level
353347 element = jqLite ( '<div> \n<div></div> </div>' ) ;
354348 $compile ( element . contents ( ) ) ( $rootScope ) ;
355349 element . empty ( ) ;
356- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
350+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
357351 } ) ;
358352
359353
@@ -4242,29 +4236,23 @@ describe('$compile', function() {
42424236 return ;
42434237 }
42444238
4245- var calcCacheSize = function ( ) {
4246- var size = 0 ;
4247- forEach ( jqLite . cache , function ( item , key ) { size ++ ; } ) ;
4248- return size ;
4249- } ;
4250-
42514239 inject ( function ( $compile , $rootScope ) {
4252- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
4240+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
42534241
42544242 element = $compile ( '<div><div ng-repeat="x in xs" ng-if="x==1">{{x}}</div></div>' ) ( $rootScope ) ;
4255- expect ( calcCacheSize ( ) ) . toEqual ( 1 ) ;
4243+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 1 ) ;
42564244
42574245 $rootScope . $apply ( 'xs = [0,1]' ) ;
4258- expect ( calcCacheSize ( ) ) . toEqual ( 2 ) ;
4246+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 2 ) ;
42594247
42604248 $rootScope . $apply ( 'xs = [0]' ) ;
4261- expect ( calcCacheSize ( ) ) . toEqual ( 1 ) ;
4249+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 1 ) ;
42624250
42634251 $rootScope . $apply ( 'xs = []' ) ;
4264- expect ( calcCacheSize ( ) ) . toEqual ( 1 ) ;
4252+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 1 ) ;
42654253
42664254 element . remove ( ) ;
4267- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
4255+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
42684256 } ) ;
42694257 } ) ;
42704258
@@ -4274,32 +4262,28 @@ describe('$compile', function() {
42744262 // jQuery 2.x doesn't expose the cache storage.
42754263 return ;
42764264 }
4277- var calcCacheSize = function ( ) {
4278- var size = 0 ;
4279- forEach ( jqLite . cache , function ( item , key ) { size ++ ; } ) ;
4280- return size ;
4281- } ;
4265+
42824266 inject ( function ( $compile , $rootScope ) {
4283- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
4267+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
42844268 element = $compile ( '<div><div ng-repeat="x in xs" ng-if="val">{{x}}</div></div>' ) ( $rootScope ) ;
42854269
42864270 $rootScope . $apply ( 'xs = [0,1]' ) ;
42874271 // At this point we have a bunch of comment placeholders but no real transcluded elements
42884272 // So the cache only contains the root element's data
4289- expect ( calcCacheSize ( ) ) . toEqual ( 1 ) ;
4273+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 1 ) ;
42904274
42914275 $rootScope . $apply ( 'val = true' ) ;
42924276 // Now we have two concrete transcluded elements plus some comments so two more cache items
4293- expect ( calcCacheSize ( ) ) . toEqual ( 3 ) ;
4277+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 3 ) ;
42944278
42954279 $rootScope . $apply ( 'val = false' ) ;
42964280 // Once again we only have comments so no transcluded elements and the cache is back to just
42974281 // the root element
4298- expect ( calcCacheSize ( ) ) . toEqual ( 1 ) ;
4282+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 1 ) ;
42994283
43004284 element . remove ( ) ;
43014285 // Now we've even removed the root element along with its cache
4302- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
4286+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
43034287 } ) ;
43044288 } ) ;
43054289
@@ -4842,30 +4826,24 @@ describe('$compile', function() {
48424826
48434827
48444828 it ( 'should not leak memory with nested transclusion' , function ( ) {
4845- var calcCacheSize = function ( ) {
4846- var count = 0 ;
4847- for ( var k in jqLite . cache ) { ++ count ; }
4848- return count ;
4849- } ;
4850-
48514829 inject ( function ( $compile , $rootScope ) {
48524830 var size ;
48534831
4854- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
4832+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
48554833
48564834 element = jqLite ( '<div><ul><li ng-repeat="n in nums">{{n}} => <i ng-if="0 === n%2">Even</i><i ng-if="1 === n%2">Odd</i></li></ul></div>' ) ;
48574835 $compile ( element ) ( $rootScope . $new ( ) ) ;
48584836
48594837 $rootScope . nums = [ 0 , 1 , 2 ] ;
48604838 $rootScope . $apply ( ) ;
4861- size = calcCacheSize ( ) ;
4839+ size = jqLiteCacheSize ( ) ;
48624840
48634841 $rootScope . nums = [ 3 , 4 , 5 ] ;
48644842 $rootScope . $apply ( ) ;
4865- expect ( calcCacheSize ( ) ) . toEqual ( size ) ;
4843+ expect ( jqLiteCacheSize ( ) ) . toEqual ( size ) ;
48664844
48674845 element . remove ( ) ;
4868- expect ( calcCacheSize ( ) ) . toEqual ( 0 ) ;
4846+ expect ( jqLiteCacheSize ( ) ) . toEqual ( 0 ) ;
48694847 } ) ;
48704848 } ) ;
48714849 } ) ;
0 commit comments