mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
fix(javascript): preserve nested array iterator dependencies (#12558)
* fix(javascript): preserve nested array iterator dependencies * fix(javascript): retain reflected array prototype identity * fix(javascript): guard native arrays with ambient prototype effects Reuse the shared effect-log classifier first prepared for dense inline spread analysis. * test(javascript): keep array prototype alias fixture with sources
This commit is contained in:
1 parent
a035813e55
commit
473b3ee10e
8 files changed
+256
-33
No files matched your search
@@ -42,6 +42,8 @@ import {
|
||||
import {
|
||||
bindingHasMemberWrites,
|
||||
bindingProjectedContentsMayChangeAt,
|
||||
semanticAmbientArrayIterationUnknown,
|
||||
semanticArrayPrototypeIterationMayChange,
|
||||
} from "./javascriptSemanticEffectLog.js";
|
||||
import { semanticContainer } from "./javascriptSemanticSlots.js";
|
||||
import {
|
||||
@@ -126,23 +128,6 @@ interface MutationSelectionContext {
|
||||
|
||||
type ValueEffect = "write" | "escape";
|
||||
|
||||
/** Only replacing or possibly selecting an iterator-bearing prototype slot changes iteration. */
|
||||
const arrayPrototypeIterationMayChange = (path: PropertyPath): boolean => {
|
||||
// Array.prototype and Object.prototype are on native arrays' prototype
|
||||
// chain. Their default constructor.prototype pairs return to the same owner.
|
||||
let offset = 0;
|
||||
while (path[offset] === "constructor" && path[offset + 1] === "prototype")
|
||||
offset += 2;
|
||||
const key = path[offset];
|
||||
return (
|
||||
key === undefined ||
|
||||
key === null ||
|
||||
typeof key === "object" ||
|
||||
semanticArrayIndex(key) !== null ||
|
||||
key === "__proto__"
|
||||
);
|
||||
};
|
||||
|
||||
/** Preserve uncertainty from property writes and references exposed to calls, yielding during traversal and fixpoint iteration. */
|
||||
|
||||
/** Local methods use the same slots, prototype shadowing and array indices as aliases. */
|
||||
@@ -782,7 +767,7 @@ export function* collectSemanticMemberMutationsSteps(
|
||||
recordRequiredEffect("node:process", path.slice(2), "write", node);
|
||||
const selections = new Map<string, readonly string[]>();
|
||||
const coveringPaths = new Map<string, SemanticPropertyPathCoverage>();
|
||||
state.arrayIterationUnknown = false;
|
||||
state.arrayIterationUnknown = semanticAmbientArrayIterationUnknown(state);
|
||||
// Definition collection finishes before this phase, so a scope's bindings no
|
||||
// longer change and one node resolves to one binding. Repeated visits of the
|
||||
// same node otherwise repeat the same scope walk.
|
||||
@@ -1135,14 +1120,16 @@ export function* collectSemanticMemberMutationsSteps(
|
||||
if (
|
||||
(["Array", "Object"].includes(expression.name) &&
|
||||
(current.path[0] === "prototype" || current.path[0] === null) &&
|
||||
arrayPrototypeIterationMayChange(current.path.slice(1))) ||
|
||||
semanticArrayPrototypeIterationMayChange(
|
||||
current.path.slice(1),
|
||||
)) ||
|
||||
(["globalThis", "global", "window", "self"].includes(
|
||||
expression.name,
|
||||
) &&
|
||||
(["Array", "Object"].includes(String(current.path[0])) ||
|
||||
current.path[0] === null) &&
|
||||
(current.path[1] === "prototype" || current.path[1] === null) &&
|
||||
arrayPrototypeIterationMayChange(current.path.slice(2)))
|
||||
semanticArrayPrototypeIterationMayChange(current.path.slice(2)))
|
||||
)
|
||||
state.arrayIterationUnknown = true;
|
||||
if (lookup?.kind !== "uncertain-binding") continue;
|
||||
@@ -1669,10 +1656,10 @@ export function* collectSemanticMemberMutationsSteps(
|
||||
t.isArrayExpression(expression) &&
|
||||
((path[0] === "__proto__" &&
|
||||
(effect === "escape" || path.length > 1) &&
|
||||
arrayPrototypeIterationMayChange(path.slice(1))) ||
|
||||
semanticArrayPrototypeIterationMayChange(path.slice(1))) ||
|
||||
(path[0] === "constructor" &&
|
||||
path[1] === "prototype" &&
|
||||
arrayPrototypeIterationMayChange(path.slice(2))))
|
||||
semanticArrayPrototypeIterationMayChange(path.slice(2))))
|
||||
)
|
||||
state.arrayIterationUnknown = true;
|
||||
const references = referencedValues(
|
||||
|
||||
Reference in new issue
Block a user