fix(javascript): retain proven browser global receivers

This commit is contained in:
morluto committed 2026-10-24 09:11:30 +08:00
1 parent 673a659074
commit 45d0c3e299
5 files changed
+20 -4

No files matched your search

@@ -736,12 +736,21 @@ export function* indexJavaScriptAmbientWritesSteps(
retainSemanticAmbientEffect(state, "write", resolved, node);
}
}
for (const { node, target, browserReceiver, projection } of escapes)
for (const path of ambientWrites(target, node, true, projection).paths)
for (const { node, target, browserReceiver, projection } of escapes) {
const resolved = ambientWrites(target, node, true, projection);
if (
browserReceiver &&
resolved.ownership === "ambient" &&
resolved.paths.length > 0 &&
resolved.paths.every((path) => path.length === 1 && path[0] === "global")
)
state.retainedGlobalCallReceivers.add(target);
for (const path of resolved.paths)
// Only proven browser APIs keep their global receiver from user code.
if (!(browserReceiver && path.length === 1 && path[0] === "global")) {
retainSemanticAmbientEffect(state, "escape", path, node);
}
}
// A function may call a browser method replaced later in source order.
if (
[...browserReceiverMethods].some((method) =>