From 7edb348807e0447bb25c101f1be140386f0775bd Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sat, 24 Jan 2026 14:33:16 -0500 Subject: [PATCH] fix: [#2045] Replace JSON.parse(JSON.stringify()) with structuredClone() --- .../property-manager/CSSStyleDeclarationPropertyManager.ts | 2 +- packages/happy-dom/src/fetch/Headers.ts | 2 +- .../src/nodes/html-media-element/MediaStreamTrack.ts | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationPropertyManager.ts b/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationPropertyManager.ts index a460b2ef2..f22b9c3e0 100644 --- a/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationPropertyManager.ts +++ b/packages/happy-dom/src/css/declaration/property-manager/CSSStyleDeclarationPropertyManager.ts @@ -539,7 +539,7 @@ export default class CSSStyleDeclarationPropertyManager { const _class = this.constructor; const clone: CSSStyleDeclarationPropertyManager = new _class(); - clone.properties = JSON.parse(JSON.stringify(this.properties)); + clone.properties = structuredClone(this.properties); clone.definedPropertyNames = Object.assign({}, this.definedPropertyNames); return clone; diff --git a/packages/happy-dom/src/fetch/Headers.ts b/packages/happy-dom/src/fetch/Headers.ts index 22dcefd99..028749dd3 100644 --- a/packages/happy-dom/src/fetch/Headers.ts +++ b/packages/happy-dom/src/fetch/Headers.ts @@ -23,7 +23,7 @@ export default class Headers { constructor(init?: IHeadersInit | null) { if (init) { if (init instanceof Headers) { - this[PropertySymbol.entries] = JSON.parse(JSON.stringify(init[PropertySymbol.entries])); + this[PropertySymbol.entries] = structuredClone(init[PropertySymbol.entries]); } else if (Array.isArray(init)) { for (const entry of init) { if (entry.length !== 2) { diff --git a/packages/happy-dom/src/nodes/html-media-element/MediaStreamTrack.ts b/packages/happy-dom/src/nodes/html-media-element/MediaStreamTrack.ts index 34cf9f40a..2c5645560 100644 --- a/packages/happy-dom/src/nodes/html-media-element/MediaStreamTrack.ts +++ b/packages/happy-dom/src/nodes/html-media-element/MediaStreamTrack.ts @@ -58,10 +58,8 @@ export default class MediaStreamTrack extends EventTarget { public [PropertySymbol.label]: string = ''; public [PropertySymbol.kind]: 'audio' | 'video' = 'video'; public [PropertySymbol.constraints]: IMediaTrackConstraints = {}; - public [PropertySymbol.capabilities]: IMediaTrackCapabilities = JSON.parse( - JSON.stringify(CAPABILITIES) - ); - public [PropertySymbol.settings]: IMediaTrackSettings = JSON.parse(JSON.stringify(SETTINGS)); + public [PropertySymbol.capabilities]: IMediaTrackCapabilities = structuredClone(CAPABILITIES); + public [PropertySymbol.settings]: IMediaTrackSettings = structuredClone(SETTINGS); // Events public onended: ((event: Event) => void) | null = null;