fix(javascript): retain global escapes across repeated calls

This commit is contained in:
RRFZ authored and Ysopwnable committed 2026-11-14 04:46:27 +01:00
1 parent 4e1e9b62a7
commit 4a4e959513
2 files changed
+21 -18

No files matched your search

@@ -961,24 +961,15 @@ const createGlobalPathRead = (
};
byNamespace.set(namespace, effects);
}
// The call that escapes a receiver contains the callee being identified.
// That escape cannot have replaced the callee before the call selects it.
const escapePrecedesRead = effects.escapes.some((effect) => {
const escape = effect.node;
// Containment alone does not order deferred callback/class bodies.
// Only a read reached without crossing such a boundary precedes escape.
if (escape !== undefined && escape !== site) {
let parent = state.parentsByNode.get(site);
while (
parent !== undefined &&
!t.isFunction(parent) &&
!t.isClass(parent)
) {
if (parent === escape) return false;
parent = state.parentsByNode.get(parent);
}
}
return semanticEffectTiming(site, escape, state) !== "after";
const escapePrecedesRead = effects.escapes.some(({ node }) => {
// Selecting this callee precedes exposing its own receiver. Other reads,
// including arguments, need activation-aware ordering across repetitions.
if (
(t.isCallExpression(node) || t.isOptionalCallExpression(node)) &&
node.callee === site
)
return false;
return semanticEffectTiming(site, node, state) !== "after";
});
if (
(escapesCovered && effects.escapes.length === 0) ||
@@ -175,3 +175,15 @@ it.each(["Symbol", "BigInt"])(
expect(result[1]?.linkedTimerId).toBe(result[0]?.timerId);
},
);
it.each([
'for (let i=0;i<2;i++) configure(globalThis, i ? setTimeout(()=>{}, Symbol("1")) : null);',
'function run(first) { configure(globalThis, first ? null : setTimeout(()=>{}, BigInt("1"))); } run(true); run(false);',
'let first=true; while (next()) { configure(globalThis, first ? null : setTimeout(()=>{}, Symbol("1"))); first=false; }',
])("retains constructor uncertainty across repeated escapes: %s", (source) => {
expect(
operations(
`import configure from "./configure.js"; import {setTimeout} from "node:timers"; ${source}`,
),
).toMatchObject([{ kind: "schedule" }]);
});