@scriptc/compiler 0.0.10 → 0.0.12

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.
Files changed (111) hide show
  1. package/ambient/scriptc-node-fallback.d.ts +63 -15
  2. package/ambient/scriptc.d.ts +2 -2
  3. package/dist/backend/cc.d.ts +2 -2
  4. package/dist/backend/emission/emit-async.js +1 -1
  5. package/dist/backend/emission/emit-exprs.js +131 -54
  6. package/dist/backend/emission/emit-exprs.js.map +1 -1
  7. package/dist/backend/emission/emit-island.js +1 -1
  8. package/dist/backend/emission/emit-shapes.js +1 -1
  9. package/dist/backend/emission/emit-walkers.d.ts +14 -14
  10. package/dist/backend/emission/emit-walkers.js +44 -44
  11. package/dist/backend/emission/emit-walkers.js.map +1 -1
  12. package/dist/backend/emission/emitter.d.ts +3 -3
  13. package/dist/backend/emission/emitter.js +33 -9
  14. package/dist/backend/emission/emitter.js.map +1 -1
  15. package/dist/backend/emission/may-throw.js +1 -1
  16. package/dist/backend/llvm/dyn.d.ts +10 -10
  17. package/dist/backend/llvm/dyn.js +26 -26
  18. package/dist/backend/llvm/dyn.js.map +1 -1
  19. package/dist/backend/llvm/emitter.js +156 -47
  20. package/dist/backend/llvm/emitter.js.map +1 -1
  21. package/dist/backend/llvm/shapes.js +1 -1
  22. package/dist/backend/llvm/walkers.js +2 -2
  23. package/dist/backend/llvm/walkers.js.map +1 -1
  24. package/dist/coverage/surface-manifest.js +16 -2
  25. package/dist/coverage/surface-manifest.js.map +1 -1
  26. package/dist/diagnostics/diagnostic.d.ts +21 -8
  27. package/dist/diagnostics/diagnostic.js +48 -14
  28. package/dist/diagnostics/diagnostic.js.map +1 -1
  29. package/dist/frontend/lowering/lib-boundary.js +5 -5
  30. package/dist/frontend/lowering/lib-boundary.js.map +1 -1
  31. package/dist/frontend/lowering/lower-assert.js +12 -12
  32. package/dist/frontend/lowering/lower-assert.js.map +1 -1
  33. package/dist/frontend/lowering/lower-builtins.d.ts +63 -7
  34. package/dist/frontend/lowering/lower-builtins.js +327 -35
  35. package/dist/frontend/lowering/lower-builtins.js.map +1 -1
  36. package/dist/frontend/lowering/lower-calls.d.ts +4 -4
  37. package/dist/frontend/lowering/lower-calls.js +104 -70
  38. package/dist/frontend/lowering/lower-calls.js.map +1 -1
  39. package/dist/frontend/lowering/lower-classes.d.ts +7 -0
  40. package/dist/frontend/lowering/lower-classes.js +82 -6
  41. package/dist/frontend/lowering/lower-classes.js.map +1 -1
  42. package/dist/frontend/lowering/lower-containers.d.ts +9 -5
  43. package/dist/frontend/lowering/lower-containers.js +88 -26
  44. package/dist/frontend/lowering/lower-containers.js.map +1 -1
  45. package/dist/frontend/lowering/lower-emitter.d.ts +70 -3
  46. package/dist/frontend/lowering/lower-emitter.js +438 -31
  47. package/dist/frontend/lowering/lower-emitter.js.map +1 -1
  48. package/dist/frontend/lowering/lower-exprs.d.ts +87 -12
  49. package/dist/frontend/lowering/lower-exprs.js +630 -125
  50. package/dist/frontend/lowering/lower-exprs.js.map +1 -1
  51. package/dist/frontend/lowering/lower-inspect.js +5 -5
  52. package/dist/frontend/lowering/lower-inspect.js.map +1 -1
  53. package/dist/frontend/lowering/lower-island.js +12 -3
  54. package/dist/frontend/lowering/lower-island.js.map +1 -1
  55. package/dist/frontend/lowering/lower-modules.d.ts +8 -5
  56. package/dist/frontend/lowering/lower-modules.js +157 -63
  57. package/dist/frontend/lowering/lower-modules.js.map +1 -1
  58. package/dist/frontend/lowering/lower-namespaces.d.ts +24 -0
  59. package/dist/frontend/lowering/lower-namespaces.js +158 -16
  60. package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
  61. package/dist/frontend/lowering/lower-server.js +11 -11
  62. package/dist/frontend/lowering/lower-server.js.map +1 -1
  63. package/dist/frontend/lowering/lower-stmts.d.ts +1 -1
  64. package/dist/frontend/lowering/lower-stmts.js +271 -36
  65. package/dist/frontend/lowering/lower-stmts.js.map +1 -1
  66. package/dist/frontend/lowering/lower-stream.js +171 -20
  67. package/dist/frontend/lowering/lower-stream.js.map +1 -1
  68. package/dist/frontend/lowering/lowerer.d.ts +27 -10
  69. package/dist/frontend/lowering/lowerer.js +156 -54
  70. package/dist/frontend/lowering/lowerer.js.map +1 -1
  71. package/dist/frontend/lowering/surfaces.d.ts +44 -0
  72. package/dist/frontend/lowering/surfaces.js +236 -5
  73. package/dist/frontend/lowering/surfaces.js.map +1 -1
  74. package/dist/frontend/npm.d.ts +12 -0
  75. package/dist/frontend/npm.js +30 -0
  76. package/dist/frontend/npm.js.map +1 -1
  77. package/dist/frontend/program.d.ts +25 -0
  78. package/dist/frontend/program.js +145 -136
  79. package/dist/frontend/program.js.map +1 -1
  80. package/dist/frontend/shared.d.ts +1 -1
  81. package/dist/frontend/shared.js +8 -8
  82. package/dist/frontend/shared.js.map +1 -1
  83. package/dist/frontend/types.d.ts +2 -2
  84. package/dist/frontend/types.js +15 -15
  85. package/dist/frontend/types.js.map +1 -1
  86. package/dist/index.d.ts +2 -1
  87. package/dist/index.js +169 -5
  88. package/dist/index.js.map +1 -1
  89. package/dist/ir/nodes.d.ts +174 -106
  90. package/dist/ir/nodes.js +69 -24
  91. package/dist/ir/nodes.js.map +1 -1
  92. package/dist/ir/validate.js +55 -36
  93. package/dist/ir/validate.js.map +1 -1
  94. package/dist/library/fence-eval.js +12 -2
  95. package/dist/library/fence-eval.js.map +1 -1
  96. package/dist/library/int-infer.d.ts +119 -0
  97. package/dist/library/int-infer.js +1314 -0
  98. package/dist/library/int-infer.js.map +1 -0
  99. package/dist/library/int-infer.test.d.ts +1 -0
  100. package/dist/library/int-infer.test.js +279 -0
  101. package/dist/library/int-infer.test.js.map +1 -0
  102. package/dist/library/profile.d.ts +34 -5
  103. package/dist/library/profile.js +77 -13
  104. package/dist/library/profile.js.map +1 -1
  105. package/dist/library/sidecar-validate.js +1 -1
  106. package/dist/library/sidecar-validate.js.map +1 -1
  107. package/dist/library/sidecar.d.ts +24 -1
  108. package/dist/library/sidecar.js +163 -16
  109. package/dist/library/sidecar.js.map +1 -1
  110. package/package.json +2 -2
  111. package/surface-manifest.json +210 -12
@@ -1,4 +1,4 @@
1
- import { arrayOf, BOOL, BYTES_U8, bytesOf, canAdaptDynFuncTo, canConvertToDyn, canExitIslandToType, canMarshalIntoIsland, canMarshalTypedFuncIntoIsland, CHILD_T, CHILDSTREAM_T, DGRAMSOCK_T, DYN, DYN_HANDLE_KINDS, F64, FSWATCHER_T, HTTP2SESSION_T, HTTP2STREAM_T, HTTPCLIENTREQ_T, HTTPREQ_T, HTTPRES_T, isJsonSafeType, isRefCounted, isSupportedIndexValue, isSupportedMapKey, isSupportedMapValue, isSupportedSetElem, isUnitType, jsOpResultKind, JSVAL, NETSERVER_T, NETSOCKET_T, PROCSTREAM_T, REF_TRUTHY_KINDS, REGEX, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, SEARCH_PARAMS_T, SECURECTX_T, SPAWNRES_T, STATS_T, STRING, SYMBOL_T, TESTCTX_T, typeEquals, typeKey, unionFuncSetArmsOk, URL_T, VOID } from "./nodes.js";
1
+ import { arrayOf, BOOL, BYTES_U8, bytesOf, canAdaptDynFuncTo, canConvertToDyn, canExitIslandToType, canMarshalIntoIsland, canMarshalTypedFuncIntoIsland, CHILD_T, CHILDSTREAM_T, DGRAMSOCK_T, DYN, DYN_HANDLE_KINDS, F64, FSWATCHER_T, HTTP2SESSION_T, HTTP2STREAM_T, HTTPCLIENTREQ_T, HTTPREQ_T, HTTPRES_T, islandPromisePayloadTag, isJsonSafeType, isRefCounted, isSupportedIndexValue, isSupportedMapKey, isSupportedMapValue, isSupportedSetElem, isUnitType, jsOpResultKind, JSVAL, NETSERVER_T, NETSOCKET_T, PROCSTREAM_T, REF_TRUTHY_KINDS, REGEX, RUNTIME_EMITTER_CLASS, RUNTIME_ERROR_CLASSES, RUNTIME_STREAM_CLASSES, SEARCH_PARAMS_T, SECURECTX_T, SPAWNRES_T, STATS_T, STRING, SYMBOL_T, TESTCTX_T, typeEquals, typeKey, unionFuncSetArmsOk, URL_T, VOID } from "./nodes.js";
2
2
  /** Per-method signature for strIntrinsic: `argTypes` lists every argument
3
3
  * position (optional ones included); `minArgs` is how many may be omitted
4
4
  * from the end (backends fill the documented defaults). Exported for the
@@ -63,6 +63,8 @@ export const LIB_FN_SIGS = {
63
63
  "json.parse": { argTypes: [STRING], result: DYN },
64
64
  "dyn.keySet": { argTypes: [DYN, STRING, DYN], result: VOID },
65
65
  "dyn.iterPack": { argTypes: [DYN, STRING], result: DYN },
66
+ "dyn.arrLen": { argTypes: [DYN], result: F64 },
67
+ "dyn.arrAt": { argTypes: [DYN, F64], result: DYN },
66
68
  "dyn.toString": { argTypes: [DYN, STRING, STRING], result: STRING },
67
69
  "dyn.defineProps": { argTypes: [DYN, DYN], result: DYN },
68
70
  "dyn.typeof": { argTypes: [DYN], result: STRING },
@@ -163,6 +165,8 @@ export const LIB_FN_SIGS = {
163
165
  "math.floor": { argTypes: [F64], result: F64 },
164
166
  "math.abs": { argTypes: [F64], result: F64 },
165
167
  "math.round": { argTypes: [F64], result: F64 },
168
+ "math.trunc": { argTypes: [F64], result: F64 },
169
+ "math.ceil": { argTypes: [F64], result: F64 },
166
170
  "math.min": { argTypes: [F64, F64], result: F64 },
167
171
  "math.max": { argTypes: [F64, F64], result: F64 },
168
172
  "math.random": { argTypes: [], result: F64 },
@@ -171,7 +175,7 @@ export const LIB_FN_SIGS = {
171
175
  "num.fromString": { argTypes: [STRING], result: F64 },
172
176
  "num.isNaN": { argTypes: [F64], result: BOOL },
173
177
  "str.encodeUriComponent": { argTypes: [STRING], result: STRING },
174
- // The base64 globals: the argument is a DOM value (WebIDL ToString
178
+ // The base64 globals: the argument is a dyn value (WebIDL ToString
175
179
  // runs in the runtime); the zero-argument form always throws.
176
180
  "str.atob": { argTypes: [DYN], result: STRING },
177
181
  "str.btoa": { argTypes: [DYN], result: STRING },
@@ -228,7 +232,7 @@ export const LIB_FN_SIGS = {
228
232
  // node:querystring. qs.parse's result is the call site's ParsedUrlQuery
229
233
  // dictionary record (VOID is the networkInterfaces sentinel — the
230
234
  // libCall case checks the structure); qs.stringify's object argument
231
- // is a DOM value (the frontend dynFroms typed records).
235
+ // is a dyn value (the frontend dynFroms typed records).
232
236
  "qs.parse": { argTypes: [STRING, STRING, STRING, F64], result: VOID },
233
237
  "qs.stringify": { argTypes: [DYN, STRING, STRING], result: STRING },
234
238
  "qs.escape": { argTypes: [STRING], result: STRING },
@@ -645,7 +649,7 @@ export const LIB_FN_SIGS = {
645
649
  "buffer.isEncoding": { argTypes: [STRING], result: BOOL },
646
650
  "buffer.concatLen": { argTypes: [arrayOf(BYTES_U8), F64], result: BYTES_U8 },
647
651
  // The checked-dynamic compare/equals validators (Node's argument
648
- // ladders over DOM-boxed invalid-input probes).
652
+ // ladders over dyn-boxed invalid-input probes).
649
653
  "buffer.compareChk": { argTypes: [DYN, DYN], result: F64 },
650
654
  "bytes.equalsChk": { argTypes: [BYTES_U8, DYN], result: BOOL },
651
655
  "bytes.compareChk": { argTypes: [BYTES_U8, DYN, DYN, DYN, DYN, DYN], result: F64 },
@@ -724,7 +728,7 @@ export const LIB_FN_SIGS = {
724
728
  // Receiver (any error-hierarchy object) and the program-dependent
725
729
  // `string | undefined` result are checked in the libCall case.
726
730
  "error.code": { argTypes: [null], result: VOID },
727
- // DOMException: construction takes the two DOM args (WebIDL's
731
+ // DOMException: construction takes the two dyn args (WebIDL's
728
732
  // resolution runs in the runtime); the %DOMException result is a
729
733
  // program-dependent object type, checked in the libCall case. The
730
734
  // read surface takes the %DOMException receiver (a null slot — the
@@ -807,6 +811,9 @@ export const LIB_FN_SIGS = {
807
811
  "stream.pipelineDyn": { argTypes: [F64], result: VOID },
808
812
  "sp.finished": { argTypes: [null], result: { kind: "promise", inner: VOID } },
809
813
  "sp.pipeline": { argTypes: [F64], result: { kind: "promise", inner: VOID } },
814
+ "sc.text": { argTypes: [null], result: { kind: "promise", inner: STRING } },
815
+ "sc.json": { argTypes: [null], result: { kind: "promise", inner: DYN } },
816
+ "sc.buffer": { argTypes: [null], result: { kind: "promise", inner: BYTES_U8 } },
810
817
  "readable.newDyn": { argTypes: [DYN], result: VOID },
811
818
  "writable.newDyn": { argTypes: [DYN], result: VOID },
812
819
  "duplex.newDyn": { argTypes: [DYN], result: VOID },
@@ -832,6 +839,8 @@ export const LIB_FN_SIGS = {
832
839
  "readable.read": { argTypes: [null, F64], result: VOID },
833
840
  "readable.pause": { argTypes: [null], result: VOID },
834
841
  "readable.setEncoding": { argTypes: [null, STRING], result: VOID },
842
+ "readable.pushStrEnc": { argTypes: [null, STRING, STRING], result: BOOL },
843
+ "readable.pushEncoding": { argTypes: [null, STRING], result: VOID },
835
844
  "readable.nextChunk": { argTypes: [null], result: VOID },
836
845
  "readable.nextChunkDyn": { argTypes: [null], result: VOID },
837
846
  "readable.fromArr": { argTypes: [null, BOOL], result: VOID },
@@ -870,7 +879,7 @@ export const LIB_FN_SIGS = {
870
879
  // Symbol strict equality (pointer identity; scr_symbol.c).
871
880
  "assert.eqSym": { argTypes: [{ kind: "symbol" }, { kind: "symbol" }, BOOL, BOOL, STRING, BOOL], result: VOID },
872
881
  // The equality quartet over checked-dynamic operands (the frontend
873
- // boxes a static side into the DOM first).
882
+ // boxes a static side into the checked-dynamic tree first).
874
883
  "assert.eqDyn": { argTypes: [DYN, DYN, BOOL, BOOL, STRING, BOOL], result: VOID },
875
884
  // The throws(fn, {shape}) accumulator: begin/slot calls never throw;
876
885
  // shapeEnd throws the Comparison diff. The error slot is the
@@ -1176,7 +1185,7 @@ export function validateModule(mod) {
1176
1185
  // Unit kinds (undefinedT/nullT) exist only as union arms — a BARE
1177
1186
  // unit field is as malformed as a void one. dyn fields are VALID
1178
1187
  // (`[string, unknown]` entries tuples, `{ v: unknown }` records):
1179
- // the slot holds a DOM value with the overflow map's plumbing.
1188
+ // the slot holds a dyn value with the overflow map's plumbing.
1180
1189
  if (f.type.kind === "void" || f.type.kind === "jsval" ||
1181
1190
  isUnitType(f.type)) {
1182
1191
  errors.push({ message: `record ${rec.id}: field "${f.name}" is ${f.type.kind}`, loc: noLoc });
@@ -1734,10 +1743,10 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
1734
1743
  }
1735
1744
  break;
1736
1745
  }
1737
- // A dyn (DOM) chain (`rawName?.match(re)` on a JSON.parse result):
1746
+ // A dyn (dyn) chain (`rawName?.match(re)` on a JSON.parse result):
1738
1747
  // the nullish test reads the node's kind tag; the body is the
1739
1748
  // validated dynamic dispatch, its result converted back into the
1740
- // DOM (dynFrom) — so body and result are dyn, or void for
1749
+ // dyn (dynFrom) — so body and result are dyn, or void for
1741
1750
  // statement-position chains.
1742
1751
  if (e.receiver.type.kind === "dyn") {
1743
1752
  if (activeChains.has(e.id))
@@ -1782,7 +1791,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
1782
1791
  break;
1783
1792
  }
1784
1793
  expectType(e.body, e.type, "optChain body");
1785
- // dyn results carry the unit path as the undefined DOM value; every
1794
+ // dyn results carry the unit path as the undefined dyn value; every
1786
1795
  // other value result needs an undefined arm to land on.
1787
1796
  if (e.type.kind !== "dyn") {
1788
1797
  const rdef = e.type.kind === "union" ? unions.get(e.type.unionId) : undefined;
@@ -1814,7 +1823,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
1814
1823
  }
1815
1824
  // The CHECKED-DYNAMIC form: the runtime kind decides (the
1816
1825
  // emitters' scr_dyn_is_nullish arm) — left, right, and result
1817
- // all live in the DOM.
1826
+ // all live in the checked-dynamic tree.
1818
1827
  if (e.left.type.kind === "dyn") {
1819
1828
  if (e.type.kind !== "dyn")
1820
1829
  err("dyn nullish must answer dyn", e.loc);
@@ -2076,6 +2085,8 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
2076
2085
  includesNum: { argTypes: [F64, F64], minArgs: 1, result: BOOL },
2077
2086
  fill: { argTypes: [BYTES_U8, F64, F64], minArgs: 1, result: BYTES_U8 },
2078
2087
  fillNum: { argTypes: [F64, F64, F64], minArgs: 1, result: BYTES_U8 },
2088
+ // Per-element TypedArray fill (any elem — the non-u8 fill path).
2089
+ fillElem: { argTypes: [F64, F64, F64], minArgs: 1, result: bytesOf(recv.elem) },
2079
2090
  fillStr: { argTypes: [STRING, STRING, F64, F64], minArgs: 2, result: BYTES_U8 },
2080
2091
  copy: { argTypes: [BYTES_U8, F64, F64, F64], minArgs: 1, result: F64 },
2081
2092
  swap16: { argTypes: [], minArgs: 0, result: BYTES_U8 },
@@ -2090,7 +2101,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
2090
2101
  ? { argTypes: [], minArgs: 0, result: F64 }
2091
2102
  : e.method === "get"
2092
2103
  ? { argTypes: [F64], minArgs: 1, result: F64 }
2093
- : e.method === "slice"
2104
+ : e.method === "slice" || e.method === "subarray"
2094
2105
  ? { argTypes: [F64, F64], minArgs: 0, result: bytesOf(recv.elem) }
2095
2106
  : e.method === "setFrom"
2096
2107
  ? { argTypes: [bytesOf(recv.elem), F64], minArgs: 1, result: VOID }
@@ -2389,7 +2400,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
2389
2400
  }
2390
2401
  });
2391
2402
  // Result func type must match the target's signature. A VARIADIC
2392
- // (rest-marked) type hides one synthetic trailing DOM-array param
2403
+ // (rest-marked) type hides one synthetic trailing dyn-array param
2393
2404
  // in the lifted function (the thunk fills it) — the type's
2394
2405
  // declared params plus that one must match.
2395
2406
  if (e.type.kind === "func") {
@@ -2762,7 +2773,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
2762
2773
  expectType(e.obj, { kind: "record", shapeId: e.shapeId }, "recordKeyGet receiver");
2763
2774
  expectType(e.key, STRING, "recordKeyGet key");
2764
2775
  // Every reachable value must SURFACE as the result type: identity,
2765
- // an arm of a union result, or (dyn results) a DOM conversion —
2776
+ // an arm of a union result, or (dyn results) a dyn conversion —
2766
2777
  // the frontend's recordKeyResultOk mirror. overflowOnly reads (a
2767
2778
  // literal key naming no declared field) skip the declared check
2768
2779
  // and require the overflow to exist.
@@ -2803,7 +2814,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
2803
2814
  if (e.type.kind !== "dyn")
2804
2815
  err(`dynFrom must be dyn-typed, got ${e.type.kind}`, e.loc);
2805
2816
  // A bare unit literal is legal exactly here (like unionWrap): the
2806
- // DOM has first-class undefined/null values.
2817
+ // dyn has first-class undefined/null values.
2807
2818
  if (e.value.kind === "unitLit") {
2808
2819
  const want = e.value.unit === "undefined" ? "undefinedT" : "nullT";
2809
2820
  if (e.value.type.kind !== want) {
@@ -2812,19 +2823,19 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
2812
2823
  break;
2813
2824
  }
2814
2825
  checkExpr(e.value);
2815
- // Domain: JSON-safe, bytes<u8> (the DOM's bytes kind — payload
2826
+ // Domain: JSON-safe, bytes<u8> (the checked-dynamic tree's bytes kind — payload
2816
2827
  // copied), an undefined-armed union of JSON-safe arms (the
2817
- // undefined arm becomes the undefined DOM value), or a BOXABLE
2818
- // function type (the DOM's function kind — canConvertToDyn folds
2828
+ // undefined arm becomes the undefined dyn value), or a BOXABLE
2829
+ // function type (the checked-dynamic tree's function kind — canConvertToDyn folds
2819
2830
  // all four in).
2820
2831
  const vt = e.value.type;
2821
2832
  if (!canConvertToDyn(vt, (id) => records.get(id), (id) => unions.get(id))) {
2822
- err(`dynFrom of non-DOM-convertible type ${vt.kind}`, e.loc);
2833
+ err(`dynFrom of non-dyn-convertible type ${vt.kind}`, e.loc);
2823
2834
  }
2824
2835
  break;
2825
2836
  }
2826
2837
  case "dynFromJsval": {
2827
- // The jsval→DOM crossing: exactly a jsval operand into a dyn
2838
+ // The jsval→dyn crossing: exactly a jsval operand into a dyn
2828
2839
  // result (the by-reference island wrap; scalars normalize at
2829
2840
  // runtime).
2830
2841
  checkExpr(e.value);
@@ -3004,7 +3015,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
3004
3015
  break;
3005
3016
  }
3006
3017
  case "caughtToDyn": {
3007
- // The caught snapshot converting to a dyn DOM value (an unknown
3018
+ // The caught snapshot converting to a dyn value (an unknown
3008
3019
  // slot): operand caught, result dyn — the runtime dispatch handles
3009
3020
  // every payload kind, so nothing else constrains it.
3010
3021
  checkExpr(e.value);
@@ -4108,7 +4119,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
4108
4119
  }
4109
4120
  if (e.fn === "readable.pause" || e.fn === "readable.resume" ||
4110
4121
  e.fn === "readable.unpipe" || e.fn === "writable.end" ||
4111
- e.fn === "readable.setEncoding" ||
4122
+ e.fn === "readable.setEncoding" || e.fn === "readable.pushEncoding" ||
4112
4123
  e.fn === "stream.destroy" || e.fn === "stream.destroyErr") {
4113
4124
  if (!typeEquals(e.type, e.args[0].type)) {
4114
4125
  err(`libCall ${e.fn} must return its receiver's type (the chaining 'this')`, e.loc);
@@ -4250,7 +4261,7 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
4250
4261
  }
4251
4262
  // The value's STATIC type drives the emitted serializer — it must be
4252
4263
  // JSON-safe (the frontend rejects the rest with a specific message).
4253
- // A dyn ROOT is the one non-static shape allowed: the runtime's DOM
4264
+ // A dyn ROOT is the one non-static shape allowed: the runtime's dyn
4254
4265
  // walker serializes it (scr_dyn_format_j), no emitted serializer.
4255
4266
  if (e.value.type.kind !== "dyn" &&
4256
4267
  !isJsonSafeType(e.value.type, (id) => records.get(id), (id) => unions.get(id))) {
@@ -4263,24 +4274,24 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
4263
4274
  expectType(e.value, DYN, "dynCheck operand");
4264
4275
  // The target drives the emitted validator/builder: non-dyn,
4265
4276
  // non-void, JSON-representable (closures/class instances can never
4266
- // be found inside a JSON DOM — the frontend rejects those casts).
4277
+ // be found inside a JSON dyn — the frontend rejects those casts).
4267
4278
  // Bare undefined-armed unions of JSON-safe arms are additionally
4268
- // valid: the DOM holds a first-class undefined value (overflow
4279
+ // valid: the checked-dynamic tree holds a first-class undefined value (overflow
4269
4280
  // reads), which matches exactly the undefined arm.
4270
4281
  const jsonOk = (t) => isJsonSafeType(t, (id) => records.get(id), (id) => unions.get(id));
4271
4282
  const undefArmedOk = e.type.kind === "union" &&
4272
4283
  (unions.get(e.type.unionId)?.arms.every((a) => a.kind === "undefinedT" || jsonOk(a)) ??
4273
4284
  false);
4274
- // bytes<u8> targets extract the DOM's bytes kind (a copy).
4285
+ // bytes<u8> targets extract the checked-dynamic tree's bytes kind (a copy).
4275
4286
  const bytesOk = e.type.kind === "bytes" && e.type.elem === "u8";
4276
- // The %Error root extracts the DOM's error encoding (the "%error"
4287
+ // The %Error root extracts the checked-dynamic tree's error encoding (the "%error"
4277
4288
  // marker object caughtToDyn builds) as a fresh runtime error.
4278
4289
  const errorOk = e.type.kind === "object" && e.type.className === "%Error";
4279
- // ADAPTABLE function targets unwrap or wrap the DOM's function
4290
+ // ADAPTABLE function targets unwrap or wrap the checked-dynamic tree's function
4280
4291
  // kind (the checked-dynamic function boundary, nodes.ts).
4281
4292
  const funcOk = e.type.kind === "func" &&
4282
4293
  canAdaptDynFuncTo(e.type, (id) => records.get(id), (id) => unions.get(id));
4283
- // Runtime HANDLE targets unwrap the DOM's handle kind by tag (a
4294
+ // Runtime HANDLE targets unwrap the checked-dynamic tree's handle kind by tag (a
4284
4295
  // retained reference, no copy — DYN_HANDLE_KINDS).
4285
4296
  const handleOk = DYN_HANDLE_KINDS.has(e.type.kind);
4286
4297
  if (!jsonOk(e.type) && !undefArmedOk && !bytesOk && !errorOk && !funcOk && !handleOk) {
@@ -4503,7 +4514,11 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
4503
4514
  // exactly what it produces.
4504
4515
  if (src.kind !== "bytes" &&
4505
4516
  src.kind !== "url" &&
4506
- src.kind !== "dyn" && // DOM values deep-copy in (data kinds; the runtime throws on boxes)
4517
+ src.kind !== "dyn" && // dyn values deep-copy in (data kinds; the runtime throws on boxes)
4518
+ // A STATIC promise crosses as a real engine thenable when its
4519
+ // fulfillment is in the reverse bridge's payload domain
4520
+ // (scr_jsval_from_promise — the async-callback return bridge).
4521
+ !(src.kind === "promise" && islandPromisePayloadTag(src.inner) !== null) &&
4507
4522
  !canMarshalIntoIsland(src, (id) => records.get(id), (id) => unions.get(id)) &&
4508
4523
  !canMarshalTypedFuncIntoIsland(src, (id) => records.get(id), (id) => unions.get(id))) {
4509
4524
  err(`jsMarshal of unmarshalable type ${src.kind}`, e.loc);
@@ -4561,11 +4576,15 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
4561
4576
  case "jsBridgePromise": {
4562
4577
  checkExpr(e.value);
4563
4578
  expectType(e.value, JSVAL, "jsBridgePromise operand");
4564
- // The settled engine value crosses as a HANDLE (or not at all):
4565
- // the bridge never converts payloads — typed uses exit later.
4579
+ // The settled engine value crosses as a HANDLE (or not at all) —
4580
+ // plus the ONE converting payload: an `any[]`-declared
4581
+ // fulfillment exits Array.isArray-gated by reference AT THE
4582
+ // SETTLE (SCR_ISLP_JSVAL_ARR); every other typed use exits later.
4566
4583
  if (e.type.kind !== "promise" ||
4567
- (e.type.inner.kind !== "jsval" && e.type.inner.kind !== "void")) {
4568
- err("jsBridgePromise must be a promise of jsval or void", e.loc);
4584
+ (e.type.inner.kind !== "jsval" &&
4585
+ e.type.inner.kind !== "void" &&
4586
+ !(e.type.inner.kind === "array" && e.type.inner.elem.kind === "jsval"))) {
4587
+ err("jsBridgePromise must be a promise of jsval, void, or jsval-element array", e.loc);
4569
4588
  }
4570
4589
  break;
4571
4590
  }
@@ -4854,8 +4873,8 @@ function validateFunction(fn, functions, classes, records, unions, globals, erro
4854
4873
  break;
4855
4874
  case "throw":
4856
4875
  checkExpr(s.value);
4857
- // dyn throws are allowed: the DOM node rides the REF cell arm by
4858
- // reference (the JS-lane `throw err` of a DOM argument).
4876
+ // dyn throws are allowed: the dyn node rides the REF cell arm by
4877
+ // reference (the JS-lane `throw err` of a dyn argument).
4859
4878
  if (s.value.type.kind === "void" || s.value.type.kind === "caught") {
4860
4879
  err(`throw of a ${s.value.type.kind} value`, s.loc);
4861
4880
  }