Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
283a6e8
fix(javascript): resolve module-level Electron options in functions
ShuaixinHuang Oct 30, 2026
4edd03e
fix(javascript): limit module option ancestry walk
ShuaixinHuang Oct 30, 2026
fb2532a
fix(javascript): preserve uncertain captured argument ordering
ShuaixinHuang Oct 30, 2026
9bafc83
fix(javascript): retain hoisted activation uncertainty
ShuaixinHuang Oct 30, 2026
cc2bb12
fix(javascript): retain function ownership through loops
ShuaixinHuang Oct 30, 2026
9611e5c
fix(javascript): account for classic global activations
ShuaixinHuang Nov 1, 2026
4cd804c
fix(javascript): bind first activations to lexical identities
ShuaixinHuang Nov 2, 2026
507b50a
fix(javascript): retain uncertain global activation timing
ShuaixinHuang Nov 2, 2026
acf9452
fix(javascript): isolate receiver facts and share computed reads
ShuaixinHuang Nov 2, 2026
438a745
fix(javascript): retain projected and opaque global activations
ShuaixinHuang Nov 3, 2026
c347f9a
fix(javascript): refresh activation bounds as opaque effects grow
ShuaixinHuang Nov 3, 2026
32d0656
Merge current main to retain upstream changes for CI formatting repair
ShuaixinHuang Nov 3, 2026
e2e3576
fix(ci): format website watch directories without changing configuration
ShuaixinHuang Nov 3, 2026
e4cf01f
fix(javascript): share source reads across opaque-effect updates
ShuaixinHuang Nov 3, 2026
13f5340
fix(javascript): retain constructed-code global activation bounds
ShuaixinHuang Nov 3, 2026
1016f6c
fix(javascript): share runtime activation and receiver facts
ShuaixinHuang Nov 3, 2026
5b8594a
fix(javascript): reuse pattern reads and function positions
ShuaixinHuang Nov 3, 2026
f45be16
fix(javascript): isolate copied paths and preserve runtime reads
ShuaixinHuang Nov 3, 2026
d9e845f
style(javascript): format migrated reference imports
ShuaixinHuang Nov 3, 2026
e13c376
fix(javascript): normalize constructor activation and receiver effects
ShuaixinHuang Nov 3, 2026
5d9db0e
fix(javascript): retain aliased receiver timing and lexical global this
ShuaixinHuang Nov 3, 2026
9da5935
fix(javascript): preserve effect-free receiver identity across activa…
ShuaixinHuang Nov 3, 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
Prev Previous commit
Next Next commit
fix(javascript): retain constructed-code global activation bounds
  • Loading branch information
ShuaixinHuang committed Nov 3, 2026
commit 13f5340e8bfe199766d6af982ff4342520a11626
25 changes: 25 additions & 0 deletions src/domain/javascript/electronStaticAnalysisOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,24 @@ it.each([
);

describe("Classic-script global function activation", () => {
it("keeps a shadowed Function constructor independent of global activation", () => {
const source = `const { BrowserWindow } = require('electron');
const Function = () => () => {}; Function('createWindow()')();
const webPreferences = { nodeIntegration: true };
function createWindow() { return new BrowserWindow({ webPreferences }); }
createWindow();`;
expect(() =>
runInNewContext(source, { require: () => ({ BrowserWindow: class {} }) }),
).not.toThrow();
expect(
analyzeJavaScriptStaticSource(source).electron.browser_windows[0],
).toMatchObject({
web_preferences_status: "object-literal",
web_preferences: [
{ name: "nodeIntegration", value: { status: "literal", value: true } },
],
});
});
it.each([
"globalThis.createWindow();",
'globalThis["createWindow"]();',
Expand All @@ -358,6 +376,13 @@ describe("Classic-script global function activation", () => {
"const root = { __proto__: globalThis }; root.createWindow();",
"const root = { ...globalThis }; root.createWindow();",
"(0, eval)('createWindow()');",
"Function('createWindow()')();",
"new Function('createWindow()')();",
"const F = Function; F('createWindow()')();",
"Function.call(null, 'createWindow()')();",
"Function.apply(null, ['createWindow()'])();",
"globalThis.Function('createWindow()')();",
"const F = Function.bind(null); F('createWindow()')();",
"const noop = () => {}; function unused() { noop(); } (0, eval)('createWindow()');",
"const noop = () => {}; (0, eval)(''); function unused() { noop(); } (0, eval)('createWindow()');",
])("keeps early global access unresolved: %s", (activation) => {
Expand Down
11 changes: 6 additions & 5 deletions src/domain/javascript/javascriptSemanticAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ const createState = (
arrayIterationUnknown: false,
program,
opaqueEffects: {
mayReferenceGlobalEval: false,
mayReferenceGlobalCode: false,
sites: new WeakSet(),
sloppySites: new WeakSet(),
byScope: new Map(),
Expand Down Expand Up @@ -1081,8 +1081,9 @@ const createState = (
};
};

const globalEvalRoots = new Set([
const globalCodeRoots = new Set([
"eval",
"Function",
"globalThis",
"global",
"window",
Expand Down Expand Up @@ -1213,10 +1214,10 @@ function* collectDefinitionsSteps(
bindInnerDeclaration(node, parent, scope, state);
if (t.isThrowStatement(node))
thrownValues.push({ node, ancestors: readAncestors() });
// Every supported global eval origin starts with one of these decoded
// Every supported global-code origin starts with one of these decoded
// identifiers, including computed properties and destructured aliases.
if (t.isIdentifier(node) && globalEvalRoots.has(node.name))
state.opaqueEffects.mayReferenceGlobalEval = true;
if (t.isIdentifier(node) && globalCodeRoots.has(node.name))
state.opaqueEffects.mayReferenceGlobalCode = true;
if (
t.isCallExpression(node) &&
t.isIdentifier(unwrapJavaScriptExpression(node.callee).node, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,9 @@ const moduleFunctionFirstRead = (
if (t.isFunction(node)) active.add(node);
if (
classicScript &&
(t.isCallExpression(node) || t.isOptionalCallExpression(node))
(t.isCallExpression(node) ||
t.isOptionalCallExpression(node) ||
t.isNewExpression(node))
) {
opaquePositions.set(node, active.size > 0 ? null : index);
}
Expand Down
29 changes: 22 additions & 7 deletions src/domain/javascript/javascriptSemanticOpaqueEffects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,52 @@ export const createSemanticOpaqueGlobalObserver = (
intrinsicPath: (node: t.Node) => readonly string[] | undefined;
},
) => {
intrinsicPath: (node: t.Node) => readonly string[] | undefined;
intrinsicInvocation: (
node: t.CallExpression | t.OptionalCallExpression,
) => { readonly path: readonly string[] } | undefined;
};
},
): ((node: t.Node) => void) | undefined => {
if (!state.opaqueEffects.mayReferenceGlobalEval) return undefined;
if (!state.opaqueEffects.mayReferenceGlobalCode) return undefined;
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
const ambientPaths = dependencies.createAmbientPathResolver(state, true);
let invocationSite: t.Node | undefined;
const interop = dependencies.createSemanticModuleInterop(state, {
intrinsicPath: (node) => {
const paths = ambientPaths(node, invocationSite).paths;
const path = paths.find((path) => path[1] === "eval") ?? paths[0];
const path =
paths.find((path) => path[1] === "eval" || path[1] === "Function") ??
paths[0];
if (path?.[0] !== "global" || path.some((key) => key === null))
return undefined;
// Keep the global callable owner for generic call/apply/bind resolution.
return path[1] === "eval"
return path[1] === "eval" || path[1] === "Function"
? ["intrinsic", ...(path as readonly string[])]
: ["intrinsic", ...(path.slice(1) as readonly string[])];
},
});
return (node) => {
if (!t.isCallExpression(node) && !t.isOptionalCallExpression(node)) return;
if (
!t.isCallExpression(node) &&
!t.isOptionalCallExpression(node) &&
!t.isNewExpression(node)
)
return;
invocationSite = node;
const invocation = interop.intrinsicInvocation(node);
if (invocation?.path.join(".") === "intrinsic.global.eval")
const path = t.isNewExpression(node)
? interop.intrinsicPath(node.callee)
: interop.intrinsicInvocation(node)?.path;
// Constructed code may escape and activate a classic-script global. Keep
// its creation as a conservative timing bound, not proof of execution.
if (
path?.join(".") === "intrinsic.global.eval" ||
path?.join(".") === "intrinsic.global.Function"
)
state.opaqueEffects.globalSites.push(node);
};
};

/** Indirect eval can change globals, but cannot rebind its caller's locals. */
/** Global code can affect globals, but cannot rebind its caller's locals. */
export const semanticOpaqueGlobalMayHaveChanged = (
read: t.Node,
state: JavaScriptSemanticAnalysisState,
Expand Down
8 changes: 6 additions & 2 deletions src/domain/javascript/javascriptSemanticState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@ export interface JavaScriptSemanticScopeState {
/** One source owns sites and the minimal scope tree reaching them; O(AST) storage. */
export interface JavaScriptOpaqueScopeEffects {
/** Cheap source evidence collected with declarations, before alias queries. */
mayReferenceGlobalEval: boolean;
mayReferenceGlobalCode: boolean;
readonly sites: WeakSet<t.Node>;
readonly sloppySites: WeakSet<t.Node>;
readonly byScope: Map<string, t.CallExpression[]>;
readonly children: Map<string, Set<string>>;
readonly globalSites: (t.CallExpression | t.OptionalCallExpression)[];
readonly globalSites: (
| t.CallExpression
| t.OptionalCallExpression
| t.NewExpression
)[];
}

/** Shared state for semantic collection and evaluation. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,22 @@ cliTest.for([
["stdio MCP", true],
["CLI", "cached-eval"],
["stdio MCP", "cached-eval"],
["CLI", "constructed-function"],
["stdio MCP", "constructed-function"],
] as const)(
"preserves classic global initialization uncertainty through %s",
async ([surface, alias], { cli }) => {
const root = await createTestTempDirectory(
"rea-electron-global-initialization-",
);
const activation =
alias === "cached-eval"
? "const noop = () => {}; function unused() { noop(); } (0, eval)('createWindow()');"
: alias
? "root.createWindow();"
: "globalThis.createWindow();";
alias === "constructed-function"
? "new Function('createWindow()')();"
: alias === "cached-eval"
? "const noop = () => {}; function unused() { noop(); } (0, eval)('createWindow()');"
: alias
? "root.createWindow();"
: "globalThis.createWindow();";
const source = (early: boolean) => `
const { BrowserWindow } = require("electron");
${alias ? "const root = globalThis;" : ""}
Expand Down
Loading