@@ -633,6 +633,8 @@ shaka.dash.DashParser = class {
633
633
}
634
634
}
635
635
}
636
+ // Clean the array instead of creating a new one. By doing this we ensure
637
+ // that references to the array does not change in callback functions.
636
638
this . lastCalculatedBaseUris_ . splice ( 0 ) ;
637
639
if ( ! someLocationValid || ! this . contentSteeringManager_ ) {
638
640
const uris = uriObjs . map ( TXml . getContents ) ;
@@ -641,13 +643,18 @@ shaka.dash.DashParser = class {
641
643
manifestBaseUris , uris ) ) ;
642
644
}
643
645
646
+ // Here we are creating local variables to avoid direct references to `this`
647
+ // in a callback function. By doing this we can ensure that garbage
648
+ // collector can clean up `this` object when it is no longer needed.
644
649
const contentSteeringManager = this . contentSteeringManager_ ;
645
650
const lastCalculatedBaseUris = this . lastCalculatedBaseUris_ ;
646
651
647
652
const getBaseUris = ( ) => {
648
653
if ( contentSteeringManager && someLocationValid ) {
649
654
return contentSteeringManager . getLocations ( 'BaseURL' ) ;
650
655
}
656
+ // Return the copy, because caller of this function is not an owner
657
+ // of the array.
651
658
return lastCalculatedBaseUris . slice ( ) ;
652
659
} ;
653
660
@@ -2785,6 +2792,9 @@ shaka.dash.DashParser = class {
2785
2792
calculatedBaseUris = uriObjs . map ( TXml . getContents ) ;
2786
2793
}
2787
2794
2795
+ // Here we are creating local variable to avoid direct references to `this`
2796
+ // in a callback function. By doing this we can ensure that garbage
2797
+ // collector can clean up `this` object when it is no longer needed.
2788
2798
const contentSteeringManager = this . contentSteeringManager_ ;
2789
2799
2790
2800
const getFrameUris = ( ) => {
0 commit comments