mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-17 05:09:24 +08:00
- Remove C emission, debugging options, and automatic backend fallback. - Complete LLVM lowering and native bootstrap coverage across supported targets. - Link executables and libraries with precompiled C runtime packs, including iOS and Android.
41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { expect, test } from "vitest";
|
|
import { compile } from "../src/index.js";
|
|
|
|
test.each(["llvm"] as const)("untyped Buffer inputs keep explicit object-boundary refusals (%s)", async (backend) => {
|
|
const dir = mkdtempSync(join(tmpdir(), "scriptc-buffer-from-"));
|
|
try {
|
|
const entry = join(dir, "main.cjs");
|
|
writeFileSync(entry, `
|
|
/** @param {unknown} value */
|
|
function from(value) { return Buffer.from(value); }
|
|
function attempt(value) {
|
|
try { from(value); }
|
|
catch (error) { console.log(error.name, error.message); }
|
|
}
|
|
attempt({ valueOf() { console.log("must not execute hook"); return "abc"; } });
|
|
class Input { length = 0; }
|
|
attempt(new Input());
|
|
console.log("after");
|
|
`);
|
|
const result = await compile(entry, {
|
|
backend, dynamic: false, sanitize: process.env["SCRIPTC_SAN"] === "1",
|
|
outDir: dir, outPath: join(dir, "program"),
|
|
});
|
|
expect(result.ok, JSON.stringify(result.diagnostics)).toBe(true);
|
|
if (!result.ok) return;
|
|
const child = spawnSync(result.binaryPath, [], { encoding: "utf8" });
|
|
expect(child.status).toBe(0);
|
|
expect(child.stderr).toBe("");
|
|
expect(child.stdout).toBe(
|
|
"Error Buffer.from with a custom valueOf is not supported yet\n" +
|
|
"Error Buffer.from with an opaque reference is not supported yet\nafter\n",
|
|
);
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|