@hew-lang/sandbox-vm 0.10.0 → 0.11.0-rc3

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.
@@ -358,6 +358,39 @@ const UNIT_FAMILIES = {
358
358
  },
359
359
  StringAppend: (_host, args) => indexed(args, 0).append(indexed(args, 1)),
360
360
  StringPush: (_host, args) => indexed(args, 0).append(indexed(args, 1)),
361
+ StringAppendI64: (_host, args) => appendRendered(args),
362
+ StringAppendU64: (_host, args) => appendRendered(args),
363
+ StringAppendF64: (_host, args) => appendRendered(args),
364
+ StringAppendBool: (_host, args) => appendRendered(args),
365
+ StringAppendLiteral: (_host, args) => {
366
+ const receiver = indexed(args, 0);
367
+ const count = arg(args, 2);
368
+ if (count.kind !== "i64")
369
+ throw new TypeError("literal byte length must be an integer");
370
+ const length = Number(count.value);
371
+ if (!Number.isSafeInteger(length) || length < 0 || length > 0xffffffff)
372
+ throw new RangeError("literal byte length is outside u32");
373
+ if (length === 0)
374
+ return receiver;
375
+ const literal = indexed(args, 1);
376
+ if (length > literal.byteLength)
377
+ throw new RangeError("literal byte length exceeds its storage");
378
+ if (length === literal.byteLength)
379
+ return receiver.append(literal);
380
+ // The ABI lends exactly this UTF-8 prefix. Malformed untrusted packages
381
+ // must not silently append a different value or replace a split scalar.
382
+ const text = new TextDecoder("utf-8", {
383
+ fatal: true,
384
+ ignoreBOM: true,
385
+ }).decode(literal.encoded().subarray(0, length));
386
+ const prefix = stringValue(text);
387
+ try {
388
+ return receiver.append(prefix);
389
+ }
390
+ finally {
391
+ prefix.release();
392
+ }
393
+ },
361
394
  StringClear: (_host, args) => {
362
395
  indexed(args, 0).release();
363
396
  return str("");
@@ -1300,6 +1333,16 @@ function indexed(args, at) {
1300
1333
  throw new TypeError(`runtime call expected a string operand, got ${value.kind}`);
1301
1334
  return value;
1302
1335
  }
1336
+ /** Append a scalar segment, rendered as its `to_string` renders it. */
1337
+ function appendRendered(args) {
1338
+ const rendered = stringValue(renderStdout(arg(args, 1)));
1339
+ try {
1340
+ return indexed(args, 0).append(rendered);
1341
+ }
1342
+ finally {
1343
+ rendered.release();
1344
+ }
1345
+ }
1303
1346
  function text(args, at) {
1304
1347
  const value = arg(args, at);
1305
1348
  return value.kind === "string" ? value.value : renderStdout(value);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@hew-lang/sandbox-vm",
3
- "version": "0.10.0",
3
+ "version": "0.11.0-rc3",
4
4
  "hewSource": {
5
- "commit": "75e14a2775f9af8fd77a6a907da277b2de666824",
6
- "tag": "v0.10.0",
5
+ "commit": "c2cabbedb5109295808886e65eabd1fe385bdc61",
6
+ "tag": "v0.11.0-rc3",
7
7
  "dirty": false
8
8
  },
9
9
  "description": "Deterministic TypeScript interpreter for the Hew educational sandbox",
@@ -21,7 +21,7 @@
21
21
  "cli/"
22
22
  ],
23
23
  "dependencies": {
24
- "@hew-lang/wasm": "0.10.0"
24
+ "@hew-lang/wasm": "0.11.0-rc3"
25
25
  },
26
26
  "keywords": [
27
27
  "hew",