From 3a67efca0cd0de26235f5b2356d01a357e61a1ca Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Thu, 15 Jan 2026 03:42:44 +0000 Subject: [PATCH] Preserve DontEnum on EventSource reassignment, fix test leak Changes: - Preserve DontEnum attribute when EventSource is reassigned so the property remains non-enumerable after reassignment - Wrap EventSource reassignment test in try/finally to ensure the original EventSource is always restored even if assertions fail Co-Authored-By: Claude Opus 4.5 --- src/bun.js/bindings/ZigGlobalObject.cpp | 4 ++-- test/regression/issue/3319.test.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index a5a3af62a0..d4274a23cb 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -937,8 +937,8 @@ JSC_DEFINE_CUSTOM_SETTER(EventSource_setter, JSValue value = JSValue::decode(encodedValue); auto* globalObject = jsCast(lexicalGlobalObject); - // Replace the accessor with a plain data property - globalObject->putDirect(vm, Identifier::fromString(vm, "EventSource"_s), value, 0); + // Replace the accessor with a plain data property, preserving DontEnum + globalObject->putDirect(vm, Identifier::fromString(vm, "EventSource"_s), value, static_cast(PropertyAttribute::DontEnum)); return true; } diff --git a/test/regression/issue/3319.test.ts b/test/regression/issue/3319.test.ts index fc6b56e771..85adc06568 100644 --- a/test/regression/issue/3319.test.ts +++ b/test/regression/issue/3319.test.ts @@ -546,12 +546,14 @@ describe("EventSource", () => { const original = EventSource; const fake = function FakeEventSource() {}; - // Reassign should work - (globalThis as any).EventSource = fake; - expect(EventSource).toBe(fake); - - // Restore - (globalThis as any).EventSource = original; + try { + // Reassign should work + (globalThis as any).EventSource = fake; + expect(EventSource).toBe(fake); + } finally { + // Always restore original to avoid leaking mutated global + (globalThis as any).EventSource = original; + } expect(EventSource).toBe(original); }); });