Skip to content

Commit 397b124

Browse files
committed
fixup! fix(core): mark functions for optimization before requesting it
1 parent 4b2b6ab commit 397b124

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
import { execFileSync } from "child_process";
22
import path from "path";
33

4-
// The optimization helpers reach V8 natives syntax, so their behaviour only shows
5-
// up in a process started with --allow-natives-syntax. A function optimized
6-
// without being marked for manual optimization first aborts the process on
7-
// V8 >= 14.6, which no in-process assertion can observe.
4+
// A function optimized without being marked for manual optimization first aborts
5+
// the process on V8 >= 14.6, which no in-process assertion can observe. The helpers
6+
// are exercised through the built package so the bundled natives calls are covered.
87
const runWithNatives = (snippet: string): string =>
98
execFileSync(process.execPath, ["--allow-natives-syntax", "-e", snippet], {
109
encoding: "utf8",
1110
});
1211

1312
const corePath = JSON.stringify(path.join(__dirname, ".."));
1413

14+
// %GetOptimizationStatus's bitmask layout shifts between V8 versions, so a
15+
// specific bit isn't safe to assert on. Comparing the status before and after
16+
// the optimize call instead proves TurboFan recompiled the function, without
17+
// depending on what any bit means.
1518
describe("optimization helpers", () => {
16-
it("should optimize a sync function", () => {
19+
it("should optimize a sync function without aborting", () => {
1720
const stdout = runWithNatives(
18-
`require(${corePath}).optimizeFunctionSync(() => 1);
19-
console.log("done");`,
21+
`const target = () => 1;
22+
const before = %GetOptimizationStatus(target);
23+
require(${corePath}).optimizeFunctionSync(target);
24+
console.log("done", before, %GetOptimizationStatus(target));`,
2025
);
26+
const [, before, after] = stdout.match(/done (\d+) (\d+)/) ?? [];
2127
expect(stdout).toContain("done");
28+
expect(after).not.toEqual(before);
2229
});
2330

24-
it("should optimize an async function", () => {
31+
it("should optimize an async function without aborting", () => {
2532
const stdout = runWithNatives(
26-
`require(${corePath})
27-
.optimizeFunction(async () => 1)
28-
.then(() => console.log("done"));`,
33+
`const target = async () => 1;
34+
const before = %GetOptimizationStatus(target);
35+
require(${corePath})
36+
.optimizeFunction(target)
37+
.then(() => console.log("done", before, %GetOptimizationStatus(target)));`,
2938
);
39+
const [, before, after] = stdout.match(/done (\d+) (\d+)/) ?? [];
3040
expect(stdout).toContain("done");
41+
expect(after).not.toEqual(before);
3142
});
3243
});

0 commit comments

Comments
 (0)