mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 06:04:03 +00:00
fix(javascript): observe shared array iterator prototype effects (#12493)
* fix(javascript): observe shared array iterator prototype effects * fix(javascript): follow iterator escapes and projected receivers * fix(javascript): retain packed prototype reads and receiver captures * fix(javascript): treat proven prototype inspections as read-only * fix(javascript): retain ordinary array destructuring read dependencies (#12505)
This commit is contained in:
1 parent
6cbd9cf994
commit
50913e3ba0
10 files changed
+927
-168
No files matched your search
@@ -8,7 +8,7 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"retains earlier property dependencies through analysis and default tracing",
|
||||
"traces proved destructuring dependencies and leaves custom iteration uncertain",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-js-destructuring-evidence-",
|
||||
@@ -26,6 +26,27 @@ cliTest(
|
||||
const { a: [plain] } = nested;
|
||||
const { a: [fallback] = [] } = nested;
|
||||
const { b: scalar = 0 } = nested;
|
||||
const previous = { items: new Map() };
|
||||
const captured = previous.items;
|
||||
previous.items = [];
|
||||
Object.getPrototypeOf(captured.values()).next = () => ({ done: true });
|
||||
Reflect.apply(Reflect.getPrototypeOf, null, [[].values(), [].values()]);
|
||||
const sourcePrototype = Object.getPrototypeOf([].values());
|
||||
Object.getPrototypeOf(sourcePrototype);
|
||||
const before = ["first"];
|
||||
const [ordinary] = before;
|
||||
let arrayAssigned;
|
||||
[arrayAssigned] = before;
|
||||
before[0] = "later";
|
||||
const box = { items: [] };
|
||||
const iterator = box.items.values();
|
||||
const prototype = Reflect.getPrototypeOf(iterator);
|
||||
Object.defineProperty(prototype, "next", {
|
||||
value: () => ({ value: "other", done: false }),
|
||||
});
|
||||
const after = ["second"];
|
||||
let selected;
|
||||
[selected] = after;
|
||||
`,
|
||||
);
|
||||
const output = await cli.run({
|
||||
@@ -36,12 +57,15 @@ cliTest(
|
||||
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
|
||||
.parse(output.json);
|
||||
const graph = result.semantic_graph;
|
||||
for (const [name, path] of [
|
||||
for (const [name, path, resolution = "resolved"] of [
|
||||
["declared", ["a"]],
|
||||
["a", ["a"]],
|
||||
["plain", ["a", "0"]],
|
||||
["fallback", ["a", "0"]],
|
||||
["scalar", ["b"]],
|
||||
["ordinary", ["0"]],
|
||||
["arrayAssigned", ["0"]],
|
||||
["selected", ["0"], "candidate"],
|
||||
] as const) {
|
||||
const binding = graph.nodes.find(
|
||||
(node) => node.kind === "binding" && node.label === name,
|
||||
@@ -53,43 +77,54 @@ cliTest(
|
||||
relation.target_node_id === binding?.node_id,
|
||||
);
|
||||
expect(relations).toHaveLength(1);
|
||||
expect(relations[0]?.resolution).toBe("resolved");
|
||||
expect(relations[0]?.resolution).toBe(resolution);
|
||||
expect(
|
||||
graph.nodes.find(
|
||||
(node) => node.node_id === relations[0]?.source_node_id,
|
||||
)?.properties.property_path,
|
||||
).toEqual(path);
|
||||
}
|
||||
const directRead = graph.nodes.find(
|
||||
({ kind, label }) => kind === "expression" && label === "read:/a",
|
||||
);
|
||||
expect(
|
||||
graph.relations.find(({ relation }) => relation === "reads-property"),
|
||||
graph.relations.find(
|
||||
({ relation, target_node_id }) =>
|
||||
relation === "reads-property" &&
|
||||
target_node_id === directRead?.node_id,
|
||||
),
|
||||
).toMatchObject({ resolution: "resolved" });
|
||||
const declared = graph.nodes.find(
|
||||
({ kind, label }) => kind === "binding" && label === "declared",
|
||||
);
|
||||
const queryPath = join(root, "query.json");
|
||||
await writeFile(
|
||||
queryPath,
|
||||
JSON.stringify({
|
||||
application: output.json,
|
||||
query: {
|
||||
seed: { kind: "semantic-node", node_id: declared?.node_id },
|
||||
direction: "backward-provenance",
|
||||
for (const name of ["declared", "ordinary", "arrayAssigned", "selected"]) {
|
||||
const binding = graph.nodes.find(
|
||||
({ kind, label }) => kind === "binding" && label === name,
|
||||
);
|
||||
await writeFile(
|
||||
queryPath,
|
||||
JSON.stringify({
|
||||
application: output.json,
|
||||
query: {
|
||||
seed: { kind: "semantic-node", node_id: binding?.node_id },
|
||||
direction: "backward-provenance",
|
||||
},
|
||||
}),
|
||||
);
|
||||
const trace = await cli.run({
|
||||
arguments: ["trace-javascript-semantics", queryPath, "--json"],
|
||||
});
|
||||
expect(trace.exitCode, trace.stderr).toBe(0);
|
||||
const relation = {
|
||||
normalized_result: {
|
||||
relations: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
relation: "destructures",
|
||||
target_node_id: binding?.node_id,
|
||||
}),
|
||||
]),
|
||||
},
|
||||
}),
|
||||
);
|
||||
const trace = await cli.run({
|
||||
arguments: ["trace-javascript-semantics", queryPath, "--json"],
|
||||
});
|
||||
expect(trace.exitCode, trace.stderr).toBe(0);
|
||||
expect(trace.json).toMatchObject({
|
||||
normalized_result: {
|
||||
relations: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
relation: "destructures",
|
||||
resolution: "resolved",
|
||||
}),
|
||||
]),
|
||||
},
|
||||
});
|
||||
};
|
||||
if (name === "selected") expect(trace.json).not.toMatchObject(relation);
|
||||
else expect(trace.json).toMatchObject(relation);
|
||||
}
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user