Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

test(javascript): verify escaped receivers through CLI and MCP

Ysopwnablef9ce32b47490
diff --git a/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts b/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts
index bf7d35c47..11bf30d0b 100644
--- a/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts
+++ b/src/domain/javascript/javascriptSemanticAnalysis.member_mutations.test.ts
@@ -628,7 +628,7 @@ describe("results of methods on an escaped receiver", () => {
});
});
- it("expands a receiver's methods once rather than once per call (#1495)", () => {
+ it("keeps a shared result uncertain across a wide escaped receiver (#1495)", () => {
const count = 2000;
const methods = Array.from(
{ length: count },
@@ -638,11 +638,9 @@ describe("results of methods on an escaped receiver", () => {
{ length: count },
(_, index) => `box.m${index}().p${index} = ${index};`,
).join(" ");
- const start = performance.now();
const value = resultValue(
`const shared = { token: "TOKEN" }; const box = { ${methods} }; ${calls} return [shared.token];`,
);
- expect(performance.now() - start).toBeLessThan(2000);
expect(value).toMatchObject({
status: "array",
items: [{ value: { status: "unknown" } }],
diff --git a/tests/acceptance/applications/javascriptReturnedReferences.test.ts b/tests/acceptance/applications/javascriptReturnedReferences.test.ts
index bd9a05c76..d9f4c324b 100644
--- a/tests/acceptance/applications/javascriptReturnedReferences.test.ts
+++ b/tests/acceptance/applications/javascriptReturnedReferences.test.ts
@@ -47,6 +47,10 @@ const writes = {
constructor:
"function Box() { return shared; } const t = new Box(); t.x = 2;",
callback: "const get = () => shared; [0].forEach(() => { get().x = 2; });",
+ wideMethods: `const box = { ${Array.from(
+ { length: 64 },
+ (_, index) => `m${index}() { return shared; }`,
+ ).join(", ")} }; box.m0().x = 2; box.m63().other = 3;`,
};
const source = [
...Object.entries(writes).map(
@@ -61,6 +65,8 @@ const source = [
"export function unused(){ const shared = {x: 1}; const get = () => shared; get(); return shared.x; }",
"export function nestedCallable(){ const shared = {x: 1}; const get = () => { const inner = () => shared; return {x: 0}; }; get().x = 2; return shared.x; }",
"export function unrelated(){ const shared = {x: 1}; const other = {x: 9}; const get = () => shared; get().x = 2; return other.x; }",
+ "export function receiverDistinctScopes(){ const shared = {x: 1}; const box = {outer(){ return shared; }, inner(){ const shared = {x: 9}; return shared; }, noop(){}}; box.noop(); return {outer: shared.x, inner: box.inner().x}; }",
+ "export function receiverDistinctPaths(){ const parent = {left: {x: 1}, right: {x: 9}, keep: 7}; const box = {left(){ return parent.left; }, right(){ return parent.right; }, noop(){}}; box.noop(); return {left: parent.left.x, right: parent.right.x, keep: parent.keep}; }",
].join("\n");
const assertReturns = (fields: JavaScriptReturnFields): void => {
@@ -91,6 +97,17 @@ const assertReturns = (fields: JavaScriptReturnFields): void => {
expect(fields("unrelated")).toContainEqual(
expect.objectContaining({ path: "", state: "literal", value: 9 }),
);
+ for (const path of ["/outer", "/inner"])
+ expect(fields("receiverDistinctScopes")).toContainEqual(
+ expect.objectContaining({ path, state: "unknown" }),
+ );
+ for (const path of ["/left", "/right"])
+ expect(fields("receiverDistinctPaths")).toContainEqual(
+ expect.objectContaining({ path, state: "unknown" }),
+ );
+ expect(fields("receiverDistinctPaths")).toContainEqual(
+ expect.objectContaining({ path: "/keep", state: "literal", value: 7 }),
+ );
};
cliTest(