mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
* refactor(native): select ELF sections through the keyed owner * test(native): pin returned exports and versions for repeated version sections * refactor(nativeaot): read neither of repeated frozen object regions (#10790) * refactor(nativeaot): read neither of repeated frozen object regions through the keyed owner * refactor(parsers): retire every first-match section lookup (#10793) * fix(nativeaot): report an ambiguous frozen object region as partial (#10812) * refactor(native): select program headers and load commands through the keyed owner (#10827) * refactor(native): select the GOT base and dependency segments through the keyed owner (#10847) * refactor(native): select the GOT base and dependency segments through the keyed owner resolveGotBase selects the SHT_DYNAMIC section and the allocated .got.plt/.got sections with uniqueKeyed, so a repeat leaves the GOT base unknown instead of taking the first match; elfDependencies reads PT_LOAD segments through the same keyed program table as PT_DYNAMIC. A new keyed-first-match guard recognizes a find/findLast or filter-then-[0] whose predicate compares a key field, whatever the table is called; existing matches are baselined. The unwind fixture can declare PT_DYNAMIC headers and repeated .dynamic/.got.plt sections. * test(native): pin the PT_DYNAMIC path and destructured keyed lookups The keyed-first-match guard moves to scripts/verify/keyed-first-match.mjs with focused tests, and now recognizes a destructured key in any position and a destructured filter predicate. The single PT_DYNAMIC unwind test declares .dynamic as SHT_PROGBITS so only the program header supplies DT_PLTGOT, and asserts the resolved ranges. * fix(macho): refuse repeated chained-fixup and dyld-info tables (#10850) parseMachoLayout kept the last LC_DYLD_CHAINED_FIXUPS range and merged the rebase/bind streams of every LC_DYLD_INFO(_ONLY) command. A repeat now refuses the slice as malformed. NativeMachoInspection's chained import-name reader already declined repeated LC_DYLD_CHAINED_FIXUPS; that rule is now covered by a test. * fix(verify): count a filter index only on the filter's own result
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
allKeyed,
|
|
firstKeyed,
|
|
keyedBy,
|
|
lastKeyed,
|
|
uniqueKeyed,
|
|
} from "./keyedCollection.js";
|
|
|
|
const sections = [
|
|
{ name: "__text", id: 0 },
|
|
{ name: null, id: 1 },
|
|
{ name: "__data", id: 2 },
|
|
{ name: "__text", id: 3 },
|
|
];
|
|
|
|
describe("keyed collections", () => {
|
|
const keyed = keyedBy(sections, ({ name }) => name);
|
|
|
|
it("retains every keyed declaration in source order and names repeats", () => {
|
|
expect(keyed.entries.map(({ key, ordinal }) => [key, ordinal])).toEqual([
|
|
["__text", 0],
|
|
["__data", 1],
|
|
["__text", 2],
|
|
]);
|
|
expect(keyed.duplicates).toEqual(["__text"]);
|
|
});
|
|
|
|
it("selects a single declaration, or nothing when absent", () => {
|
|
expect(uniqueKeyed(keyed, "__data")).toEqual({
|
|
ok: true,
|
|
value: sections[2],
|
|
});
|
|
expect(uniqueKeyed(keyed, "__bss")).toEqual({
|
|
ok: true,
|
|
value: undefined,
|
|
});
|
|
});
|
|
|
|
it("refuses to choose among repeated declarations", () => {
|
|
expect(uniqueKeyed(keyed, "__text")).toEqual({
|
|
ok: false,
|
|
error: { kind: "duplicate", key: "__text", ordinals: [0, 2] },
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("keyed precedence and repeated keys", () => {
|
|
const byType = keyedBy(
|
|
[
|
|
{ type: 11, id: 0 },
|
|
{ type: 2, id: 1 },
|
|
{ type: 11, id: 2 },
|
|
],
|
|
({ type }) => type,
|
|
);
|
|
|
|
it("keys by a numeric tag and lists every declaration", () => {
|
|
expect(byType.duplicates).toEqual([11]);
|
|
expect(allKeyed(byType, 11).map(({ id }) => id)).toEqual([0, 2]);
|
|
expect(allKeyed(byType, 3)).toEqual([]);
|
|
});
|
|
|
|
it("chooses first or last only under a stated precedence rule", () => {
|
|
expect(firstKeyed(byType, 11, "the loader reads the first")?.id).toBe(0);
|
|
expect(lastKeyed(byType, 11, "the loader reads the last")?.id).toBe(2);
|
|
expect(() => firstKeyed(byType, 11, " ")).toThrow(TypeError);
|
|
});
|
|
});
|