From 8361024c1b5c6a7d6bbcfe6648d6a368b6894bd7 Mon Sep 17 00:00:00 2001 From: dajiaohuang Date: Fri, 2 Oct 2026 00:06:16 +0800 Subject: [PATCH] fix: freeze nested stream codec arrays --- src/core/source/stream_selection.ts | 3 +++ test/core/source/hls/stream_catalog.test.ts | 1 + 2 files changed, 4 insertions(+) diff --git a/src/core/source/stream_selection.ts b/src/core/source/stream_selection.ts index 6b05edc..36c6746 100644 --- a/src/core/source/stream_selection.ts +++ b/src/core/source/stream_selection.ts @@ -51,6 +51,9 @@ export type StreamSelector = ( /** Prevents selectors from mutating the canonical identities and compatibility graph they inspect. */ export function freezeStreamCatalog(catalog: StreamCatalog): StreamCatalog { for (const track of catalog.tracks) { + if (track.codecs) { + Object.freeze(track.codecs); + } Object.freeze(track); } for (const option of catalog.options) { diff --git a/test/core/source/hls/stream_catalog.test.ts b/test/core/source/hls/stream_catalog.test.ts index 4f86d79..0165026 100644 --- a/test/core/source/hls/stream_catalog.test.ts +++ b/test/core/source/hls/stream_catalog.test.ts @@ -51,6 +51,7 @@ describe("HLS stream catalog", () => { expect(Object.isFrozen(plan.catalog)).toBe(true); expect(Object.isFrozen(plan.catalog.options[0].tracks)).toBe(true); expect(plan.catalog.tracks.every(Object.isFrozen)).toBe(true); + expect(Object.isFrozen(plan.catalog.tracks[0].codecs)).toBe(true); expect(plan.catalog.tracks.every((track) => !("url" in track))).toBe(true); expect(plan.catalog.tracks.map((track) => plan.mediaTracks.get(track)?.sourcePath)).toEqual([ "https://media.example/low.m3u8",