@hew-lang/sandbox-vm 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import process from "node:process";
3
+ import path from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
5
  import { runBytecode } from "./index.js";
4
6
  const DEFAULT_SEED = 42;
5
7
  const DEFAULT_STEP_BUDGET = 1_000_000;
@@ -45,7 +47,30 @@ function parseArgs(argv) {
45
47
  try {
46
48
  const args = parseArgs(process.argv.slice(2));
47
49
  const bytecode = JSON.parse(fs.readFileSync(args.bytecodePath, "utf8"));
50
+ let codecBridge;
51
+ if (typeof bytecode === "object" &&
52
+ bytecode !== null &&
53
+ "codecs" in bytecode &&
54
+ Array.isArray(bytecode.codecs) &&
55
+ bytecode.codecs.length) {
56
+ const local = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../hew-wasm/pkg/hew_wasm.js");
57
+ const location = process.env.HEW_WASM_MODULE ?? pathToFileURL(local).href;
58
+ const wasm = await import(location);
59
+ if (typeof wasm.default === "function") {
60
+ const resolved = location.startsWith("file:")
61
+ ? location
62
+ : import.meta.resolve(location);
63
+ await wasm.default({
64
+ module_or_path: fs.readFileSync(new URL(resolved.replace(/\.js$/, "_bg.wasm"))),
65
+ });
66
+ }
67
+ codecBridge = wasm.executeCodec ?? wasm.default?.executeCodec;
68
+ if (typeof codecBridge !== "function") {
69
+ throw new Error("hew-wasm executeCodec export is missing; supply a compatible HEW_WASM_MODULE");
70
+ }
71
+ }
48
72
  const trace = await runBytecode(bytecode, {
73
+ codecBridge,
49
74
  replay: {
50
75
  seed: args.seed,
51
76
  step_budget: DEFAULT_STEP_BUDGET,
@@ -667,7 +667,7 @@ export type RuntimeCallFamily = {
667
667
  IntArith: [IntArithKind, IntMethodWidth];
668
668
  } | {
669
669
  FloatMethod: FloatMethodOp;
670
- } | "NodeAllowPeer" | "NodeConnect" | "NodeId" | "NodeIdDisplay" | "LocationNodeId" | "LocationIncarnation" | "LocationDisplay" | "NodeIdentityKey" | "NodeLoadKeys" | "NodeLookup" | "NodeRegister" | "NodeSetTransport" | "NodeShutdown" | "NodeStart" | "MetricCounterRegister" | "MetricCounterInc" | "MetricCounterAdd" | "MetricGaugeRegister" | "MetricGaugeSet" | "MetricGaugeInc" | "MetricGaugeDec" | "MetricGaugeAdd" | "MetricHistogramRegister" | "MetricHistogramRegisterSimple" | "MetricHistogramRecord" | "MetricVecRegister" | "MetricVecWith" | "ObserveReadU64" | "ObserveScrape" | "ObserveSeries" | "ObserveBarrier" | "RcClone" | "RcDowngrade" | "RcDrop" | "RcGet" | "RcIsUnique" | "RcNew" | "RcSet" | "RcStrongCount" | "RcWeakCount" | "WeakCloneRc" | "WeakDropRc" | "WeakUpgradeRc" | "RegexCapture" | "RegexCompile" | "RegexFreeCapture" | "RegexHandle" | "RegexMatch" | "ReplyChannelCancel" | "ReplyChannelFree" | "ReplyChannelNew" | "ReplyPayloadFree" | "ReplyWait" | "SelectFirst" | "SinkClone" | "SinkClose" | "StreamClose" | "StreamChunks" | "StreamForward" | "StreamFromGenerator" | "SinkFromEncoder" | "StreamLines" | "StreamNextLayout" | "StreamPairSink" | "StreamPairStream" | "StreamSendLayout" | "StreamTake" | "StreamTryNextLayout" | "StreamTrySendLayout" | "CharIsDigit" | "CharIsLetter" | "CharIsAlphanumeric" | "CharIsWhitespace" | "CharIsUpper" | "CharIsLower" | "CharIsPunctuation" | "CharIsControl" | "CharIsAscii" | "CharToUpper" | "CharToLower" | "CharToTitle" | "CharLenUtf8" | "CharToDigit" | "CharFromI64" | "CharFromU64" | "StringGet" | "StringGetRange" | "StringSliceRange" | "StringAppend" | "StringPush" | "StringClear" | "StringFindFrom" | "StringByteLen" | "StringConcat" | "StringEquals" | "StringCompare" | "StringStartsWith" | "StringEndsWith" | "StringContains" | "StringIsEmpty" | "StructuralFormat" | "StringFind" | "StringIndex" | "StringLen" | "StringRepeat" | "StringReplace" | "StringClone" | "StringSplit" | "StringLines" | "StringSliceCodepoints" | "StringSliceCodepointsFrom" | "StringToLowercase" | "StringToBytes" | "StringToUppercase" | "StringTrim" | "U8ToString" | "I32ToString" | "I64ToString" | "U32ToString" | "U64ToString" | "F64ToString" | "CharToString" | {
670
+ } | "NodeConnect" | "NodeId" | "NodeIdDisplay" | "LocationNodeId" | "LocationIncarnation" | "LocationDisplay" | "NodeIdentityKey" | "NodeLoadKeys" | "NodeLookup" | "NodeRegister" | "NodeSetTransport" | "NodeShutdown" | "NodeStart" | "MetricCounterRegister" | "MetricCounterInc" | "MetricCounterAdd" | "MetricGaugeRegister" | "MetricGaugeSet" | "MetricGaugeInc" | "MetricGaugeDec" | "MetricGaugeAdd" | "MetricHistogramRegister" | "MetricHistogramRegisterSimple" | "MetricHistogramRecord" | "MetricVecRegister" | "MetricVecWith" | "ObserveReadU64" | "ObserveScrape" | "ObserveSeries" | "ObserveBarrier" | "RcClone" | "RcDowngrade" | "RcDrop" | "RcGet" | "RcIsUnique" | "RcNew" | "RcSet" | "RcStrongCount" | "RcWeakCount" | "WeakCloneRc" | "WeakDropRc" | "WeakUpgradeRc" | "RegexCapture" | "RegexCompile" | "RegexFreeCapture" | "RegexHandle" | "RegexMatch" | "ReplyChannelCancel" | "ReplyChannelFree" | "ReplyChannelNew" | "ReplyPayloadFree" | "ReplyWait" | "SelectFirst" | "SinkClone" | "SinkClose" | "StreamClose" | "StreamChunks" | "StreamForward" | "StreamFromGenerator" | "SinkFromEncoder" | "StreamLines" | "StreamNextLayout" | "StreamPairSink" | "StreamPairStream" | "StreamSendLayout" | "StreamTake" | "StreamTryNextLayout" | "StreamTrySendLayout" | "CharIsDigit" | "CharIsLetter" | "CharIsAlphanumeric" | "CharIsWhitespace" | "CharIsUpper" | "CharIsLower" | "CharIsPunctuation" | "CharIsControl" | "CharIsAscii" | "CharToUpper" | "CharToLower" | "CharToTitle" | "CharLenUtf8" | "CharToDigit" | "CharFromI64" | "CharFromU64" | "StringGet" | "StringGetRange" | "StringSliceRange" | "StringAppend" | "StringPush" | "StringClear" | "StringFindFrom" | "StringByteLen" | "StringConcat" | "StringEquals" | "StringCompare" | "StringStartsWith" | "StringEndsWith" | "StringContains" | "StringIsEmpty" | "StructuralFormat" | "StringFind" | "StringIndex" | "StringLen" | "StringRepeat" | "StringReplace" | "StringClone" | "StringSplit" | "StringLines" | "StringSliceCodepoints" | "StringSliceCodepointsFrom" | "StringToLowercase" | "StringToBytes" | "StringToUppercase" | "StringTrim" | "U8ToString" | "I32ToString" | "I64ToString" | "U32ToString" | "U64ToString" | "F64ToString" | "CharToString" | {
671
671
  Print: {
672
672
  kind: PrintKind;
673
673
  newline: boolean;