Files
Chris Tate fc6408a662 Compile native class caches and environment proxies
- Keep cached native class instances callable, including inherited methods and JavaScript arguments.
- Support plain-object Proxy traps with live receivers, enumeration, and data-property invariants.
- Compile untyped addition, computed environment keys, and text-codec startup storage natively.
2026-09-28 12:25:30 -05:00

67 lines
2.3 KiB
JavaScript

import { Base2, View2 as LocalView } from "./chunk.js";
import { Parser2 as InputParser } from "./chunk.js";
export { Base2 as Base, LocalView as View };
export { Metrics2 as Metrics } from "./chunk.js";
export class Input {
parser = null;
constructor() { this.parser = new InputParser(); }
push(value) { this.parser?.push(value); }
read() { return this.parser ? this.parser.describe() : "absent"; }
save() { return this.parser; }
clear() { this.parser?.reset(); }
close() { this.parser = null; }
open() { this.parser = new InputParser(); }
}
export class FactoryInput {
parser = null;
open(value) { this.parser = InputParser.create(value); }
close() { this.parser = null; }
read() { return this.parser ? this.parser.describe() : "absent"; }
save() { return this.parser; }
}
export function describeOptions(config) {
return [config.name, String(config.required), String(config.default), typeof config.type].join(":");
}
const storeKey = Symbol.for("bundled-methods.store");
class Store {
values = new Map();
set(key, value) { this.values.set(key, value); return this; }
get(key) { return this.values.get(key); }
clearCache() { this.values.clear(); }
}
function cachedStore() { return globalThis[storeKey] ??= new Store(); }
export function exerciseCachedStore() {
const store = cachedStore();
const same = store.set("value", "native") === cachedStore();
const value = store.get("value");
store.clearCache();
const cleared = store.get("value") === undefined;
delete globalThis[storeKey];
return `${same}:${value}:${cleared}`;
}
export function exerciseEnvironmentProxy() {
const store = cachedStore();
store.set("value", 4);
const env = new Proxy({}, {
get(target, key) { return store.get(key); },
has(target, key) { return store.get(key) !== undefined; },
ownKeys() { return ["value"]; },
getOwnPropertyDescriptor(target, key) {
if (key === "value") return { enumerable: true, configurable: true, get: () => store.get(key) };
}
});
const first = env.value;
const keys = Object.keys(env).join(",");
const own = Object.hasOwn(env, "value");
store.set("value", 8);
const value = env.value;
const present = "value" in env;
delete globalThis[storeKey];
return `${first}:${keys}:${own}:${value}:${present}`;
}