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); }); });