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 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-15 03:42:44 +00:00
parent e49dce35be
commit 3a67efca0c
2 changed files with 10 additions and 8 deletions

View File

@@ -937,8 +937,8 @@ JSC_DEFINE_CUSTOM_SETTER(EventSource_setter,
JSValue value = JSValue::decode(encodedValue);
auto* globalObject = jsCast<Zig::GlobalObject*>(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<unsigned>(PropertyAttribute::DontEnum));
return true;
}

View File

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