@@ -1666,7 +1666,6 @@ describe('parser', function() {
16661666 $filterProvider = filterProvider ;
16671667 } ] ) ) ;
16681668
1669-
16701669 forEach ( [ true , false ] , function ( cspEnabled ) {
16711670 describe ( 'csp: ' + cspEnabled , function ( ) {
16721671
@@ -2372,6 +2371,64 @@ describe('parser', function() {
23722371 '$parse' , 'isecwindow' , 'Referencing the Window in Angular expressions is disallowed! ' +
23732372 'Expression: foo.w = 1' ) ;
23742373 } ) ) ;
2374+
2375+ they ( 'should propagate expensive checks when calling $prop' ,
2376+ [ 'foo.w && true' ,
2377+ '$eval("foo.w && true")' ,
2378+ 'this["$eval"]("foo.w && true")' ,
2379+ 'bar;$eval("foo.w && true")' ,
2380+ '$eval("foo.w && true");bar' ,
2381+ '$eval("foo.w && true", null, false)' ,
2382+ '$eval("foo");$eval("foo.w && true")' ,
2383+ '$eval("$eval(\\"foo.w && true\\")")' ,
2384+ '$eval("foo.e()")' ,
2385+ '$evalAsync("foo.w && true")' ,
2386+ 'this["$evalAsync"]("foo.w && true")' ,
2387+ 'bar;$evalAsync("foo.w && true")' ,
2388+ '$evalAsync("foo.w && true");bar' ,
2389+ '$evalAsync("foo.w && true", null, false)' ,
2390+ '$evalAsync("foo");$evalAsync("foo.w && true")' ,
2391+ '$evalAsync("$evalAsync(\\"foo.w && true\\")")' ,
2392+ '$evalAsync("foo.e()")' ,
2393+ '$evalAsync("$eval(\\"foo.w && true\\")")' ,
2394+ '$eval("$evalAsync(\\"foo.w && true\\")")' ,
2395+ '$watch("foo.w && true")' ,
2396+ '$watchCollection("foo.w && true", foo.f)' ,
2397+ '$watchGroup(["foo.w && true"])' ,
2398+ '$applyAsync("foo.w && true")' ] , function ( expression ) {
2399+ inject ( function ( $parse , $window ) {
2400+ scope . foo = {
2401+ w : $window ,
2402+ bar : 'bar' ,
2403+ e : function ( ) { scope . $eval ( "foo.w && true" ) ; } ,
2404+ f : function ( ) { }
2405+ } ;
2406+ expect ( $parse . $$runningExpensiveChecks ( ) ) . toEqual ( false ) ;
2407+ expect ( function ( ) {
2408+ scope . $eval ( $parse ( expression , null , true ) ) ;
2409+ scope . $digest ( ) ;
2410+ } ) . toThrowMinErr (
2411+ '$parse' , 'isecwindow' , 'Referencing the Window in Angular expressions is disallowed! ' +
2412+ 'Expression: foo.w && true' ) ;
2413+ expect ( $parse . $$runningExpensiveChecks ( ) ) . toEqual ( false ) ;
2414+ } ) ;
2415+ } ) ;
2416+
2417+ they ( 'should restore the state of $$runningExpensiveChecks when the expression $prop throws' ,
2418+ [ '$eval("foo.t()")' ,
2419+ '$evalAsync("foo.t()", {foo: foo})' ] , function ( expression ) {
2420+ inject ( function ( $parse , $window ) {
2421+ scope . foo = {
2422+ t : function ( ) { throw new Error ( ) ; }
2423+ } ;
2424+ expect ( $parse . $$runningExpensiveChecks ( ) ) . toEqual ( false ) ;
2425+ expect ( function ( ) {
2426+ scope . $eval ( $parse ( expression , null , true ) ) ;
2427+ scope . $digest ( ) ;
2428+ } ) . toThrow ( ) ;
2429+ expect ( $parse . $$runningExpensiveChecks ( ) ) . toEqual ( false ) ;
2430+ } ) ;
2431+ } ) ;
23752432 } ) ;
23762433 } ) ;
23772434
@@ -2932,6 +2989,25 @@ describe('parser', function() {
29322989 expect ( log ) . toEqual ( '' ) ;
29332990 } ) ) ;
29342991
2992+ it ( 'should work with expensive checks' , inject ( function ( $parse , $rootScope , log ) {
2993+ var fn = $parse ( '::foo' , null , true ) ;
2994+ $rootScope . $watch ( fn , function ( value , old ) { if ( value !== old ) log ( value ) ; } ) ;
2995+
2996+ $rootScope . $digest ( ) ;
2997+ expect ( $rootScope . $$watchers . length ) . toBe ( 1 ) ;
2998+
2999+ $rootScope . foo = 'bar' ;
3000+ $rootScope . $digest ( ) ;
3001+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
3002+ expect ( log ) . toEqual ( 'bar' ) ;
3003+ log . reset ( ) ;
3004+
3005+ $rootScope . foo = 'man' ;
3006+ $rootScope . $digest ( ) ;
3007+ expect ( $rootScope . $$watchers . length ) . toBe ( 0 ) ;
3008+ expect ( log ) . toEqual ( '' ) ;
3009+ } ) ) ;
3010+
29353011 it ( 'should have a stable value if at the end of a $digest it has a defined value' , inject ( function ( $parse , $rootScope , log ) {
29363012 var fn = $parse ( '::foo' ) ;
29373013 $rootScope . $watch ( fn , function ( value , old ) { if ( value !== old ) log ( value ) ; } ) ;
0 commit comments