mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 03:48:56 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user