Repository navigation
fix(javascript): resolve module-level Electron options in functions - #8666
ShuaixinHuang wants to merge 20 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[High impact] The PR changes shared JavaScript timing facts used by several analysis features. The PR needs changes before merging: the earlier getter finding remains, and unrelated property writes now hide known Electron preferences. FindingsFix with agent prompt### Issue 1
src/domain/javascript/javascriptSemanticMutationInitializers.ts:1102-1111
The new check trusts the original nested property even when an earlier getter replaces it during destructuring. For example, place this before `webPreferences` initialization:
```js
const { x, nested: { createWindow: start } } = {
get x() { this.nested = globalThis; return 0; },
nested: { createWindow() {} },
};
start();
```
In a classic script, `start()` calls the global `createWindow` before its captured constant is initialized. But `staticObjectProperty` selects the original nested literal, and `globalReceiver(receiver) === false` skips that early read. A later bare `createWindow()` can then make Electron preferences look definite even though the earlier call throws.
Keep the read uncertain unless the selected receiver is proven unchanged by earlier pattern reads. `AGENTS.md` requires identity and uncertainty to survive these boundaries; the original literal alone does not prove the receiver at this read.
### Issue 2
src/domain/javascript/javascriptSemanticMutationInitializers.ts:1028-1035
`receiverAtRead` treats every earlier member write as a possible change to the method being read. In a classic script, `const other = { createWindow() {} }; other.unrelated = 1; other.createWindow();` before `webPreferences` initialization now counts as an early read of the module's separate `createWindow`. The later real call loses its proven preferences, although the unrelated method cannot activate that function.
Check whether the recorded path can change the selected method or its lookup before dropping the receiver proof. `AGENTS.md` requires consumers to preserve identity across boundaries. This requirement must be satisfied before merging.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.SummaryThe PR resolves captured module-level Electron options while keeping early function activations uncertain.
Supersession could not be checked because GitHub access required authentication. No new security issue was established by the source review; no runtime verification was performed. Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read captured module constant] --> B[Find earliest possible function read]
B --> C[Check receiver identity and recorded writes]
C --> D{Initializer comes first?}
D -->|Yes| E[Resolve unchanged Electron options]
D -->|No or unknown| F[Keep options dynamic]
G[Member-write inventory completes] --> H[Rebuild cached function-read bounds]
H --> B
Reviews (12) · Last reviewed commit: "fix(javascript): normalize constructor a..." · Reviewed by Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4cd804cbcc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| owner !== undefined; | ||
| owner = parents.get(owner) | ||
| ) | ||
| if (t.isStatement(owner)) return statementPosition(owner, parents); |
There was a problem hiding this comment.
Stop statement lookup at intervening function boundaries
When a callback is created in a hoisted function's default parameter, this walk reaches the outer function declaration and treats its declaration position as the callback's activation bound. For example, createWindow(); const webPreferences = { nodeIntegration: true }; function createWindow(make = () => new BrowserWindow({ webPreferences })) { return make(); } now gets hasDefiniteInitializer: true, although the early call invokes the callback while webPreferences is still in the temporal dead zone. optionObjectCandidate relies on that flag, allowing unresolved preferences to become literal evidence. Stop at intervening function boundaries, or establish the owning function's activation timing instead.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| name = semanticStaticPropertyKey(node.property, node.computed); | ||
| } | ||
| if (name === null) return; |
There was a problem hiding this comment.
Retain unknown timing for computed global accesses
For a classic script with const key = 'createWindow'; globalThis[key](); before the captured options initializer and a later bare createWindow() call, semanticStaticPropertyKey returns null and the early read is silently discarded. The index consequently selects the later call as the first use and marks the captured options definitely initialized, even though the earlier global call reaches them in the temporal dead zone. Resolve computed global keys through the shared semantic facts, or let unresolved global reads invalidate the timing proof rather than treating them as absent.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| (candidate != null && | ||
| binding?.initializers.some( | ||
| ({ node: value }) => value === candidate, | ||
| )) |
There was a problem hiding this comment.
Preserve uncertain binding matches in the activation index
When an early call appears inside with ({}) { createWindow(); }, the lexical owner returns an uncertain-binding, so resolveSemanticBindingState returns undefined. Requiring a definite binding match here drops that possible activation entirely. If the captured const initializer follows the block and another bare call appears later, the new index reports definite initialization despite the early call reaching the uninitialized value. Use semanticBindingLookupAt to retain possible binding ownership and keep its timing unknown; only a definitely different binding should be ignored.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| return binding.initializers.some(({ node: value }) => | ||
| globalReceiver(value, seen), |
There was a problem hiding this comment.
Make global-receiver alias traversal stack-safe
A flat classic script containing a few thousand chained global-object aliases followed by a member read drives one recursive call per alias here; seen prevents cycles but does not bound call depth. The new walk throws RangeError: Maximum call stack size exceeded during first-read indexing even though the source has shallow syntax. In the analysis worker this occurs before the static checkpoint, so the source loses its static facts and is reported as a memory-resource failure. Traverse the alias graph with an iterative worklist and reuse resolved results instead of recursively expanding each receiver.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 507b50a97c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| classicScript && | ||
| (t.isMemberExpression(node) || t.isOptionalMemberExpression(node)) |
There was a problem hiding this comment.
Include destructured global functions in the activation index
In a classic script, const { createWindow: start } = globalThis; start(); before the webPreferences initializer is missed because the object-pattern property is neither a referenced identifier nor a member expression. If a bare createWindow() also appears after initialization, the index selects that later call and reports hasDefiniteInitializer: true. Consequently, optionObjectCandidate emits literal preferences even though the early invocation reaches the temporal dead zone, as confirmed by the inert VM control. Account for global property reads through destructuring projections, or retain unknown activation timing instead of treating those reads as absent.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| if ( | ||
| t.isIdentifier(node) && | ||
| parent !== null && | ||
| t.isReferenced(node, parent) |
There was a problem hiding this comment.
Count logical-assignment targets as function reads
When const start = (createWindow ||= null); start(); precedes the captured webPreferences initializer, the assignment target reads and returns the existing hoisted function, but t.isReferenced excludes that target. A later bare createWindow() after initialization is therefore treated as the first read, allowing optionObjectCandidate to publish literal settings despite the early invocation reaching the temporal dead zone. Include the shared read-before-write semantics, already represented by semanticWriteSiteReadsFirst, rather than dropping these assignment-target reads.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: acf94528c3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| } | ||
| } else if ( | ||
| !t.isObjectExpression(node) && |
There was a problem hiding this comment.
Retain activations through inherited or copied global functions
In a classic script, const root = { __proto__: globalThis }; root.createWindow(); before the captured webPreferences initializer invokes the hoisted function through its prototype. A spread copy of globalThis does the same. This branch classifies either object literal as definitively unrelated, so the index ignores that activation and selects a later bare createWindow() call instead. The resulting hasDefiniteInitializer: true is incorrect—the early invocation reaches the temporal dead zone—and optionObjectCandidate trusts that flag when resolving literal preferences. Retain unknown identity for prototype/spread-bearing receivers, or resolve their selected property through the shared reference facts.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| functionPosition !== null && | ||
| sourcePosition.body === functionPosition.body && | ||
| (t.isFunctionDeclaration(enclosingFunction) | ||
| ? firstFunctionRead !== null && sourcePosition.index < firstFunctionRead |
There was a problem hiding this comment.
Account for opaque global eval in the activation bound
In a classic script, (0, eval)('createWindow()') before the captured options initializer invokes the hoisted function without a matching identifier or member read in the surrounding AST. If a bare createWindow() appears after initialization, this condition accepts that later reference as proof and incorrectly returns hasDefiniteInitializer: true; the early eval invocation actually reaches the temporal dead zone. The existing opaque-effects owner recognizes indirect eval invocations in javascriptSemanticOpaqueEffects.ts:86-91, but this activation bound does not consume those facts. Incorporate opaque global execution into the timing uncertainty rather than allowing the later named read to establish definite initialization.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 438a745ba7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let reads = cache.get(body); | ||
| if (reads === undefined) { | ||
| reads = new WeakMap(); | ||
| cache.set(body, reads); |
There was a problem hiding this comment.
Invalidate activation reads when opaque effects are still growing
In a classic script with const log = console.log; function helper() { log('x'); } before an early (0, eval)('createWindow()'), the opaque observer resolves log through semanticBindingAtRead before adding the eval to globalSites (javascriptSemanticOpaqueEffects.ts:76-91). That lookup populates this body-only cache from an incomplete opaque-site snapshot; the subsequent append never invalidates it. If webPreferences is initialized after the eval and a bare createWindow() appears later, the cached later read yields hasDefiniteInitializer: true, allowing literal preferences even though eval invokes the function in the temporal dead zone. Populate the cache only after opaque-effect indexing completes, or invalidate it when those facts change.
AGENTS.md reference: AGENTS.md:L50-L52
Useful? React with 👍 / 👎.
| } | ||
| } | ||
| } | ||
| if (name === null) return; |
There was a problem hiding this comment.
Retain activation uncertainty for reflective global reads
With a classic-script Reflect.get(globalThis, 'createWindow')(); before the webPreferences initializer and a bare call afterward, none of the recognized branches records the early function read: the member node is Reflect.get, while the selected property's name is a string argument. The index consequently chooses the later call and sets hasDefiniteInitializer: true, allowing optionObjectCandidate to emit literal preferences even though the early reflective invocation reaches the temporal dead zone, as confirmed by an inert VM control. Account for reflective global-property reads, or retain unknown activation timing rather than treating them as absent.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e4cf01fa4a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| // Callee resolution can query timing during the ambient walk. Source reads | ||
| // stay fixed; consume each newly observed opaque call once without rescanning. | ||
| const sites = state?.opaqueEffects.globalSites ?? []; |
There was a problem hiding this comment.
Include Function constructors in opaque activation timing
In a classic script whose hoisted createWindow captures webPreferences, an early Function('createWindow()')() before the initializer and a bare createWindow() afterward incorrectly establish definite initialization. The early activation never reaches this list: unlike the handled eval case, createSemanticOpaqueGlobalObserver only publishes eval invocations (javascriptSemanticOpaqueEffects.ts:84–89). The index therefore selects the later named call and returns hasDefiniteInitializer: true, although the constructed function reaches webPreferences in the temporal dead zone, as confirmed by an inert VM control. optionObjectCandidate trusts that flag and can publish literal preferences. Extend the owning opaque-effect facts to cover Function-constructor execution, or retain unknown activation timing for such sites.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 13f5340e8b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const classicScript = | ||
| t.isProgram(program) && program.sourceType === "script"; |
There was a problem hiding this comment.
Use parser-owned runtime context for global activation checks
For an unknown-context TypeScript source containing import type { T } from './types', an early globalThis.createWindow() before webPreferences initialization, and a later bare createWindow(), Babel's syntactic classification can be module while REA's javaScriptRuntimeContext remains unknown. This gate discards the early global read and establishes definite initialization, allowing literal preference evidence even when the type-stripped source executes as a classic script and reaches the temporal dead zone. Use the parser-owned runtime-context fact and retain possible global activation when isolation is unknown, rather than deriving runtime isolation from Babel's syntax classification.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| classicScript && | ||
| (t.isCallExpression(node) || | ||
| t.isOptionalCallExpression(node) || | ||
| t.isNewExpression(node)) |
There was a problem hiding this comment.
Include direct eval in ES module activation bounds
In an ES module such as export {}; eval('open()'); const make = () => 1; function open() { return make(); } open();, direct eval invokes open while make is still in the temporal dead zone. Because opaque positions are recorded only for classic scripts, the indexed eval site is ignored and the later bare call makes semanticBindingAtRead return hasDefiniteInitializer: true; collectCallSite consequently reports make() as an exact call despite its uninitialized target. Direct eval can access module lexical bindings, unlike indirect eval or constructed functions, so include the existing scope-owned direct-eval facts in this timing proof.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| for (const initializer of binding.initializers) { | ||
| if (initializer.projection.length > 0) fact.unknown = true; | ||
| else fact.dependencies.push(initializer.node); |
There was a problem hiding this comment.
Reuse receiver-origin summaries across binding references
When a classic script has N assignments to a receiver and N distinct root.document reads, every identifier node misses the node-keyed globalReceivers cache and walks all of the same binding's initializers again. This makes the new first-read index perform N(N+1) initializer visits on a flat, O(N)-size source, even though document cannot name a tracked module function. Building the source index only once therefore still introduces quadratic CPU and allocation growth on generated scripts. Cache the combined receiver-origin fact by binding identity, while preserving separate facts for individual initializer expressions, instead of re-expanding the binding at every member read.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1016f6c9d4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| t.isVariableDeclarator(declaration) && | ||
| declaration.init != null && | ||
| globalReceiver(declaration.init) !== false |
There was a problem hiding this comment.
Include assignment-pattern global function reads
In a classic script with a hoisted createWindow capturing webPreferences, let start; ({ createWindow: start } = globalThis); start(); before the const initializer still invokes the function in the temporal dead zone. The new branch accepts only VariableDeclarator patterns, so it discards this early property read; a later bare createWindow() then makes hasDefiniteInitializer true, allowing optionObjectCandidate to publish literal preferences incorrectly. Consume the existing semanticPropertyReadSources projections, which already cover assignments and for-of patterns, or preserve unknown activation timing for these reads.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| if (t.isStatement(enclosingFunction)) | ||
| return statementPosition(enclosingFunction, parents); |
There was a problem hiding this comment.
Cache each enclosing function's statement position
For a flat source with M top-level statements and N captured-const reads inside a function near the end, every semanticBindingAtRead call repeats this lookup. statementPosition scans parent.body with indexOf, adding O(M×N) work even though the enclosing-function ownership and first-read index are cached. resolveLocalCallables reaches this path for every distinct captured call-target identifier, so an O(M+N)-size generated source can incur quadratic work that the previous path avoided. Cache the immutable function position alongside the enclosing-function facts, or index statement positions once per body.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b8594a6c8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (t.isIdentifier(node) && globalCodeRoots.has(node.name)) | ||
| state.opaqueEffects.mayReferenceGlobalCode = true; |
There was a problem hiding this comment.
Preserve opaque activations reached through script
this
In a classic script with no other globalCodeRoots identifiers, this['Function']('createWindow()')() before the captured webPreferences initializer activates the function in the TDZ, as confirmed with an inert VM. Unlike the now-covered bare-Function case, this identifier-free form never enables the opaque observer. A later bare createWindow() consequently establishes definite initialization incorrectly, allowing Electron's option resolver to emit literal preferences for the uninitialized capture. Recognize script-this global-code origins through both this prefilter and the ambient origin resolver, or retain unknown activation timing.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| !t.isCallExpression(node) && | ||
| !t.isOptionalCallExpression(node) && | ||
| !t.isNewExpression(node) |
There was a problem hiding this comment.
Include tagged Function construction in opaque activation timing
In a classic script, Function used as a tag—Function followed by the template literal createWindow() and then ()—constructs and immediately executes the early call, producing a TDZ error when placed before the captured options initializer. This newly checked tagged-template form is forwarded by collectJavaScriptIdentityWritesSteps, but this guard drops it, and moduleFunctionFirstRead also omits tagged templates from opaquePositions. A later bare createWindow() therefore yields hasDefiniteInitializer: true and permits literal preferences despite the early activation. Carry tagged Function construction through both the shared opaque-site facts and their timing projection.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| } | ||
| let name: string | null = null; | ||
| if ( | ||
| t.isIdentifier(node) && |
There was a problem hiding this comment.
Count JSX component references when indexing function activation
For supported JSX/TSX inputs, <Component /> passes the hoisted component to the JSX factory through a JSXIdentifier, so this Identifier gate ignores that early reference. With an eager factory such as /** @jsx h */ function h(C) { return C(); }, placing that JSX before const make = () => 1; function Component() { return make(); } Component(); activates the component while make is uninitialized. The index instead selects the final bare call and marks the capture definitely initialized, allowing collectCallSite to report an exact target for the TDZ read. Record lexically resolved JSX component references as possible escapes, or keep their activation timing unknown.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| const selected = staticObjectProperty(receiver, String(key)); | ||
| receiver = | ||
| selected.status === "explicit" ? selected.value : undefined; | ||
| if (receiver === undefined) break; | ||
| } | ||
| if ( | ||
| receiver !== undefined && | ||
| globalReceiver(receiver) === false | ||
| ) | ||
| continue; |
There was a problem hiding this comment.
The new check trusts the original nested property even when an earlier getter replaces it during destructuring. For example, place this before webPreferences initialization:
const { x, nested: { createWindow: start } } = {
get x() { this.nested = globalThis; return 0; },
nested: { createWindow() {} },
};
start();In a classic script, start() calls the global createWindow before its captured constant is initialized. But staticObjectProperty selects the original nested literal, and globalReceiver(receiver) === false skips that early read. A later bare createWindow() can then make Electron preferences look definite even though the earlier call throws.
Keep the read uncertain unless the selected receiver is proven unchanged by earlier pattern reads. AGENTS.md requires identity and uncertainty to survive these boundaries; the original literal alone does not prove the receiver at this read.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticMutationInitializers.ts
Line: 1077-1086
Comment:
**Getters hide early calls**
The new check trusts the original nested property even when an earlier getter replaces it during destructuring. For example, place this before `webPreferences` initialization:
```js
const { x, nested: { createWindow: start } } = {
get x() { this.nested = globalThis; return 0; },
nested: { createWindow() {} },
};
start();
```
In a classic script, `start()` calls the global `createWindow` before its captured constant is initialized. But `staticObjectProperty` selects the original nested literal, and `globalReceiver(receiver) === false` skips that early read. A later bare `createWindow()` can then make Electron preferences look definite even though the earlier call throws.
Keep the read uncertain unless the selected receiver is proven unchanged by earlier pattern reads. `AGENTS.md` requires identity and uncertainty to survive these boundaries; the original literal alone does not prove the receiver at this read.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9e845f7e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const path = t.isNewExpression(node) | ||
| ? interop.intrinsicPath(node.callee) | ||
| : interop.intrinsicInvocation(node)?.path; |
There was a problem hiding this comment.
Normalize constructor targets before indexing opaque activations
When placed before a captured const initializer in a classic script, both const F = Function.bind(null); new F('open()')(); and Reflect.construct(Function, ['open()'])(); can activate the hoisted open in the temporal dead zone, yet neither reaches globalSites. The new NewExpression branch bypasses boundIntrinsic, while the ordinary invocation normalizer leaves Reflect.construct as the target. A later bare open() therefore establishes definite initialization, allowing collectCallSite to label a captured make() target exact despite its uninitialized binding. Resolve constructor targets through shared invocation facts, or retain unknown activation timing rather than relying solely on the nominal callee path.
AGENTS.md reference: AGENTS.md:L21-L21
Useful? React with 👍 / 👎.
| if ( | ||
| binding.initializers.length === 0 || | ||
| binding.referenceInitializers.length > 0 | ||
| ) | ||
| fact.unknown = true; |
There was a problem hiding this comment.
Include post-allocation receiver effects in activation timing
For a classic script such as const root = {}; Object.setPrototypeOf(root, globalThis); root.open(); const make = () => 1; function open() { return make(); } open();, this summary follows only the binding initializer and concludes that root is unrelated. Unlike the now-covered prototype/spread initializers, the post-allocation prototype change never enters the summary; Object.assign(root, globalThis) has the same problem. The early root.open() is consequently discarded, and the final bare call makes the capture definitely initialized, allowing collectCallSite to report make() as exact despite the early TDZ read. Consume the receiver's owned mutation/escape facts, or retain uncertainty instead of proving isolation from its allocation alone.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| for (const effect of [...binding.memberWrites, ...binding.escapedPaths]) { | ||
| if ( | ||
| effect.node !== undefined && | ||
| semanticReadPrecedesEffectWithinActivation(read, effect.node, parents) | ||
| ) | ||
| continue; | ||
| if (semanticEffectTiming(read, effect.node, state) !== "after") | ||
| return null; |
There was a problem hiding this comment.
Unrelated writes hide preferences
receiverAtRead treats every earlier member write as a possible change to the method being read. In a classic script, const other = { createWindow() {} }; other.unrelated = 1; other.createWindow(); before webPreferences initialization now counts as an early read of the module's separate createWindow. The later real call loses its proven preferences, although the unrelated method cannot activate that function.
Check whether the recorded path can change the selected method or its lookup before dropping the receiver proof. AGENTS.md requires consumers to preserve identity across boundaries. This requirement must be satisfied before merging.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptSemanticMutationInitializers.ts
Line: 1028-1035
Comment:
**Unrelated writes hide preferences**
`receiverAtRead` treats every earlier member write as a possible change to the method being read. In a classic script, `const other = { createWindow() {} }; other.unrelated = 1; other.createWindow();` before `webPreferences` initialization now counts as an early read of the module's separate `createWindow`. The later real call loses its proven preferences, although the unrelated method cannot activate that function.
Check whether the recorded path can change the selected method or its lookup before dropping the receiver proof. `AGENTS.md` requires consumers to preserve identity across boundaries. This requirement must be satisfied before merging.
**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e13c376f13
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| t.isCallExpression(node) && | ||
| state?.opaqueEffects.sites.has(node) |
There was a problem hiding this comment.
Include intrinsic-valued local eval in lexical activation facts
In a non-strict .cjs file, const eval = globalThis.eval; eval('open()'); const make = () => 1; function open() { return make(); } open(); invokes open while make is in the TDZ. Unlike the fixed unshadowed-eval case, indexSemanticOpaqueEffects rejects this local binding at javascriptSemanticOpaqueEffects.ts:26, while opaquePositions excludes CommonJS global sites. The later bare call consequently makes hasDefiniteInitializer true and lets collectCallSite label make() exact. Preserve this direct-eval identity in the owning lexical facts, or retain unknown activation timing, rather than relying only on unshadowed globals.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| invocationSite = node; | ||
| const invocation = interop.intrinsicInvocation(node); | ||
| if (invocation?.path.join(".") === "intrinsic.global.eval") | ||
| const path = interop.intrinsicInvocation(node)?.path; |
There was a problem hiding this comment.
Resolve stored constructor aliases before trusting activation bounds
In a classic script, const box = {}; box.run = Function; box.run('open()')(); before const make = () => 1; function open() { return make(); } open(); activates the hoisted function in the TDZ. Unlike an initializer alias such as {run: Function}, this post-allocation store is not resolved: the observer creates createAmbientPathResolver(state, true) without the stored-value facts available to the ambient-write resolver, so box.run yields no intrinsic path and the activation never enters globalSites. The later bare open() therefore makes the capture definite and allows collectCallSite to label make() exact. Reuse the owning stored-value facts instead of treating the unresolved callable origin as absent.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
Superseded by #8749 at the author's request: #8749 . Same published branch/HEAD; original discussion and historical validation are preserved below.
Constructor and receiver-effect timing correction
Normalize bound constructors and Reflect.construct through the shared intrinsic invocation owner. Receiver allocation identity stays cached separately from source-owned read-time effects; recompute module read bounds after the member-effect inventory completes. This retains early TDZ uncertainty for post-allocation Object.assign/setPrototypeOf while preserving unrelated own-method and nested-literal controls.
Validation: baseline four VM-backed early/late regressions failed; 252/252 tests across nine files now pass, including actual compiled CLI/stdio MCP cases, cycle check, identity and long-alias controls. check:fast 2/2 (31.93s), all eight local files byte-exact after hooks. Exact-context patch preserves integrated upstream contents; the complete remote integrated tree still needs fresh hosted CI.
Runtime-read and import-cycle correction
Pure copied-reference paths now have a separate owner, removing the Source/Portable test import cycle. Shared static property selection preserves unrelated nested receiver identity; erased TypeScript reads no longer activate module functions.
Validation: 231/231 tests across eight files including unchanged cycle checks and compiled CLI/stdio MCP; check:fast 2/2 (22.329s). All nine local files byte-exact after hooks. Two integrated upstream files preserve their remote contents with import-only migration. The full integrated remote tree was not locally rerun; fresh hosted CI is required.
Problem and outcome
Keep module-level Electron const options uncertain when a hoisted function can be read or activated before initialization. Use parser-owned runtime context, lexical direct-eval facts and conservative global-code bounds rather than Babel syntax alone.
Pattern property reads now come from the existing
semanticPropertyReadSourcesowner, covering declarations, assignment destructuring and for-of patterns. The specialized declarator-only decoder is removed. Nested/iteration projections without a disjointness proof retain possible activation rather than proving global isolation. Ordinary unrelated receiver controls remain.Immutable enclosing-function positions are cached with the existing parent-map facts. The shared source-read index, incremental opaque effects and per-binding receiver summaries remain; distinct initializer identities are preserved.
Validation and limits
check:fast: 2/2 passed in 56.193s.5b8594a6c806d0fd7dc9386f38f3ea7ba47d7f5c; new hosted CI pending. Previous complete green runs cover earlier heads only. Human declarations remain intact, and no target Electron application execution is claimed.Earlier validation records and scope limits
Runtime-context and lexical-eval corrections
Use the parser-owned runtime context for hoisted-function global activation: erased TypeScript imports do not establish module isolation. Include the already indexed, scope-owned direct-eval sites in initialization timing even in ESM/CommonJS; indirect eval and Function construction retain their separate global-visibility rules.
Receiver summaries now share a representative by binding identity while keeping initializer-expression identities separate. Repeated member reads reuse the same initializer summary instead of expanding the binding again.
Validation: previous producer fails both new P1 regressions (2 failed / 114 passed); the fixed final selection passes 217 tests in seven complete files, including compiled CLI/stdio MCP TypeScript and ESM fixtures, lexical early/late controls and prior identity/alias/opaque-effect cases. Independent Node ESM controls throw ReferenceError before initialization and return 1 after initialization.
check:fastpasses 2/2 in 29.693s.The owned diagnostic for 64/128/256 receiver reads recorded 4160/16512/65792 initializer visits before and 65/129/257 after. This establishes removed repeated expansion; one warm in-process sample per size does not establish general end-to-end speed or memory improvement. Logs include wall time, CPU and cumulative process peak RSS. No probe instrumentation is committed.
Current head:
1016f6c9d433727e1cc3b2ef8dba1461458958bb; new hosted CI pending. All four changed files match the checked local bytes after hooks. Upstream's existing call-site presence assertion is preserved. Other checkout files remain from earlier integration, so complete current-tree validation still requires hosted CI. The ESM positive public control omits opaque eval because eval may mutate the options object even after initialization; the dedicated lexical-binding regression separately checks early versus late direct-eval ordering.Problem and outcome
Keep hoisted Electron option reads uncertain when classic-script global code may activate the function before its captured const is initialized. The shared opaque-global observer now recognizes Function construction as well as eval through the existing global identity and intrinsic call owner, including
new, aliases, call/apply and bound calls. Local shadowed constructors retain definite options.Constructed code may escape, so construction supplies a conservative possible-activation bound. This does not assert that merely creating a function executed it; unused constructed functions can therefore retain uncertainty. No source strings or target Electron programs are executed by the analyzer.
The source timing index remains shared and incremental. Internal discovery facts now name global code rather than eval alone; call positions and retained effect facts include constructor nodes.
Validation and limits
npm run check:fast: 2/2 passed in 43.954s. Precommit preserved all six checked files byte-for-byte.13f5340e8bfe199766d6af982ff4342520a11626. New hosted CI is pending; the previous head's full CI success does not cover this push.Earlier evidence and verification limits
Problem and outcome
Hoisted Electron functions could treat module-level const options as initialized despite an earlier possible classic-script activation. Preserve uncertainty for early global aliases, destructuring, logical assignment, prototype/spread receivers and indirect eval; retain concrete values where initialization is actually ordered.
The shared initializer owner builds the source-read index once. It records possible call positions during that walk, then consumes newly observed opaque global calls incrementally. This keeps callee-resolution prewarming from freezing incomplete timing facts and avoids rebuilding the entire source index after each eval. Existing per-node receiver facts, unrelated-object controls and function-boundary rules remain.
Validation and limits
npm run check:fastpassed 2/2 in 62.068s.e4cf01fa4a9ccfa766c5ad9427be4fd0c40f60c3; new hosted CI pending. Existing human declarations are preserved. No target Electron application was executed, and no new real-platform/provider coverage is claimed.Earlier validation records and execution limits
Current CI integration — 2026-11-03
Current head:
e2e3576f238df648d9fd714b1425d0769a9be153. The first cache-fix run failed only the formatting gate: Static checks identifies the upstreamwebsite/wrangler.tomlwatch-directory array. The same exact blob (7c64886b3005bda755a580e36eb058d3f84d7755) exists on maind496d803a4f50dc82248db0630042894c1136d00. Integrated that main normally, preserving its GitHub-computed merge tree, then applied only the formatter's array wrapping. TOML parsing before/after produces identical values; the exact affected file fails formatting before and passes afterward. #7716 already contains the same incidental gate correction, so no duplicate standalone PR was opened.The 126 tests and check:fast below cover the local cache correction before upstream integration. The full integrated tree has not been rerun locally; its new hosted CI is pending. No runtime/configuration values or test expectations were weakened.
Activation-cache lifetime correction — 2026-11-03
Callee resolution could populate module-function timing before the ambient observer had recorded a later indirect eval. That stale cache then incorrectly treated an early classic-script function call as occurring after const initialization. Cache entries now include the append-only opaque-global-site count and are rebuilt when that producing index grows; unchanged effect prefixes still reuse the shared timing facts.
Reproduction against the previous published producer: 1 failed / 77 passed, including a VM-backed early-throw / late-success control. Fixed validation: 126 passed in four complete files, including compiled CLI and stdio MCP coverage of this cache-prewarming case;
npm run check:fastpassed 2/2 in 31.009s. Existing unrelated-object, late-call and 6000-alias controls remain. No performance improvement or new real Electron runtime claim. Current head:c347f9ad462f812a128a514dc35954b370c3d10d; its new hosted CI is pending. Precommit only wrapped a condition; remote tree exactly matches the committed local tree.Projected and opaque activation correction — 2026-11-03
Retain classic-script function reads through global destructuring, logical assignment, prototype/spread receivers and opaque global eval. Reuse the shared write-read and opaque-effects facts. Receiver aliases now use an iterative per-node postorder cache: each initializer retains its own answer, cycles stay uncertain, and shared alias prefixes are reused.
Previous production fails all five new VM-backed cases (5 failed / 72 passed). Fixed focused validation passes 123 tests in four complete files, including compiled CLI/stdio MCP; final option grouping passes 77 tests. The 6000-alias control now reads every intermediate receiver. check:fast passes 2/2 in 36.912s. Precommit removed one blank line only; production and assertions remain the tested bytes. No measured performance speedup is claimed. Fresh hosted CI is required for this HEAD.
Receiver identity follow-up — 2026-11-02
An alias with both an ordinary object and the global object as possible origins previously cached its combined answer on the ordinary object's initializer. A later unrelated method call then incorrectly made safely initialized Electron preferences dynamic. Cache the combined answer only on the queried receiver. Unknown computed global properties now share one earliest-read/uncertainty fact, applied to module functions once after the source scan, removing the repeated function scan per access.
The strengthened unrelated-object runtime control passes while the previous production code fails its static assertion (1 failed / 71 passed). Fixed four-file focused validation: 118 passed, including compiled CLI and stdio MCP; all 3 prerequisite tasks pass.
check:fast: 2/2 passed, 45.104s. No measured performance speedup is claimed. This new HEAD requires fresh hosted CI.Latest conservative activation correction
The previous correction still missed classic-script receiver projections, computed global keys and uncertain with-scope binding ownership. The shared first-activation owner now keeps these possible reads in its timing bound instead of treating unsupported identity as absence. Aliases use an iterative visited-node worklist with conservative cached may-alias results, so alias depth does not become JavaScript recursion depth. Callback statement lookup stops at intervening functions, including hoisted default-parameter callbacks. Existing unrelated object and shadowed-local controls remain.
Executed evidence: replacing only the production owner with the previous committed version causes 5 failures / 67 passes in the expanded option file; restoring the final owner yields 118 passing tests across options, initializer ordering, call resolution and actual compiled CLI/stdio MCP, plus 277 passing sibling binding/loader/fingerprint tests. check:fast passed 2/2 in 41.573s; diff check passed. A 6000-link flat alias fixture passes; it also passed on the previous version on this host, so stack exhaustion is source-supported rather than reproduced. No target source was executed by static analysis. Real Electron/platform coverage remains limited as recorded below.
Current HEAD:
507b50a97ca70bab1e25bbb3c201aff1097c522c. Hosted code CI for this new head is pending; previous green checks below belong to previous heads. Human declarations are preserved. No review thread was replied to or resolved.Supersedes #8634 at the author's explicit request to resubmit all current PRs. Same published branch and HEAD 4cd804c. Original discussion and historical validation remain at #8634. This new PR requires its own hosted CI and new human declarations for this PR ID.
Current review correction
Current HEAD:
4cd804cbcc17dc76f02c27f327f577d2fc7b3665.Reproduced the global-object-alias early-call case and the unrelated same-named parameter case (3 new cases failed on the prior head). The shared initializer timing owner now consumes existing lexical binding state: identifier reads match the actual function binding, and classic-script global receivers follow binding-owned initializer aliases with a cycle guard. All production callers now pass their existing analysis state rather than only its parent map; low-level parent-map-only tests retain their API. No target source is executed by analysis. Validation: 112 passed across initializer, call-resolution, Electron options and compiled CLI/stdio MCP files, plus 277 sibling binding/loader/fingerprint cases; check:fast 2/2 passed (43.349s). The VM controls confirm the early alias call reaches the temporal dead zone while the late control succeeds. These are synthetic source/VM and actual compiled CLI/MCP checks, not a real Electron application run.
The new HEAD requires its own hosted CI; earlier green runs below belong to earlier commits. Existing human declarations remain in force. The original replacement description and its execution points follow as historical context.
Supersedes #8495 at the author's explicit request to resubmit all current PRs. Same published branch and HEAD
9611e5cbe8d0d3639f87df529d2989e69a63d1f2. Original discussion and historical validation remain at #8495. This new PR requires its own hosted CI and a new human declaration for this PR ID; prior review declarations are historical.Supersedes #8250 at the author's explicit request to resubmit the existing PRs. This replacement reuses the identical published head
cc2bb1242a5611527bfb99935bc7dbcf85e902f7and full three-file patch. Prior discussion and historical verification remain at #8250 (earlier #8087). No code changes or new local test runs were made for this resubmission. This new PR requires its own hosted CI. The owner has specifically confirmed review of this replacement PR's final diff, evidence, limitations and unresolved P1, accepted full responsibility, and approved it for initial maintainer review. The P1 remains a before-merge blocker.Outstanding review follow-up — addressed in the current published revision
The known P1 review finding was addressed in the current head. In a classic script, an early
globalThis.createWindow()followed by a later bare call can make module-constant initialization appear definite even though the early activation encounters the temporal dead zone. The previously reported 115-test verification below does not establish that this additional case is fixed.A separate local draft follow-up has 67 focused tests and three build tasks passing, plus
check:fast; expanded verification and commit/push are not complete. That draft is not part of this PR's published commit or diff, and those draft results are not claimed as a fix in this revision. The prior finding is covered by the current-head regression; hosted CI and maintainer review still apply; the original review is preserved rather than marked resolved.Supersedes #8087 at the author's request. This replacement reuses verified head cc2bb12 and preserves the original discussion and validation record at #8087. Historical revision-specific validation below remains at its stated execution points. This new PR must pass its own hosted CI.
Problem and resulting behavior
Fixes #7227. Electron static analysis loses module-level immutable
webPreferencesread inside a later activation. Retain those settings when initialization precedes the function's module-level uses, while preserving uncertainty when a hoisted function can run earlier.For example, this source must remain dynamic rather than report a proven
nodeIntegration: true:Moving the call after the const initializer yields
object-literalwith the literal setting, including when the function declaration appears before the initializer.Owning change and scope
Initialization coverage stays in
javascriptSemanticMutationInitializers.ts; Electron consumers use that fact without reinterpreting declaration order. A hoisted declaration's position does not prove activation timing. The owner indexes module-level function references once per immutable module body and treats earlier aliases, indirect activations, live exports and unproven timing conservatively. This is a bounded reference-order check, not a general call graph or runtime execution proof.The existing ancestry cache also retains the enclosing function, avoiding repeated walks from deep reads. Initialization coverage remains separate from cross-function capture ordering: the latter stays unresolved so named child-process argv shapes retain their existing uncertainty. No public schema, provider, execution authority, deadline, resource ceiling or assertion was weakened.
Validation at the current follow-up
Windows, Node 24.22.1 / npm 11.16.0:
fb2532ad61ceb4cce7d233131fc1edd4305925ff, with the new source regressions: 4 failed / 47 passed. Three cases expose early direct, aliased and forwarding calls; the fourth exposes a late-call positive control.9bafc838629358fb8ebc0ce86abefa5c82c8a0ab: 112/112 passed across six complete files: Electron options 51, existing scope-depth/resource controls 14, binding initializers 13, argument shapes 30, existing child-process compiled CLI/stdio MCP 2, and new Electron initialization compiled CLI/stdio MCP 2. Three build prerequisite tasks passed.The earlier head's independent hosted CI passed, but it did not cover this hoisted-declaration review case. The new head requires its own hosted CI; an earlier green run does not validate it. Local checks use synthetic JavaScript through production static analysis and real local compiled CLI/stdio MCP. No real Electron application or Linux/macOS execution is claimed.
Loop ownership review follow-up
Commit
cc2bb1242a5611527bfb99935bc7dbcf85e902f7keeps enclosing-function identity in its own immutable ancestry cache. Loop ordering remains uncertain; entering a loop no longer erases which function owns the read. This retains initialized module-level Electron settings inside for-of, for and while loops while keeping early calls dynamic. No downstream reinterpretation or call graph expansion was added.On exact preceding head
9bafc838, the three new loop source cases fail while the existing 51 pass. With the correction, six complete files pass 115/115 (Electron 54, scope-depth 14, initializers 13, shapes 30, existing child-process CLI/MCP 2, Electron initialization CLI/MCP 2). The public adapter cases include both early and late calls inside loops and outside loops, with source provenance. All three committed files match the tested bytes exactly after normal precommit hooks. Three build tasks passed; normal prepush typecheck/lint passed 2/2, 46.166 seconds. No assertions or resource controls were relaxed.The earlier
9bafc838own hosted workflow41009833080completed successfully; the newcc2bb124head requires independent hosted validation. Validation uses synthetic inert JavaScript and real local compiled CLI/stdio MCP on Windows, Node 24.22.1 / npm 11.16.0; no real Electron application or Linux/macOS run is claimed.Author readiness
Human owner: @ShuaixinHuang
Before merge
type(scope): outcome.Current-head P1 correction
Commit
9611e5cbe8d0d3639f87df529d2989e69a63d1f2covers the classic-script global activation case. Focused domain and CLI/stdio MCP validation passed 67/67 tests;check:fastpassed 2/2. The local regression covers early and lateglobalThis/window/self/thisactivations without expanding call-graph or authority semantics.This replacement preserves the prior PR discussion and validation history at #8331. It reuses the verified published head and requires its own hosted CI.