Skip to content

Commit ca63ed0

Browse files
authored
chore(DASH): Add comments to latest DashParser changes (#8888)
Follow up to #8884 based on comment #8884 (comment)
1 parent 03050c8 commit ca63ed0

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/dash/dash_parser.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ shaka.dash.DashParser = class {
633633
}
634634
}
635635
}
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.
636638
this.lastCalculatedBaseUris_.splice(0);
637639
if (!someLocationValid || !this.contentSteeringManager_) {
638640
const uris = uriObjs.map(TXml.getContents);
@@ -641,13 +643,18 @@ shaka.dash.DashParser = class {
641643
manifestBaseUris, uris));
642644
}
643645

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.
644649
const contentSteeringManager = this.contentSteeringManager_;
645650
const lastCalculatedBaseUris = this.lastCalculatedBaseUris_;
646651

647652
const getBaseUris = () => {
648653
if (contentSteeringManager && someLocationValid) {
649654
return contentSteeringManager.getLocations('BaseURL');
650655
}
656+
// Return the copy, because caller of this function is not an owner
657+
// of the array.
651658
return lastCalculatedBaseUris.slice();
652659
};
653660

@@ -2785,6 +2792,9 @@ shaka.dash.DashParser = class {
27852792
calculatedBaseUris = uriObjs.map(TXml.getContents);
27862793
}
27872794

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.
27882798
const contentSteeringManager = this.contentSteeringManager_;
27892799

27902800
const getFrameUris = () => {

0 commit comments

Comments
 (0)