mirror of
https://github.com/morluto/rea.git
synced 2026-10-28 18:35:53 +00:00
fix(javascript): invalidate Electron reads after direct eval (#7053)
This commit is contained in:
1 parent
69a2faa120
commit
26e155987f
6 files changed
+308
-5
No files matched your search
@@ -1,6 +1,9 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
|
||||
import { onlyCallable } from "./javascriptSemanticAnalysis.fixture.js";
|
||||
import {
|
||||
onlyBinding,
|
||||
onlyCallable,
|
||||
} from "./javascriptSemanticAnalysis.fixture.js";
|
||||
const returned = (body: string) =>
|
||||
onlyCallable(analyzeJavaScriptSemantics(body), "run").returnSites[0]?.value;
|
||||
|
||||
@@ -20,6 +23,23 @@ it.each([
|
||||
expect(returned(source)).toMatchObject({ status: "unknown" });
|
||||
});
|
||||
|
||||
it("retains uncertainty for outer function declarations across eval-bearing calls", () => {
|
||||
const ir = analyzeJavaScriptSemantics(
|
||||
'function value(){} function run(){const saved=value;eval("value=2");return saved;} run();run();',
|
||||
);
|
||||
expect(onlyBinding(ir, "saved").provenance.status).toBe("ambiguous");
|
||||
});
|
||||
|
||||
it.each(["||=", "??="])(
|
||||
"does not treat %s as a fresh reset before eval",
|
||||
(operator) => {
|
||||
const ir = analyzeJavaScriptSemantics(
|
||||
`let value; function run(){value ${operator} 1;const saved=(0,value);eval('value=require("node:fs")');return saved;}run();run();`,
|
||||
);
|
||||
expect(onlyBinding(ir, "saved").provenance.status).toBe("ambiguous");
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
'eval("var value=2"); function run(){const value=1;return value;}',
|
||||
'export function run(){const value={n:1};const saved=value.n;eval("value.n=2");return saved;}',
|
||||
|
||||
Reference in new issue
Block a user