Skip to content
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
041a506
fix(javascript): emit no event operation for a missing listener argument
gongfpp Nov 2, 2026
f1d30fe
fix(javascript): hold only a proven Node emitter to the listener cont…
gongfpp Nov 3, 2026
4d36250
fix(javascript): require the native listener method itself, not just …
gongfpp Nov 3, 2026
b6917aa
chore: merge main to pick up the Wrangler config format fix
gongfpp Nov 3, 2026
9617f1a
fix(javascript): keep the listener operation when the method or the r…
gongfpp Nov 3, 2026
cb36de8
fix(javascript): read prototype writes by slot, not by exact key
gongfpp Nov 3, 2026
e9e604a
fix(javascript): withdraw the listener proof when the prototype itsel…
gongfpp Nov 3, 2026
0bd6c11
fix(javascript): require the events class surface to be untouched
gongfpp Nov 3, 2026
c964e98
fix(javascript): scope the class-surface proof to the events class
gongfpp Nov 3, 2026
87b7be8
Merge upstream main into missing-listener fix
gongfpp Nov 5, 2026
c9427ea
fix(javascript): keep listener candidates after shared mutations
gongfpp Nov 5, 2026
f038fdc
fix(javascript): retain constructed receiver class references
gongfpp Nov 5, 2026
47e3b9b
fix(javascript): time ambient prototype effects at XHR reads
gongfpp Nov 5, 2026
ad13261
perf(javascript): share ambient path effect matching
gongfpp Nov 5, 2026
94dc27a
merge: sync main into missing-listener fix
gongfpp Nov 9, 2026
98316a1
perf(javascript): index shared EventEmitter effects
gongfpp Nov 9, 2026
c719fb1
fix(javascript): track EventEmitter initializer escapes
gongfpp Nov 9, 2026
88d5732
fix(javascript): honor initializer binding provenance
gongfpp Nov 9, 2026
514a306
fix(javascript): preserve timed native receiver proofs
gongfpp Nov 9, 2026
9a7b483
fix(javascript): retain builtin acquisition mutation effects
gongfpp Nov 9, 2026
3c3684c
fix(javascript): retain awaited module acquisition effects
gongfpp Nov 9, 2026
65d74b0
fix(javascript): keep intrinsic Map calls from escaping
gongfpp Nov 9, 2026
b6cc762
fix(javascript): preserve pristine XHR and getter alias effects
gongfpp Nov 9, 2026
5944b69
chore: merge upstream main to refresh CI base
gongfpp Nov 9, 2026
676c01d
fix(javascript): share mutable events default effects
gongfpp Nov 9, 2026
25cc26b
fix(javascript): track inherited initializer call effects
gongfpp Nov 9, 2026
95cd68c
fix(javascript): preserve iterator and initializer effect boundaries
gongfpp Nov 9, 2026
e118fc9
fix(javascript): retain pristine Array receiver certainty
gongfpp Nov 9, 2026
ba119f3
fix(javascript): preserve builtin receiver and getter effects
gongfpp Nov 9, 2026
6b18b70
fix(javascript): preserve pristine Array read certainty
gongfpp Nov 9, 2026
9b39943
fix(javascript): preserve Array iteration read timing
gongfpp Nov 10, 2026
09001af
merge: sync main and preserve timed iteration effects
gongfpp Nov 10, 2026
be61d5c
fix(javascript): preserve native inspection and discarded-result proofs
gongfpp Nov 10, 2026
048274c
fix(javascript): preserve inherited native method proofs
gongfpp Nov 10, 2026
486aade
fix(javascript): reconcile listener proofs with upstream main
gongfpp Nov 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions src/domain/javascript/javascriptAstValues.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as t from "@babel/types";
import { expect, it } from "vitest";

import {
javaScriptExpressionResultIsUsed,
semanticMemberChain,
semanticStaticPropertyKey,
staticObjectProperty,
Expand All @@ -10,6 +11,102 @@ import {
staticObjectPropertyNames,
} from "./javascriptAstValues.js";

it("keeps missing and mismatched result-parent edges conservative", () => {
const call = t.callExpression(t.identifier("invoke"), []);
const other = t.numericLiteral(0);
const parents = new WeakMap<t.Node, t.Node>();
expect(javaScriptExpressionResultIsUsed(call, parents)).toBe(true);
for (const parent of [
t.expressionStatement(other),
t.unaryExpression("void", other),
t.sequenceExpression([other]),
t.parenthesizedExpression(other),
t.tsAsExpression(other, t.tsUnknownKeyword()),
t.conditionalExpression(other, other, other),
t.logicalExpression("&&", other, other),
t.forStatement(other, null, other, t.emptyStatement()),
]) {
parents.set(call, parent);
if (t.isExpression(parent))
parents.set(parent, t.expressionStatement(parent));
expect(javaScriptExpressionResultIsUsed(call, parents), parent.type).toBe(
true,
);
}
});

it("follows an explicit grouping wrapper through a final comma operand", () => {
const call = t.callExpression(t.identifier("invoke"), []);
const wrapper = t.parenthesizedExpression(call);
const sequence = t.sequenceExpression([t.numericLiteral(0), wrapper]);
const parents = new WeakMap<t.Node, t.Node>([
[call, wrapper],
[wrapper, sequence],
]);
expect(javaScriptExpressionResultIsUsed(call, parents)).toBe(true);
parents.set(sequence, t.expressionStatement(sequence));
expect(javaScriptExpressionResultIsUsed(call, parents)).toBe(false);
parents.set(sequence, t.callExpression(t.identifier("consume"), [sequence]));
expect(javaScriptExpressionResultIsUsed(call, parents)).toBe(true);
parents.delete(sequence);
expect(javaScriptExpressionResultIsUsed(call, parents)).toBe(true);
});

it.each([128, 256, 512])(
"indexes comma membership once for %i sibling calls per parent map",
(count) => {
const calls = Array.from({ length: count }, () =>
t.callExpression(t.identifier("invoke"), []),
);
const sequence = t.sequenceExpression(calls);
let memberReads = 0;
sequence.expressions = new Proxy(sequence.expressions, {
get(target, key, receiver) {
if (typeof key === "string" && /^\d+$/u.test(key)) memberReads += 1;
return Reflect.get(target, key, receiver);
},
});
const parentMap = () =>
new WeakMap<t.Node, t.Node>([
...calls.map((call): [t.Node, t.Node] => [call, sequence]),
[sequence, t.expressionStatement(sequence)],
]);
const parents = parentMap();
for (const call of calls)
expect(javaScriptExpressionResultIsUsed(call, parents)).toBe(false);
expect(memberReads).toBeLessThanOrEqual(count * 2);
const firstReads = memberReads;
for (const call of calls)
expect(javaScriptExpressionResultIsUsed(call, parents)).toBe(false);
expect(memberReads - firstReads).toBeLessThanOrEqual(count);
const repeatedReads = memberReads;
const independentParents = parentMap();
for (const call of calls)
expect(javaScriptExpressionResultIsUsed(call, independentParents)).toBe(
false,
);
// A different analysis owns its own membership, even for the same AST.
expect(memberReads - repeatedReads).toBe(firstReads);
},
);

it("keeps sequence membership isolated and rejects mismatches after indexing", () => {
const first = t.callExpression(t.identifier("first"), []);
const second = t.callExpression(t.identifier("second"), []);
const firstSequence = t.sequenceExpression([first, t.numericLiteral(0)]);
const secondSequence = t.sequenceExpression([second, t.numericLiteral(0)]);
const parents = new WeakMap<t.Node, t.Node>([
[first, firstSequence],
[second, secondSequence],
]);
expect(javaScriptExpressionResultIsUsed(first, parents)).toBe(false);
expect(javaScriptExpressionResultIsUsed(second, parents)).toBe(false);
parents.set(first, secondSequence);
expect(javaScriptExpressionResultIsUsed(first, parents)).toBe(true);
parents.delete(first);
expect(javaScriptExpressionResultIsUsed(first, parents)).toBe(true);
});

it("keeps string spread indices separate from named descriptor fields", () => {
for (const text of ["", "x", "😀", "x".repeat(1_000_000)]) {
const original = t.objectProperty(
Expand Down
59 changes: 59 additions & 0 deletions src/domain/javascript/javascriptAstValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,65 @@ export const javaScriptExpressionWrapperTarget = (
? node.expression
: undefined;

// Parent facts and sequence children belong to one immutable parsed tree. Retain
// only child membership; result use still follows the current outer parent edges.
const sequenceMembersByParents = new WeakMap<
Pick<WeakMap<t.Node, t.Node>, "get">,
WeakMap<t.SequenceExpression, ReadonlySet<t.Node>>
>();

/** Follow only transparent result edges to an explicit value-discarding context. */
export const javaScriptExpressionResultIsUsed = (
node: t.Node,
parents: Pick<WeakMap<t.Node, t.Node>, "get">,
): boolean => {
let child = node;
for (
let parent = parents.get(child);
parent !== undefined;
parent = parents.get(child)
) {
if (javaScriptExpressionWrapperTarget(parent) === child) {
child = parent;
continue;
}
if (
(t.isConditionalExpression(parent) &&
(parent.consequent === child || parent.alternate === child)) ||
(t.isLogicalExpression(parent) && parent.right === child)
) {
child = parent;
continue;
}
if (t.isSequenceExpression(parent)) {
let sequences = sequenceMembersByParents.get(parents);
if (sequences === undefined) {
sequences = new WeakMap();
sequenceMembersByParents.set(parents, sequences);
}
let members = sequences.get(parent);
if (members === undefined) {
members = new Set(parent.expressions);
sequences.set(parent, members);
}
if (!members.has(child)) return true;
if (parent.expressions.at(-1) !== child) return false;
child = parent;
continue;
}
if (t.isExpressionStatement(parent)) return parent.expression !== child;
if (t.isUnaryExpression(parent, { operator: "void" }))
return parent.argument !== child;
// for/of and for/in heads use their expressions. A C-style for initializer
// or update discards the value, but a variable initializer still stores it.
return !(
t.isForStatement(parent) &&
(parent.init === child || parent.update === child)
);
}
return true;
};

/**
* Remove wrappers that affect TypeScript or Flow checking but not runtime
* expression identity. The returned depth lets bounded evaluators account for
Expand Down
103 changes: 53 additions & 50 deletions src/domain/javascript/javascriptNetworkRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ import {
semanticStaticPropertyName,
unwrapJavaScriptExpression,
} from "./javascriptAstValues.js";
import { semanticBindingAtRead } from "./javascriptSemanticMutationInitializers.js";
import { semanticOpaqueGlobalMayHaveChanged } from "./javascriptSemanticOpaqueEffects.js";
import {
resolveSemanticBindingState,
semanticStableInitializer,
type JavaScriptBindingIndex,
type JavaScriptSemanticAnalysisState,
semanticConstructedReceiver,
semanticPrimitiveArguments,
} from "./javascriptSemanticIntrinsicReceivers.js";
import { semanticOpaqueGlobalMayHaveChanged } from "./javascriptSemanticOpaqueEffects.js";
import type {
JavaScriptBindingIndex,
JavaScriptSemanticAnalysisState,
} from "./javascriptSemanticState.js";
import * as t from "@babel/types";
import { isUnmodifiedGlobalReference } from "./javascriptSemanticAmbientWrites.js";
import {
isUnmodifiedGlobalReference,
semanticAmbientPathMayHaveChangedAt,
} from "./javascriptSemanticAmbientWrites.js";

export const isFetchCall = (
node: t.Node,
Expand Down Expand Up @@ -40,6 +44,7 @@ const isXhrOpenRequest = (
node: t.Node,
bindings: JavaScriptSemanticAnalysisState,
index?: Pick<JavaScriptBindingIndex, "referenceMayHaveChangedAt">,
purpose: "request" | "receiver" = "request",
): boolean | undefined => {
if (!t.isCallExpression(node) && !t.isOptionalCallExpression(node))
return false;
Expand All @@ -49,60 +54,58 @@ const isXhrOpenRequest = (
semanticStaticPropertyName(callee.property, callee.computed) !== "open"
)
return false;
// Native open can dispatch readystatechange. Its receiver is nonescaping
// only when no handler or prior opaque operation can have configured it.
// Primitive arguments also avoid user code during WebIDL string conversion.
if (
["XMLHttpRequest", "Object"].some((owner) =>
["open", "__proto__"].some(
(member) =>
bindings.ambientWrites.covers([
"global",
owner,
"prototype",
member,
]) ||
bindings.ambientEscapes.covers([
"global",
owner,
"prototype",
member,
]),
purpose === "receiver" &&
!semanticPrimitiveArguments(node.arguments, bindings)
)
return false;
const prototypeOwners =
purpose === "receiver"
? ["XMLHttpRequest", "XMLHttpRequestEventTarget", "EventTarget", "Object"]
: ["XMLHttpRequest", "Object"];
if (
prototypeOwners.some((owner) =>
(purpose === "receiver"
? ["open", "__proto__", "onreadystatechange"]
: ["open", "__proto__"]
).some((member) =>
semanticAmbientPathMayHaveChangedAt(
purpose === "receiver" ? node : callee,
bindings,
["global", owner, "prototype", member],
node,
),
),
)
)
return false;
let receiver = unwrapJavaScriptExpression(callee.object).node;
const seen = new Set<string>();
while (t.isIdentifier(receiver)) {
if (
index !== undefined &&
(index.referenceMayHaveChangedAt(node, receiver, ["open"]) ||
index.referenceMayHaveChangedAt(node, receiver, ["__proto__"]))
)
return false;
const binding = resolveSemanticBindingState(
bindings,
receiver,
receiver.name,
);
if (binding === undefined || seen.has(binding.bindingId)) return false;
seen.add(binding.bindingId);
const initializer = semanticStableInitializer(binding, bindings);
if (
initializer === undefined ||
initializer.projection.length !== 0 ||
!semanticBindingAtRead(binding, receiver, bindings).hasDefiniteInitializer
)
return false;
receiver = unwrapJavaScriptExpression(initializer.node).node;
}
const receiver = semanticConstructedReceiver(callee.object, node, bindings, {
paths: purpose === "receiver" ? [[]] : [["open"], ["__proto__"]],
index,
});
if (
!t.isNewExpression(receiver) ||
!isUnmodifiedGlobalReference(receiver.callee, bindings, "XMLHttpRequest") ||
receiver === undefined ||
!isUnmodifiedGlobalReference(
receiver.construction.callee,
bindings,
"XMLHttpRequest",
) ||
semanticOpaqueGlobalMayHaveChanged(callee, bindings)
)
return false;
return index === undefined && seen.size > 0 ? undefined : true;
return index === undefined && receiver.viaBinding ? undefined : true;
};

/** A pristine native open is safe for the mutation producer, not every XHR call. */
export const isIntrinsicNonEscapingXhrOpen = (
node: t.Node,
bindings: JavaScriptSemanticAnalysisState,
index?: Pick<JavaScriptBindingIndex, "referenceMayHaveChangedAt">,
): boolean | undefined => isXhrOpenRequest(node, bindings, index, "receiver");

/** Resolve once through the shared mutation index when lexical proof needs it. */
export const createXhrOpenRequestQuery =
(index: JavaScriptBindingIndex): ((node: t.Node) => boolean) =>
Expand Down
Loading
Loading