@@ -2438,19 +2438,6 @@ describe('Scope', function() {
2438
2438
} ) ) ;
2439
2439
2440
2440
2441
- // See issue https://github.com/angular/angular.js/issues/16135
2442
- it ( 'should deallocate the listener array entry' , inject ( function ( $rootScope ) {
2443
- var remove1 = $rootScope . $on ( 'abc' , noop ) ;
2444
- $rootScope . $on ( 'abc' , noop ) ;
2445
-
2446
- expect ( $rootScope . $$listeners [ 'abc' ] . length ) . toBe ( 2 ) ;
2447
-
2448
- remove1 ( ) ;
2449
-
2450
- expect ( $rootScope . $$listeners [ 'abc' ] . length ) . toBe ( 1 ) ;
2451
- } ) ) ;
2452
-
2453
-
2454
2441
it ( 'should call next listener after removing the current listener via its own handler' , inject ( function ( $rootScope ) {
2455
2442
var listener1 = jasmine . createSpy ( 'listener1' ) . and . callFake ( function ( ) { remove1 ( ) ; } ) ;
2456
2443
var remove1 = $rootScope . $on ( 'abc' , listener1 ) ;
@@ -2583,107 +2570,6 @@ describe('Scope', function() {
2583
2570
expect ( $rootScope . $$listenerCount ) . toEqual ( { abc : 1 } ) ;
2584
2571
expect ( child . $$listenerCount ) . toEqual ( { abc : 1 } ) ;
2585
2572
} ) ) ;
2586
-
2587
-
2588
- it ( 'should throw on recursive $broadcast' , inject ( function ( $rootScope ) {
2589
- $rootScope . $on ( 'e' , function ( ) { $rootScope . $broadcast ( 'e' ) ; } ) ;
2590
-
2591
- expect ( function ( ) { $rootScope . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2592
- expect ( function ( ) { $rootScope . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2593
- } ) ) ;
2594
-
2595
-
2596
- it ( 'should throw on nested recursive $broadcast' , inject ( function ( $rootScope ) {
2597
- $rootScope . $on ( 'e2' , function ( ) { $rootScope . $broadcast ( 'e' ) ; } ) ;
2598
- $rootScope . $on ( 'e' , function ( ) { $rootScope . $broadcast ( 'e2' ) ; } ) ;
2599
-
2600
- expect ( function ( ) { $rootScope . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2601
- expect ( function ( ) { $rootScope . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2602
- } ) ) ;
2603
-
2604
-
2605
- it ( 'should throw on recursive $emit' , inject ( function ( $rootScope ) {
2606
- $rootScope . $on ( 'e' , function ( ) { $rootScope . $emit ( 'e' ) ; } ) ;
2607
-
2608
- expect ( function ( ) { $rootScope . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2609
- expect ( function ( ) { $rootScope . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2610
- } ) ) ;
2611
-
2612
-
2613
- it ( 'should throw on nested recursive $emit' , inject ( function ( $rootScope ) {
2614
- $rootScope . $on ( 'e2' , function ( ) { $rootScope . $emit ( 'e' ) ; } ) ;
2615
- $rootScope . $on ( 'e' , function ( ) { $rootScope . $emit ( 'e2' ) ; } ) ;
2616
-
2617
- expect ( function ( ) { $rootScope . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2618
- expect ( function ( ) { $rootScope . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2619
- } ) ) ;
2620
-
2621
-
2622
- it ( 'should throw on recursive $broadcast on child listener' , inject ( function ( $rootScope ) {
2623
- var child = $rootScope . $new ( ) ;
2624
- child . $on ( 'e' , function ( ) { $rootScope . $broadcast ( 'e' ) ; } ) ;
2625
-
2626
- expect ( function ( ) { child . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (2)' ) ;
2627
- expect ( function ( ) { child . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (2)' ) ;
2628
- } ) ) ;
2629
-
2630
-
2631
- it ( 'should throw on nested recursive $broadcast on child listener' , inject ( function ( $rootScope ) {
2632
- var child = $rootScope . $new ( ) ;
2633
- child . $on ( 'e2' , function ( ) { $rootScope . $broadcast ( 'e' ) ; } ) ;
2634
- child . $on ( 'e' , function ( ) { $rootScope . $broadcast ( 'e2' ) ; } ) ;
2635
-
2636
- expect ( function ( ) { child . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (2)' ) ;
2637
- expect ( function ( ) { child . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (2)' ) ;
2638
- } ) ) ;
2639
-
2640
-
2641
- it ( 'should throw on recursive $emit parent listener' , inject ( function ( $rootScope ) {
2642
- var child = $rootScope . $new ( ) ;
2643
- $rootScope . $on ( 'e' , function ( ) { child . $emit ( 'e' ) ; } ) ;
2644
-
2645
- expect ( function ( ) { child . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2646
- expect ( function ( ) { $rootScope . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2647
- expect ( function ( ) { $rootScope . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2648
- } ) ) ;
2649
-
2650
-
2651
- it ( 'should throw on nested recursive $emit parent listener' , inject ( function ( $rootScope ) {
2652
- var child = $rootScope . $new ( ) ;
2653
- $rootScope . $on ( 'e2' , function ( ) { child . $emit ( 'e' ) ; } ) ;
2654
- $rootScope . $on ( 'e' , function ( ) { child . $emit ( 'e2' ) ; } ) ;
2655
-
2656
- expect ( function ( ) { child . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2657
- expect ( function ( ) { $rootScope . $emit ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2658
- expect ( function ( ) { $rootScope . $broadcast ( 'e' , 5 ) ; } ) . toThrowMinErr ( '$rootScope' , 'inevt' , 'e already $emit/$broadcast-ing on scope (1)' ) ;
2659
- } ) ) ;
2660
-
2661
-
2662
- it ( 'should clear recursive state of $broadcast if $exceptionHandler rethrows' , function ( ) {
2663
- module ( function ( $exceptionHandlerProvider ) {
2664
- $exceptionHandlerProvider . mode ( 'rethrow' ) ;
2665
- } ) ;
2666
- inject ( function ( $rootScope ) {
2667
- var throwingListener = jasmine . createSpy ( 'thrower' ) . and . callFake ( function ( ) {
2668
- throw new Error ( 'Listener Error!' ) ;
2669
- } ) ;
2670
- var secondListener = jasmine . createSpy ( 'second' ) ;
2671
-
2672
- $rootScope . $on ( 'e' , throwingListener ) ;
2673
- $rootScope . $on ( 'e' , secondListener ) ;
2674
-
2675
- expect ( function ( ) { $rootScope . $broadcast ( 'e' ) ; } ) . toThrowError ( 'Listener Error!' ) ;
2676
- expect ( throwingListener ) . toHaveBeenCalled ( ) ;
2677
- expect ( secondListener ) . not . toHaveBeenCalled ( ) ;
2678
-
2679
- throwingListener . calls . reset ( ) ;
2680
- secondListener . calls . reset ( ) ;
2681
-
2682
- expect ( function ( ) { $rootScope . $broadcast ( 'e' ) ; } ) . toThrowError ( 'Listener Error!' ) ;
2683
- expect ( throwingListener ) . toHaveBeenCalled ( ) ;
2684
- expect ( secondListener ) . not . toHaveBeenCalled ( ) ;
2685
- } ) ;
2686
- } ) ;
2687
2573
} ) ;
2688
2574
} ) ;
2689
2575
@@ -2773,7 +2659,7 @@ describe('Scope', function() {
2773
2659
expect ( spy1 ) . toHaveBeenCalledOnce ( ) ;
2774
2660
expect ( spy2 ) . toHaveBeenCalledOnce ( ) ;
2775
2661
expect ( spy3 ) . toHaveBeenCalledOnce ( ) ;
2776
- expect ( child . $$listeners [ 'evt' ] . length ) . toBe ( 2 ) ;
2662
+ expect ( child . $$listeners [ 'evt' ] . length ) . toBe ( 3 ) ; // cleanup will happen on next $emit
2777
2663
2778
2664
spy1 . calls . reset ( ) ;
2779
2665
spy2 . calls . reset ( ) ;
@@ -2807,7 +2693,7 @@ describe('Scope', function() {
2807
2693
expect ( spy1 ) . toHaveBeenCalledOnce ( ) ;
2808
2694
expect ( spy2 ) . toHaveBeenCalledOnce ( ) ;
2809
2695
expect ( spy3 ) . toHaveBeenCalledOnce ( ) ;
2810
- expect ( child . $$listeners [ 'evt' ] . length ) . toBe ( 2 ) ;
2696
+ expect ( child . $$listeners [ 'evt' ] . length ) . toBe ( 3 ) ; //cleanup will happen on next $broadcast
2811
2697
2812
2698
spy1 . calls . reset ( ) ;
2813
2699
spy2 . calls . reset ( ) ;
0 commit comments