@scriptc/cli-darwin-x64 0.0.0 → 0.2.0

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 (960) hide show
  1. package/dist/LICENSE +202 -0
  2. package/dist/THIRD_PARTY_NOTICES +4 -0
  3. package/dist/bin/scriptc +0 -0
  4. package/dist/bin/scriptc.json +21 -0
  5. package/dist/lib/declarations/scriptc-node-fallback.d.ts +3847 -0
  6. package/dist/lib/declarations/scriptc-overrides.d.ts +92 -0
  7. package/dist/lib/declarations/scriptc.d.ts +98 -0
  8. package/dist/lib/llvm/LICENSE +1 -0
  9. package/dist/lib/llvm/SCRIPTC_LICENSE +1 -0
  10. package/dist/lib/llvm/THIRD_PARTY_NOTICES +1 -0
  11. package/dist/lib/llvm/bin/scriptc-llvm-codegen +0 -0
  12. package/dist/lib/llvm/package.json +35 -0
  13. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_array.o +0 -0
  14. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_assert.o +0 -0
  15. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_async.o +0 -0
  16. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_async_dyn.o +0 -0
  17. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bigint.o +0 -0
  18. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bigint_assert.o +0 -0
  19. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes.o +0 -0
  20. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_bytes_io.o +0 -0
  21. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_child.o +0 -0
  22. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_closure.o +0 -0
  23. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_console.o +0 -0
  24. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_console_native.o +0 -0
  25. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_copying.o +0 -0
  26. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_crypto_async.o +0 -0
  27. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_cycle.o +0 -0
  28. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dc.o +0 -0
  29. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dgram.o +0 -0
  30. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dyn_handle.o +0 -0
  31. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_dyn_invoke.o +0 -0
  32. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_error.o +0 -0
  33. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_events.o +0 -0
  34. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_events_emitter.o +0 -0
  35. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_exception.o +0 -0
  36. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_fetch.o +0 -0
  37. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_ffi.o +0 -0
  38. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_ffi_queue.o +0 -0
  39. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_file_handle.o +0 -0
  40. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_grapheme.o +0 -0
  41. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_http.o +0 -0
  42. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_http2.o +0 -0
  43. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_inspect.o +0 -0
  44. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_json.o +0 -0
  45. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_lib.o +0 -0
  46. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_loop_epoll.o +0 -0
  47. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_loop_kqueue.o +0 -0
  48. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_loop_wsapoll.o +0 -0
  49. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_map.o +0 -0
  50. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_net.o +0 -0
  51. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_node_builtin.o +0 -0
  52. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_number.o +0 -0
  53. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_object.o +0 -0
  54. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_path.o +0 -0
  55. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_qs.o +0 -0
  56. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_readline.o +0 -0
  57. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_regex.o +0 -0
  58. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_stream.o +0 -0
  59. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_string.o +0 -0
  60. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_symbol.o +0 -0
  61. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_test.o +0 -0
  62. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_tls.o +0 -0
  63. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_tls_ca.o +0 -0
  64. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_union.o +0 -0
  65. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_url.o +0 -0
  66. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_url_params.o +0 -0
  67. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_util.o +0 -0
  68. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_watch.o +0 -0
  69. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/default/scr_zlib.o +0 -0
  70. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_array.o +0 -0
  71. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_assert.o +0 -0
  72. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_async.o +0 -0
  73. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_async_dyn.o +0 -0
  74. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bigint.o +0 -0
  75. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bigint_assert.o +0 -0
  76. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes.o +0 -0
  77. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_bytes_io.o +0 -0
  78. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_child.o +0 -0
  79. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_closure.o +0 -0
  80. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_console.o +0 -0
  81. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_console_native.o +0 -0
  82. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_copying.o +0 -0
  83. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_crypto_async.o +0 -0
  84. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_cycle.o +0 -0
  85. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dc.o +0 -0
  86. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dgram.o +0 -0
  87. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dyn_handle.o +0 -0
  88. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_dyn_invoke.o +0 -0
  89. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_error.o +0 -0
  90. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_events.o +0 -0
  91. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_events_emitter.o +0 -0
  92. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_exception.o +0 -0
  93. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_fetch.o +0 -0
  94. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_ffi.o +0 -0
  95. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_ffi_queue.o +0 -0
  96. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_file_handle.o +0 -0
  97. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_grapheme.o +0 -0
  98. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_http.o +0 -0
  99. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_http2.o +0 -0
  100. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_inspect.o +0 -0
  101. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_inspect_island.o +0 -0
  102. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_island.o +0 -0
  103. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_json.o +0 -0
  104. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_lib.o +0 -0
  105. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_loop_epoll.o +0 -0
  106. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_loop_kqueue.o +0 -0
  107. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_loop_wsapoll.o +0 -0
  108. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_map.o +0 -0
  109. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_net.o +0 -0
  110. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_net_island.o +0 -0
  111. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_node_builtin.o +0 -0
  112. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_number.o +0 -0
  113. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_object.o +0 -0
  114. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_path.o +0 -0
  115. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_qs.o +0 -0
  116. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_readline.o +0 -0
  117. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_regex.o +0 -0
  118. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_stream.o +0 -0
  119. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_string.o +0 -0
  120. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_symbol.o +0 -0
  121. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_test.o +0 -0
  122. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_tls.o +0 -0
  123. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_tls_ca.o +0 -0
  124. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_union.o +0 -0
  125. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_url.o +0 -0
  126. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_url_params.o +0 -0
  127. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_util.o +0 -0
  128. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_watch.o +0 -0
  129. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_web.o +0 -0
  130. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_zlib.o +0 -0
  131. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic/scr_zlib_island.o +0 -0
  132. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
  133. package/dist/lib/runtime-darwin-x64/artifacts/dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  134. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_array.o +0 -0
  135. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_assert.o +0 -0
  136. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bigint.o +0 -0
  137. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bigint_assert.o +0 -0
  138. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes.o +0 -0
  139. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_bytes_io.o +0 -0
  140. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_closure.o +0 -0
  141. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_console.o +0 -0
  142. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_console_native.o +0 -0
  143. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_copying.o +0 -0
  144. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_cycle.o +0 -0
  145. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_dyn_handle.o +0 -0
  146. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_dyn_invoke.o +0 -0
  147. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_error.o +0 -0
  148. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_events_emitter.o +0 -0
  149. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_exception.o +0 -0
  150. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_grapheme.o +0 -0
  151. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_inspect.o +0 -0
  152. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_json.o +0 -0
  153. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_lib.o +0 -0
  154. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_library.o +0 -0
  155. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_map.o +0 -0
  156. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_node_builtin.o +0 -0
  157. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_number.o +0 -0
  158. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_object.o +0 -0
  159. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_path.o +0 -0
  160. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_regex.o +0 -0
  161. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_string.o +0 -0
  162. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_symbol.o +0 -0
  163. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_union.o +0 -0
  164. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_url.o +0 -0
  165. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_url_params.o +0 -0
  166. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/default/scr_zlib.o +0 -0
  167. package/dist/lib/runtime-darwin-x64/artifacts/library-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  168. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_array.o +0 -0
  169. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_assert.o +0 -0
  170. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bigint.o +0 -0
  171. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bigint_assert.o +0 -0
  172. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes.o +0 -0
  173. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_bytes_io.o +0 -0
  174. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_closure.o +0 -0
  175. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_console.o +0 -0
  176. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_console_native.o +0 -0
  177. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_copying.o +0 -0
  178. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_cycle.o +0 -0
  179. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_dyn_handle.o +0 -0
  180. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_dyn_invoke.o +0 -0
  181. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_error.o +0 -0
  182. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_events_emitter.o +0 -0
  183. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_exception.o +0 -0
  184. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_grapheme.o +0 -0
  185. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_inspect.o +0 -0
  186. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_json.o +0 -0
  187. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_lib.o +0 -0
  188. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_library.o +0 -0
  189. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_map.o +0 -0
  190. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_node_builtin.o +0 -0
  191. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_number.o +0 -0
  192. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_object.o +0 -0
  193. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_path.o +0 -0
  194. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_regex.o +0 -0
  195. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_string.o +0 -0
  196. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_symbol.o +0 -0
  197. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_union.o +0 -0
  198. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_url.o +0 -0
  199. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_url_params.o +0 -0
  200. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/default/scr_zlib.o +0 -0
  201. package/dist/lib/runtime-darwin-x64/artifacts/library-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  202. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_array.o +0 -0
  203. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_assert.o +0 -0
  204. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bigint.o +0 -0
  205. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bigint_assert.o +0 -0
  206. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes.o +0 -0
  207. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_bytes_io.o +0 -0
  208. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_closure.o +0 -0
  209. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_console.o +0 -0
  210. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_console_native.o +0 -0
  211. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_copying.o +0 -0
  212. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_cycle.o +0 -0
  213. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_dyn_handle.o +0 -0
  214. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_dyn_invoke.o +0 -0
  215. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_error.o +0 -0
  216. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_events_emitter.o +0 -0
  217. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_exception.o +0 -0
  218. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_grapheme.o +0 -0
  219. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_inspect.o +0 -0
  220. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_json.o +0 -0
  221. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_lib.o +0 -0
  222. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_library.o +0 -0
  223. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_map.o +0 -0
  224. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_node_builtin.o +0 -0
  225. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_number.o +0 -0
  226. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_object.o +0 -0
  227. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_path.o +0 -0
  228. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_regex.o +0 -0
  229. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_string.o +0 -0
  230. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_symbol.o +0 -0
  231. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_union.o +0 -0
  232. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_url.o +0 -0
  233. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_url_params.o +0 -0
  234. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/default/scr_zlib.o +0 -0
  235. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-dev/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  236. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_array.o +0 -0
  237. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_assert.o +0 -0
  238. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bigint.o +0 -0
  239. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bigint_assert.o +0 -0
  240. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes.o +0 -0
  241. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_bytes_io.o +0 -0
  242. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_closure.o +0 -0
  243. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_console.o +0 -0
  244. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_console_native.o +0 -0
  245. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_copying.o +0 -0
  246. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_cycle.o +0 -0
  247. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_dyn_handle.o +0 -0
  248. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_dyn_invoke.o +0 -0
  249. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_error.o +0 -0
  250. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_events_emitter.o +0 -0
  251. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_exception.o +0 -0
  252. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_grapheme.o +0 -0
  253. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_inspect.o +0 -0
  254. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_json.o +0 -0
  255. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_lib.o +0 -0
  256. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_library.o +0 -0
  257. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_map.o +0 -0
  258. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_node_builtin.o +0 -0
  259. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_number.o +0 -0
  260. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_object.o +0 -0
  261. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_path.o +0 -0
  262. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_regex.o +0 -0
  263. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_string.o +0 -0
  264. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_symbol.o +0 -0
  265. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_union.o +0 -0
  266. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_url.o +0 -0
  267. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_url_params.o +0 -0
  268. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/default/scr_zlib.o +0 -0
  269. package/dist/lib/runtime-darwin-x64/artifacts/library-thread-release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  270. package/dist/lib/runtime-darwin-x64/artifacts/licenses/mbedtls.txt +553 -0
  271. package/dist/lib/runtime-darwin-x64/artifacts/licenses/quickjs-ng.txt +24 -0
  272. package/dist/lib/runtime-darwin-x64/artifacts/licenses/ryu.txt +23 -0
  273. package/dist/lib/runtime-darwin-x64/artifacts/licenses/scriptc-runtime.txt +202 -0
  274. package/dist/lib/runtime-darwin-x64/artifacts/licenses/unicode.txt +39 -0
  275. package/dist/lib/runtime-darwin-x64/artifacts/licenses/zlib.txt +22 -0
  276. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_array.o +0 -0
  277. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_assert.o +0 -0
  278. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_async.o +0 -0
  279. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_async_dyn.o +0 -0
  280. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bigint.o +0 -0
  281. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bigint_assert.o +0 -0
  282. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes.o +0 -0
  283. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_bytes_io.o +0 -0
  284. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_child.o +0 -0
  285. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_closure.o +0 -0
  286. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_console.o +0 -0
  287. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_console_native.o +0 -0
  288. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_copying.o +0 -0
  289. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_crypto_async.o +0 -0
  290. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_cycle.o +0 -0
  291. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dc.o +0 -0
  292. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dgram.o +0 -0
  293. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dyn_handle.o +0 -0
  294. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_dyn_invoke.o +0 -0
  295. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_error.o +0 -0
  296. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_events.o +0 -0
  297. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_events_emitter.o +0 -0
  298. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_exception.o +0 -0
  299. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_fetch.o +0 -0
  300. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_ffi.o +0 -0
  301. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_ffi_queue.o +0 -0
  302. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_file_handle.o +0 -0
  303. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_grapheme.o +0 -0
  304. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_http.o +0 -0
  305. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_http2.o +0 -0
  306. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_inspect.o +0 -0
  307. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_json.o +0 -0
  308. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_lib.o +0 -0
  309. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_loop_epoll.o +0 -0
  310. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_loop_kqueue.o +0 -0
  311. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_loop_wsapoll.o +0 -0
  312. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_map.o +0 -0
  313. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_net.o +0 -0
  314. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_node_builtin.o +0 -0
  315. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_number.o +0 -0
  316. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_object.o +0 -0
  317. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_path.o +0 -0
  318. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_qs.o +0 -0
  319. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_readline.o +0 -0
  320. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_regex.o +0 -0
  321. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_stream.o +0 -0
  322. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_string.o +0 -0
  323. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_symbol.o +0 -0
  324. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_test.o +0 -0
  325. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_tls.o +0 -0
  326. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_tls_ca.o +0 -0
  327. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_union.o +0 -0
  328. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_url.o +0 -0
  329. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_url_params.o +0 -0
  330. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_util.o +0 -0
  331. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_watch.o +0 -0
  332. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/default/scr_zlib.o +0 -0
  333. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_array.o +0 -0
  334. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_assert.o +0 -0
  335. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_async.o +0 -0
  336. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_async_dyn.o +0 -0
  337. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bigint.o +0 -0
  338. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bigint_assert.o +0 -0
  339. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes.o +0 -0
  340. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_bytes_io.o +0 -0
  341. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_child.o +0 -0
  342. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_closure.o +0 -0
  343. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_console.o +0 -0
  344. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_console_native.o +0 -0
  345. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_copying.o +0 -0
  346. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_crypto_async.o +0 -0
  347. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_cycle.o +0 -0
  348. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dc.o +0 -0
  349. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dgram.o +0 -0
  350. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dyn_handle.o +0 -0
  351. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_dyn_invoke.o +0 -0
  352. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_error.o +0 -0
  353. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_events.o +0 -0
  354. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_events_emitter.o +0 -0
  355. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_exception.o +0 -0
  356. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_fetch.o +0 -0
  357. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_ffi.o +0 -0
  358. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_ffi_queue.o +0 -0
  359. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_file_handle.o +0 -0
  360. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_grapheme.o +0 -0
  361. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_http.o +0 -0
  362. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_http2.o +0 -0
  363. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_inspect.o +0 -0
  364. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_inspect_island.o +0 -0
  365. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_island.o +0 -0
  366. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_json.o +0 -0
  367. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_lib.o +0 -0
  368. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_loop_epoll.o +0 -0
  369. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_loop_kqueue.o +0 -0
  370. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_loop_wsapoll.o +0 -0
  371. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_map.o +0 -0
  372. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_net.o +0 -0
  373. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_net_island.o +0 -0
  374. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_node_builtin.o +0 -0
  375. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_number.o +0 -0
  376. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_object.o +0 -0
  377. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_path.o +0 -0
  378. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_qs.o +0 -0
  379. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_readline.o +0 -0
  380. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_regex.o +0 -0
  381. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_stream.o +0 -0
  382. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_string.o +0 -0
  383. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_symbol.o +0 -0
  384. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_test.o +0 -0
  385. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_tls.o +0 -0
  386. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_tls_ca.o +0 -0
  387. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_union.o +0 -0
  388. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_url.o +0 -0
  389. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_url_params.o +0 -0
  390. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_util.o +0 -0
  391. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_watch.o +0 -0
  392. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_web.o +0 -0
  393. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_zlib.o +0 -0
  394. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic/scr_zlib_island.o +0 -0
  395. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/dynamic-text-decoder-legacy/scr_bytes.o +0 -0
  396. package/dist/lib/runtime-darwin-x64/artifacts/release/runtime/text-decoder-legacy/scr_bytes.o +0 -0
  397. package/dist/lib/runtime-darwin-x64/artifacts/vendor/libregexp/libscriptc-libregexp.a +0 -0
  398. package/dist/lib/runtime-darwin-x64/artifacts/vendor/mbedtls/libscriptc-mbedtls.a +0 -0
  399. package/dist/lib/runtime-darwin-x64/artifacts/vendor/quickjs/libscriptc-quickjs.a +0 -0
  400. package/dist/lib/runtime-darwin-x64/artifacts/vendor/zlib/libscriptc-zlib.a +0 -0
  401. package/dist/lib/runtime-darwin-x64/package.json +24 -0
  402. package/dist/lib/runtime-darwin-x64/runtime-pack.json +5758 -0
  403. package/dist/lib/runtime-sources/LICENSE +202 -0
  404. package/dist/lib/runtime-sources/package.json +22 -0
  405. package/dist/lib/runtime-sources/src/scr_array.c +1444 -0
  406. package/dist/lib/runtime-sources/src/scr_assert.c +1537 -0
  407. package/dist/lib/runtime-sources/src/scr_async.c +3920 -0
  408. package/dist/lib/runtime-sources/src/scr_async.test.c +134 -0
  409. package/dist/lib/runtime-sources/src/scr_async.test.ts +34 -0
  410. package/dist/lib/runtime-sources/src/scr_async_dyn.c +803 -0
  411. package/dist/lib/runtime-sources/src/scr_bigint.c +890 -0
  412. package/dist/lib/runtime-sources/src/scr_bigint_assert.c +22 -0
  413. package/dist/lib/runtime-sources/src/scr_bytes.c +2518 -0
  414. package/dist/lib/runtime-sources/src/scr_bytes_io.c +755 -0
  415. package/dist/lib/runtime-sources/src/scr_child.c +5808 -0
  416. package/dist/lib/runtime-sources/src/scr_closure.c +213 -0
  417. package/dist/lib/runtime-sources/src/scr_console.c +259 -0
  418. package/dist/lib/runtime-sources/src/scr_console_native.c +95 -0
  419. package/dist/lib/runtime-sources/src/scr_copying.c +146 -0
  420. package/dist/lib/runtime-sources/src/scr_crypto_async.c +24 -0
  421. package/dist/lib/runtime-sources/src/scr_cycle.c +565 -0
  422. package/dist/lib/runtime-sources/src/scr_dc.c +814 -0
  423. package/dist/lib/runtime-sources/src/scr_dgram.c +1182 -0
  424. package/dist/lib/runtime-sources/src/scr_dyn_handle.c +96 -0
  425. package/dist/lib/runtime-sources/src/scr_dyn_invoke.c +1626 -0
  426. package/dist/lib/runtime-sources/src/scr_error.c +372 -0
  427. package/dist/lib/runtime-sources/src/scr_events.c +1222 -0
  428. package/dist/lib/runtime-sources/src/scr_events_emitter.c +842 -0
  429. package/dist/lib/runtime-sources/src/scr_exception.c +468 -0
  430. package/dist/lib/runtime-sources/src/scr_fetch.c +7215 -0
  431. package/dist/lib/runtime-sources/src/scr_fetch_curl.c +666 -0
  432. package/dist/lib/runtime-sources/src/scr_ffi.c +143 -0
  433. package/dist/lib/runtime-sources/src/scr_ffi_queue.c +379 -0
  434. package/dist/lib/runtime-sources/src/scr_file_handle.c +562 -0
  435. package/dist/lib/runtime-sources/src/scr_grapheme.c +203 -0
  436. package/dist/lib/runtime-sources/src/scr_grapheme_data.h +842 -0
  437. package/dist/lib/runtime-sources/src/scr_http.c +5808 -0
  438. package/dist/lib/runtime-sources/src/scr_http2.c +3243 -0
  439. package/dist/lib/runtime-sources/src/scr_inspect.c +923 -0
  440. package/dist/lib/runtime-sources/src/scr_inspect_island.c +51 -0
  441. package/dist/lib/runtime-sources/src/scr_island.c +9987 -0
  442. package/dist/lib/runtime-sources/src/scr_island_manifest.h +153 -0
  443. package/dist/lib/runtime-sources/src/scr_json.c +7928 -0
  444. package/dist/lib/runtime-sources/src/scr_json.test.c +182 -0
  445. package/dist/lib/runtime-sources/src/scr_json.test.ts +33 -0
  446. package/dist/lib/runtime-sources/src/scr_lib.c +6304 -0
  447. package/dist/lib/runtime-sources/src/scr_library.c +444 -0
  448. package/dist/lib/runtime-sources/src/scr_loop_epoll.c +241 -0
  449. package/dist/lib/runtime-sources/src/scr_loop_kqueue.c +121 -0
  450. package/dist/lib/runtime-sources/src/scr_loop_wsapoll.c +208 -0
  451. package/dist/lib/runtime-sources/src/scr_map.c +705 -0
  452. package/dist/lib/runtime-sources/src/scr_musl.c +438 -0
  453. package/dist/lib/runtime-sources/src/scr_net.c +3708 -0
  454. package/dist/lib/runtime-sources/src/scr_net_island.c +458 -0
  455. package/dist/lib/runtime-sources/src/scr_node_builtin.c +281 -0
  456. package/dist/lib/runtime-sources/src/scr_number.c +192 -0
  457. package/dist/lib/runtime-sources/src/scr_object.c +80 -0
  458. package/dist/lib/runtime-sources/src/scr_path.c +1281 -0
  459. package/dist/lib/runtime-sources/src/scr_platform.h +119 -0
  460. package/dist/lib/runtime-sources/src/scr_qs.c +496 -0
  461. package/dist/lib/runtime-sources/src/scr_readline.c +288 -0
  462. package/dist/lib/runtime-sources/src/scr_regex.c +1274 -0
  463. package/dist/lib/runtime-sources/src/scr_runtime.h +7207 -0
  464. package/dist/lib/runtime-sources/src/scr_stream.c +3149 -0
  465. package/dist/lib/runtime-sources/src/scr_string.c +1849 -0
  466. package/dist/lib/runtime-sources/src/scr_symbol.c +234 -0
  467. package/dist/lib/runtime-sources/src/scr_test.c +662 -0
  468. package/dist/lib/runtime-sources/src/scr_text_decoder_data.h +7389 -0
  469. package/dist/lib/runtime-sources/src/scr_tls.c +1806 -0
  470. package/dist/lib/runtime-sources/src/scr_tls_ca.c +433 -0
  471. package/dist/lib/runtime-sources/src/scr_union.c +105 -0
  472. package/dist/lib/runtime-sources/src/scr_url.c +1231 -0
  473. package/dist/lib/runtime-sources/src/scr_url_internal.h +29 -0
  474. package/dist/lib/runtime-sources/src/scr_url_params.c +526 -0
  475. package/dist/lib/runtime-sources/src/scr_util.c +984 -0
  476. package/dist/lib/runtime-sources/src/scr_watch.c +568 -0
  477. package/dist/lib/runtime-sources/src/scr_web.c +1854 -0
  478. package/dist/lib/runtime-sources/src/scr_win.c +231 -0
  479. package/dist/lib/runtime-sources/src/scr_win_stats.h +23 -0
  480. package/dist/lib/runtime-sources/src/scr_zlib.c +358 -0
  481. package/dist/lib/runtime-sources/src/scr_zlib_island.c +15 -0
  482. package/dist/lib/runtime-sources/vendor/README.md +60 -0
  483. package/dist/lib/runtime-sources/vendor/curl/COPYRIGHT +534 -0
  484. package/dist/lib/runtime-sources/vendor/curl/include/curl/curl.h +3214 -0
  485. package/dist/lib/runtime-sources/vendor/curl/include/curl/curlver.h +79 -0
  486. package/dist/lib/runtime-sources/vendor/curl/include/curl/easy.h +125 -0
  487. package/dist/lib/runtime-sources/vendor/curl/include/curl/header.h +74 -0
  488. package/dist/lib/runtime-sources/vendor/curl/include/curl/mprintf.h +52 -0
  489. package/dist/lib/runtime-sources/vendor/curl/include/curl/multi.h +460 -0
  490. package/dist/lib/runtime-sources/vendor/curl/include/curl/options.h +70 -0
  491. package/dist/lib/runtime-sources/vendor/curl/include/curl/stdcheaders.h +35 -0
  492. package/dist/lib/runtime-sources/vendor/curl/include/curl/system.h +508 -0
  493. package/dist/lib/runtime-sources/vendor/curl/include/curl/typecheck-gcc.h +716 -0
  494. package/dist/lib/runtime-sources/vendor/curl/include/curl/urlapi.h +149 -0
  495. package/dist/lib/runtime-sources/vendor/curl/include/curl/websockets.h +84 -0
  496. package/dist/lib/runtime-sources/vendor/mbedtls/LICENSE +553 -0
  497. package/dist/lib/runtime-sources/vendor/mbedtls/include/CMakeLists.txt +22 -0
  498. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/aes.h +631 -0
  499. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/aria.h +343 -0
  500. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/asn1.h +642 -0
  501. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/asn1write.h +390 -0
  502. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/base64.h +82 -0
  503. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/bignum.h +1088 -0
  504. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/block_cipher.h +76 -0
  505. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/build_info.h +194 -0
  506. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/camellia.h +305 -0
  507. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ccm.h +526 -0
  508. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/chacha20.h +209 -0
  509. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/chachapoly.h +351 -0
  510. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/check_config.h +1149 -0
  511. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/cipher.h +1250 -0
  512. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/cmac.h +246 -0
  513. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/compat-2.x.h +46 -0
  514. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_legacy_crypto.h +578 -0
  515. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_legacy_from_psa.h +873 -0
  516. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_psa_from_legacy.h +359 -0
  517. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_psa_superset_legacy.h +145 -0
  518. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_ssl.h +91 -0
  519. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_adjust_x509.h +35 -0
  520. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/config_psa.h +61 -0
  521. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/constant_time.h +36 -0
  522. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ctr_drbg.h +596 -0
  523. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/debug.h +156 -0
  524. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/des.h +385 -0
  525. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/dhm.h +972 -0
  526. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecdh.h +455 -0
  527. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecdsa.h +674 -0
  528. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecjpake.h +298 -0
  529. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ecp.h +1517 -0
  530. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/entropy.h +274 -0
  531. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/error.h +201 -0
  532. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/gcm.h +387 -0
  533. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/hkdf.h +124 -0
  534. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/hmac_drbg.h +434 -0
  535. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/lms.h +440 -0
  536. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/mbedtls_config.h +4446 -0
  537. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/md.h +526 -0
  538. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/md5.h +190 -0
  539. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/memory_buffer_alloc.h +142 -0
  540. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/net_sockets.h +299 -0
  541. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/nist_kw.h +166 -0
  542. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/oid.h +727 -0
  543. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pem.h +160 -0
  544. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pk.h +1303 -0
  545. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pkcs12.h +186 -0
  546. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pkcs5.h +198 -0
  547. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/pkcs7.h +252 -0
  548. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/platform.h +516 -0
  549. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/platform_time.h +79 -0
  550. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/platform_util.h +247 -0
  551. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/poly1305.h +168 -0
  552. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/private_access.h +20 -0
  553. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/psa_util.h +207 -0
  554. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ripemd160.h +136 -0
  555. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/rsa.h +1170 -0
  556. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha1.h +219 -0
  557. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha256.h +200 -0
  558. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha3.h +172 -0
  559. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/sha512.h +208 -0
  560. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl.h +5887 -0
  561. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_cache.h +187 -0
  562. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_ciphersuites.h +482 -0
  563. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_cookie.h +106 -0
  564. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/ssl_ticket.h +199 -0
  565. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/threading.h +167 -0
  566. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/timing.h +94 -0
  567. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/version.h +78 -0
  568. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509.h +500 -0
  569. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509_crl.h +184 -0
  570. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509_crt.h +1208 -0
  571. package/dist/lib/runtime-sources/vendor/mbedtls/include/mbedtls/x509_csr.h +382 -0
  572. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/build_info.h +20 -0
  573. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto.h +4998 -0
  574. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_auto_enabled.h +31 -0
  575. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_config_dependencies.h +51 -0
  576. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_config_key_pair_types.h +101 -0
  577. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_adjust_config_synonyms.h +49 -0
  578. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_builtin_composites.h +214 -0
  579. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_builtin_key_derivation.h +118 -0
  580. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_builtin_primitives.h +114 -0
  581. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_compat.h +230 -0
  582. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_config.h +145 -0
  583. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_common.h +44 -0
  584. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_contexts_composites.h +151 -0
  585. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h +52 -0
  586. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_driver_contexts_primitives.h +105 -0
  587. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_extra.h +2145 -0
  588. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_legacy.h +88 -0
  589. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_platform.h +102 -0
  590. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_se_driver.h +1383 -0
  591. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_sizes.h +1319 -0
  592. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_struct.h +527 -0
  593. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_types.h +508 -0
  594. package/dist/lib/runtime-sources/vendor/mbedtls/include/psa/crypto_values.h +2782 -0
  595. package/dist/lib/runtime-sources/vendor/mbedtls/library/aes.c +2294 -0
  596. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesce.c +624 -0
  597. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesce.h +136 -0
  598. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesni.c +846 -0
  599. package/dist/lib/runtime-sources/vendor/mbedtls/library/aesni.h +162 -0
  600. package/dist/lib/runtime-sources/vendor/mbedtls/library/alignment.h +704 -0
  601. package/dist/lib/runtime-sources/vendor/mbedtls/library/aria.c +969 -0
  602. package/dist/lib/runtime-sources/vendor/mbedtls/library/asn1parse.c +468 -0
  603. package/dist/lib/runtime-sources/vendor/mbedtls/library/asn1write.c +440 -0
  604. package/dist/lib/runtime-sources/vendor/mbedtls/library/base64.c +322 -0
  605. package/dist/lib/runtime-sources/vendor/mbedtls/library/base64_internal.h +45 -0
  606. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum.c +2583 -0
  607. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_core.c +1240 -0
  608. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_core.h +872 -0
  609. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_core_invasive.h +38 -0
  610. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_internal.h +122 -0
  611. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod.c +394 -0
  612. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod.h +452 -0
  613. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod_raw.c +276 -0
  614. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod_raw.h +416 -0
  615. package/dist/lib/runtime-sources/vendor/mbedtls/library/bignum_mod_raw_invasive.h +34 -0
  616. package/dist/lib/runtime-sources/vendor/mbedtls/library/block_cipher.c +207 -0
  617. package/dist/lib/runtime-sources/vendor/mbedtls/library/block_cipher_internal.h +99 -0
  618. package/dist/lib/runtime-sources/vendor/mbedtls/library/bn_mul.h +1094 -0
  619. package/dist/lib/runtime-sources/vendor/mbedtls/library/camellia.c +1058 -0
  620. package/dist/lib/runtime-sources/vendor/mbedtls/library/ccm.c +777 -0
  621. package/dist/lib/runtime-sources/vendor/mbedtls/library/chacha20.c +563 -0
  622. package/dist/lib/runtime-sources/vendor/mbedtls/library/chacha20_internal.h +23 -0
  623. package/dist/lib/runtime-sources/vendor/mbedtls/library/chachapoly.c +487 -0
  624. package/dist/lib/runtime-sources/vendor/mbedtls/library/check_crypto_config.h +136 -0
  625. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher.c +1712 -0
  626. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher_invasive.h +28 -0
  627. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher_wrap.c +2482 -0
  628. package/dist/lib/runtime-sources/vendor/mbedtls/library/cipher_wrap.h +178 -0
  629. package/dist/lib/runtime-sources/vendor/mbedtls/library/cmac.c +1067 -0
  630. package/dist/lib/runtime-sources/vendor/mbedtls/library/common.h +487 -0
  631. package/dist/lib/runtime-sources/vendor/mbedtls/library/constant_time.c +247 -0
  632. package/dist/lib/runtime-sources/vendor/mbedtls/library/constant_time_impl.h +541 -0
  633. package/dist/lib/runtime-sources/vendor/mbedtls/library/constant_time_internal.h +579 -0
  634. package/dist/lib/runtime-sources/vendor/mbedtls/library/ctr.h +35 -0
  635. package/dist/lib/runtime-sources/vendor/mbedtls/library/ctr_drbg.c +1016 -0
  636. package/dist/lib/runtime-sources/vendor/mbedtls/library/debug.c +475 -0
  637. package/dist/lib/runtime-sources/vendor/mbedtls/library/debug_internal.h +185 -0
  638. package/dist/lib/runtime-sources/vendor/mbedtls/library/des.c +1042 -0
  639. package/dist/lib/runtime-sources/vendor/mbedtls/library/dhm.c +700 -0
  640. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecdh.c +696 -0
  641. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecdsa.c +858 -0
  642. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecjpake.c +1216 -0
  643. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp.c +3674 -0
  644. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_curves.c +6125 -0
  645. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_curves_new.c +9 -0
  646. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_internal_alt.h +287 -0
  647. package/dist/lib/runtime-sources/vendor/mbedtls/library/ecp_invasive.h +305 -0
  648. package/dist/lib/runtime-sources/vendor/mbedtls/library/entropy.c +680 -0
  649. package/dist/lib/runtime-sources/vendor/mbedtls/library/entropy_poll.c +233 -0
  650. package/dist/lib/runtime-sources/vendor/mbedtls/library/entropy_poll.h +64 -0
  651. package/dist/lib/runtime-sources/vendor/mbedtls/library/error.c +878 -0
  652. package/dist/lib/runtime-sources/vendor/mbedtls/library/gcm.c +1330 -0
  653. package/dist/lib/runtime-sources/vendor/mbedtls/library/hkdf.c +161 -0
  654. package/dist/lib/runtime-sources/vendor/mbedtls/library/hmac_drbg.c +633 -0
  655. package/dist/lib/runtime-sources/vendor/mbedtls/library/lmots.c +789 -0
  656. package/dist/lib/runtime-sources/vendor/mbedtls/library/lmots.h +288 -0
  657. package/dist/lib/runtime-sources/vendor/mbedtls/library/lms.c +778 -0
  658. package/dist/lib/runtime-sources/vendor/mbedtls/library/md.c +1108 -0
  659. package/dist/lib/runtime-sources/vendor/mbedtls/library/md5.c +426 -0
  660. package/dist/lib/runtime-sources/vendor/mbedtls/library/md_psa.h +26 -0
  661. package/dist/lib/runtime-sources/vendor/mbedtls/library/md_wrap.h +46 -0
  662. package/dist/lib/runtime-sources/vendor/mbedtls/library/memory_buffer_alloc.c +751 -0
  663. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_common.h +181 -0
  664. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_error.h +89 -0
  665. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_reader.c +538 -0
  666. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_reader.h +366 -0
  667. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_trace.c +112 -0
  668. package/dist/lib/runtime-sources/vendor/mbedtls/library/mps_trace.h +154 -0
  669. package/dist/lib/runtime-sources/vendor/mbedtls/library/net_sockets.c +694 -0
  670. package/dist/lib/runtime-sources/vendor/mbedtls/library/nist_kw.c +729 -0
  671. package/dist/lib/runtime-sources/vendor/mbedtls/library/oid.c +1166 -0
  672. package/dist/lib/runtime-sources/vendor/mbedtls/library/padlock.c +157 -0
  673. package/dist/lib/runtime-sources/vendor/mbedtls/library/padlock.h +111 -0
  674. package/dist/lib/runtime-sources/vendor/mbedtls/library/pem.c +554 -0
  675. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk.c +1602 -0
  676. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_ecc.c +261 -0
  677. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_internal.h +241 -0
  678. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_wrap.c +1618 -0
  679. package/dist/lib/runtime-sources/vendor/mbedtls/library/pk_wrap.h +138 -0
  680. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkcs12.c +437 -0
  681. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkcs5.c +500 -0
  682. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkcs7.c +787 -0
  683. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkparse.c +1392 -0
  684. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkwrite.c +631 -0
  685. package/dist/lib/runtime-sources/vendor/mbedtls/library/pkwrite.h +121 -0
  686. package/dist/lib/runtime-sources/vendor/mbedtls/library/platform.c +402 -0
  687. package/dist/lib/runtime-sources/vendor/mbedtls/library/platform_util.c +258 -0
  688. package/dist/lib/runtime-sources/vendor/mbedtls/library/poly1305.c +492 -0
  689. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto.c +9532 -0
  690. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_aead.c +646 -0
  691. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_aead.h +499 -0
  692. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_cipher.c +747 -0
  693. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_cipher.h +316 -0
  694. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_client.c +22 -0
  695. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_core.h +983 -0
  696. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_core_common.h +52 -0
  697. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_driver_wrappers.h +2896 -0
  698. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.c +256 -0
  699. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.h +31 -0
  700. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ecp.c +594 -0
  701. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ecp.h +267 -0
  702. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ffdh.c +361 -0
  703. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_ffdh.h +131 -0
  704. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_hash.c +470 -0
  705. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_hash.h +211 -0
  706. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_invasive.h +92 -0
  707. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_its.h +131 -0
  708. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_mac.c +505 -0
  709. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_mac.h +264 -0
  710. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_pake.c +571 -0
  711. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_pake.h +159 -0
  712. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_random.c +181 -0
  713. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_random.h +72 -0
  714. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_random_impl.h +200 -0
  715. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_rsa.c +714 -0
  716. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_rsa.h +321 -0
  717. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_se.c +373 -0
  718. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_se.h +192 -0
  719. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_slot_management.c +1137 -0
  720. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_slot_management.h +344 -0
  721. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_storage.c +481 -0
  722. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_crypto_storage.h +392 -0
  723. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_its_file.c +254 -0
  724. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_util.c +614 -0
  725. package/dist/lib/runtime-sources/vendor/mbedtls/library/psa_util_internal.h +100 -0
  726. package/dist/lib/runtime-sources/vendor/mbedtls/library/ripemd160.c +490 -0
  727. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa.c +3121 -0
  728. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa_alt_helpers.c +455 -0
  729. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa_alt_helpers.h +209 -0
  730. package/dist/lib/runtime-sources/vendor/mbedtls/library/rsa_internal.h +188 -0
  731. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha1.c +480 -0
  732. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha256.c +983 -0
  733. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha3.c +721 -0
  734. package/dist/lib/runtime-sources/vendor/mbedtls/library/sha512.c +1115 -0
  735. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_cache.c +410 -0
  736. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_ciphersuites.c +2050 -0
  737. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_ciphersuites_internal.h +154 -0
  738. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_client.c +1023 -0
  739. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_client.h +22 -0
  740. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_cookie.c +384 -0
  741. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_debug_helpers.h +85 -0
  742. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_debug_helpers_generated.c +251 -0
  743. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_misc.h +3198 -0
  744. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_msg.c +6619 -0
  745. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_ticket.c +556 -0
  746. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls.c +10234 -0
  747. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls12_client.c +3688 -0
  748. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls12_server.c +4311 -0
  749. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_client.c +3208 -0
  750. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_generic.c +1793 -0
  751. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_invasive.h +23 -0
  752. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_keys.c +1918 -0
  753. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_keys.h +668 -0
  754. package/dist/lib/runtime-sources/vendor/mbedtls/library/ssl_tls13_server.c +3624 -0
  755. package/dist/lib/runtime-sources/vendor/mbedtls/library/threading.c +193 -0
  756. package/dist/lib/runtime-sources/vendor/mbedtls/library/threading_internal.h +28 -0
  757. package/dist/lib/runtime-sources/vendor/mbedtls/library/timing.c +152 -0
  758. package/dist/lib/runtime-sources/vendor/mbedtls/library/version.c +32 -0
  759. package/dist/lib/runtime-sources/vendor/mbedtls/library/version_features.c +856 -0
  760. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509.c +1776 -0
  761. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_create.c +570 -0
  762. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_crl.c +708 -0
  763. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_crt.c +3311 -0
  764. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_csr.c +648 -0
  765. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509_internal.h +101 -0
  766. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509write.c +174 -0
  767. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509write_crt.c +688 -0
  768. package/dist/lib/runtime-sources/vendor/mbedtls/library/x509write_csr.c +336 -0
  769. package/dist/lib/runtime-sources/vendor/quickjs-ng/CMakeLists.txt +566 -0
  770. package/dist/lib/runtime-sources/vendor/quickjs-ng/LICENSE +24 -0
  771. package/dist/lib/runtime-sources/vendor/quickjs-ng/README.md +24 -0
  772. package/dist/lib/runtime-sources/vendor/quickjs-ng/api-test.c +1195 -0
  773. package/dist/lib/runtime-sources/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
  774. package/dist/lib/runtime-sources/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
  775. package/dist/lib/runtime-sources/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
  776. package/dist/lib/runtime-sources/vendor/quickjs-ng/cutils.h +1998 -0
  777. package/dist/lib/runtime-sources/vendor/quickjs-ng/dtoa.c +1619 -0
  778. package/dist/lib/runtime-sources/vendor/quickjs-ng/dtoa.h +87 -0
  779. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/function_source.c +81 -0
  780. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/hello.c +53 -0
  781. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/hello_module.c +106 -0
  782. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/repl.c +3036 -0
  783. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/standalone.c +323 -0
  784. package/dist/lib/runtime-sources/vendor/quickjs-ng/gen/test_fib.c +81 -0
  785. package/dist/lib/runtime-sources/vendor/quickjs-ng/libregexp-opcode.h +73 -0
  786. package/dist/lib/runtime-sources/vendor/quickjs-ng/libregexp.c +3474 -0
  787. package/dist/lib/runtime-sources/vendor/quickjs-ng/libregexp.h +101 -0
  788. package/dist/lib/runtime-sources/vendor/quickjs-ng/libunicode-table.h +5173 -0
  789. package/dist/lib/runtime-sources/vendor/quickjs-ng/libunicode.c +2069 -0
  790. package/dist/lib/runtime-sources/vendor/quickjs-ng/libunicode.h +172 -0
  791. package/dist/lib/runtime-sources/vendor/quickjs-ng/list.h +107 -0
  792. package/dist/lib/runtime-sources/vendor/quickjs-ng/lre-test.c +52 -0
  793. package/dist/lib/runtime-sources/vendor/quickjs-ng/qjs.c +762 -0
  794. package/dist/lib/runtime-sources/vendor/quickjs-ng/qjsc.c +673 -0
  795. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-atom.h +280 -0
  796. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
  797. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-libc.c +5037 -0
  798. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-libc.h +87 -0
  799. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs-opcode.h +377 -0
  800. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs.c +64041 -0
  801. package/dist/lib/runtime-sources/vendor/quickjs-ng/quickjs.h +1447 -0
  802. package/dist/lib/runtime-sources/vendor/quickjs-ng/run-test262.c +2374 -0
  803. package/dist/lib/runtime-sources/vendor/quickjs-ng/unicode_gen.c +3121 -0
  804. package/dist/lib/runtime-sources/vendor/quickjs-ng/unicode_gen_def.h +310 -0
  805. package/dist/lib/runtime-sources/vendor/ryu/LICENSE-Boost +23 -0
  806. package/dist/lib/runtime-sources/vendor/ryu/common.h +114 -0
  807. package/dist/lib/runtime-sources/vendor/ryu/d2s.c +509 -0
  808. package/dist/lib/runtime-sources/vendor/ryu/d2s_full_table.h +367 -0
  809. package/dist/lib/runtime-sources/vendor/ryu/d2s_intrinsics.h +357 -0
  810. package/dist/lib/runtime-sources/vendor/ryu/d2s_small_table.h +186 -0
  811. package/dist/lib/runtime-sources/vendor/ryu/digit_table.h +35 -0
  812. package/dist/lib/runtime-sources/vendor/ryu/ryu.h +46 -0
  813. package/dist/lib/runtime-sources/vendor/unicode/LICENSE +39 -0
  814. package/dist/lib/runtime-sources/vendor/zlib/LICENSE +22 -0
  815. package/dist/lib/runtime-sources/vendor/zlib/adler32.c +164 -0
  816. package/dist/lib/runtime-sources/vendor/zlib/compress.c +75 -0
  817. package/dist/lib/runtime-sources/vendor/zlib/crc32.c +1049 -0
  818. package/dist/lib/runtime-sources/vendor/zlib/crc32.h +9446 -0
  819. package/dist/lib/runtime-sources/vendor/zlib/deflate.c +2139 -0
  820. package/dist/lib/runtime-sources/vendor/zlib/deflate.h +377 -0
  821. package/dist/lib/runtime-sources/vendor/zlib/gzclose.c +23 -0
  822. package/dist/lib/runtime-sources/vendor/zlib/gzguts.h +214 -0
  823. package/dist/lib/runtime-sources/vendor/zlib/gzlib.c +582 -0
  824. package/dist/lib/runtime-sources/vendor/zlib/gzread.c +602 -0
  825. package/dist/lib/runtime-sources/vendor/zlib/gzwrite.c +631 -0
  826. package/dist/lib/runtime-sources/vendor/zlib/infback.c +628 -0
  827. package/dist/lib/runtime-sources/vendor/zlib/inffast.c +320 -0
  828. package/dist/lib/runtime-sources/vendor/zlib/inffast.h +11 -0
  829. package/dist/lib/runtime-sources/vendor/zlib/inffixed.h +94 -0
  830. package/dist/lib/runtime-sources/vendor/zlib/inflate.c +1526 -0
  831. package/dist/lib/runtime-sources/vendor/zlib/inflate.h +126 -0
  832. package/dist/lib/runtime-sources/vendor/zlib/inftrees.c +299 -0
  833. package/dist/lib/runtime-sources/vendor/zlib/inftrees.h +62 -0
  834. package/dist/lib/runtime-sources/vendor/zlib/trees.c +1117 -0
  835. package/dist/lib/runtime-sources/vendor/zlib/trees.h +128 -0
  836. package/dist/lib/runtime-sources/vendor/zlib/uncompr.c +85 -0
  837. package/dist/lib/runtime-sources/vendor/zlib/zconf.h +543 -0
  838. package/dist/lib/runtime-sources/vendor/zlib/zlib.h +1938 -0
  839. package/dist/lib/runtime-sources/vendor/zlib/zutil.c +299 -0
  840. package/dist/lib/runtime-sources/vendor/zlib/zutil.h +254 -0
  841. package/dist/lib/scriptc-comptime +0 -0
  842. package/dist/lib/typescript/LICENSE +55 -0
  843. package/dist/lib/typescript/NOTICE.txt +436 -0
  844. package/dist/lib/typescript/lib/lib.d.ts +20 -0
  845. package/dist/lib/typescript/lib/lib.decorators.d.ts +382 -0
  846. package/dist/lib/typescript/lib/lib.decorators.legacy.d.ts +20 -0
  847. package/dist/lib/typescript/lib/lib.dom.asynciterable.d.ts +18 -0
  848. package/dist/lib/typescript/lib/lib.dom.d.ts +45125 -0
  849. package/dist/lib/typescript/lib/lib.dom.iterable.d.ts +18 -0
  850. package/dist/lib/typescript/lib/lib.es2015.collection.d.ts +159 -0
  851. package/dist/lib/typescript/lib/lib.es2015.core.d.ts +595 -0
  852. package/dist/lib/typescript/lib/lib.es2015.d.ts +26 -0
  853. package/dist/lib/typescript/lib/lib.es2015.generator.d.ts +75 -0
  854. package/dist/lib/typescript/lib/lib.es2015.iterable.d.ts +603 -0
  855. package/dist/lib/typescript/lib/lib.es2015.promise.d.ts +79 -0
  856. package/dist/lib/typescript/lib/lib.es2015.proxy.d.ts +126 -0
  857. package/dist/lib/typescript/lib/lib.es2015.reflect.d.ts +142 -0
  858. package/dist/lib/typescript/lib/lib.es2015.symbol.d.ts +44 -0
  859. package/dist/lib/typescript/lib/lib.es2015.symbol.wellknown.d.ts +324 -0
  860. package/dist/lib/typescript/lib/lib.es2016.array.include.d.ts +114 -0
  861. package/dist/lib/typescript/lib/lib.es2016.d.ts +19 -0
  862. package/dist/lib/typescript/lib/lib.es2016.full.d.ts +21 -0
  863. package/dist/lib/typescript/lib/lib.es2016.intl.d.ts +29 -0
  864. package/dist/lib/typescript/lib/lib.es2017.arraybuffer.d.ts +19 -0
  865. package/dist/lib/typescript/lib/lib.es2017.d.ts +24 -0
  866. package/dist/lib/typescript/lib/lib.es2017.date.d.ts +29 -0
  867. package/dist/lib/typescript/lib/lib.es2017.full.d.ts +21 -0
  868. package/dist/lib/typescript/lib/lib.es2017.intl.d.ts +42 -0
  869. package/dist/lib/typescript/lib/lib.es2017.object.d.ts +47 -0
  870. package/dist/lib/typescript/lib/lib.es2017.sharedmemory.d.ts +133 -0
  871. package/dist/lib/typescript/lib/lib.es2017.string.d.ts +47 -0
  872. package/dist/lib/typescript/lib/lib.es2017.typedarrays.d.ts +51 -0
  873. package/dist/lib/typescript/lib/lib.es2018.asyncgenerator.d.ts +75 -0
  874. package/dist/lib/typescript/lib/lib.es2018.asynciterable.d.ts +51 -0
  875. package/dist/lib/typescript/lib/lib.es2018.d.ts +22 -0
  876. package/dist/lib/typescript/lib/lib.es2018.full.d.ts +22 -0
  877. package/dist/lib/typescript/lib/lib.es2018.intl.d.ts +81 -0
  878. package/dist/lib/typescript/lib/lib.es2018.promise.d.ts +28 -0
  879. package/dist/lib/typescript/lib/lib.es2018.regexp.d.ts +35 -0
  880. package/dist/lib/typescript/lib/lib.es2019.array.d.ts +77 -0
  881. package/dist/lib/typescript/lib/lib.es2019.d.ts +22 -0
  882. package/dist/lib/typescript/lib/lib.es2019.full.d.ts +22 -0
  883. package/dist/lib/typescript/lib/lib.es2019.intl.d.ts +21 -0
  884. package/dist/lib/typescript/lib/lib.es2019.object.d.ts +31 -0
  885. package/dist/lib/typescript/lib/lib.es2019.string.d.ts +35 -0
  886. package/dist/lib/typescript/lib/lib.es2019.symbol.d.ts +22 -0
  887. package/dist/lib/typescript/lib/lib.es2020.bigint.d.ts +763 -0
  888. package/dist/lib/typescript/lib/lib.es2020.d.ts +25 -0
  889. package/dist/lib/typescript/lib/lib.es2020.date.d.ts +40 -0
  890. package/dist/lib/typescript/lib/lib.es2020.full.d.ts +22 -0
  891. package/dist/lib/typescript/lib/lib.es2020.intl.d.ts +472 -0
  892. package/dist/lib/typescript/lib/lib.es2020.number.d.ts +26 -0
  893. package/dist/lib/typescript/lib/lib.es2020.promise.d.ts +45 -0
  894. package/dist/lib/typescript/lib/lib.es2020.sharedmemory.d.ts +97 -0
  895. package/dist/lib/typescript/lib/lib.es2020.string.d.ts +42 -0
  896. package/dist/lib/typescript/lib/lib.es2020.symbol.wellknown.d.ts +39 -0
  897. package/dist/lib/typescript/lib/lib.es2021.d.ts +21 -0
  898. package/dist/lib/typescript/lib/lib.es2021.full.d.ts +22 -0
  899. package/dist/lib/typescript/lib/lib.es2021.intl.d.ts +164 -0
  900. package/dist/lib/typescript/lib/lib.es2021.promise.d.ts +46 -0
  901. package/dist/lib/typescript/lib/lib.es2021.string.d.ts +31 -0
  902. package/dist/lib/typescript/lib/lib.es2021.weakref.d.ts +76 -0
  903. package/dist/lib/typescript/lib/lib.es2022.array.d.ts +119 -0
  904. package/dist/lib/typescript/lib/lib.es2022.d.ts +23 -0
  905. package/dist/lib/typescript/lib/lib.es2022.error.d.ts +73 -0
  906. package/dist/lib/typescript/lib/lib.es2022.full.d.ts +22 -0
  907. package/dist/lib/typescript/lib/lib.es2022.intl.d.ts +143 -0
  908. package/dist/lib/typescript/lib/lib.es2022.object.d.ts +24 -0
  909. package/dist/lib/typescript/lib/lib.es2022.regexp.d.ts +37 -0
  910. package/dist/lib/typescript/lib/lib.es2022.string.d.ts +23 -0
  911. package/dist/lib/typescript/lib/lib.es2023.array.d.ts +922 -0
  912. package/dist/lib/typescript/lib/lib.es2023.collection.d.ts +19 -0
  913. package/dist/lib/typescript/lib/lib.es2023.d.ts +20 -0
  914. package/dist/lib/typescript/lib/lib.es2023.full.d.ts +22 -0
  915. package/dist/lib/typescript/lib/lib.es2023.intl.d.ts +62 -0
  916. package/dist/lib/typescript/lib/lib.es2024.arraybuffer.d.ts +63 -0
  917. package/dist/lib/typescript/lib/lib.es2024.collection.d.ts +27 -0
  918. package/dist/lib/typescript/lib/lib.es2024.d.ts +24 -0
  919. package/dist/lib/typescript/lib/lib.es2024.full.d.ts +22 -0
  920. package/dist/lib/typescript/lib/lib.es2024.object.d.ts +27 -0
  921. package/dist/lib/typescript/lib/lib.es2024.promise.d.ts +33 -0
  922. package/dist/lib/typescript/lib/lib.es2024.regexp.d.ts +23 -0
  923. package/dist/lib/typescript/lib/lib.es2024.sharedmemory.d.ts +66 -0
  924. package/dist/lib/typescript/lib/lib.es2024.string.d.ts +27 -0
  925. package/dist/lib/typescript/lib/lib.es2025.collection.d.ts +94 -0
  926. package/dist/lib/typescript/lib/lib.es2025.d.ts +23 -0
  927. package/dist/lib/typescript/lib/lib.es2025.float16.d.ts +443 -0
  928. package/dist/lib/typescript/lib/lib.es2025.full.d.ts +22 -0
  929. package/dist/lib/typescript/lib/lib.es2025.intl.d.ts +200 -0
  930. package/dist/lib/typescript/lib/lib.es2025.iterator.d.ts +146 -0
  931. package/dist/lib/typescript/lib/lib.es2025.promise.d.ts +32 -0
  932. package/dist/lib/typescript/lib/lib.es2025.regexp.d.ts +30 -0
  933. package/dist/lib/typescript/lib/lib.es5.d.ts +4599 -0
  934. package/dist/lib/typescript/lib/lib.es6.d.ts +21 -0
  935. package/dist/lib/typescript/lib/lib.esnext.array.d.ts +33 -0
  936. package/dist/lib/typescript/lib/lib.esnext.collection.d.ts +47 -0
  937. package/dist/lib/typescript/lib/lib.esnext.d.ts +27 -0
  938. package/dist/lib/typescript/lib/lib.esnext.date.d.ts +21 -0
  939. package/dist/lib/typescript/lib/lib.esnext.decorators.d.ts +26 -0
  940. package/dist/lib/typescript/lib/lib.esnext.disposable.d.ts +191 -0
  941. package/dist/lib/typescript/lib/lib.esnext.error.d.ts +22 -0
  942. package/dist/lib/typescript/lib/lib.esnext.full.d.ts +22 -0
  943. package/dist/lib/typescript/lib/lib.esnext.intl.d.ts +107 -0
  944. package/dist/lib/typescript/lib/lib.esnext.sharedmemory.d.ts +23 -0
  945. package/dist/lib/typescript/lib/lib.esnext.temporal.d.ts +485 -0
  946. package/dist/lib/typescript/lib/lib.esnext.typedarrays.d.ts +90 -0
  947. package/dist/lib/typescript/lib/lib.scripthost.d.ts +320 -0
  948. package/dist/lib/typescript/lib/lib.webworker.asynciterable.d.ts +18 -0
  949. package/dist/lib/typescript/lib/lib.webworker.d.ts +15606 -0
  950. package/dist/lib/typescript/lib/lib.webworker.importscripts.d.ts +21 -0
  951. package/dist/lib/typescript/lib/lib.webworker.iterable.d.ts +18 -0
  952. package/dist/lib/typescript/lib/tsc +0 -0
  953. package/dist/lib/typescript/package.json +45 -0
  954. package/dist/lib/wasi/cli/wasi-paths.js +41 -0
  955. package/dist/lib/wasi/cli/wasi-runner.js +28 -0
  956. package/dist/lib/wasi/package.json +1 -0
  957. package/dist/lib/wasi/wasi-paths.js +25 -0
  958. package/package.json +22 -6
  959. package/README.md +0 -3
  960. package/index.js +0 -2
@@ -0,0 +1,3149 @@
1
+ /* node:stream — the runtime-provided stream classes behind the
2
+ * options-object constructor forms (`new Readable({ read() {} })` et al).
3
+ * This translation unit links ONLY into binaries whose IR touches the
4
+ * stream surface (moduleUsesStream — the scr_events_emitter.c gating
5
+ * precedent); stream-free binaries keep their exact link line.
6
+ *
7
+ * ONE layout for all five classes (ScrStream: the ScrEmitter prefix plus
8
+ * a state block), so upcasts among them and to ScrEmitter are pointer
9
+ * reinterprets. Events dispatch through the embedded emitter registry —
10
+ * scr_emitter_emit's variadic core — with the frontend's PER-BASE forced
11
+ * tuples guaranteeing every 'data' listener reads one ScrBytes*, every
12
+ * 'pipe'/'unpipe' listener one ScrStream*, and the lifecycle events
13
+ * nothing.
14
+ *
15
+ * EVENT TIMING. Node schedules most stream emissions on process.nextTick;
16
+ * here each deferral enqueues on the stream tick FIFO AND posts a raw
17
+ * marker on the USER nextTick queue (scr_next_tick_raw), so stream
18
+ * emissions and user nextTicks run in true FIFO enqueue order — Node's,
19
+ * where they are the same queue. The scr_loop_set_stream station remains
20
+ * as the drain of anything a marker never reached (and the uncaught-throw
21
+ * cleanup). The implemented orderings follow lib/internal/streams:
22
+ * - on('data') starts flowing on a TICK (resume_): synchronous code
23
+ * after the registration runs before the first 'data'.
24
+ * - push() while flowing with an empty buffer emits 'data'
25
+ * SYNCHRONOUSLY (addChunk's direct-emit fast path).
26
+ * - 'readable' is emitted on a tick (emitReadable_), collapsed while
27
+ * one is already scheduled (emittedReadable).
28
+ * - push(null) → 'end' fires on a tick once the buffer drains, then
29
+ * autoDestroy (default) destroys and 'close' follows on the NEXT
30
+ * tick.
31
+ * - write() calls the user write synchronously; a SYNCHRONOUS
32
+ * completion defers afterWrite (the user cb + 'drain') to a tick
33
+ * (Node's onwrite sync guard), an async completion runs it directly.
34
+ * - end() → (buffer drains) → _final → 'prefinish' (sync) → 'finish'
35
+ * on a tick → autoDestroy → 'close' on the next tick.
36
+ * - destroy(err) calls _destroy synchronously; 'error' then 'close'
37
+ * fire on ticks (error first, close after — Node's order).
38
+ * An unhandled 'error' event throws its payload through the exception
39
+ * cell (scr_emitter_emit_error) — the loop's dispatch surfaces it as the
40
+ * uncaught crash, Node's contract.
41
+ *
42
+ * DOCUMENTED DIVERGENCES (SEMANTICS.md, the stream block): tick-vs-
43
+ * microtask interleaving (Node runs nextTick callbacks before promise
44
+ * jobs; this queue drains after the fiber ready-queue), pipe() without
45
+ * registry-visible listeners (listenerCount('data') does not count the
46
+ * C-side pipe hookup), and Transform completing writes without read-side
47
+ * backpressure. */
48
+ #include "scr_runtime.h"
49
+
50
+ #include <stdio.h>
51
+ #include <stdlib.h>
52
+ #include <string.h>
53
+
54
+ /* Node v24's stream default (lib/internal/streams/state.js — 64 KiB
55
+ * since nodejs/node#52037, EXCEPT win32, where the very same line keeps
56
+ * the old 16 KiB: `process.platform === 'win32' ? 16 * 1024 : 64 * 1024`.
57
+ * The triple decides at compile time, like the path/EOL bindings). */
58
+ #ifdef _WIN32
59
+ #define SCR_STREAM_DEFAULT_HWM 16384
60
+ #else
61
+ #define SCR_STREAM_DEFAULT_HWM 65536
62
+ #endif
63
+
64
+ static void scr_stream_oom(void) {
65
+ fputs("scriptc: out of memory\n", stderr);
66
+ abort();
67
+ }
68
+
69
+ /* ── state ────────────────────────────────────────────────────────────── */
70
+
71
+ typedef struct ScrWEntry {
72
+ ScrBytes *chunk; /* owned */
73
+ ScrClosure *cb; /* owned or NULL (the user's write(chunk, cb) callback) */
74
+ } ScrWEntry;
75
+
76
+ struct ScrStreamState {
77
+ bool has_r, has_w;
78
+ bool passthrough; /* identity transform (PassThrough) */
79
+ bool is_transform; /* the writable side routes through transform/flush */
80
+ bool allow_half_open;
81
+ bool auto_destroy, emit_close;
82
+
83
+ /* shared lifecycle */
84
+ bool destroyed, destroy_calling, error_emitted, close_emitted, error_scheduled, close_scheduled;
85
+ /* a parked for-await consumed the error as its rejection: the 'error'
86
+ * EVENT is suppressed unless a user listener exists (Node's iterator
87
+ * registers its own handler, so no unhandled-'error' crash occurs) */
88
+ bool next_err_consumed;
89
+ ScrError *errored; /* owned */
90
+
91
+ /* readable side. The buffer holds owned ScrBytes* chunks — or, once an
92
+ * encoding is set (setEncoding / the encoding option), owned ScrStr*
93
+ * entries: pushes decode through the StringDecoder machinery, lengths
94
+ * count JS string units (Node's encoded accounting), and head_off
95
+ * counts CHARS consumed of buf[0] instead of bytes. */
96
+ struct {
97
+ size_t hwm, length;
98
+ void **buf; /* queue of owned chunks; buf[0] read from head_off */
99
+ size_t n, cap, head_off;
100
+ int flowing; /* -1 null, 0 paused, 1 flowing */
101
+ bool reading, in_read_sync, ended, end_emitted, end_scheduled;
102
+ bool need_readable, emitted_readable, readable_listening;
103
+ bool resume_scheduled, maybe_more_scheduled;
104
+ bool encoded; /* string-chunk mode (decoder active) */
105
+ ScrStr *enc; /* owned canonical encoding name, or NULL */
106
+ double dec_pending; /* scr_strdec packed pending state */
107
+ /* The defaultEncoding option's push-side effect: how push(string)
108
+ * DECODES string chunks into bytes (Node's Buffer.from(chunk,
109
+ * state.defaultEncoding)). Owned canonical name; NULL = utf8. */
110
+ ScrStr *push_enc;
111
+ /* Readable.from mode: entries are whole OBJECTS (each counts 1
112
+ * toward length/hwm and delivers undivided — Node's objectMode
113
+ * accounting for the from() surface; hwm is 1). */
114
+ bool object_entries;
115
+ /* The parked for-await next() promise (at most one — the loop awaits
116
+ * each chunk before asking again). next_dyn picks the resolution
117
+ * shape: a dyn boxed by tag (the JS lane), or bytes. */
118
+ ScrPromise *next_waiter;
119
+ bool next_dyn;
120
+ ScrClosure *read_cb;
121
+ ScrStreamReadInv read_inv;
122
+ } r;
123
+
124
+ /* writable side */
125
+ struct {
126
+ size_t hwm, length, inflight_len;
127
+ ScrWEntry *q;
128
+ size_t n, cap, head;
129
+ int corked;
130
+ bool writing, wsync, need_drain, after_scheduled;
131
+ bool ending, finished, prefinished, final_called, finish_scheduled;
132
+ ScrClosure *inflight_cb; /* owned or NULL */
133
+ ScrClosure *write_cb;
134
+ ScrStreamChunkInv write_inv;
135
+ ScrClosure *final_cb;
136
+ ScrStreamPlainInv final_inv;
137
+ ScrClosure **end_cbs; /* owned end(cb) callbacks, fired at 'finish' */
138
+ size_t end_cbs_n, end_cbs_cap;
139
+ } w;
140
+
141
+ /* transform */
142
+ ScrClosure *transform_cb;
143
+ ScrStreamChunkInv transform_inv;
144
+ ScrClosure *flush_cb;
145
+ ScrStreamPlainInv flush_inv;
146
+ bool flush_called;
147
+
148
+ /* destroy */
149
+ ScrClosure *destroy_cb;
150
+ ScrStreamErrInv destroy_inv;
151
+
152
+ /* finished()/pipeline() watchers: fired once at the terminal point
153
+ * (the 'close' tick — or a registration-time tick when already closed)
154
+ * with the stream's finish status (NULL / the error / premature close).
155
+ * A watcher's presence marks lifecycle errors HANDLED (Node's eos and
156
+ * pipeline both register 'error' listeners, so no unhandled crash). */
157
+ struct {
158
+ ScrClosure **cb;
159
+ ScrStreamErrInv *inv;
160
+ size_t n, cap;
161
+ } fin;
162
+
163
+ /* pipes (src side): owned destination refs */
164
+ struct {
165
+ ScrStream **dst;
166
+ bool *end;
167
+ size_t n, cap;
168
+ } pipes;
169
+ size_t await_drain; /* pipe destinations we are waiting on */
170
+
171
+ /* pipe sources awaiting THIS stream's drain (dst side): owned refs */
172
+ struct {
173
+ ScrStream **src;
174
+ size_t n, cap;
175
+ } drain_srcs;
176
+ };
177
+
178
+ /* ── vtables and RC ───────────────────────────────────────────────────── */
179
+
180
+ /* The five runtime vtables start with the EMPTY preorder interval
181
+ * (pre 1 > post 0): main() stamps the real interval exactly when the
182
+ * class def rides the module, and an unstamped vt must never claim a
183
+ * user class whose preorder number happens to collide (scr_stream_is
184
+ * below tests interval membership for compiler-emitted subclasses). */
185
+ static void scr_stream_release_direct(void *obj);
186
+ ScrVt scr_readable_vt = {1, 0, &scr_stream_release_direct};
187
+ ScrVt scr_writable_vt = {1, 0, &scr_stream_release_direct};
188
+ ScrVt scr_duplex_vt = {1, 0, &scr_stream_release_direct};
189
+ ScrVt scr_transform_vt = {1, 0, &scr_stream_release_direct};
190
+ ScrVt scr_passthrough_vt = {1, 0, &scr_stream_release_direct};
191
+
192
+ static bool scr_vt_within(const ScrVt *vt, const ScrVt *cls) {
193
+ return cls->pre <= vt->pre && vt->pre <= cls->post;
194
+ }
195
+
196
+ /* True for the five runtime classes AND compiler-emitted user subclasses
197
+ * (their structs embed the full ScrStream prefix, and their vtable's
198
+ * preorder number sits inside a stream class's stamped interval — the
199
+ * instanceof machinery). Duplex/Transform/PassThrough intervals nest
200
+ * inside Readable's, so two tests cover the forest. */
201
+ static bool scr_stream_is(const ScrEmitter *em) {
202
+ const ScrVt *vt = em->vt;
203
+ if (vt == &scr_readable_vt || vt == &scr_writable_vt || vt == &scr_duplex_vt ||
204
+ vt == &scr_transform_vt || vt == &scr_passthrough_vt) {
205
+ return true;
206
+ }
207
+ return scr_vt_within(vt, &scr_readable_vt) || scr_vt_within(vt, &scr_writable_vt) ||
208
+ scr_vt_within(vt, &scr_duplex_vt) || scr_vt_within(vt, &scr_transform_vt) ||
209
+ scr_vt_within(vt, &scr_passthrough_vt);
210
+ }
211
+
212
+ /* Readable-buffer entry accessors: bytes chunks, or strings once an
213
+ * encoding is set (lengths then count JS string units, Node's encoded
214
+ * accounting). */
215
+ static size_t scr_stream_entry_len(const ScrStreamState *st, void *e) {
216
+ if (st->r.object_entries) return 1; /* objectMode-style accounting */
217
+ return st->r.encoded ? (size_t)scr_str_utf16_len((ScrStr *)e) : ((ScrBytes *)e)->len;
218
+ }
219
+
220
+ static void scr_stream_entry_release(const ScrStreamState *st, void *e) {
221
+ if (st->r.encoded) scr_str_release((ScrStr *)e);
222
+ else scr_bytes_release((ScrBytes *)e);
223
+ }
224
+
225
+ static void scr_stream_state_drop(ScrStreamState *st, bool gc) {
226
+ if (!st) return;
227
+ if (st->errored) scr_error_release(st->errored);
228
+ for (size_t i = 0; i < st->r.n; i++) scr_stream_entry_release(st, st->r.buf[i]);
229
+ free(st->r.buf);
230
+ if (st->r.enc) scr_str_release(st->r.enc);
231
+ if (st->r.push_enc) scr_str_release(st->r.push_enc);
232
+ if (!gc && st->r.next_waiter) scr_promise_release(st->r.next_waiter);
233
+ if (!gc) {
234
+ if (st->r.read_cb) scr_closure_release(st->r.read_cb);
235
+ if (st->w.write_cb) scr_closure_release(st->w.write_cb);
236
+ if (st->w.final_cb) scr_closure_release(st->w.final_cb);
237
+ if (st->w.inflight_cb) scr_closure_release(st->w.inflight_cb);
238
+ if (st->transform_cb) scr_closure_release(st->transform_cb);
239
+ if (st->flush_cb) scr_closure_release(st->flush_cb);
240
+ if (st->destroy_cb) scr_closure_release(st->destroy_cb);
241
+ for (size_t i = 0; i < st->w.end_cbs_n; i++) scr_closure_release(st->w.end_cbs[i]);
242
+ for (size_t i = 0; i < st->fin.n; i++) scr_closure_release(st->fin.cb[i]);
243
+ for (size_t i = 0; i < st->pipes.n; i++) scr_stream_release(st->pipes.dst[i]);
244
+ for (size_t i = 0; i < st->drain_srcs.n; i++) scr_stream_release(st->drain_srcs.src[i]);
245
+ }
246
+ for (size_t i = st->w.head; i < st->w.n; i++) {
247
+ scr_bytes_release(st->w.q[i].chunk);
248
+ if (!gc && st->w.q[i].cb) scr_closure_release(st->w.q[i].cb);
249
+ }
250
+ free(st->w.q);
251
+ free(st->w.end_cbs);
252
+ free(st->fin.cb);
253
+ free(st->fin.inv);
254
+ free(st->pipes.dst);
255
+ free(st->pipes.end);
256
+ free(st->drain_srcs.src);
257
+ free(st);
258
+ }
259
+
260
+ /* The compiler-emitted subclass RC/trace entry points: a user `extends
261
+ * Readable` struct embeds the ScrStream prefix (vt, registry, display
262
+ * name, state pointer), so its emitted teardown/trace delegate the STATE
263
+ * here (the registry rides scr_emitter_reg_* like any emitter subclass).
264
+ * NULL-safe: an exception before super(options) leaves st unset. */
265
+ void scr_stream_st_release(ScrStreamState *st) { scr_stream_state_drop(st, false); }
266
+ void scr_stream_st_gcfree(ScrStreamState *st) { scr_stream_state_drop(st, true); }
267
+
268
+ void scr_stream_st_trace(ScrStreamState *st, ScrTraceVisit visit, void *ctx) {
269
+ if (!st) return;
270
+ if (st->r.next_waiter) visit(st->r.next_waiter, ctx);
271
+ if (st->r.read_cb) visit(st->r.read_cb, ctx);
272
+ if (st->w.write_cb) visit(st->w.write_cb, ctx);
273
+ if (st->w.final_cb) visit(st->w.final_cb, ctx);
274
+ if (st->w.inflight_cb) visit(st->w.inflight_cb, ctx);
275
+ if (st->transform_cb) visit(st->transform_cb, ctx);
276
+ if (st->flush_cb) visit(st->flush_cb, ctx);
277
+ if (st->destroy_cb) visit(st->destroy_cb, ctx);
278
+ for (size_t i = 0; i < st->w.end_cbs_n; i++) visit(st->w.end_cbs[i], ctx);
279
+ for (size_t i = 0; i < st->fin.n; i++) visit(st->fin.cb[i], ctx);
280
+ for (size_t i = st->w.head; i < st->w.n; i++) {
281
+ if (st->w.q[i].cb) visit(st->w.q[i].cb, ctx);
282
+ }
283
+ for (size_t i = 0; i < st->pipes.n; i++) visit(st->pipes.dst[i], ctx);
284
+ for (size_t i = 0; i < st->drain_srcs.n; i++) visit(st->drain_srcs.src[i], ctx);
285
+ }
286
+
287
+ void scr_stream_trace(void *obj, ScrTraceVisit visit, void *ctx) {
288
+ ScrStream *s = obj;
289
+ scr_emitter_reg_trace(s->reg, visit, ctx);
290
+ scr_stream_st_trace(s->st, visit, ctx);
291
+ }
292
+
293
+ static void scr_stream_gcfree(void *obj) {
294
+ ScrStream *s = obj;
295
+ scr_emitter_reg_gcfree(s->reg);
296
+ scr_stream_state_drop(s->st, true);
297
+ scr_obj_free_note();
298
+ scr_cyc_free(obj);
299
+ }
300
+
301
+ static void scr_stream_release_direct(void *obj) {
302
+ ScrStream *s = obj;
303
+ if (--s->rc == 0) {
304
+ scr_cyc_on_dead(s);
305
+ scr_emitter_reg_drop(s->reg);
306
+ scr_stream_state_drop(s->st, false);
307
+ scr_obj_free_note();
308
+ scr_cyc_free(s);
309
+ } else {
310
+ scr_cyc_on_release(s);
311
+ }
312
+ }
313
+
314
+ ScrStream *scr_stream_retain(ScrStream *s) {
315
+ if (s && s->rc != SIZE_MAX) {
316
+ s->rc++;
317
+ scr_cyc_mark_live(s);
318
+ }
319
+ return s;
320
+ }
321
+
322
+ void scr_stream_release(ScrStream *s) {
323
+ if (!s || s->rc == SIZE_MAX) return;
324
+ s->vt->release(s);
325
+ }
326
+
327
+ void *scr_stream_retain_v(void *s) { return scr_stream_retain(s); }
328
+ void scr_stream_release_v(void *s) { scr_stream_release(s); }
329
+
330
+ /* ── the tick queue (the nextTick stand-in) ───────────────────────────── */
331
+
332
+ typedef enum {
333
+ SCR_ST_RESUME, /* resume_: read(0) kick, 'resume', flow */
334
+ SCR_ST_READABLE, /* emitReadable_: 'readable', then flow */
335
+ SCR_ST_END, /* endReadableNT: 'end', autoDestroy/half-open */
336
+ SCR_ST_MAYBE_MORE, /* maybeReadMore_: refill toward hwm */
337
+ SCR_ST_AFTER_WRITE, /* deferred afterWrite (sync completion) */
338
+ SCR_ST_FINISH, /* 'finish', end cbs, autoDestroy */
339
+ SCR_ST_ERROR, /* 'error' with the owned payload */
340
+ SCR_ST_CLOSE, /* 'close' (when emitClose) */
341
+ SCR_ST_END_W, /* half-open: end the writable side */
342
+ SCR_ST_WCB_ERR, /* a failed write's user cb (called plain) */
343
+ SCR_ST_NEXT_EOF, /* a parked for-await's EOF sentinel, AFTER 'end' */
344
+ SCR_ST_FIN, /* notify finished()/pipeline watchers (already-
345
+ * terminal registration) */
346
+ } ScrStreamTickOp;
347
+
348
+ typedef struct ScrStreamTick {
349
+ ScrStream *s; /* owned */
350
+ ScrStreamTickOp op;
351
+ ScrError *err; /* owned or NULL (SCR_ST_ERROR) */
352
+ ScrClosure *cb; /* owned or NULL (SCR_ST_AFTER_WRITE / SCR_ST_WCB_ERR) */
353
+ struct ScrStreamTick *next;
354
+ } ScrStreamTick;
355
+
356
+ static ScrStreamTick *scr_st_head = NULL;
357
+ static ScrStreamTick *scr_st_tail = NULL;
358
+
359
+ static void scr_stream_dispatch_one(void);
360
+
361
+ static void scr_st_tick(ScrStream *s, ScrStreamTickOp op, ScrError *err /*moves*/,
362
+ ScrClosure *cb /*moves*/) {
363
+ ScrStreamTick *t = calloc(1, sizeof *t);
364
+ if (!t) scr_stream_oom();
365
+ t->s = scr_stream_retain(s);
366
+ t->op = op;
367
+ t->err = err;
368
+ t->cb = cb;
369
+ if (scr_st_tail) scr_st_tail->next = t;
370
+ else scr_st_head = t;
371
+ scr_st_tail = t;
372
+ /* One marker per tick on the USER nextTick queue: stream emissions are
373
+ * process.nextTicks in Node (resume_, emitReadable_, endReadableNT,
374
+ * afterWrite, ...), so they must interleave with user nextTicks in
375
+ * enqueue order — a `push(); on('data'); process.nextTick(assert)`
376
+ * sequence sees its data before the assert runs. The station dispatch
377
+ * below stays as the drain of anything a marker never reached. */
378
+ scr_next_tick_raw(&scr_stream_dispatch_one);
379
+ }
380
+
381
+ static bool scr_stream_ticks_pending(void) { return scr_st_head != NULL; }
382
+
383
+ /* ── emit helpers ─────────────────────────────────────────────────────── */
384
+
385
+ static bool scr_stream_emit0(ScrStream *s, const char *name) {
386
+ ScrStr *n = scr_str_new(name, strlen(name));
387
+ bool had = scr_emitter_emit((ScrEmitter *)s, n);
388
+ scr_str_release(n);
389
+ return had;
390
+ }
391
+
392
+ static void scr_stream_emit_stream(ScrStream *s, const char *name, ScrStream *payload) {
393
+ ScrStr *n = scr_str_new(name, strlen(name));
394
+ scr_emitter_emit((ScrEmitter *)s, n, payload);
395
+ scr_str_release(n);
396
+ }
397
+
398
+ /* 'error': unhandled throws the payload (Node's crash), via the emitter's
399
+ * error contract. Borrows err. */
400
+ static void scr_stream_emit_error(ScrStream *s, ScrError *err) {
401
+ ScrStr *n = scr_str_new("error", 5);
402
+ scr_emitter_emit_error((ScrEmitter *)s, n, err);
403
+ scr_str_release(n);
404
+ }
405
+
406
+ static ScrError *scr_stream_mkerr(const char *code, const char *msg) {
407
+ ScrStr *m = scr_str_new(msg, strlen(msg));
408
+ ScrError *e = scr_error_new(SCR_ERR_ERROR, m);
409
+ scr_str_release(m);
410
+ scr_error_set_code(e, code);
411
+ return e;
412
+ }
413
+
414
+ /* ── forward decls ────────────────────────────────────────────────────── */
415
+
416
+ static void scr_stream_flow(ScrStream *s);
417
+ static void scr_stream_emit_readable_now(ScrStream *s);
418
+ static void scr_stream_maybe_read_more(ScrStream *s);
419
+ static void scr_stream_finish_maybe(ScrStream *s);
420
+ static void scr_stream_clear_buffer(ScrStream *s);
421
+ static void scr_stream_do_destroy(ScrStream *s, ScrError *err /*borrowed*/);
422
+ static void scr_stream_notify_finished(ScrStream *s);
423
+ static void *scr_stream_read_n(ScrStream *s, double size);
424
+ static void scr_stream_settle_next(ScrStream *s);
425
+ static ScrStream *scr_stream_alloc(const ScrVt *vt, const char *cls, bool has_r, bool has_w,
426
+ double rhwm, double whwm, bool auto_destroy,
427
+ bool emit_close, bool allow_half_open);
428
+
429
+ /* errorOrDestroy: autoDestroy (the default) destroys with the error;
430
+ * otherwise the error emits on a tick. Borrows err. */
431
+ static void scr_stream_error_or_destroy(ScrStream *s, ScrError *err) {
432
+ ScrStreamState *st = s->st;
433
+ if (st->destroyed) return; /* err stays the caller's borrow */
434
+ if (st->auto_destroy) {
435
+ scr_stream_do_destroy(s, err);
436
+ } else {
437
+ if (!st->errored) st->errored = scr_error_retain(err);
438
+ if (!st->error_scheduled) {
439
+ st->error_scheduled = true;
440
+ scr_st_tick(s, SCR_ST_ERROR, scr_error_retain(err), NULL);
441
+ }
442
+ scr_stream_settle_next(s); /* a parked for-await rejects with the error */
443
+ }
444
+ }
445
+
446
+ /* ── readable internals ───────────────────────────────────────────────── */
447
+
448
+ static void scr_stream_rbuf_push(ScrStreamState *st, void *chunk /*moves*/, bool front) {
449
+ if (st->r.n == st->r.cap) {
450
+ st->r.cap = st->r.cap ? st->r.cap * 2 : 4;
451
+ st->r.buf = realloc(st->r.buf, st->r.cap * sizeof *st->r.buf);
452
+ if (!st->r.buf) scr_stream_oom();
453
+ }
454
+ if (front) {
455
+ /* unshift: head_off must be zero (only buf[0] is partially consumed,
456
+ * and unshift with a part-read head keeps the remainder intact by
457
+ * materializing it first — the caller slices). */
458
+ memmove(st->r.buf + 1, st->r.buf, st->r.n * sizeof *st->r.buf);
459
+ st->r.buf[0] = chunk;
460
+ } else {
461
+ st->r.buf[st->r.n] = chunk;
462
+ }
463
+ st->r.n++;
464
+ st->r.length += scr_stream_entry_len(st, chunk);
465
+ }
466
+
467
+ /* Takes n units (n <= length; bytes, or chars once encoded) off the
468
+ * buffer head as one +1 Buffer / string. */
469
+ static void *scr_stream_rbuf_take(ScrStreamState *st, size_t n) {
470
+ void *first = st->r.n > 0 ? st->r.buf[0] : NULL;
471
+ if (first && st->r.head_off == 0 && scr_stream_entry_len(st, first) == n) {
472
+ /* whole-chunk fast path: hand the buffered chunk out as-is */
473
+ memmove(st->r.buf, st->r.buf + 1, (st->r.n - 1) * sizeof *st->r.buf);
474
+ st->r.n--;
475
+ st->r.length -= n;
476
+ return first;
477
+ }
478
+ if (st->r.encoded) {
479
+ /* string mode: slice by JS string units (Node's fromList over
480
+ * strings), concatenating across entries. */
481
+ ScrStr *out = NULL;
482
+ size_t at = 0;
483
+ while (at < n) {
484
+ ScrStr *head = st->r.buf[0];
485
+ size_t head_len = (size_t)scr_str_utf16_len(head);
486
+ size_t avail = head_len - st->r.head_off;
487
+ size_t take = avail < n - at ? avail : n - at;
488
+ ScrStr *piece = scr_str_slice(head, (double)st->r.head_off, (double)(st->r.head_off + take));
489
+ if (out == NULL) {
490
+ out = piece;
491
+ } else {
492
+ ScrStr *joined = scr_str_concat(out, piece);
493
+ scr_str_release(out);
494
+ scr_str_release(piece);
495
+ out = joined;
496
+ }
497
+ at += take;
498
+ st->r.head_off += take;
499
+ if (st->r.head_off == head_len) {
500
+ scr_str_release(head);
501
+ memmove(st->r.buf, st->r.buf + 1, (st->r.n - 1) * sizeof *st->r.buf);
502
+ st->r.n--;
503
+ st->r.head_off = 0;
504
+ }
505
+ }
506
+ st->r.length -= n;
507
+ return out;
508
+ }
509
+ ScrBytes *out = scr_bytes_new(SCR_BYTES_U8, (double)n);
510
+ size_t at = 0;
511
+ while (at < n) {
512
+ ScrBytes *head = st->r.buf[0];
513
+ size_t avail = head->len - st->r.head_off;
514
+ size_t take = avail < n - at ? avail : n - at;
515
+ memcpy(out->data + at, head->data + st->r.head_off, take);
516
+ at += take;
517
+ st->r.head_off += take;
518
+ if (st->r.head_off == head->len) {
519
+ scr_bytes_release(head);
520
+ memmove(st->r.buf, st->r.buf + 1, (st->r.n - 1) * sizeof *st->r.buf);
521
+ st->r.n--;
522
+ st->r.head_off = 0;
523
+ }
524
+ }
525
+ st->r.length -= n;
526
+ return out;
527
+ }
528
+
529
+ /* emit('data', chunk) + pipe delivery. Borrows chunk (a Buffer, or a
530
+ * string once encoded). The emit ABI carries BOTH payload slots — the
531
+ * bytes chunk and the string chunk, exactly one non-NULL — and the
532
+ * compiler's stream-data listener thunks dispatch on which (typed
533
+ * listeners unwrap their declared side; dyn listeners box by tag). */
534
+ static void scr_stream_emit_data(ScrStream *s, void *chunk) {
535
+ ScrStreamState *st = s->st;
536
+ ScrBytes *b = st->r.encoded ? NULL : (ScrBytes *)chunk;
537
+ ScrStr *str = st->r.encoded ? (ScrStr *)chunk : NULL;
538
+ ScrStr *n = scr_str_new("data", 4);
539
+ scr_emitter_emit((ScrEmitter *)s, n, b, str);
540
+ scr_str_release(n);
541
+ if (scr_exc_pending()) return;
542
+ /* pipe delivery, with backpressure: a full destination pauses us until
543
+ * its 'drain'. Encoded sources write the string (utf8 bytes at the
544
+ * destination — Node writes the decoded string through). */
545
+ for (size_t i = 0; i < st->pipes.n;) {
546
+ ScrStream *dst = st->pipes.dst[i];
547
+ if (dst->st->destroyed) {
548
+ /* Node's pipe cleanup: a destroyed destination unhooks (the
549
+ * onerror/onclose → unpipe path) and pauses the source — writing
550
+ * after destroy would drop the error silently and spin an infinite
551
+ * synchronous flow over an endless source. */
552
+ scr_stream_release(scr_stream_unpipe(s, dst));
553
+ if (scr_exc_pending()) return;
554
+ continue; /* the pipes array shifted down over i */
555
+ }
556
+ bool ok = b ? scr_stream_write(dst, b, NULL) : scr_stream_write_str(dst, str, NULL);
557
+ if (scr_exc_pending()) return;
558
+ i++;
559
+ if (!ok && !dst->st->destroyed) {
560
+ ScrStreamState *dstt = dst->st;
561
+ /* register once */
562
+ bool already = false;
563
+ for (size_t j = 0; j < dstt->drain_srcs.n; j++) {
564
+ if (dstt->drain_srcs.src[j] == s) already = true;
565
+ }
566
+ if (!already) {
567
+ if (dstt->drain_srcs.n == dstt->drain_srcs.cap) {
568
+ dstt->drain_srcs.cap = dstt->drain_srcs.cap ? dstt->drain_srcs.cap * 2 : 2;
569
+ dstt->drain_srcs.src = realloc(dstt->drain_srcs.src, dstt->drain_srcs.cap * sizeof *dstt->drain_srcs.src);
570
+ if (!dstt->drain_srcs.src) scr_stream_oom();
571
+ }
572
+ dstt->drain_srcs.src[dstt->drain_srcs.n++] = scr_stream_retain(s);
573
+ st->await_drain++;
574
+ st->r.flowing = 0;
575
+ }
576
+ }
577
+ }
578
+ }
579
+
580
+ static void scr_stream_emit_readable_nt(ScrStream *s) {
581
+ ScrStreamState *st = s->st;
582
+ st->r.need_readable = false; /* Node's emitReadable clears the ask */
583
+ if (!st->r.emitted_readable) {
584
+ st->r.emitted_readable = true;
585
+ scr_st_tick(s, SCR_ST_READABLE, NULL, NULL);
586
+ }
587
+ }
588
+
589
+ static void scr_stream_end_readable(ScrStream *s) {
590
+ ScrStreamState *st = s->st;
591
+ if (st->r.end_emitted || st->r.end_scheduled) return;
592
+ st->r.end_scheduled = true;
593
+ scr_st_tick(s, SCR_ST_END, NULL, NULL);
594
+ }
595
+
596
+ /* The user _read call (reading guard + sync flag). Absent read cb means
597
+ * ERR_METHOD_NOT_IMPLEMENTED, Node's contract. */
598
+ static void scr_stream_call_read(ScrStream *s) {
599
+ ScrStreamState *st = s->st;
600
+ if (st->r.read_cb == NULL && st->r.object_entries) {
601
+ /* Readable.from: fully seeded at construction — _read is a no-op */
602
+ st->r.in_read_sync = false;
603
+ return;
604
+ }
605
+ if (st->r.read_cb == NULL && !st->is_transform && !st->passthrough) {
606
+ ScrError *e = scr_stream_mkerr("ERR_METHOD_NOT_IMPLEMENTED", "The _read() method is not implemented");
607
+ scr_stream_error_or_destroy(s, e);
608
+ scr_error_release(e);
609
+ return;
610
+ }
611
+ if (st->r.read_cb == NULL) {
612
+ /* transform reads are push-driven; the attempt still clears the
613
+ * initial sync flag (Node's Transform._read ran) */
614
+ st->r.in_read_sync = false;
615
+ return;
616
+ }
617
+ st->r.reading = true;
618
+ st->r.in_read_sync = true;
619
+ st->r.read_inv(st->r.read_cb, s, (double)st->r.hwm);
620
+ st->r.in_read_sync = false;
621
+ }
622
+
623
+ /* readableAddChunk. Borrows chunk (retains its own ref). Returns the
624
+ * below-hwm answer. Encoded streams decode the bytes through the
625
+ * StringDecoder first (Node decodes at push); an empty decode (a partial
626
+ * multi-byte tail held pending) adds nothing but still clears the
627
+ * reading flag. */
628
+ static bool scr_stream_add_chunk(ScrStream *s, ScrBytes *chunk, bool front) {
629
+ ScrStreamState *st = s->st;
630
+ if (!st->has_r) {
631
+ ScrError *e = scr_stream_mkerr("ERR_STREAM_PUSH_AFTER_EOF", "push on a Writable (no readable side)");
632
+ scr_stream_error_or_destroy(s, e);
633
+ scr_error_release(e);
634
+ return false;
635
+ }
636
+ if (st->r.ended && !front) {
637
+ ScrError *e = scr_stream_mkerr("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF");
638
+ scr_stream_error_or_destroy(s, e);
639
+ scr_error_release(e);
640
+ return false;
641
+ }
642
+ if (st->destroyed) return false;
643
+ if (!front) st->r.reading = false;
644
+ void *entry;
645
+ size_t entry_len;
646
+ if (st->r.encoded) {
647
+ ScrStr *dec = scr_strdec_write(st->r.enc, st->r.dec_pending, chunk);
648
+ st->r.dec_pending = scr_strdec_next(st->r.enc, st->r.dec_pending, chunk);
649
+ entry_len = (size_t)scr_str_utf16_len(dec);
650
+ if (entry_len == 0) {
651
+ scr_str_release(dec);
652
+ if (!front) scr_stream_maybe_read_more(s);
653
+ return !st->r.ended && (st->r.length < st->r.hwm || st->r.length == 0);
654
+ }
655
+ entry = dec; /* owned */
656
+ } else {
657
+ entry = scr_bytes_retain(chunk);
658
+ entry_len = chunk->len;
659
+ }
660
+ if (entry_len > 0 &&
661
+ st->r.flowing == 1 && st->r.length == 0 && !st->r.in_read_sync && !front &&
662
+ (scr_emitter_has((ScrEmitter *)s, "data") || st->pipes.n > 0)) {
663
+ /* the direct-emit fast path: flowing, empty buffer, async push */
664
+ if (st->r.emitted_readable) st->r.emitted_readable = false;
665
+ scr_stream_emit_data(s, entry);
666
+ scr_stream_entry_release(st, entry);
667
+ if (scr_exc_pending()) return false;
668
+ } else {
669
+ scr_stream_rbuf_push(st, entry, front);
670
+ if (st->r.need_readable) scr_stream_emit_readable_nt(s);
671
+ }
672
+ if (!front) scr_stream_maybe_read_more(s);
673
+ scr_stream_settle_next(s); /* a parked for-await consumes buffered content */
674
+ return !st->r.ended && (st->r.length < st->r.hwm || st->r.length == 0);
675
+ }
676
+
677
+ static void scr_stream_maybe_read_more(ScrStream *s) {
678
+ ScrStreamState *st = s->st;
679
+ if (st->r.maybe_more_scheduled || st->r.reading || st->r.ended || st->destroyed) return;
680
+ if (!(st->r.length < st->r.hwm && (st->r.flowing == 1 || st->r.need_readable))) return;
681
+ st->r.maybe_more_scheduled = true;
682
+ scr_st_tick(s, SCR_ST_MAYBE_MORE, NULL, NULL);
683
+ }
684
+
685
+ /* howMuchToRead + fromList + the doRead discipline: readable.read().
686
+ * Answers a +1 Buffer — or a +1 string once encoded (lengths and the
687
+ * size argument then count JS string units, Node's encoded accounting). */
688
+ static void *scr_stream_read_n(ScrStream *s, double size) {
689
+ ScrStreamState *st = s->st;
690
+ bool absent = size < 0;
691
+ size_t n = 0;
692
+ if (!absent) {
693
+ n = (size_t)size;
694
+ if (n > st->r.hwm) {
695
+ /* Node grows hwm to the next power of two above n */
696
+ size_t h = st->r.hwm;
697
+ while (h < n) h *= 2;
698
+ st->r.hwm = h;
699
+ }
700
+ }
701
+ /* Node's read(): `if (n !== 0) state.emittedReadable = false` — the
702
+ * absent form is NaN there, which also clears; only read(0) keeps it. */
703
+ if (absent || n != 0) st->r.emitted_readable = false;
704
+ if (!absent && n == 0 && st->r.need_readable &&
705
+ (st->r.length >= st->r.hwm || st->r.ended)) {
706
+ if (st->r.length == 0 && st->r.ended) scr_stream_end_readable(s);
707
+ else scr_stream_emit_readable_nt(s);
708
+ return NULL;
709
+ }
710
+ /* howMuchToRead */
711
+ size_t want;
712
+ if (st->r.object_entries) {
713
+ /* objectMode-style: one whole entry per read, whatever n says */
714
+ want = st->r.length > 0 ? 1 : 0;
715
+ } else if (absent) {
716
+ want = st->r.flowing == 1 && st->r.n > 0
717
+ ? scr_stream_entry_len(st, st->r.buf[0]) - st->r.head_off
718
+ : st->r.length;
719
+ } else {
720
+ want = n <= st->r.length ? n : (st->r.ended ? st->r.length : 0);
721
+ }
722
+ if (want == 0 && st->r.ended) {
723
+ if (st->r.length == 0) scr_stream_end_readable(s);
724
+ return NULL;
725
+ }
726
+ bool do_read = st->r.need_readable || st->r.length == 0 ||
727
+ st->r.length - want < st->r.hwm;
728
+ if (st->r.ended || st->r.reading || st->destroyed || st->errored) do_read = false;
729
+ if (do_read) {
730
+ if (st->r.length == 0) st->r.need_readable = true;
731
+ scr_stream_call_read(s);
732
+ if (scr_exc_pending()) return NULL;
733
+ /* a synchronous push may have refilled */
734
+ if (!st->r.reading) {
735
+ if (st->r.object_entries) {
736
+ want = st->r.length > 0 ? 1 : 0;
737
+ } else if (absent) {
738
+ want = st->r.flowing == 1 && st->r.n > 0
739
+ ? scr_stream_entry_len(st, st->r.buf[0]) - st->r.head_off
740
+ : st->r.length;
741
+ } else {
742
+ want = n <= st->r.length ? n : (st->r.ended ? st->r.length : 0);
743
+ }
744
+ }
745
+ }
746
+ void *ret = want > 0 && want <= st->r.length ? scr_stream_rbuf_take(st, want) : NULL;
747
+ if (ret == NULL) {
748
+ st->r.need_readable = st->r.length <= st->r.hwm;
749
+ } else if (st->r.flowing == 1 && st->r.length == 0) {
750
+ st->r.need_readable = true;
751
+ }
752
+ if (st->r.length == 0) {
753
+ if (!st->r.ended) st->r.need_readable = true;
754
+ if (st->r.ended && !absent && n != want) scr_stream_end_readable(s);
755
+ if (st->r.ended && absent) scr_stream_end_readable(s);
756
+ }
757
+ if (ret != NULL && !st->error_emitted && !st->close_emitted) {
758
+ scr_stream_emit_data(s, ret);
759
+ if (scr_exc_pending()) {
760
+ scr_stream_entry_release(st, ret);
761
+ return NULL;
762
+ }
763
+ }
764
+ return ret;
765
+ }
766
+
767
+ static void scr_stream_flow(ScrStream *s) {
768
+ ScrStreamState *st = s->st;
769
+ while (st->r.flowing == 1 && !scr_exc_pending()) {
770
+ void *b = scr_stream_read_n(s, -1);
771
+ if (b == NULL) break;
772
+ scr_stream_entry_release(st, b);
773
+ }
774
+ }
775
+
776
+ static void scr_stream_resume_kick(ScrStream *s) {
777
+ ScrStreamState *st = s->st;
778
+ if (st->r.resume_scheduled) return;
779
+ st->r.resume_scheduled = true;
780
+ scr_st_tick(s, SCR_ST_RESUME, NULL, NULL);
781
+ }
782
+
783
+ /* ── the dyn-flavored completion callbacks (the JS lane) ──────────────── */
784
+
785
+ /* The JS lane's option callbacks and underscore methods declare their
786
+ * parameters implicitly-any: the compiler-emitted invoke thunks box the
787
+ * chunk/encoding/error into dyn, and the COMPLETION callback arrives as
788
+ * a callable dyn function whose glue lands here — arguments arrive as
789
+ * borrowed dyn values: the error is null/undefined (none), an
790
+ * error-shaped object ({message}), or a string; transform/flush data is
791
+ * bytes, a string, or absent. clo->caps[0] boxes the retained stream. */
792
+
793
+ static ScrError *scr_stream_dyn_err(ScrDyn *const *args, size_t argc) {
794
+ if (argc < 1) return NULL;
795
+ const ScrDyn *a = args[0];
796
+ if (a->kind == SCR_DYN_UNDEF || a->kind == SCR_DYN_NULL) return NULL;
797
+ if (a->kind == SCR_DYN_STR) {
798
+ ScrError *e = scr_error_new(SCR_ERR_ERROR, a->v.str);
799
+ return e;
800
+ }
801
+ if (a->kind == SCR_DYN_OBJ) {
802
+ ScrDyn *m = scr_dyn_obj_get((ScrDyn *)a, "message", 7);
803
+ ScrStr *msg = m && m->kind == SCR_DYN_STR ? scr_str_retain(m->v.str) : scr_str_new("", 0);
804
+ ScrError *e = scr_error_new(SCR_ERR_ERROR, msg);
805
+ scr_str_release(msg);
806
+ return e;
807
+ }
808
+ /* any other truthy value: Node would wrap it — approximate with "" */
809
+ ScrStr *empty = scr_str_new("", 0);
810
+ ScrError *e = scr_error_new(SCR_ERR_ERROR, empty);
811
+ scr_str_release(empty);
812
+ return e;
813
+ }
814
+
815
+ static ScrStream *scr_stream_dyn_recv(ScrClosure *clo) {
816
+ return scr_box_get_ref(clo->caps[0]);
817
+ }
818
+
819
+ static ScrDyn *scr_stream_done_dyn_ret(void) { return scr_dyn_retain(scr_dyn_undefined()); }
820
+
821
+ ScrDyn *scr_stream_done_dyn_w(ScrClosure *clo, ScrDyn *const *args, size_t argc) {
822
+ ScrStream *s = scr_stream_dyn_recv(clo);
823
+ scr_stream_write_done(s, scr_stream_dyn_err(args, argc));
824
+ scr_stream_release(s);
825
+ return scr_stream_done_dyn_ret();
826
+ }
827
+
828
+ ScrDyn *scr_stream_done_dyn_f(ScrClosure *clo, ScrDyn *const *args, size_t argc) {
829
+ ScrStream *s = scr_stream_dyn_recv(clo);
830
+ scr_stream_final_done(s, scr_stream_dyn_err(args, argc));
831
+ scr_stream_release(s);
832
+ return scr_stream_done_dyn_ret();
833
+ }
834
+
835
+ ScrDyn *scr_stream_done_dyn_d(ScrClosure *clo, ScrDyn *const *args, size_t argc) {
836
+ ScrStream *s = scr_stream_dyn_recv(clo);
837
+ scr_stream_destroy_done(s, scr_stream_dyn_err(args, argc));
838
+ scr_stream_release(s);
839
+ return scr_stream_done_dyn_ret();
840
+ }
841
+
842
+ static void scr_stream_dyn_data(ScrDyn *const *args, size_t argc,
843
+ ScrBytes **data, ScrStr **data_str) {
844
+ *data = NULL;
845
+ *data_str = NULL;
846
+ if (argc < 2) return;
847
+ const ScrDyn *a = args[1];
848
+ if (a->kind == SCR_DYN_BYTES) *data = scr_bytes_raw_view(a->v.bytes);
849
+ else if (a->kind == SCR_DYN_STR) *data_str = scr_str_retain(a->v.str);
850
+ }
851
+
852
+ ScrDyn *scr_stream_done_dyn_t(ScrClosure *clo, ScrDyn *const *args, size_t argc) {
853
+ ScrStream *s = scr_stream_dyn_recv(clo);
854
+ ScrBytes *data;
855
+ ScrStr *data_str;
856
+ scr_stream_dyn_data(args, argc, &data, &data_str);
857
+ scr_stream_transform_done(s, scr_stream_dyn_err(args, argc), data, data_str);
858
+ scr_stream_release(s);
859
+ return scr_stream_done_dyn_ret();
860
+ }
861
+
862
+ ScrDyn *scr_stream_done_dyn_l(ScrClosure *clo, ScrDyn *const *args, size_t argc) {
863
+ ScrStream *s = scr_stream_dyn_recv(clo);
864
+ ScrBytes *data;
865
+ ScrStr *data_str;
866
+ scr_stream_dyn_data(args, argc, &data, &data_str);
867
+ scr_stream_flush_done(s, scr_stream_dyn_err(args, argc), data, data_str);
868
+ scr_stream_release(s);
869
+ return scr_stream_done_dyn_ret();
870
+ }
871
+
872
+ /* Checked-dynamic chunks (the JS lane's push/write of any-typed values):
873
+ * dispatch by dyn tag — bytes copy out, strings convert utf8, null takes
874
+ * the null path (EOF for push; ERR_STREAM_NULL_VALUES for write), and
875
+ * anything else throws the write TypeError (Node would throw
876
+ * ERR_INVALID_ARG_TYPE — approximated by the same shape). Borrow d. */
877
+ bool scr_stream_push_dyn(ScrStream *s, const ScrDyn *d) {
878
+ switch (d->kind) {
879
+ case SCR_DYN_BYTES: {
880
+ ScrBytes *b = scr_bytes_raw_view(d->v.bytes);
881
+ bool r = scr_stream_push(s, b);
882
+ scr_bytes_release(b);
883
+ return r;
884
+ }
885
+ case SCR_DYN_STR:
886
+ return scr_stream_push_str(s, d->v.str);
887
+ case SCR_DYN_NULL:
888
+ return scr_stream_push_null(s);
889
+ default: {
890
+ static const char msg[] = "May not write null values to stream";
891
+ scr_throw_error_msg_code(SCR_ERR_TYPE, msg, sizeof msg - 1, "ERR_STREAM_NULL_VALUES");
892
+ return false;
893
+ }
894
+ }
895
+ }
896
+
897
+ bool scr_stream_write_dyn(ScrStream *s, const ScrDyn *d, ScrClosure *cb) {
898
+ switch (d->kind) {
899
+ case SCR_DYN_BYTES: {
900
+ ScrBytes *b = scr_bytes_raw_view(d->v.bytes);
901
+ bool r = scr_stream_write(s, b, cb);
902
+ scr_bytes_release(b);
903
+ return r;
904
+ }
905
+ case SCR_DYN_STR:
906
+ return scr_stream_write_str(s, d->v.str, cb);
907
+ default:
908
+ if (cb) scr_closure_release(cb);
909
+ return scr_stream_write_null(s);
910
+ }
911
+ }
912
+
913
+ /* ── the for-await surface (readable.nextChunk) ───────────────────────── */
914
+
915
+ /* Resolve the parked waiter with a taken chunk (moves), the EOF
916
+ * sentinel, or dyn-boxed content per next_dyn. */
917
+ static void scr_stream_next_fulfill(ScrStreamState *st, ScrPromise *w /*moves*/, void *chunk /*moves or NULL=EOF*/) {
918
+ if (st->r.next_dyn) {
919
+ ScrDyn *d;
920
+ if (chunk == NULL) {
921
+ d = scr_dyn_retain(scr_dyn_undefined()); /* the EOF sentinel */
922
+ } else if (st->r.encoded) {
923
+ d = scr_dyn_new_str((ScrStr *)chunk);
924
+ scr_str_release((ScrStr *)chunk);
925
+ } else {
926
+ d = scr_dyn_new_buffer((ScrBytes *)chunk);
927
+ scr_bytes_release((ScrBytes *)chunk);
928
+ }
929
+ scr_promise_fulfill_ref(w, d, scr_dyn_retain_v, scr_dyn_release_v, NULL);
930
+ } else {
931
+ ScrBytes *b = chunk ? (ScrBytes *)chunk : scr_bytes_new(SCR_BYTES_U8, 0);
932
+ scr_promise_fulfill_ref(w, b, scr_bytes_retain_v, scr_bytes_release_v, NULL);
933
+ }
934
+ scr_promise_release(w);
935
+ }
936
+
937
+ /* Settle the parked waiter if the stream's state can answer now: an
938
+ * error rejects, buffered content fulfills (one whole entry in from
939
+ * mode, the whole buffer otherwise — Node's iterator read()), EOF
940
+ * fulfills the sentinel. Called from push/eof/destroy transitions. */
941
+ static void scr_stream_settle_next(ScrStream *s) {
942
+ ScrStreamState *st = s->st;
943
+ if (!st->r.next_waiter) return;
944
+ if (st->errored) {
945
+ ScrPromise *w = st->r.next_waiter;
946
+ st->r.next_waiter = NULL;
947
+ st->next_err_consumed = true;
948
+ scr_throw_obj(scr_error_retain(st->errored), &scr_error_retain_v, &scr_error_release_v,
949
+ scr_error_trace_arg());
950
+ scr_promise_reject_pending(w);
951
+ scr_promise_release(w);
952
+ return;
953
+ }
954
+ if (st->r.length > 0) {
955
+ ScrPromise *w = st->r.next_waiter;
956
+ st->r.next_waiter = NULL;
957
+ void *chunk = scr_stream_rbuf_take(st, st->r.object_entries ? 1 : st->r.length);
958
+ scr_stream_next_fulfill(st, w, chunk);
959
+ if (st->r.ended && st->r.length == 0) scr_stream_end_readable(s);
960
+ return;
961
+ }
962
+ if (st->r.ended || st->destroyed) {
963
+ if (st->r.ended && !st->r.end_emitted) {
964
+ /* Node's iterator completes AFTER 'end' (and its autoDestroy):
965
+ * queue the sentinel BEHIND the pending 'end' tick, so code after
966
+ * the loop reads readableEnded/destroyed true. */
967
+ scr_stream_end_readable(s);
968
+ scr_st_tick(s, SCR_ST_NEXT_EOF, NULL, NULL);
969
+ return;
970
+ }
971
+ ScrPromise *w = st->r.next_waiter;
972
+ st->r.next_waiter = NULL;
973
+ scr_stream_next_fulfill(st, w, NULL);
974
+ }
975
+ }
976
+
977
+ static ScrPromise *scr_stream_next_chunk_impl(ScrStream *s, bool dyn) {
978
+ ScrStreamState *st = s->st;
979
+ ScrPromise *p = scr_promise_new();
980
+ if (!st->has_r) {
981
+ st->r.next_dyn = dyn;
982
+ scr_stream_next_fulfill(st, scr_promise_retain(p), NULL);
983
+ return p;
984
+ }
985
+ if (st->r.next_waiter) {
986
+ /* the desugared loop awaits each chunk before asking again */
987
+ static const char msg[] = "concurrent for-await iteration of one stream is not supported yet";
988
+ scr_throw_error_msg(SCR_ERR_ERROR, msg, sizeof msg - 1);
989
+ scr_promise_reject_pending(p);
990
+ return p;
991
+ }
992
+ st->r.next_dyn = dyn;
993
+ st->r.next_waiter = scr_promise_retain(p);
994
+ /* answer from the current state, or kick a _read and park */
995
+ scr_stream_settle_next(s);
996
+ if (st->r.next_waiter && !st->r.reading && !st->r.ended && !st->destroyed) {
997
+ st->r.need_readable = true;
998
+ scr_stream_call_read(s);
999
+ if (scr_exc_pending()) {
1000
+ ScrPromise *w = st->r.next_waiter;
1001
+ st->r.next_waiter = NULL;
1002
+ scr_promise_reject_pending(w);
1003
+ scr_promise_release(w);
1004
+ return p;
1005
+ }
1006
+ /* a synchronous push may have answered already */
1007
+ scr_stream_settle_next(s);
1008
+ }
1009
+ return p;
1010
+ }
1011
+
1012
+ ScrPromise *scr_stream_next_chunk(ScrStream *s) {
1013
+ ScrStreamState *st = s->st;
1014
+ if (st->has_r && st->r.encoded) {
1015
+ /* the typed lane's chunk is a Buffer; string chunks would confuse */
1016
+ ScrPromise *p = scr_promise_new();
1017
+ static const char msg[] =
1018
+ "for-await over a stream with an encoding set is not supported yet in "
1019
+ "typed code (chunks are Buffers here)";
1020
+ scr_throw_error_msg(SCR_ERR_ERROR, msg, sizeof msg - 1);
1021
+ scr_promise_reject_pending(p);
1022
+ return p;
1023
+ }
1024
+ return scr_stream_next_chunk_impl(s, false);
1025
+ }
1026
+
1027
+ ScrPromise *scr_stream_next_chunk_dyn(ScrStream *s) {
1028
+ return scr_stream_next_chunk_impl(s, true);
1029
+ }
1030
+
1031
+ /* ── Readable.from (array-seeded object-entry streams) ────────────────── */
1032
+
1033
+ /* +1 stream fully seeded from the array's elements (strings or Buffers —
1034
+ * one WHOLE entry per element, Node's objectMode delivery; hwm 1) and
1035
+ * already EOF'd. Borrows arr. */
1036
+ ScrStream *scr_stream_from_arr(ScrArr *arr, bool strings) {
1037
+ ScrStream *s = scr_stream_alloc(&scr_readable_vt, "Readable", true, false,
1038
+ 1, -1, true, true, true);
1039
+ ScrStreamState *st = s->st;
1040
+ st->r.object_entries = true;
1041
+ st->r.encoded = strings;
1042
+ if (strings) st->r.enc = scr_str_new("utf8", 4);
1043
+ for (size_t i = 0; i < arr->len; i++) {
1044
+ scr_stream_rbuf_push(st, scr_arr_get_ref(arr, (double)i), false);
1045
+ }
1046
+ scr_stream_push_null(s);
1047
+ return s;
1048
+ }
1049
+
1050
+ /* ── the registration hook ('data'/'readable' listeners kick flow) ────── */
1051
+
1052
+ static void scr_stream_on_listener(ScrEmitter *em, ScrStr *name) {
1053
+ if (!scr_stream_is(em)) return;
1054
+ ScrStream *s = (ScrStream *)em;
1055
+ ScrStreamState *st = s->st;
1056
+ if (!st || !st->has_r) return;
1057
+ if (name->len == 4 && memcmp(name->data, "data", 4) == 0) {
1058
+ st->r.readable_listening = scr_emitter_has(em, "readable");
1059
+ if (st->r.flowing != 0) {
1060
+ st->r.flowing = 1;
1061
+ scr_stream_resume_kick(s);
1062
+ }
1063
+ } else if (name->len == 8 && memcmp(name->data, "readable", 8) == 0) {
1064
+ if (!st->r.end_emitted && !st->r.readable_listening) {
1065
+ st->r.readable_listening = true;
1066
+ st->r.need_readable = true;
1067
+ st->r.flowing = 0;
1068
+ st->r.emitted_readable = false;
1069
+ if (st->r.length > 0) {
1070
+ scr_stream_emit_readable_nt(s);
1071
+ } else if (!st->r.reading) {
1072
+ /* nReadingNextTick: a read(0) kick on a tick */
1073
+ scr_st_tick(s, SCR_ST_MAYBE_MORE, NULL, NULL);
1074
+ st->r.maybe_more_scheduled = true;
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
+
1080
+ /* ── writable internals ───────────────────────────────────────────────── */
1081
+
1082
+ static void scr_stream_wq_push(ScrStreamState *st, ScrBytes *chunk /*moves*/, ScrClosure *cb /*moves*/) {
1083
+ if (st->w.n == st->w.cap) {
1084
+ st->w.cap = st->w.cap ? st->w.cap * 2 : 4;
1085
+ st->w.q = realloc(st->w.q, st->w.cap * sizeof *st->w.q);
1086
+ if (!st->w.q) scr_stream_oom();
1087
+ }
1088
+ st->w.q[st->w.n].chunk = chunk;
1089
+ st->w.q[st->w.n].cb = cb;
1090
+ st->w.n++;
1091
+ }
1092
+
1093
+ static void scr_stream_do_write(ScrStream *s, ScrBytes *chunk /*moves*/, ScrClosure *cb /*moves*/) {
1094
+ ScrStreamState *st = s->st;
1095
+ st->w.writing = true;
1096
+ st->w.wsync = true;
1097
+ st->w.inflight_len = chunk->len;
1098
+ st->w.inflight_cb = cb;
1099
+ if (st->passthrough && st->transform_cb == NULL) {
1100
+ /* identity: push through, complete synchronously */
1101
+ scr_stream_add_chunk(s, chunk, false);
1102
+ scr_bytes_release(chunk);
1103
+ if (!scr_exc_pending()) scr_stream_write_done(s, NULL);
1104
+ st->w.wsync = false;
1105
+ return;
1106
+ }
1107
+ if (st->is_transform || st->passthrough) {
1108
+ if (st->transform_cb == NULL) {
1109
+ scr_bytes_release(chunk);
1110
+ ScrError *e = scr_stream_mkerr("ERR_METHOD_NOT_IMPLEMENTED", "The _transform() method is not implemented");
1111
+ st->w.wsync = false;
1112
+ scr_stream_error_or_destroy(s, e);
1113
+ scr_error_release(e);
1114
+ return;
1115
+ }
1116
+ st->transform_inv(st->transform_cb, s, chunk);
1117
+ scr_bytes_release(chunk);
1118
+ st->w.wsync = false;
1119
+ return;
1120
+ }
1121
+ if (st->w.write_cb == NULL) {
1122
+ scr_bytes_release(chunk);
1123
+ ScrError *e = scr_stream_mkerr("ERR_METHOD_NOT_IMPLEMENTED", "The _write() method is not implemented");
1124
+ st->w.wsync = false;
1125
+ scr_stream_error_or_destroy(s, e);
1126
+ scr_error_release(e);
1127
+ return;
1128
+ }
1129
+ st->w.write_inv(st->w.write_cb, s, chunk);
1130
+ scr_bytes_release(chunk);
1131
+ st->w.wsync = false;
1132
+ }
1133
+
1134
+ /* afterWrite — Node's exact order: 'drain' first (when the queue is
1135
+ * empty), THEN the user's write(chunk, cb) callback, then finishMaybe.
1136
+ * The buffered queue was already restarted by write_done (Node's onwrite
1137
+ * calls clearBuffer before afterWrite). cb moves. */
1138
+ static void scr_stream_after_write(ScrStream *s, ScrClosure *cb) {
1139
+ ScrStreamState *st = s->st;
1140
+ if (st->w.length == 0 && st->w.need_drain && !st->w.ending && !st->destroyed) {
1141
+ st->w.need_drain = false;
1142
+ scr_stream_emit0(s, "drain");
1143
+ if (scr_exc_pending()) {
1144
+ if (cb) scr_closure_release(cb);
1145
+ return;
1146
+ }
1147
+ /* pipe sources waiting on this drain resume now */
1148
+ while (st->drain_srcs.n > 0) {
1149
+ ScrStream *src = st->drain_srcs.src[--st->drain_srcs.n];
1150
+ if (src->st && src->st->await_drain > 0 && --src->st->await_drain == 0 && !src->st->destroyed) {
1151
+ src->st->r.flowing = 1;
1152
+ scr_stream_resume_kick(src);
1153
+ }
1154
+ scr_stream_release(src);
1155
+ }
1156
+ }
1157
+ if (cb) {
1158
+ ((void (*)(ScrClosure *))cb->fn)(cb);
1159
+ scr_closure_release(cb);
1160
+ if (scr_exc_pending()) return;
1161
+ }
1162
+ scr_stream_finish_maybe(s);
1163
+ }
1164
+
1165
+ static void scr_stream_clear_buffer(ScrStream *s) {
1166
+ ScrStreamState *st = s->st;
1167
+ while (!st->w.writing && st->w.head < st->w.n && st->w.corked == 0 &&
1168
+ !st->destroyed && !scr_exc_pending()) {
1169
+ ScrWEntry e = st->w.q[st->w.head++];
1170
+ if (st->w.head == st->w.n) {
1171
+ st->w.head = 0;
1172
+ st->w.n = 0;
1173
+ }
1174
+ scr_stream_do_write(s, e.chunk, e.cb);
1175
+ }
1176
+ }
1177
+
1178
+ /* prefinish + 'finish' scheduling once the writable side has fully
1179
+ * drained after end(). */
1180
+ static void scr_stream_finish_maybe(ScrStream *s) {
1181
+ ScrStreamState *st = s->st;
1182
+ if (!st->w.ending || st->w.writing || st->w.head < st->w.n || st->w.finished ||
1183
+ st->destroyed || st->w.finish_scheduled) {
1184
+ return;
1185
+ }
1186
+ if (!st->w.prefinished) {
1187
+ if ((st->is_transform || st->passthrough) && !st->flush_called) {
1188
+ st->flush_called = true;
1189
+ if (st->flush_cb) {
1190
+ st->flush_inv(st->flush_cb, s);
1191
+ return; /* flush_done resumes the finish path */
1192
+ }
1193
+ /* no flush: EOF the readable side now */
1194
+ scr_stream_push_null(s);
1195
+ if (scr_exc_pending()) return;
1196
+ }
1197
+ if (st->w.final_cb && !st->w.final_called) {
1198
+ st->w.final_called = true;
1199
+ st->w.final_inv(st->w.final_cb, s);
1200
+ return; /* final_done resumes the finish path */
1201
+ }
1202
+ st->w.prefinished = true;
1203
+ scr_stream_emit0(s, "prefinish");
1204
+ if (scr_exc_pending()) return;
1205
+ }
1206
+ st->w.finish_scheduled = true;
1207
+ scr_st_tick(s, SCR_ST_FINISH, NULL, NULL);
1208
+ }
1209
+
1210
+ /* ── construction ─────────────────────────────────────────────────────── */
1211
+
1212
+ static ScrStreamState *scr_stream_state_new(bool has_r, bool has_w,
1213
+ double rhwm, double whwm, bool auto_destroy,
1214
+ bool emit_close, bool allow_half_open) {
1215
+ ScrStreamState *st = calloc(1, sizeof *st);
1216
+ if (!st) scr_stream_oom();
1217
+ st->has_r = has_r;
1218
+ st->has_w = has_w;
1219
+ st->auto_destroy = auto_destroy;
1220
+ st->emit_close = emit_close;
1221
+ st->allow_half_open = allow_half_open;
1222
+ st->r.hwm = rhwm >= 0 ? (size_t)rhwm : SCR_STREAM_DEFAULT_HWM;
1223
+ st->w.hwm = whwm >= 0 ? (size_t)whwm : SCR_STREAM_DEFAULT_HWM;
1224
+ st->r.flowing = -1;
1225
+ /* Node's ReadableState.sync starts TRUE: pushes before the first _read
1226
+ * attempt take the buffered path (never the direct 'data' emit). */
1227
+ st->r.in_read_sync = true;
1228
+ return st;
1229
+ }
1230
+
1231
+ static ScrStream *scr_stream_alloc(const ScrVt *vt, const char *cls, bool has_r, bool has_w,
1232
+ double rhwm, double whwm, bool auto_destroy,
1233
+ bool emit_close, bool allow_half_open) {
1234
+ ScrStream *s = scr_cyc_alloc(sizeof *s, &scr_stream_trace, &scr_stream_gcfree);
1235
+ s->rc = 1;
1236
+ s->vt = vt;
1237
+ s->reg = NULL;
1238
+ s->cls = cls;
1239
+ s->st = scr_stream_state_new(has_r, has_w, rhwm, whwm, auto_destroy, emit_close, allow_half_open);
1240
+ /* Node's stream constructors pre-create their known _events keys (a V8
1241
+ * shape optimization) — eventNames() lists these BEFORE user events
1242
+ * added earlier. Same names, same order: Readable close/error/data/end/
1243
+ * readable, Writable close/error/prefinish/finish/drain, Duplex the
1244
+ * union (writable trio first — Node's observed key order). */
1245
+ ScrEmitter *em = (ScrEmitter *)s;
1246
+ scr_emitter_reserve(em, "close");
1247
+ scr_emitter_reserve(em, "error");
1248
+ if (has_w) {
1249
+ scr_emitter_reserve(em, "prefinish");
1250
+ scr_emitter_reserve(em, "finish");
1251
+ scr_emitter_reserve(em, "drain");
1252
+ }
1253
+ if (has_r) {
1254
+ scr_emitter_reserve(em, "data");
1255
+ scr_emitter_reserve(em, "end");
1256
+ scr_emitter_reserve(em, "readable");
1257
+ }
1258
+ scr_obj_alloc_note();
1259
+ return s;
1260
+ }
1261
+
1262
+ ScrStream *scr_stream_new_readable(double hwm, bool auto_destroy, bool emit_close,
1263
+ ScrClosure *read, ScrStreamReadInv read_inv,
1264
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1265
+ ScrStream *s = scr_stream_alloc(&scr_readable_vt, "Readable", true, false,
1266
+ hwm, -1, auto_destroy, emit_close, true);
1267
+ s->st->r.read_cb = read;
1268
+ s->st->r.read_inv = read_inv;
1269
+ s->st->destroy_cb = destroy;
1270
+ s->st->destroy_inv = destroy_inv;
1271
+ return s;
1272
+ }
1273
+
1274
+ ScrStream *scr_stream_new_writable(double hwm, bool auto_destroy, bool emit_close,
1275
+ ScrClosure *write, ScrStreamChunkInv write_inv,
1276
+ ScrClosure *final_cb, ScrStreamPlainInv final_inv,
1277
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1278
+ ScrStream *s = scr_stream_alloc(&scr_writable_vt, "Writable", false, true,
1279
+ -1, hwm, auto_destroy, emit_close, true);
1280
+ s->st->w.write_cb = write;
1281
+ s->st->w.write_inv = write_inv;
1282
+ s->st->w.final_cb = final_cb;
1283
+ s->st->w.final_inv = final_inv;
1284
+ s->st->destroy_cb = destroy;
1285
+ s->st->destroy_inv = destroy_inv;
1286
+ return s;
1287
+ }
1288
+
1289
+ ScrStream *scr_stream_new_duplex(double rhwm, double whwm, bool auto_destroy,
1290
+ bool emit_close, bool allow_half_open, bool readable_side, bool writable_side,
1291
+ ScrClosure *read, ScrStreamReadInv read_inv,
1292
+ ScrClosure *write, ScrStreamChunkInv write_inv,
1293
+ ScrClosure *final_cb, ScrStreamPlainInv final_inv,
1294
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1295
+ ScrStream *s = scr_stream_alloc(&scr_duplex_vt, "Duplex", readable_side, writable_side,
1296
+ rhwm, whwm, auto_destroy, emit_close, allow_half_open);
1297
+ if (!readable_side) {
1298
+ /* Node: a { readable: false } duplex reads as an already-ended half */
1299
+ s->st->r.ended = true;
1300
+ s->st->r.end_emitted = true;
1301
+ }
1302
+ if (!writable_side) {
1303
+ s->st->w.ending = true;
1304
+ s->st->w.finished = true;
1305
+ }
1306
+ s->st->r.read_cb = read;
1307
+ s->st->r.read_inv = read_inv;
1308
+ s->st->w.write_cb = write;
1309
+ s->st->w.write_inv = write_inv;
1310
+ s->st->w.final_cb = final_cb;
1311
+ s->st->w.final_inv = final_inv;
1312
+ s->st->destroy_cb = destroy;
1313
+ s->st->destroy_inv = destroy_inv;
1314
+ return s;
1315
+ }
1316
+
1317
+ static ScrStream *scr_stream_new_transformish(const ScrVt *vt, const char *cls, bool passthrough,
1318
+ double rhwm, double whwm, bool auto_destroy, bool emit_close, bool allow_half_open,
1319
+ ScrClosure *transform, ScrStreamChunkInv transform_inv,
1320
+ ScrClosure *flush, ScrStreamPlainInv flush_inv,
1321
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1322
+ ScrStream *s = scr_stream_alloc(vt, cls, true, true, rhwm, whwm,
1323
+ auto_destroy, emit_close, allow_half_open);
1324
+ s->st->is_transform = !passthrough;
1325
+ s->st->passthrough = passthrough;
1326
+ /* Node's Transform constructor: the readable half starts with
1327
+ * sync=false and needReadable=true (transformed data direct-emits). */
1328
+ s->st->r.in_read_sync = false;
1329
+ s->st->r.need_readable = true;
1330
+ s->st->transform_cb = transform;
1331
+ s->st->transform_inv = transform_inv;
1332
+ s->st->flush_cb = flush;
1333
+ s->st->flush_inv = flush_inv;
1334
+ s->st->destroy_cb = destroy;
1335
+ s->st->destroy_inv = destroy_inv;
1336
+ return s;
1337
+ }
1338
+
1339
+ ScrStream *scr_stream_new_transform(double rhwm, double whwm, bool auto_destroy,
1340
+ bool emit_close, bool allow_half_open, bool readable_side, bool writable_side,
1341
+ ScrClosure *transform, ScrStreamChunkInv transform_inv,
1342
+ ScrClosure *flush, ScrStreamPlainInv flush_inv,
1343
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1344
+ (void)readable_side;
1345
+ (void)writable_side;
1346
+ return scr_stream_new_transformish(&scr_transform_vt, "Transform", false,
1347
+ rhwm, whwm, auto_destroy, emit_close, allow_half_open,
1348
+ transform, transform_inv, flush, flush_inv, destroy, destroy_inv);
1349
+ }
1350
+
1351
+ ScrStream *scr_stream_new_passthrough(double rhwm, double whwm, bool auto_destroy,
1352
+ bool emit_close, bool allow_half_open, bool readable_side, bool writable_side,
1353
+ ScrClosure *transform, ScrStreamChunkInv transform_inv,
1354
+ ScrClosure *flush, ScrStreamPlainInv flush_inv,
1355
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1356
+ (void)readable_side;
1357
+ (void)writable_side;
1358
+ ScrStream *s = scr_stream_new_transformish(&scr_passthrough_vt, "PassThrough",
1359
+ transform == NULL, rhwm, whwm, auto_destroy, emit_close, allow_half_open,
1360
+ transform, transform_inv, flush, flush_inv, destroy, destroy_inv);
1361
+ if (transform != NULL) s->st->is_transform = true;
1362
+ return s;
1363
+ }
1364
+
1365
+ /* ── subclass initialization (the emitted super(options) call) ────────── */
1366
+
1367
+ /* A compiler-emitted `extends Readable` subclass allocates its own struct
1368
+ * (vt stamped with the SUBCLASS vtable, display name stamped, registry
1369
+ * and state NULL — the emitter-subclass story plus one slot); super(
1370
+ * options) lands here to build the stream state. The callback closures
1371
+ * move; overridden underscore methods arrive as compiler-synthesized
1372
+ * wrapper closures dispatching through the vt, so a further-derived
1373
+ * override wins even when an inherited constructor runs the init. */
1374
+
1375
+ void scr_stream_init_readable(ScrStream *s, double hwm, bool auto_destroy, bool emit_close,
1376
+ ScrClosure *read, ScrStreamReadInv read_inv,
1377
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1378
+ ScrStreamState *st = scr_stream_state_new(true, false, hwm, -1, auto_destroy, emit_close, true);
1379
+ s->st = st;
1380
+ st->r.read_cb = read;
1381
+ st->r.read_inv = read_inv;
1382
+ st->destroy_cb = destroy;
1383
+ st->destroy_inv = destroy_inv;
1384
+ }
1385
+
1386
+ void scr_stream_init_writable(ScrStream *s, double hwm, bool auto_destroy, bool emit_close,
1387
+ ScrClosure *write, ScrStreamChunkInv write_inv,
1388
+ ScrClosure *final_cb, ScrStreamPlainInv final_inv,
1389
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1390
+ ScrStreamState *st = scr_stream_state_new(false, true, -1, hwm, auto_destroy, emit_close, true);
1391
+ s->st = st;
1392
+ st->w.write_cb = write;
1393
+ st->w.write_inv = write_inv;
1394
+ st->w.final_cb = final_cb;
1395
+ st->w.final_inv = final_inv;
1396
+ st->destroy_cb = destroy;
1397
+ st->destroy_inv = destroy_inv;
1398
+ }
1399
+
1400
+ void scr_stream_init_duplex(ScrStream *s, double rhwm, double whwm, bool auto_destroy,
1401
+ bool emit_close, bool allow_half_open, bool readable_side, bool writable_side,
1402
+ ScrClosure *read, ScrStreamReadInv read_inv,
1403
+ ScrClosure *write, ScrStreamChunkInv write_inv,
1404
+ ScrClosure *final_cb, ScrStreamPlainInv final_inv,
1405
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1406
+ ScrStreamState *st = scr_stream_state_new(readable_side, writable_side, rhwm, whwm,
1407
+ auto_destroy, emit_close, allow_half_open);
1408
+ s->st = st;
1409
+ if (!readable_side) {
1410
+ st->r.ended = true;
1411
+ st->r.end_emitted = true;
1412
+ }
1413
+ if (!writable_side) {
1414
+ st->w.ending = true;
1415
+ st->w.finished = true;
1416
+ }
1417
+ st->r.read_cb = read;
1418
+ st->r.read_inv = read_inv;
1419
+ st->w.write_cb = write;
1420
+ st->w.write_inv = write_inv;
1421
+ st->w.final_cb = final_cb;
1422
+ st->w.final_inv = final_inv;
1423
+ st->destroy_cb = destroy;
1424
+ st->destroy_inv = destroy_inv;
1425
+ }
1426
+
1427
+ static void scr_stream_init_transformish(ScrStream *s, bool passthrough,
1428
+ double rhwm, double whwm, bool auto_destroy, bool emit_close, bool allow_half_open,
1429
+ ScrClosure *transform, ScrStreamChunkInv transform_inv,
1430
+ ScrClosure *flush, ScrStreamPlainInv flush_inv,
1431
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1432
+ ScrStreamState *st = scr_stream_state_new(true, true, rhwm, whwm,
1433
+ auto_destroy, emit_close, allow_half_open);
1434
+ s->st = st;
1435
+ st->is_transform = !passthrough;
1436
+ st->passthrough = passthrough;
1437
+ /* the Transform constructor's readable-half stance (see new_transformish) */
1438
+ st->r.in_read_sync = false;
1439
+ st->r.need_readable = true;
1440
+ st->transform_cb = transform;
1441
+ st->transform_inv = transform_inv;
1442
+ st->flush_cb = flush;
1443
+ st->flush_inv = flush_inv;
1444
+ st->destroy_cb = destroy;
1445
+ st->destroy_inv = destroy_inv;
1446
+ }
1447
+
1448
+ void scr_stream_init_transform(ScrStream *s, double rhwm, double whwm, bool auto_destroy,
1449
+ bool emit_close, bool allow_half_open, bool readable_side, bool writable_side,
1450
+ ScrClosure *transform, ScrStreamChunkInv transform_inv,
1451
+ ScrClosure *flush, ScrStreamPlainInv flush_inv,
1452
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1453
+ (void)readable_side;
1454
+ (void)writable_side;
1455
+ scr_stream_init_transformish(s, false, rhwm, whwm, auto_destroy, emit_close, allow_half_open,
1456
+ transform, transform_inv, flush, flush_inv, destroy, destroy_inv);
1457
+ }
1458
+
1459
+ void scr_stream_init_passthrough(ScrStream *s, double rhwm, double whwm, bool auto_destroy,
1460
+ bool emit_close, bool allow_half_open, bool readable_side, bool writable_side,
1461
+ ScrClosure *transform, ScrStreamChunkInv transform_inv,
1462
+ ScrClosure *flush, ScrStreamPlainInv flush_inv,
1463
+ ScrClosure *destroy, ScrStreamErrInv destroy_inv) {
1464
+ (void)readable_side;
1465
+ (void)writable_side;
1466
+ scr_stream_init_transformish(s, transform == NULL, rhwm, whwm, auto_destroy, emit_close,
1467
+ allow_half_open, transform, transform_inv, flush, flush_inv, destroy, destroy_inv);
1468
+ }
1469
+
1470
+ /* ── the underscore-method assignment surface ─────────────────────────
1471
+ * `r._read = fn` / `w._write = fn` (and _final/_destroy/_transform/
1472
+ * _flush) AFTER construction: Node assigns an own property that shadows
1473
+ * the prototype method, and the machinery calls through it from then on.
1474
+ * Here the same slot the option callbacks fill swaps its closure — the
1475
+ * old callback releases, the new one (+1, moves) takes the slot with its
1476
+ * compiler-emitted invoke thunk. In-flight operations already dispatched
1477
+ * through the OLD callback complete against it (they hold no further
1478
+ * reference); the next _read/_write/... dispatch uses the new one, which
1479
+ * is Node's own timing. A NULL state block (assignment before a
1480
+ * subclass's super()) cannot be reached from lowered code — super()
1481
+ * lowers before any statement that could see `this`. */
1482
+ void scr_stream_set_read(ScrStream *s, ScrClosure *cb /*moves*/, ScrStreamReadInv inv) {
1483
+ ScrStreamState *st = s->st;
1484
+ if (st->r.read_cb) scr_closure_release(st->r.read_cb);
1485
+ st->r.read_cb = cb;
1486
+ st->r.read_inv = inv;
1487
+ }
1488
+
1489
+ void scr_stream_set_write(ScrStream *s, ScrClosure *cb /*moves*/, ScrStreamChunkInv inv) {
1490
+ ScrStreamState *st = s->st;
1491
+ if (st->w.write_cb) scr_closure_release(st->w.write_cb);
1492
+ st->w.write_cb = cb;
1493
+ st->w.write_inv = inv;
1494
+ }
1495
+
1496
+ void scr_stream_set_final(ScrStream *s, ScrClosure *cb /*moves*/, ScrStreamPlainInv inv) {
1497
+ ScrStreamState *st = s->st;
1498
+ if (st->w.final_cb) scr_closure_release(st->w.final_cb);
1499
+ st->w.final_cb = cb;
1500
+ st->w.final_inv = inv;
1501
+ }
1502
+
1503
+ void scr_stream_set_destroy(ScrStream *s, ScrClosure *cb /*moves*/, ScrStreamErrInv inv) {
1504
+ ScrStreamState *st = s->st;
1505
+ if (st->destroy_cb) scr_closure_release(st->destroy_cb);
1506
+ st->destroy_cb = cb;
1507
+ st->destroy_inv = inv;
1508
+ }
1509
+
1510
+ void scr_stream_set_transform(ScrStream *s, ScrClosure *cb /*moves*/, ScrStreamChunkInv inv) {
1511
+ ScrStreamState *st = s->st;
1512
+ if (st->transform_cb) scr_closure_release(st->transform_cb);
1513
+ st->transform_cb = cb;
1514
+ st->transform_inv = inv;
1515
+ }
1516
+
1517
+ void scr_stream_set_flush(ScrStream *s, ScrClosure *cb /*moves*/, ScrStreamPlainInv inv) {
1518
+ ScrStreamState *st = s->st;
1519
+ if (st->flush_cb) scr_closure_release(st->flush_cb);
1520
+ st->flush_cb = cb;
1521
+ st->flush_inv = inv;
1522
+ }
1523
+
1524
+ /* ── dyn options (a checked-dynamic options record at construction) ─────
1525
+ *
1526
+ * The JS lane's `constructor(options) { super(options); }` forwarding and
1527
+ * `new Readable(dynVar)`: the record's SHAPE is runtime data, so the
1528
+ * option walk happens here — scalar options read with Node's own rules
1529
+ * (highWaterMark wins over the sided keys; autoDestroy/emitClose/
1530
+ * allowHalfOpen and the Duplex side toggles compare `!== false`; unknown
1531
+ * keys are ignored exactly like Node), and callback slots holding
1532
+ * callable values (Node's `typeof === 'function'` guard — anything else
1533
+ * leaves the slot to the prototype/fallback) bind as closures whose one
1534
+ * cap boxes the dyn callable; the invs below build the dyn arguments the
1535
+ * way the compiler-emitted dyn thunks do (chunk as Buffer-flavored bytes,
1536
+ * encoding 'buffer', the error via the boundary encoding, the completion
1537
+ * callback as a callable dyn over the *_done glue). Options that Node's
1538
+ * base WOULD consume but have no lowering here (objectMode truthy,
1539
+ * decodeStrings:false, non-utf8 defaultEncoding, signal, construct,
1540
+ * writev, and read/write/final on the transformish bases) throw the loud
1541
+ * unsupported Error — the compile-time fence's runtime twin. */
1542
+
1543
+ /* The boxed dyn callable (+1 — scr_box_get_ref retains; callers release
1544
+ * after the call). */
1545
+ static ScrDyn *scr_stream_dynopt_target(ScrClosure *cb) {
1546
+ return scr_box_get_ref(cb->caps[0]);
1547
+ }
1548
+
1549
+ static ScrDyn *scr_stream_dynopt_done(ScrStream *s, ScrDynThunk glue, uint32_t arity, const char *sig) {
1550
+ ScrClosure *c = scr_closure_new((void *)glue, 1);
1551
+ c->caps[0] = scr_box_new_obj(&scr_stream_retain_v, &scr_stream_release_v, &scr_stream_trace);
1552
+ scr_box_set_ref(c->caps[0], scr_stream_retain(s));
1553
+ return scr_dyn_new_func(c, glue, arity, sig, "callback");
1554
+ }
1555
+
1556
+ static void scr_stream_dynopt_read_inv(ScrClosure *cb, ScrStream *s, double size) {
1557
+ (void)s;
1558
+ ScrDyn *fn = scr_stream_dynopt_target(cb);
1559
+ ScrDyn *a = scr_dyn_new_num(size);
1560
+ ScrDyn *r = scr_dyn_call(fn, &a, 1, "read");
1561
+ scr_dyn_release(a);
1562
+ scr_dyn_release(fn);
1563
+ if (r != NULL) scr_dyn_release(r);
1564
+ }
1565
+
1566
+ static void scr_stream_dynopt_chunk3(ScrClosure *cb, ScrStream *s, ScrBytes *chunk,
1567
+ ScrDynThunk glue, const char *what) {
1568
+ ScrDyn *args[3];
1569
+ args[0] = scr_dyn_new_buffer(chunk);
1570
+ ScrStr *enc = scr_str_new("buffer", 6);
1571
+ args[1] = scr_dyn_new_str(enc);
1572
+ scr_str_release(enc);
1573
+ args[2] = scr_stream_dynopt_done(s, glue, 1, "(error)");
1574
+ ScrDyn *fn = scr_stream_dynopt_target(cb);
1575
+ ScrDyn *r = scr_dyn_call(fn, args, 3, what);
1576
+ for (int i = 0; i < 3; i++) scr_dyn_release(args[i]);
1577
+ scr_dyn_release(fn);
1578
+ if (r != NULL) scr_dyn_release(r);
1579
+ }
1580
+
1581
+ static void scr_stream_dynopt_write_inv(ScrClosure *cb, ScrStream *s, ScrBytes *chunk) {
1582
+ scr_stream_dynopt_chunk3(cb, s, chunk, &scr_stream_done_dyn_w, "write");
1583
+ }
1584
+
1585
+ static void scr_stream_dynopt_transform_inv(ScrClosure *cb, ScrStream *s, ScrBytes *chunk) {
1586
+ ScrDyn *args[3];
1587
+ args[0] = scr_dyn_new_buffer(chunk);
1588
+ ScrStr *enc = scr_str_new("buffer", 6);
1589
+ args[1] = scr_dyn_new_str(enc);
1590
+ scr_str_release(enc);
1591
+ args[2] = scr_stream_dynopt_done(s, &scr_stream_done_dyn_t, 2, "(error,data)");
1592
+ ScrDyn *fn = scr_stream_dynopt_target(cb);
1593
+ ScrDyn *r = scr_dyn_call(fn, args, 3, "transform");
1594
+ for (int i = 0; i < 3; i++) scr_dyn_release(args[i]);
1595
+ scr_dyn_release(fn);
1596
+ if (r != NULL) scr_dyn_release(r);
1597
+ }
1598
+
1599
+ static void scr_stream_dynopt_final_inv(ScrClosure *cb, ScrStream *s) {
1600
+ ScrDyn *fn = scr_stream_dynopt_target(cb);
1601
+ ScrDyn *a = scr_stream_dynopt_done(s, &scr_stream_done_dyn_f, 1, "(error)");
1602
+ ScrDyn *r = scr_dyn_call(fn, &a, 1, "final");
1603
+ scr_dyn_release(a);
1604
+ scr_dyn_release(fn);
1605
+ if (r != NULL) scr_dyn_release(r);
1606
+ }
1607
+
1608
+ static void scr_stream_dynopt_flush_inv(ScrClosure *cb, ScrStream *s) {
1609
+ ScrDyn *fn = scr_stream_dynopt_target(cb);
1610
+ ScrDyn *a = scr_stream_dynopt_done(s, &scr_stream_done_dyn_l, 2, "(error,data)");
1611
+ ScrDyn *r = scr_dyn_call(fn, &a, 1, "flush");
1612
+ scr_dyn_release(a);
1613
+ scr_dyn_release(fn);
1614
+ if (r != NULL) scr_dyn_release(r);
1615
+ }
1616
+
1617
+ static void scr_stream_dynopt_destroy_inv(ScrClosure *cb, ScrStream *s, ScrError *err) {
1618
+ ScrDyn *args[2];
1619
+ args[0] = err != NULL ? scr_dyn_from_error(err) : scr_dyn_new_null();
1620
+ args[1] = scr_stream_dynopt_done(s, &scr_stream_done_dyn_d, 1, "(error)");
1621
+ ScrDyn *fn = scr_stream_dynopt_target(cb);
1622
+ ScrDyn *r = scr_dyn_call(fn, args, 2, "destroy");
1623
+ scr_dyn_release(args[0]);
1624
+ scr_dyn_release(args[1]);
1625
+ scr_dyn_release(fn);
1626
+ if (r != NULL) scr_dyn_release(r);
1627
+ }
1628
+
1629
+ static ScrClosure *scr_stream_dynopt_clo(ScrDyn *fn, void *inv) {
1630
+ ScrClosure *c = scr_closure_new(inv, 1);
1631
+ c->caps[0] = scr_box_new_obj(&scr_dyn_retain_v, &scr_dyn_release_v, NULL);
1632
+ scr_box_set_ref(c->caps[0], scr_dyn_retain(fn));
1633
+ return c;
1634
+ }
1635
+
1636
+ typedef struct {
1637
+ double rhwm, whwm;
1638
+ bool auto_destroy, emit_close, allow_half_open;
1639
+ bool readable_side, writable_side;
1640
+ ScrStr *enc; /* owned canonical name, or NULL */
1641
+ /* BORROWED callable fields (owned by the options record). */
1642
+ ScrDyn *read, *write, *final_fn, *destroy, *transform, *flush;
1643
+ } ScrStreamDynOpts;
1644
+
1645
+ /* Node's `=== false` comparisons (autoDestroy/emitClose/allowHalfOpen and
1646
+ * the Duplex side toggles: `options.x !== false` — 0 does NOT disable). */
1647
+ static bool scr_stream_dynopt_false(const ScrDyn *v) {
1648
+ return v != NULL && v->kind == SCR_DYN_BOOL && !v->v.b;
1649
+ }
1650
+
1651
+ static double scr_stream_dynopt_hwm(const ScrDyn *o, const char *key, size_t klen) {
1652
+ ScrDyn *v = scr_dyn_obj_get((ScrDyn *)o, key, klen);
1653
+ if (v == NULL || v->kind != SCR_DYN_NUM || v->v.num < 0) return -1;
1654
+ return v->v.num;
1655
+ }
1656
+
1657
+ static ScrDyn *scr_stream_dynopt_fn(const ScrDyn *o, const char *key, size_t klen) {
1658
+ ScrDyn *v = scr_dyn_obj_get((ScrDyn *)o, key, klen);
1659
+ return v != NULL && v->kind == SCR_DYN_FUNC ? v : NULL; /* Node's typeof guard */
1660
+ }
1661
+
1662
+ static bool scr_stream_dynopt_truthy(const ScrDyn *o, const char *key, size_t klen) {
1663
+ ScrDyn *v = scr_dyn_obj_get((ScrDyn *)o, key, klen);
1664
+ return v != NULL && scr_dyn_truthy(v);
1665
+ }
1666
+
1667
+ static bool scr_stream_dynopt_unsupported(const char *msg, size_t len) {
1668
+ scr_throw_error_msg(SCR_ERR_ERROR, msg, len);
1669
+ return false;
1670
+ }
1671
+
1672
+ /* The runtime twin of the frontend's literal-encoding fold (BUF_ENCODINGS):
1673
+ * canonicalizes or throws Node's ERR_UNKNOWN_ENCODING TypeError. */
1674
+ static ScrStr *scr_stream_dynopt_encoding(const ScrStr *raw) {
1675
+ static const struct { const char *from; const char *to; } map[] = {
1676
+ {"utf8", "utf8"}, {"utf-8", "utf8"}, {"hex", "hex"}, {"base64", "base64"},
1677
+ {"base64url", "base64url"}, {"latin1", "latin1"}, {"binary", "latin1"},
1678
+ {"ascii", "ascii"}, {"utf16le", "utf16le"}, {"utf-16le", "utf16le"},
1679
+ {"ucs2", "utf16le"}, {"ucs-2", "utf16le"},
1680
+ };
1681
+ for (size_t i = 0; i < sizeof map / sizeof map[0]; i++) {
1682
+ size_t n = strlen(map[i].from);
1683
+ if (raw->len == n && memcmp(raw->data, map[i].from, n) == 0) {
1684
+ return scr_str_new(map[i].to, strlen(map[i].to));
1685
+ }
1686
+ }
1687
+ char msg[128];
1688
+ int len = snprintf(msg, sizeof msg, "Unknown encoding: %.*s",
1689
+ (int)(raw->len < 64 ? raw->len : 64), raw->data);
1690
+ scr_throw_error_msg_code(SCR_ERR_TYPE, msg, (size_t)(len < 0 ? 0 : len), "ERR_UNKNOWN_ENCODING");
1691
+ return NULL;
1692
+ }
1693
+
1694
+ /* Parses a dyn options record for one base ('r','w','d','t','p'); false
1695
+ * with the exception pending when a consumed-but-unlowered option rides. */
1696
+ static bool scr_stream_parse_dyn_opts(const ScrDyn *opts, char base, ScrStreamDynOpts *out) {
1697
+ out->rhwm = -1;
1698
+ out->whwm = -1;
1699
+ out->auto_destroy = true;
1700
+ out->emit_close = true;
1701
+ out->allow_half_open = true;
1702
+ out->readable_side = true;
1703
+ out->writable_side = true;
1704
+ out->enc = NULL;
1705
+ out->read = out->write = out->final_fn = out->destroy = out->transform = out->flush = NULL;
1706
+ if (opts == NULL || opts->kind != SCR_DYN_OBJ) return true; /* Node's `if (options)` */
1707
+ const bool duplexish = base == 'd' || base == 't' || base == 'p';
1708
+ const bool transformish = base == 't' || base == 'p';
1709
+ const bool r_sided = base != 'w';
1710
+
1711
+ if (scr_stream_dynopt_truthy(opts, "objectMode", 10) ||
1712
+ scr_stream_dynopt_truthy(opts, "readableObjectMode", 18) ||
1713
+ scr_stream_dynopt_truthy(opts, "writableObjectMode", 18)) {
1714
+ static const char m[] = "objectMode streams are not supported yet (chunks are Buffers or utf8 strings)";
1715
+ return scr_stream_dynopt_unsupported(m, sizeof m - 1);
1716
+ }
1717
+ if (scr_stream_dynopt_false(scr_dyn_obj_get((ScrDyn *)opts, "decodeStrings", 13))) {
1718
+ static const char m[] = "decodeStrings: false is not supported yet (chunks always decode to Buffers)";
1719
+ return scr_stream_dynopt_unsupported(m, sizeof m - 1);
1720
+ }
1721
+ {
1722
+ ScrDyn *v = scr_dyn_obj_get((ScrDyn *)opts, "signal", 6);
1723
+ if (v != NULL && v->kind != SCR_DYN_NULL && v->kind != SCR_DYN_UNDEF) {
1724
+ static const char m[] = "the stream option 'signal' is not supported yet (AbortSignal-driven destruction has no lowering)";
1725
+ return scr_stream_dynopt_unsupported(m, sizeof m - 1);
1726
+ }
1727
+ }
1728
+ if (scr_stream_dynopt_fn(opts, "construct", 9) != NULL) {
1729
+ static const char m[] = "the stream option 'construct' is not supported yet (deferred construction has no lowering)";
1730
+ return scr_stream_dynopt_unsupported(m, sizeof m - 1);
1731
+ }
1732
+ if (scr_stream_dynopt_fn(opts, "writev", 6) != NULL) {
1733
+ static const char m[] = "the stream option 'writev' is not supported yet (writes deliver one chunk at a time)";
1734
+ return scr_stream_dynopt_unsupported(m, sizeof m - 1);
1735
+ }
1736
+ {
1737
+ ScrDyn *v = scr_dyn_obj_get((ScrDyn *)opts, "defaultEncoding", 15);
1738
+ if (v != NULL && v->kind == SCR_DYN_STR &&
1739
+ !(v->v.str->len == 4 && memcmp(v->v.str->data, "utf8", 4) == 0) &&
1740
+ !(v->v.str->len == 5 && memcmp(v->v.str->data, "utf-8", 5) == 0)) {
1741
+ static const char m[] = "the stream option 'defaultEncoding' is not supported yet (utf8, the default, is the write-side string encoding)";
1742
+ return scr_stream_dynopt_unsupported(m, sizeof m - 1);
1743
+ }
1744
+ }
1745
+ if (transformish) {
1746
+ /* Node's Transform would install these UNDER the transform machinery
1747
+ * (Duplex consumes read/write/final before Transform overrides). */
1748
+ if (scr_stream_dynopt_fn(opts, "read", 4) != NULL ||
1749
+ scr_stream_dynopt_fn(opts, "write", 5) != NULL ||
1750
+ scr_stream_dynopt_fn(opts, "final", 5) != NULL) {
1751
+ static const char m[] = "a read/write/final option on a Transform is not supported yet (it would replace the transform composition)";
1752
+ return scr_stream_dynopt_unsupported(m, sizeof m - 1);
1753
+ }
1754
+ }
1755
+
1756
+ /* highWaterMark wins over the sided keys (Node's getHighWaterMark). */
1757
+ {
1758
+ double hwm = scr_stream_dynopt_hwm(opts, "highWaterMark", 13);
1759
+ double rh = duplexish ? scr_stream_dynopt_hwm(opts, "readableHighWaterMark", 21) : -1;
1760
+ double wh = duplexish ? scr_stream_dynopt_hwm(opts, "writableHighWaterMark", 21) : -1;
1761
+ out->rhwm = hwm >= 0 ? hwm : rh;
1762
+ out->whwm = hwm >= 0 ? hwm : wh;
1763
+ }
1764
+ out->auto_destroy = !scr_stream_dynopt_false(scr_dyn_obj_get((ScrDyn *)opts, "autoDestroy", 11));
1765
+ out->emit_close = !scr_stream_dynopt_false(scr_dyn_obj_get((ScrDyn *)opts, "emitClose", 9));
1766
+ if (duplexish) {
1767
+ out->allow_half_open = !scr_stream_dynopt_false(scr_dyn_obj_get((ScrDyn *)opts, "allowHalfOpen", 13));
1768
+ out->readable_side = !scr_stream_dynopt_false(scr_dyn_obj_get((ScrDyn *)opts, "readable", 8));
1769
+ out->writable_side = !scr_stream_dynopt_false(scr_dyn_obj_get((ScrDyn *)opts, "writable", 8));
1770
+ }
1771
+ if (r_sided) {
1772
+ ScrDyn *v = scr_dyn_obj_get((ScrDyn *)opts, "encoding", 8);
1773
+ if (v != NULL && v->kind == SCR_DYN_STR) {
1774
+ out->enc = scr_stream_dynopt_encoding(v->v.str);
1775
+ if (out->enc == NULL) return false;
1776
+ }
1777
+ }
1778
+ out->destroy = scr_stream_dynopt_fn(opts, "destroy", 7);
1779
+ if (transformish) {
1780
+ out->transform = scr_stream_dynopt_fn(opts, "transform", 9);
1781
+ out->flush = scr_stream_dynopt_fn(opts, "flush", 5);
1782
+ } else {
1783
+ if (base != 'w') out->read = scr_stream_dynopt_fn(opts, "read", 4);
1784
+ if (base != 'r') {
1785
+ out->write = scr_stream_dynopt_fn(opts, "write", 5);
1786
+ out->final_fn = scr_stream_dynopt_fn(opts, "final", 5);
1787
+ }
1788
+ }
1789
+ return true;
1790
+ }
1791
+
1792
+ /* One slot: an options callback SHADOWS the fallback (Node's instance-
1793
+ * property-over-prototype rule); the unused fallback releases. */
1794
+ static ScrClosure *scr_stream_dynopt_pick(ScrDyn *opt, void *dyn_inv, ScrClosure *fb, void *fb_inv, void **inv_out) {
1795
+ if (opt != NULL) {
1796
+ if (fb != NULL) scr_closure_release(fb);
1797
+ *inv_out = dyn_inv;
1798
+ return scr_stream_dynopt_clo(opt, dyn_inv);
1799
+ }
1800
+ *inv_out = fb != NULL ? fb_inv : NULL;
1801
+ return fb;
1802
+ }
1803
+
1804
+ static void scr_stream_dynopt_apply_enc(ScrStream *s, ScrStr *enc) {
1805
+ if (enc == NULL) return;
1806
+ ScrStream *chain = scr_stream_set_encoding(s, enc);
1807
+ scr_stream_release(chain);
1808
+ scr_str_release(enc);
1809
+ }
1810
+
1811
+ ScrStream *scr_stream_new_readable_dyn(ScrDyn *opts) {
1812
+ ScrStreamDynOpts o;
1813
+ if (!scr_stream_parse_dyn_opts(opts, 'r', &o)) return NULL;
1814
+ void *rinv = NULL, *dinv = NULL;
1815
+ ScrClosure *read = scr_stream_dynopt_pick(o.read, (void *)&scr_stream_dynopt_read_inv, NULL, NULL, &rinv);
1816
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, NULL, NULL, &dinv);
1817
+ ScrStream *s = scr_stream_new_readable(o.rhwm, o.auto_destroy, o.emit_close,
1818
+ read, (ScrStreamReadInv)rinv, destroy, (ScrStreamErrInv)dinv);
1819
+ scr_stream_dynopt_apply_enc(s, o.enc);
1820
+ return s;
1821
+ }
1822
+
1823
+ ScrStream *scr_stream_new_writable_dyn(ScrDyn *opts) {
1824
+ ScrStreamDynOpts o;
1825
+ if (!scr_stream_parse_dyn_opts(opts, 'w', &o)) return NULL;
1826
+ void *winv = NULL, *finv = NULL, *dinv = NULL;
1827
+ ScrClosure *write = scr_stream_dynopt_pick(o.write, (void *)&scr_stream_dynopt_write_inv, NULL, NULL, &winv);
1828
+ ScrClosure *final_cb = scr_stream_dynopt_pick(o.final_fn, (void *)&scr_stream_dynopt_final_inv, NULL, NULL, &finv);
1829
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, NULL, NULL, &dinv);
1830
+ return scr_stream_new_writable(o.whwm, o.auto_destroy, o.emit_close,
1831
+ write, (ScrStreamChunkInv)winv, final_cb, (ScrStreamPlainInv)finv, destroy, (ScrStreamErrInv)dinv);
1832
+ }
1833
+
1834
+ ScrStream *scr_stream_new_duplex_dyn(ScrDyn *opts) {
1835
+ ScrStreamDynOpts o;
1836
+ if (!scr_stream_parse_dyn_opts(opts, 'd', &o)) return NULL;
1837
+ void *rinv = NULL, *winv = NULL, *finv = NULL, *dinv = NULL;
1838
+ ScrClosure *read = scr_stream_dynopt_pick(o.read, (void *)&scr_stream_dynopt_read_inv, NULL, NULL, &rinv);
1839
+ ScrClosure *write = scr_stream_dynopt_pick(o.write, (void *)&scr_stream_dynopt_write_inv, NULL, NULL, &winv);
1840
+ ScrClosure *final_cb = scr_stream_dynopt_pick(o.final_fn, (void *)&scr_stream_dynopt_final_inv, NULL, NULL, &finv);
1841
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, NULL, NULL, &dinv);
1842
+ ScrStream *s = scr_stream_new_duplex(o.rhwm, o.whwm, o.auto_destroy, o.emit_close,
1843
+ o.allow_half_open, o.readable_side, o.writable_side,
1844
+ read, (ScrStreamReadInv)rinv, write, (ScrStreamChunkInv)winv,
1845
+ final_cb, (ScrStreamPlainInv)finv, destroy, (ScrStreamErrInv)dinv);
1846
+ scr_stream_dynopt_apply_enc(s, o.enc);
1847
+ return s;
1848
+ }
1849
+
1850
+ static ScrStream *scr_stream_new_transformish_dyn(ScrDyn *opts, char base) {
1851
+ ScrStreamDynOpts o;
1852
+ if (!scr_stream_parse_dyn_opts(opts, base, &o)) return NULL;
1853
+ void *tinv = NULL, *linv = NULL, *dinv = NULL;
1854
+ ScrClosure *transform = scr_stream_dynopt_pick(o.transform, (void *)&scr_stream_dynopt_transform_inv, NULL, NULL, &tinv);
1855
+ ScrClosure *flush = scr_stream_dynopt_pick(o.flush, (void *)&scr_stream_dynopt_flush_inv, NULL, NULL, &linv);
1856
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, NULL, NULL, &dinv);
1857
+ ScrStream *s = base == 't'
1858
+ ? scr_stream_new_transform(o.rhwm, o.whwm, o.auto_destroy, o.emit_close,
1859
+ o.allow_half_open, o.readable_side, o.writable_side,
1860
+ transform, (ScrStreamChunkInv)tinv, flush, (ScrStreamPlainInv)linv,
1861
+ destroy, (ScrStreamErrInv)dinv)
1862
+ : scr_stream_new_passthrough(o.rhwm, o.whwm, o.auto_destroy, o.emit_close,
1863
+ o.allow_half_open, o.readable_side, o.writable_side,
1864
+ transform, (ScrStreamChunkInv)tinv, flush, (ScrStreamPlainInv)linv,
1865
+ destroy, (ScrStreamErrInv)dinv);
1866
+ scr_stream_dynopt_apply_enc(s, o.enc);
1867
+ return s;
1868
+ }
1869
+
1870
+ ScrStream *scr_stream_new_transform_dyn(ScrDyn *opts) {
1871
+ return scr_stream_new_transformish_dyn(opts, 't');
1872
+ }
1873
+
1874
+ ScrStream *scr_stream_new_passthrough_dyn(ScrDyn *opts) {
1875
+ return scr_stream_new_transformish_dyn(opts, 'p');
1876
+ }
1877
+
1878
+ void scr_stream_init_readable_dyn(ScrStream *s, ScrDyn *opts,
1879
+ ScrClosure *read_fb, ScrStreamReadInv read_fb_inv,
1880
+ ScrClosure *destroy_fb, ScrStreamErrInv destroy_fb_inv) {
1881
+ ScrStreamDynOpts o;
1882
+ if (!scr_stream_parse_dyn_opts(opts, 'r', &o)) {
1883
+ if (read_fb != NULL) scr_closure_release(read_fb);
1884
+ if (destroy_fb != NULL) scr_closure_release(destroy_fb);
1885
+ return;
1886
+ }
1887
+ void *rinv = NULL, *dinv = NULL;
1888
+ ScrClosure *read = scr_stream_dynopt_pick(o.read, (void *)&scr_stream_dynopt_read_inv, read_fb, (void *)read_fb_inv, &rinv);
1889
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, destroy_fb, (void *)destroy_fb_inv, &dinv);
1890
+ scr_stream_init_readable(s, o.rhwm, o.auto_destroy, o.emit_close,
1891
+ read, (ScrStreamReadInv)rinv, destroy, (ScrStreamErrInv)dinv);
1892
+ scr_stream_dynopt_apply_enc(s, o.enc);
1893
+ }
1894
+
1895
+ void scr_stream_init_writable_dyn(ScrStream *s, ScrDyn *opts,
1896
+ ScrClosure *write_fb, ScrStreamChunkInv write_fb_inv,
1897
+ ScrClosure *final_fb, ScrStreamPlainInv final_fb_inv,
1898
+ ScrClosure *destroy_fb, ScrStreamErrInv destroy_fb_inv) {
1899
+ ScrStreamDynOpts o;
1900
+ if (!scr_stream_parse_dyn_opts(opts, 'w', &o)) {
1901
+ if (write_fb != NULL) scr_closure_release(write_fb);
1902
+ if (final_fb != NULL) scr_closure_release(final_fb);
1903
+ if (destroy_fb != NULL) scr_closure_release(destroy_fb);
1904
+ return;
1905
+ }
1906
+ void *winv = NULL, *finv = NULL, *dinv = NULL;
1907
+ ScrClosure *write = scr_stream_dynopt_pick(o.write, (void *)&scr_stream_dynopt_write_inv, write_fb, (void *)write_fb_inv, &winv);
1908
+ ScrClosure *final_cb = scr_stream_dynopt_pick(o.final_fn, (void *)&scr_stream_dynopt_final_inv, final_fb, (void *)final_fb_inv, &finv);
1909
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, destroy_fb, (void *)destroy_fb_inv, &dinv);
1910
+ scr_stream_init_writable(s, o.whwm, o.auto_destroy, o.emit_close,
1911
+ write, (ScrStreamChunkInv)winv, final_cb, (ScrStreamPlainInv)finv, destroy, (ScrStreamErrInv)dinv);
1912
+ }
1913
+
1914
+ void scr_stream_init_duplex_dyn(ScrStream *s, ScrDyn *opts,
1915
+ ScrClosure *read_fb, ScrStreamReadInv read_fb_inv,
1916
+ ScrClosure *write_fb, ScrStreamChunkInv write_fb_inv,
1917
+ ScrClosure *final_fb, ScrStreamPlainInv final_fb_inv,
1918
+ ScrClosure *destroy_fb, ScrStreamErrInv destroy_fb_inv) {
1919
+ ScrStreamDynOpts o;
1920
+ if (!scr_stream_parse_dyn_opts(opts, 'd', &o)) {
1921
+ if (read_fb != NULL) scr_closure_release(read_fb);
1922
+ if (write_fb != NULL) scr_closure_release(write_fb);
1923
+ if (final_fb != NULL) scr_closure_release(final_fb);
1924
+ if (destroy_fb != NULL) scr_closure_release(destroy_fb);
1925
+ return;
1926
+ }
1927
+ void *rinv = NULL, *winv = NULL, *finv = NULL, *dinv = NULL;
1928
+ ScrClosure *read = scr_stream_dynopt_pick(o.read, (void *)&scr_stream_dynopt_read_inv, read_fb, (void *)read_fb_inv, &rinv);
1929
+ ScrClosure *write = scr_stream_dynopt_pick(o.write, (void *)&scr_stream_dynopt_write_inv, write_fb, (void *)write_fb_inv, &winv);
1930
+ ScrClosure *final_cb = scr_stream_dynopt_pick(o.final_fn, (void *)&scr_stream_dynopt_final_inv, final_fb, (void *)final_fb_inv, &finv);
1931
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, destroy_fb, (void *)destroy_fb_inv, &dinv);
1932
+ scr_stream_init_duplex(s, o.rhwm, o.whwm, o.auto_destroy, o.emit_close,
1933
+ o.allow_half_open, o.readable_side, o.writable_side,
1934
+ read, (ScrStreamReadInv)rinv, write, (ScrStreamChunkInv)winv,
1935
+ final_cb, (ScrStreamPlainInv)finv, destroy, (ScrStreamErrInv)dinv);
1936
+ scr_stream_dynopt_apply_enc(s, o.enc);
1937
+ }
1938
+
1939
+ static void scr_stream_init_transformish_dyn(ScrStream *s, ScrDyn *opts, char base,
1940
+ ScrClosure *transform_fb, ScrStreamChunkInv transform_fb_inv,
1941
+ ScrClosure *flush_fb, ScrStreamPlainInv flush_fb_inv,
1942
+ ScrClosure *destroy_fb, ScrStreamErrInv destroy_fb_inv) {
1943
+ ScrStreamDynOpts o;
1944
+ if (!scr_stream_parse_dyn_opts(opts, base, &o)) {
1945
+ if (transform_fb != NULL) scr_closure_release(transform_fb);
1946
+ if (flush_fb != NULL) scr_closure_release(flush_fb);
1947
+ if (destroy_fb != NULL) scr_closure_release(destroy_fb);
1948
+ return;
1949
+ }
1950
+ void *tinv = NULL, *linv = NULL, *dinv = NULL;
1951
+ ScrClosure *transform = scr_stream_dynopt_pick(o.transform, (void *)&scr_stream_dynopt_transform_inv, transform_fb, (void *)transform_fb_inv, &tinv);
1952
+ ScrClosure *flush = scr_stream_dynopt_pick(o.flush, (void *)&scr_stream_dynopt_flush_inv, flush_fb, (void *)flush_fb_inv, &linv);
1953
+ ScrClosure *destroy = scr_stream_dynopt_pick(o.destroy, (void *)&scr_stream_dynopt_destroy_inv, destroy_fb, (void *)destroy_fb_inv, &dinv);
1954
+ if (base == 't') {
1955
+ scr_stream_init_transform(s, o.rhwm, o.whwm, o.auto_destroy, o.emit_close,
1956
+ o.allow_half_open, o.readable_side, o.writable_side,
1957
+ transform, (ScrStreamChunkInv)tinv, flush, (ScrStreamPlainInv)linv,
1958
+ destroy, (ScrStreamErrInv)dinv);
1959
+ } else {
1960
+ scr_stream_init_passthrough(s, o.rhwm, o.whwm, o.auto_destroy, o.emit_close,
1961
+ o.allow_half_open, o.readable_side, o.writable_side,
1962
+ transform, (ScrStreamChunkInv)tinv, flush, (ScrStreamPlainInv)linv,
1963
+ destroy, (ScrStreamErrInv)dinv);
1964
+ }
1965
+ scr_stream_dynopt_apply_enc(s, o.enc);
1966
+ }
1967
+
1968
+ void scr_stream_init_transform_dyn(ScrStream *s, ScrDyn *opts,
1969
+ ScrClosure *transform_fb, ScrStreamChunkInv transform_fb_inv,
1970
+ ScrClosure *flush_fb, ScrStreamPlainInv flush_fb_inv,
1971
+ ScrClosure *destroy_fb, ScrStreamErrInv destroy_fb_inv) {
1972
+ scr_stream_init_transformish_dyn(s, opts, 't', transform_fb, transform_fb_inv,
1973
+ flush_fb, flush_fb_inv, destroy_fb, destroy_fb_inv);
1974
+ }
1975
+
1976
+ void scr_stream_init_passthrough_dyn(ScrStream *s, ScrDyn *opts,
1977
+ ScrClosure *transform_fb, ScrStreamChunkInv transform_fb_inv,
1978
+ ScrClosure *flush_fb, ScrStreamPlainInv flush_fb_inv,
1979
+ ScrClosure *destroy_fb, ScrStreamErrInv destroy_fb_inv) {
1980
+ scr_stream_init_transformish_dyn(s, opts, 'p', transform_fb, transform_fb_inv,
1981
+ flush_fb, flush_fb_inv, destroy_fb, destroy_fb_inv);
1982
+ }
1983
+
1984
+ /* ── finished() and pipeline() (lib/internal/streams/end-of-stream and
1985
+ * pipeline — the callback forms) ─────────────────────────────────────
1986
+ *
1987
+ * PROBED ORDERINGS (Node v24.15.0):
1988
+ * - finished(s, cb): cb fires right AFTER s's 'close' (willEmitClose —
1989
+ * the default autoDestroy+emitClose lifecycle), with `this` bound to
1990
+ * the stream, no arguments on success, the error on error, and
1991
+ * ERR_STREAM_PREMATURE_CLOSE ("Premature close") when the stream
1992
+ * closed before end/finish. finished returns a CLEANUP function that
1993
+ * unhooks the callback.
1994
+ * - pipeline(a, b, c, cb) on a mid-stream error: the erroring stream
1995
+ * destroys itself and emits 'error'+'close'; the pipeline then
1996
+ * destroys every OTHER stream with the SAME error (pipeline order),
1997
+ * each emitting 'error' then 'close'; cb(err) runs after the last
1998
+ * 'close'. Success: cb(null) after the destination's 'close'.
1999
+ * - both register 'error' handlers, so an otherwise-unhandled stream
2000
+ * error no longer crashes (the SCR_ST_ERROR suppression above). */
2001
+
2002
+ static void scr_stream_fin_add(ScrStreamState *st, ScrClosure *cb /*moves*/, ScrStreamErrInv inv) {
2003
+ if (st->fin.n == st->fin.cap) {
2004
+ st->fin.cap = st->fin.cap ? st->fin.cap * 2 : 2;
2005
+ st->fin.cb = realloc(st->fin.cb, st->fin.cap * sizeof *st->fin.cb);
2006
+ st->fin.inv = realloc(st->fin.inv, st->fin.cap * sizeof *st->fin.inv);
2007
+ if (!st->fin.cb || !st->fin.inv) scr_stream_oom();
2008
+ }
2009
+ st->fin.cb[st->fin.n] = cb;
2010
+ st->fin.inv[st->fin.n] = inv;
2011
+ st->fin.n++;
2012
+ }
2013
+
2014
+ /* The stream's finish status: +1 error (the recorded one, or premature
2015
+ * close), or NULL for a clean end+finish. */
2016
+ static ScrError *scr_stream_finish_status(ScrStream *s) {
2017
+ ScrStreamState *st = s->st;
2018
+ if (st->errored) return scr_error_retain(st->errored);
2019
+ if ((st->has_r && !st->r.end_emitted) || (st->has_w && !st->w.finished)) {
2020
+ return scr_stream_mkerr("ERR_STREAM_PREMATURE_CLOSE", "Premature close");
2021
+ }
2022
+ return NULL;
2023
+ }
2024
+
2025
+ static void scr_stream_notify_finished(ScrStream *s) {
2026
+ ScrStreamState *st = s->st;
2027
+ if (st->fin.n == 0) return;
2028
+ /* Take the list out first: a watcher may register another finished()
2029
+ * or run cleanup reentrantly. */
2030
+ ScrClosure **cbs = st->fin.cb;
2031
+ ScrStreamErrInv *invs = st->fin.inv;
2032
+ size_t n = st->fin.n;
2033
+ st->fin.cb = NULL;
2034
+ st->fin.inv = NULL;
2035
+ st->fin.n = 0;
2036
+ st->fin.cap = 0;
2037
+ ScrError *err = scr_stream_finish_status(s);
2038
+ for (size_t i = 0; i < n; i++) {
2039
+ if (!scr_exc_pending()) invs[i](cbs[i], s, err);
2040
+ scr_closure_release(cbs[i]);
2041
+ }
2042
+ if (err) scr_error_release(err);
2043
+ free(cbs);
2044
+ free(invs);
2045
+ }
2046
+
2047
+ static void scr_stream_finished_cleanup_fn(ScrClosure *self) {
2048
+ ScrStream *s = scr_box_get_ref(self->caps[0]); /* +1 */
2049
+ ScrClosure *cb = scr_box_get_ref(self->caps[1]); /* +1 */
2050
+ ScrStreamState *st = s->st;
2051
+ for (size_t i = 0; i < st->fin.n; i++) {
2052
+ if (st->fin.cb[i] == cb) {
2053
+ scr_closure_release(st->fin.cb[i]);
2054
+ memmove(&st->fin.cb[i], &st->fin.cb[i + 1], (st->fin.n - i - 1) * sizeof *st->fin.cb);
2055
+ memmove(&st->fin.inv[i], &st->fin.inv[i + 1], (st->fin.n - i - 1) * sizeof *st->fin.inv);
2056
+ st->fin.n--;
2057
+ break;
2058
+ }
2059
+ }
2060
+ scr_closure_release(cb);
2061
+ scr_stream_release(s);
2062
+ }
2063
+
2064
+ ScrClosure *scr_stream_finished(ScrStream *s, ScrClosure *cb /*moves*/, ScrStreamErrInv inv) {
2065
+ ScrStreamState *st = s->st;
2066
+ scr_stream_fin_add(st, scr_closure_retain(cb), inv);
2067
+ if (st->close_emitted) {
2068
+ /* Already terminal: Node's eos still calls back asynchronously. */
2069
+ scr_st_tick(s, SCR_ST_FIN, NULL, NULL);
2070
+ }
2071
+ ScrClosure *cleanup = scr_closure_new((void *)&scr_stream_finished_cleanup_fn, 2);
2072
+ cleanup->caps[0] = scr_box_new_obj(&scr_stream_retain_v, &scr_stream_release_v, &scr_stream_trace);
2073
+ scr_box_set_ref(cleanup->caps[0], scr_stream_retain(s));
2074
+ cleanup->caps[1] = scr_box_new_obj(&scr_closure_retain_v, &scr_closure_release_v, &scr_closure_trace_v);
2075
+ scr_box_set_ref(cleanup->caps[1], cb); /* the move lands here */
2076
+ return cleanup;
2077
+ }
2078
+
2079
+ /* The dyn-valued finished/pipeline callback (a mustCall wrapper): success
2080
+ * calls with NO arguments (Node's callback.call(stream)), an error boxes
2081
+ * through the boundary encoding. */
2082
+ void scr_stream_finished_dyn_inv(ScrClosure *cb, ScrStream *s, ScrError *err) {
2083
+ (void)s;
2084
+ ScrDyn *fn = scr_stream_dynopt_target(cb);
2085
+ ScrDyn *r;
2086
+ if (err != NULL) {
2087
+ ScrDyn *a = scr_dyn_from_error(err);
2088
+ r = scr_dyn_call(fn, &a, 1, "callback");
2089
+ scr_dyn_release(a);
2090
+ } else {
2091
+ r = scr_dyn_call(fn, NULL, 0, "callback");
2092
+ }
2093
+ scr_dyn_release(fn);
2094
+ if (r != NULL) scr_dyn_release(r);
2095
+ }
2096
+
2097
+ typedef struct {
2098
+ size_t rc;
2099
+ size_t n, closed;
2100
+ ScrStream **streams; /* owned */
2101
+ ScrClosure *cb; /* owned; NULL once fired */
2102
+ ScrStreamErrInv inv;
2103
+ ScrError *err; /* first error, owned */
2104
+ } ScrStreamPipeCtx;
2105
+
2106
+ static void *scr_stream_pipectx_retain_v(void *p) {
2107
+ ((ScrStreamPipeCtx *)p)->rc++;
2108
+ return p;
2109
+ }
2110
+
2111
+ static void scr_stream_pipectx_release_v(void *p) {
2112
+ ScrStreamPipeCtx *ctx = p;
2113
+ if (--ctx->rc > 0) return;
2114
+ for (size_t i = 0; i < ctx->n; i++) scr_stream_release(ctx->streams[i]);
2115
+ free(ctx->streams);
2116
+ if (ctx->cb) scr_closure_release(ctx->cb);
2117
+ if (ctx->err) scr_error_release(ctx->err);
2118
+ free(ctx);
2119
+ }
2120
+
2121
+ static void scr_stream_pipeline_watch_inv(ScrClosure *cb, ScrStream *s, ScrError *err) {
2122
+ ScrStreamPipeCtx *ctx = scr_box_get_ref(cb->caps[0]); /* +1 */
2123
+ ctx->closed++;
2124
+ if (err != NULL && ctx->err == NULL) {
2125
+ ctx->err = scr_error_retain(err);
2126
+ /* Node's pipeline destroyer: every other stream goes down with the
2127
+ * SAME error, pipeline order (each emits 'error' then 'close'). */
2128
+ for (size_t i = 0; i < ctx->n; i++) {
2129
+ if (ctx->streams[i] != s) {
2130
+ ScrStream *chain = scr_stream_destroy(ctx->streams[i], ctx->err);
2131
+ scr_stream_release(chain);
2132
+ }
2133
+ }
2134
+ }
2135
+ if (ctx->closed == ctx->n && ctx->cb != NULL) {
2136
+ ScrClosure *ucb = ctx->cb;
2137
+ ctx->cb = NULL;
2138
+ ctx->inv(ucb, ctx->streams[ctx->n - 1], ctx->err);
2139
+ scr_closure_release(ucb);
2140
+ }
2141
+ scr_stream_pipectx_release_v(ctx);
2142
+ }
2143
+
2144
+ /* The dyn-valued twins: the callback rides as a checked-dynamic value
2145
+ * (borrowed; the closure's cap box retains it). */
2146
+ ScrClosure *scr_stream_finished_dyn(ScrStream *s, ScrDyn *cb) {
2147
+ ScrClosure *c = scr_stream_dynopt_clo(cb, (void *)&scr_stream_finished_dyn_inv);
2148
+ ScrClosure *cleanup = scr_stream_finished(s, c, &scr_stream_finished_dyn_inv);
2149
+ return cleanup;
2150
+ }
2151
+
2152
+ ScrStream *scr_stream_pipeline_dyn(double n, ScrStream **streams, ScrDyn *cb) {
2153
+ ScrClosure *c = scr_stream_dynopt_clo(cb, (void *)&scr_stream_finished_dyn_inv);
2154
+ return scr_stream_pipeline(n, streams, c, &scr_stream_finished_dyn_inv);
2155
+ }
2156
+
2157
+ ScrStream *scr_stream_pipeline(double n_d, ScrStream **streams /*borrowed*/,
2158
+ ScrClosure *cb /*moves*/, ScrStreamErrInv inv) {
2159
+ size_t n = (size_t)n_d;
2160
+ ScrStreamPipeCtx *ctx = calloc(1, sizeof *ctx);
2161
+ if (!ctx) scr_stream_oom();
2162
+ ctx->rc = 1;
2163
+ ctx->n = n;
2164
+ ctx->streams = calloc(n, sizeof *ctx->streams);
2165
+ if (!ctx->streams) scr_stream_oom();
2166
+ for (size_t i = 0; i < n; i++) ctx->streams[i] = scr_stream_retain(streams[i]);
2167
+ ctx->cb = cb;
2168
+ ctx->inv = inv;
2169
+ /* Chain the pipes first (end: true — Node's pipeline forwards EOF). */
2170
+ for (size_t i = 0; i + 1 < n; i++) {
2171
+ ScrStream *d = scr_stream_pipe(streams[i], streams[i + 1], true);
2172
+ scr_stream_release(d);
2173
+ }
2174
+ /* One watcher per stream: the terminal statuses drive error propagation
2175
+ * and the final callback (after the LAST 'close'). */
2176
+ for (size_t i = 0; i < n; i++) {
2177
+ ScrClosure *w = scr_closure_new((void *)&scr_stream_pipeline_watch_inv, 1);
2178
+ w->caps[0] = scr_box_new_obj(&scr_stream_pipectx_retain_v, &scr_stream_pipectx_release_v, NULL);
2179
+ scr_box_set_ref(w->caps[0], scr_stream_pipectx_retain_v(ctx));
2180
+ scr_stream_fin_add(streams[i]->st, w, &scr_stream_pipeline_watch_inv);
2181
+ }
2182
+ scr_stream_pipectx_release_v(ctx); /* the boxes own it now */
2183
+ return scr_stream_retain(streams[n - 1]);
2184
+ }
2185
+
2186
+ /* ── node:stream/promises ─────────────────────────────────────────────
2187
+ * The promise forms ride the callback machinery above with a settling
2188
+ * watcher: caps[0] boxes the pending promise; the terminal status
2189
+ * fulfills (NULL) or rejects (the error moves through the exception
2190
+ * cell, the reject-pending pattern). */
2191
+
2192
+ static void scr_sp_settle_inv(ScrClosure *cb, ScrStream *s, ScrError *err) {
2193
+ (void)s;
2194
+ ScrPromise *p = scr_box_get_ref(cb->caps[0]); /* +1 */
2195
+ if (err != NULL) {
2196
+ scr_throw_obj(scr_error_retain(err), &scr_error_retain_v, &scr_error_release_v,
2197
+ scr_error_trace_arg());
2198
+ scr_promise_reject_pending(p);
2199
+ } else {
2200
+ scr_promise_fulfill_void(p);
2201
+ }
2202
+ scr_promise_release(p);
2203
+ }
2204
+
2205
+ static ScrClosure *scr_sp_watcher(ScrPromise *p /*borrowed*/) {
2206
+ ScrClosure *w = scr_closure_new((void *)&scr_sp_settle_inv, 1);
2207
+ w->caps[0] = scr_box_new_obj(scr_promise_retain_v, scr_promise_release_v, scr_promise_trace_v);
2208
+ scr_box_set_ref(w->caps[0], scr_promise_retain(p));
2209
+ return w;
2210
+ }
2211
+
2212
+ ScrPromise *scr_sp_finished(ScrStream *s) {
2213
+ ScrPromise *p = scr_promise_new();
2214
+ /* The cleanup closure is the callback form's return value; the promise
2215
+ * form exposes no unhook, so it drops here (the watcher stays parked —
2216
+ * scr_stream_finished retained it into the stream's list). */
2217
+ ScrClosure *cleanup = scr_stream_finished(s, scr_sp_watcher(p), &scr_sp_settle_inv);
2218
+ scr_closure_release(cleanup);
2219
+ return p;
2220
+ }
2221
+
2222
+ ScrPromise *scr_sp_pipeline(double n, ScrStream **streams) {
2223
+ ScrPromise *p = scr_promise_new();
2224
+ ScrStream *dst = scr_stream_pipeline(n, streams, scr_sp_watcher(p), &scr_sp_settle_inv);
2225
+ scr_stream_release(dst);
2226
+ return p;
2227
+ }
2228
+
2229
+ /* ── node:stream/consumers ────────────────────────────────────────────
2230
+ * text/json/buffer over the readable machinery: a native 'data' listener
2231
+ * accumulates every chunk (Buffer chunks as-is; string chunks — an
2232
+ * encoded stream or Readable.from strings — as their utf8 bytes, the
2233
+ * Blob rule Node's consumers share for whole-stream accumulation), and
2234
+ * the finished watcher settles at the terminal point — the accumulated
2235
+ * result on a clean end (right after 'close', Node's own timing: the
2236
+ * consumer's async iterator completes through eos), the stream's error,
2237
+ * or ERR_STREAM_PREMATURE_CLOSE on an early close — and marks lifecycle
2238
+ * errors handled, exactly like the iterator's eos registration. Both
2239
+ * closures share the cap layout: caps[0] the pending promise, caps[1]
2240
+ * the chunk list (Buffer entries). */
2241
+
2242
+ enum { SCR_SC_TEXT = 0, SCR_SC_JSON = 1, SCR_SC_BUFFER = 2 };
2243
+
2244
+ static void scr_sc_settle_ok(ScrClosure *cb, int kind) {
2245
+ ScrPromise *p = scr_box_get_ref(cb->caps[0]); /* +1 */
2246
+ ScrArr *chunks = scr_box_get_ref(cb->caps[1]); /* +1 */
2247
+ ScrBytes *all = scr_bytes_concat(chunks);
2248
+ scr_arr_release(chunks);
2249
+ if (kind == SCR_SC_BUFFER) {
2250
+ scr_promise_fulfill_ref(p, all, scr_bytes_retain_v, scr_bytes_release_v, NULL);
2251
+ scr_promise_release(p);
2252
+ return;
2253
+ }
2254
+ ScrStr *enc = scr_str_new("utf8", 4);
2255
+ ScrStr *text = scr_bytes_to_str(all, enc); /* U+FFFD per invalid subpart */
2256
+ scr_str_release(enc);
2257
+ scr_bytes_release(all);
2258
+ if (kind == SCR_SC_TEXT) {
2259
+ scr_promise_fulfill_str(p, text); /* moves */
2260
+ } else {
2261
+ ScrDyn *doc = scr_json_parse(text);
2262
+ scr_str_release(text);
2263
+ if (doc == NULL) {
2264
+ /* the parse's SyntaxError rides the cell — the rejection, like
2265
+ * Node's json() rejecting with JSON.parse's throw */
2266
+ scr_promise_reject_pending(p);
2267
+ } else {
2268
+ scr_promise_fulfill_ref(p, doc, scr_dyn_retain_v, scr_dyn_release_v, NULL);
2269
+ }
2270
+ }
2271
+ scr_promise_release(p);
2272
+ }
2273
+
2274
+ /* The 'data' accumulation (the emit ABI's two payload slots — exactly
2275
+ * one non-NULL). */
2276
+ static void scr_sc_data(ScrClosure *cb, void *b, void *str) {
2277
+ ScrArr *chunks = scr_box_get_ref(cb->caps[1]); /* +1 */
2278
+ if (b != NULL) {
2279
+ scr_arr_push_ref(chunks, scr_bytes_retain((ScrBytes *)b));
2280
+ } else if (str != NULL) {
2281
+ ScrStr *enc = scr_str_new("utf8", 4);
2282
+ scr_arr_push_ref(chunks, scr_bytes_from_str((ScrStr *)str, enc));
2283
+ scr_str_release(enc);
2284
+ }
2285
+ scr_arr_release(chunks);
2286
+ }
2287
+
2288
+ static void scr_sc_fin(ScrClosure *cb, ScrError *err, int kind) {
2289
+ if (err != NULL) {
2290
+ ScrPromise *p = scr_box_get_ref(cb->caps[0]); /* +1 */
2291
+ scr_throw_obj(scr_error_retain(err), &scr_error_retain_v, &scr_error_release_v,
2292
+ scr_error_trace_arg());
2293
+ scr_promise_reject_pending(p);
2294
+ scr_promise_release(p);
2295
+ return;
2296
+ }
2297
+ scr_sc_settle_ok(cb, kind);
2298
+ }
2299
+
2300
+ static void scr_sc_fin_text(ScrClosure *cb, ScrStream *s, ScrError *err) {
2301
+ (void)s;
2302
+ scr_sc_fin(cb, err, SCR_SC_TEXT);
2303
+ }
2304
+ static void scr_sc_fin_json(ScrClosure *cb, ScrStream *s, ScrError *err) {
2305
+ (void)s;
2306
+ scr_sc_fin(cb, err, SCR_SC_JSON);
2307
+ }
2308
+ static void scr_sc_fin_buffer(ScrClosure *cb, ScrStream *s, ScrError *err) {
2309
+ (void)s;
2310
+ scr_sc_fin(cb, err, SCR_SC_BUFFER);
2311
+ }
2312
+
2313
+ static ScrClosure *scr_sc_closure(void *fn, ScrPromise *p, ScrArr *chunks) {
2314
+ ScrClosure *c = scr_closure_new(fn, 2);
2315
+ c->caps[0] = scr_box_new_obj(scr_promise_retain_v, scr_promise_release_v, scr_promise_trace_v);
2316
+ scr_box_set_ref(c->caps[0], scr_promise_retain(p));
2317
+ c->caps[1] = scr_box_new_obj(scr_arr_retain_v, scr_arr_release_v, NULL);
2318
+ scr_box_set_ref(c->caps[1], scr_arr_retain(chunks));
2319
+ return c;
2320
+ }
2321
+
2322
+ static ScrPromise *scr_sc_consume(ScrStream *s, int kind) {
2323
+ ScrPromise *p = scr_promise_new();
2324
+ if (s->st == NULL || !s->st->has_r) {
2325
+ /* Node's consumers for-await the argument; a stream with no readable
2326
+ * side has no async iterator — the TypeError rejects. */
2327
+ static const char msg[] = "stream is not async iterable";
2328
+ scr_throw_error_msg(SCR_ERR_TYPE, msg, sizeof msg - 1);
2329
+ scr_promise_reject_pending(p);
2330
+ return p;
2331
+ }
2332
+ ScrArr *chunks = scr_arr_new_ref(scr_bytes_retain_v, scr_bytes_release_v, NULL, 4);
2333
+ ScrStreamErrInv fin_inv = kind == SCR_SC_TEXT ? &scr_sc_fin_text
2334
+ : kind == SCR_SC_JSON ? &scr_sc_fin_json
2335
+ : &scr_sc_fin_buffer;
2336
+ /* The terminal watcher first (it marks lifecycle errors handled); the
2337
+ * promise form exposes no unhook — the cleanup closure drops. */
2338
+ ScrClosure *cleanup = scr_stream_finished(s, scr_sc_closure((void *)fin_inv, p, chunks), fin_inv);
2339
+ scr_closure_release(cleanup);
2340
+ ScrStr *dn = scr_str_new("data", 4);
2341
+ scr_emitter_release(scr_emitter_on((ScrEmitter *)s, dn,
2342
+ scr_sc_closure((void *)&scr_sc_data, p, chunks),
2343
+ scr_ee_inv_fixed2, false, false));
2344
+ scr_str_release(dn);
2345
+ /* resume() rather than the 'data' hook alone: Node's consumer pulls
2346
+ * through the iterator, which drains a PAUSED stream too. */
2347
+ scr_stream_release(scr_stream_resume(s));
2348
+ scr_arr_release(chunks);
2349
+ return p;
2350
+ }
2351
+
2352
+ ScrPromise *scr_sc_text(ScrStream *s) { return scr_sc_consume(s, SCR_SC_TEXT); }
2353
+ ScrPromise *scr_sc_json(ScrStream *s) { return scr_sc_consume(s, SCR_SC_JSON); }
2354
+ ScrPromise *scr_sc_buffer(ScrStream *s) { return scr_sc_consume(s, SCR_SC_BUFFER); }
2355
+
2356
+ /* ── the readable surface ─────────────────────────────────────────────── */
2357
+
2358
+ bool scr_stream_push(ScrStream *s, ScrBytes *chunk) {
2359
+ return scr_stream_add_chunk(s, chunk, false);
2360
+ }
2361
+
2362
+ bool scr_stream_push_str(ScrStream *s, ScrStr *str) {
2363
+ ScrStr *enc = s->st->has_r ? s->st->r.push_enc : NULL;
2364
+ ScrBytes *b;
2365
+ if (enc != NULL) {
2366
+ /* Node: Buffer.from(chunk, state.defaultEncoding). */
2367
+ b = scr_bytes_from_str(str, enc);
2368
+ } else {
2369
+ b = scr_bytes_new(SCR_BYTES_U8, (double)str->len);
2370
+ memcpy(b->data, str->data, str->len);
2371
+ }
2372
+ bool ret = scr_stream_add_chunk(s, b, false);
2373
+ scr_bytes_release(b);
2374
+ return ret;
2375
+ }
2376
+
2377
+ /* push(chunk, encoding) with an explicit non-utf8 literal: the per-call
2378
+ * encoding overrides the stream's default. Borrows both strings. */
2379
+ bool scr_stream_push_str_enc(ScrStream *s, ScrStr *str, ScrStr *enc) {
2380
+ ScrBytes *b = scr_bytes_from_str(str, enc);
2381
+ bool ret = scr_stream_add_chunk(s, b, false);
2382
+ scr_bytes_release(b);
2383
+ return ret;
2384
+ }
2385
+
2386
+ /* The defaultEncoding option's push side (canonical literal, frontend-
2387
+ * folded; never "utf8" — that stays the NULL fast path). Answers the
2388
+ * receiver +1, the setEncoding chaining shape. */
2389
+ ScrStream *scr_stream_set_push_encoding(ScrStream *s, ScrStr *enc) {
2390
+ ScrStreamState *st = s->st;
2391
+ if (st->has_r) {
2392
+ if (st->r.push_enc) scr_str_release(st->r.push_enc);
2393
+ st->r.push_enc = scr_str_retain(enc);
2394
+ }
2395
+ return scr_stream_retain(s);
2396
+ }
2397
+
2398
+ bool scr_stream_push_null(ScrStream *s) {
2399
+ ScrStreamState *st = s->st;
2400
+ if (!st->has_r || st->destroyed) return false;
2401
+ st->r.reading = false;
2402
+ if (!st->r.ended) {
2403
+ /* onEofChunk flushes the decoder's held partial first (utf8's
2404
+ * replacement chars et al — Node's decoder.end() push). */
2405
+ if (st->r.encoded) {
2406
+ ScrStr *tail = scr_strdec_end(st->r.enc, st->r.dec_pending);
2407
+ st->r.dec_pending = 0;
2408
+ if (scr_str_utf16_len(tail) > 0) {
2409
+ scr_stream_rbuf_push(st, tail, false);
2410
+ if (st->r.need_readable) scr_stream_emit_readable_nt(s);
2411
+ } else {
2412
+ scr_str_release(tail);
2413
+ }
2414
+ }
2415
+ st->r.ended = true;
2416
+ /* onEofChunk: inside a _read call (or before the first attempt) the
2417
+ * 'readable' pass defers to a tick; outside one it runs NOW — a
2418
+ * flowing stream delivers its buffered chunks synchronously here. */
2419
+ if (st->r.in_read_sync) {
2420
+ scr_stream_emit_readable_nt(s);
2421
+ if (st->r.length == 0) scr_stream_end_readable(s);
2422
+ } else {
2423
+ st->r.need_readable = false;
2424
+ st->r.emitted_readable = true;
2425
+ scr_stream_emit_readable_now(s);
2426
+ }
2427
+ if (!scr_exc_pending()) scr_stream_settle_next(s);
2428
+ }
2429
+ return false;
2430
+ }
2431
+
2432
+ void scr_stream_unshift(ScrStream *s, ScrBytes *chunk) {
2433
+ ScrStreamState *st = s->st;
2434
+ if (st->r.head_off > 0) {
2435
+ /* materialize the part-read head so the front slot is whole */
2436
+ void *rest = scr_stream_rbuf_take(st, scr_stream_entry_len(st, st->r.buf[0]) - st->r.head_off);
2437
+ scr_stream_rbuf_push(st, rest, true);
2438
+ }
2439
+ scr_stream_add_chunk(s, chunk, true);
2440
+ }
2441
+
2442
+ void scr_stream_unshift_str(ScrStream *s, ScrStr *str) {
2443
+ ScrBytes *b = scr_bytes_new(SCR_BYTES_U8, (double)str->len);
2444
+ memcpy(b->data, str->data, str->len);
2445
+ scr_stream_unshift(s, b);
2446
+ scr_bytes_release(b);
2447
+ }
2448
+
2449
+ ScrBytes *scr_stream_read(ScrStream *s, double size) {
2450
+ /* a destroyed readable still DRAINS its buffer (Node: destroy leaves
2451
+ * buffered chunks readable; only _read refills are blocked) */
2452
+ if (!s->st->has_r) return NULL;
2453
+ if (s->st->r.encoded) {
2454
+ /* read() answers STRINGS once encoded — the static result type here
2455
+ * is `Buffer | null`, so the honest answer is a fence, not a
2456
+ * mistyped payload (SEMANTICS.md; 'data' listeners carry strings). */
2457
+ static const char msg[] =
2458
+ "read() on a stream with an encoding set is not supported yet "
2459
+ "(consume 'data' events, which deliver strings)";
2460
+ scr_throw_error_msg(SCR_ERR_ERROR, msg, sizeof msg - 1);
2461
+ return NULL;
2462
+ }
2463
+ return scr_stream_read_n(s, size);
2464
+ }
2465
+
2466
+ /* setEncoding(enc): flips the readable buffer into string mode — Node
2467
+ * re-decodes the buffered content into ONE string entry and re-counts
2468
+ * length in string units. Borrows enc (canonical, frontend-folded);
2469
+ * answers the receiver +1. */
2470
+ ScrStream *scr_stream_set_encoding(ScrStream *s, ScrStr *enc) {
2471
+ ScrStreamState *st = s->st;
2472
+ if (!st->has_r) return scr_stream_retain(s);
2473
+ if (st->r.encoded) {
2474
+ /* switching encodings mid-stream: fold the old decoder's pending
2475
+ * tail into the buffer first (rare; Node re-creates the decoder) */
2476
+ ScrStr *tail = scr_strdec_end(st->r.enc, st->r.dec_pending);
2477
+ if (scr_str_utf16_len(tail) > 0) scr_stream_rbuf_push(st, tail, false);
2478
+ else scr_str_release(tail);
2479
+ scr_str_release(st->r.enc);
2480
+ st->r.enc = scr_str_retain(enc);
2481
+ st->r.dec_pending = 0;
2482
+ return scr_stream_retain(s);
2483
+ }
2484
+ st->r.enc = scr_str_retain(enc);
2485
+ st->r.dec_pending = 0;
2486
+ /* decode the buffered bytes into one concatenated string entry */
2487
+ ScrStr *content = NULL;
2488
+ size_t skip = st->r.head_off; /* buf[0] may be part-read (byte offset) */
2489
+ for (size_t i = 0; i < st->r.n; i++) {
2490
+ ScrBytes *chunk = st->r.buf[i];
2491
+ ScrBytes *view = chunk;
2492
+ if (i == 0 && skip > 0) {
2493
+ view = scr_bytes_new(SCR_BYTES_U8, (double)(chunk->len - skip));
2494
+ memcpy(view->data, chunk->data + skip, chunk->len - skip);
2495
+ }
2496
+ ScrStr *piece = scr_strdec_write(st->r.enc, st->r.dec_pending, view);
2497
+ st->r.dec_pending = scr_strdec_next(st->r.enc, st->r.dec_pending, view);
2498
+ if (view != chunk) scr_bytes_release(view);
2499
+ scr_bytes_release(chunk);
2500
+ if (content == NULL) {
2501
+ content = piece;
2502
+ } else {
2503
+ ScrStr *joined = scr_str_concat(content, piece);
2504
+ scr_str_release(content);
2505
+ scr_str_release(piece);
2506
+ content = joined;
2507
+ }
2508
+ }
2509
+ st->r.n = 0;
2510
+ st->r.head_off = 0;
2511
+ st->r.length = 0;
2512
+ st->r.encoded = true; /* AFTER the byte-entry walk above */
2513
+ if (content != NULL) {
2514
+ if (scr_str_utf16_len(content) > 0) scr_stream_rbuf_push(st, content, false);
2515
+ else scr_str_release(content);
2516
+ }
2517
+ return scr_stream_retain(s);
2518
+ }
2519
+
2520
+ ScrStream *scr_stream_pause(ScrStream *s) {
2521
+ ScrStreamState *st = s->st;
2522
+ if (st->has_r && st->r.flowing != 0) {
2523
+ st->r.flowing = 0;
2524
+ scr_stream_emit0(s, "pause"); /* Node emits 'pause' synchronously */
2525
+ }
2526
+ return scr_stream_retain(s);
2527
+ }
2528
+
2529
+ ScrStream *scr_stream_resume(ScrStream *s) {
2530
+ ScrStreamState *st = s->st;
2531
+ if (st->has_r && !st->destroyed && st->r.flowing != 1) {
2532
+ st->r.flowing = st->r.readable_listening ? 0 : 1;
2533
+ scr_stream_resume_kick(s);
2534
+ }
2535
+ return scr_stream_retain(s);
2536
+ }
2537
+
2538
+ bool scr_stream_is_paused(ScrStream *s) { return s->st->r.flowing == 0; }
2539
+
2540
+ double scr_stream_flowing(ScrStream *s) {
2541
+ int f = s->st->r.flowing;
2542
+ return f < 0 ? -1 : f;
2543
+ }
2544
+
2545
+ ScrStream *scr_stream_pipe(ScrStream *src, ScrStream *dst, bool end) {
2546
+ ScrStreamState *st = src->st;
2547
+ if (st->pipes.n == st->pipes.cap) {
2548
+ st->pipes.cap = st->pipes.cap ? st->pipes.cap * 2 : 2;
2549
+ st->pipes.dst = realloc(st->pipes.dst, st->pipes.cap * sizeof *st->pipes.dst);
2550
+ st->pipes.end = realloc(st->pipes.end, st->pipes.cap * sizeof *st->pipes.end);
2551
+ if (!st->pipes.dst || !st->pipes.end) scr_stream_oom();
2552
+ }
2553
+ st->pipes.dst[st->pipes.n] = scr_stream_retain(dst);
2554
+ st->pipes.end[st->pipes.n] = end;
2555
+ st->pipes.n++;
2556
+ scr_stream_emit_stream(dst, "pipe", src); /* Node emits 'pipe' synchronously */
2557
+ if (!scr_exc_pending() && st->r.flowing != 1 && st->await_drain == 0) {
2558
+ st->r.flowing = 1;
2559
+ scr_stream_resume_kick(src);
2560
+ }
2561
+ return scr_stream_retain(dst);
2562
+ }
2563
+
2564
+ ScrStream *scr_stream_unpipe(ScrStream *src, ScrStream *dst) {
2565
+ ScrStreamState *st = src->st;
2566
+ for (size_t i = 0; i < st->pipes.n;) {
2567
+ if (dst == NULL || st->pipes.dst[i] == dst) {
2568
+ ScrStream *d = st->pipes.dst[i];
2569
+ memmove(st->pipes.dst + i, st->pipes.dst + i + 1, (st->pipes.n - i - 1) * sizeof *st->pipes.dst);
2570
+ memmove(st->pipes.end + i, st->pipes.end + i + 1, (st->pipes.n - i - 1) * sizeof *st->pipes.end);
2571
+ st->pipes.n--;
2572
+ st->r.flowing = 0; /* Node pauses the source on unpipe */
2573
+ scr_stream_emit_stream(d, "unpipe", src);
2574
+ scr_stream_release(d);
2575
+ if (scr_exc_pending()) break;
2576
+ if (dst != NULL) break;
2577
+ } else {
2578
+ i++;
2579
+ }
2580
+ }
2581
+ return scr_stream_retain(src);
2582
+ }
2583
+
2584
+ /* ── the writable surface ─────────────────────────────────────────────── */
2585
+
2586
+ static bool scr_stream_write_chunk(ScrStream *s, ScrBytes *chunk /*borrowed*/, ScrClosure *cb /*moves*/) {
2587
+ ScrStreamState *st = s->st;
2588
+ if (!st->has_w || st->destroyed || st->w.ending) {
2589
+ ScrError *e = st->has_w && !st->destroyed
2590
+ ? scr_stream_mkerr("ERR_STREAM_WRITE_AFTER_END", "write after end")
2591
+ : scr_stream_mkerr("ERR_STREAM_DESTROYED", "Cannot call write after a stream was destroyed");
2592
+ if (cb) scr_st_tick(s, SCR_ST_WCB_ERR, NULL, cb);
2593
+ scr_stream_error_or_destroy(s, e);
2594
+ scr_error_release(e);
2595
+ return false;
2596
+ }
2597
+ size_t len = chunk->len;
2598
+ st->w.length += len;
2599
+ if (st->w.writing || st->w.corked > 0) {
2600
+ scr_stream_wq_push(st, scr_bytes_retain(chunk), cb);
2601
+ } else {
2602
+ scr_stream_do_write(s, scr_bytes_retain(chunk), cb);
2603
+ }
2604
+ /* Node computes the answer AFTER the (possibly synchronous) write:
2605
+ * a sync completion has already drained its bytes from length. */
2606
+ bool ret = st->w.length < st->w.hwm && !st->destroyed && !st->errored;
2607
+ if (!ret) st->w.need_drain = true;
2608
+ return ret;
2609
+ }
2610
+
2611
+ bool scr_stream_write(ScrStream *s, ScrBytes *chunk, ScrClosure *cb) {
2612
+ return scr_stream_write_chunk(s, chunk, cb);
2613
+ }
2614
+
2615
+ /* write(null) reached at runtime (a nullable-union chunk's null arm):
2616
+ * Node throws the ERR_STREAM_NULL_VALUES TypeError synchronously. */
2617
+ bool scr_stream_write_null(ScrStream *s) {
2618
+ (void)s;
2619
+ static const char msg[] = "May not write null values to stream";
2620
+ scr_throw_error_msg_code(SCR_ERR_TYPE, msg, sizeof msg - 1, "ERR_STREAM_NULL_VALUES");
2621
+ return false;
2622
+ }
2623
+
2624
+ bool scr_stream_write_str(ScrStream *s, ScrStr *str, ScrClosure *cb) {
2625
+ ScrBytes *b = scr_bytes_new(SCR_BYTES_U8, (double)str->len);
2626
+ memcpy(b->data, str->data, str->len);
2627
+ bool ret = scr_stream_write_chunk(s, b, cb);
2628
+ scr_bytes_release(b);
2629
+ return ret;
2630
+ }
2631
+
2632
+ ScrStream *scr_stream_end(ScrStream *s, ScrBytes *chunk_b, ScrStr *chunk_s, ScrClosure *cb) {
2633
+ ScrStreamState *st = s->st;
2634
+ if (chunk_b) scr_stream_write(s, chunk_b, NULL);
2635
+ else if (chunk_s) scr_stream_write_str(s, chunk_s, NULL);
2636
+ if (!st->has_w || st->destroyed) {
2637
+ if (cb) scr_closure_release(cb);
2638
+ return scr_stream_retain(s);
2639
+ }
2640
+ if (cb) {
2641
+ if (st->w.finished) {
2642
+ scr_st_tick(s, SCR_ST_WCB_ERR, NULL, cb); /* already finished: plain call */
2643
+ } else {
2644
+ if (st->w.end_cbs_n == st->w.end_cbs_cap) {
2645
+ st->w.end_cbs_cap = st->w.end_cbs_cap ? st->w.end_cbs_cap * 2 : 2;
2646
+ st->w.end_cbs = realloc(st->w.end_cbs, st->w.end_cbs_cap * sizeof *st->w.end_cbs);
2647
+ if (!st->w.end_cbs) scr_stream_oom();
2648
+ }
2649
+ st->w.end_cbs[st->w.end_cbs_n++] = cb;
2650
+ }
2651
+ }
2652
+ if (!st->w.ending) {
2653
+ st->w.ending = true;
2654
+ if (st->w.corked > 0) {
2655
+ st->w.corked = 1;
2656
+ scr_stream_uncork(s);
2657
+ }
2658
+ scr_stream_finish_maybe(s);
2659
+ }
2660
+ return scr_stream_retain(s);
2661
+ }
2662
+
2663
+ void scr_stream_cork(ScrStream *s) { s->st->w.corked++; }
2664
+
2665
+ void scr_stream_uncork(ScrStream *s) {
2666
+ ScrStreamState *st = s->st;
2667
+ if (st->w.corked > 0 && --st->w.corked == 0) {
2668
+ scr_stream_clear_buffer(s);
2669
+ scr_stream_finish_maybe(s);
2670
+ }
2671
+ }
2672
+
2673
+ /* ── completion entries (called by the emitted done closures) ─────────── */
2674
+
2675
+ void scr_stream_write_done(ScrStream *s, ScrError *err /*moves*/) {
2676
+ ScrStreamState *st = s->st;
2677
+ if (!st->w.writing) {
2678
+ /* cb called twice (or spuriously): Node's ERR_MULTIPLE_CALLBACK */
2679
+ if (err) scr_error_release(err);
2680
+ ScrError *e = scr_stream_mkerr("ERR_MULTIPLE_CALLBACK", "Callback called multiple times");
2681
+ scr_stream_error_or_destroy(s, e);
2682
+ scr_error_release(e);
2683
+ return;
2684
+ }
2685
+ st->w.writing = false;
2686
+ st->w.length -= st->w.inflight_len;
2687
+ st->w.inflight_len = 0;
2688
+ ScrClosure *ucb = st->w.inflight_cb;
2689
+ st->w.inflight_cb = NULL;
2690
+ if (err) {
2691
+ if (ucb) scr_st_tick(s, SCR_ST_WCB_ERR, NULL, ucb);
2692
+ scr_stream_error_or_destroy(s, err);
2693
+ scr_error_release(err);
2694
+ return;
2695
+ }
2696
+ /* Node's onwrite: the buffered queue restarts FIRST (clearBuffer),
2697
+ * then afterWrite — deferred to a tick for a synchronous completion. */
2698
+ bool was_sync = st->w.wsync;
2699
+ scr_stream_clear_buffer(s);
2700
+ if (scr_exc_pending()) {
2701
+ if (ucb) scr_closure_release(ucb);
2702
+ return;
2703
+ }
2704
+ if (was_sync) {
2705
+ scr_st_tick(s, SCR_ST_AFTER_WRITE, NULL, ucb);
2706
+ } else {
2707
+ scr_stream_after_write(s, ucb);
2708
+ }
2709
+ }
2710
+
2711
+ void scr_stream_final_done(ScrStream *s, ScrError *err /*moves*/) {
2712
+ ScrStreamState *st = s->st;
2713
+ if (err) {
2714
+ scr_stream_error_or_destroy(s, err);
2715
+ scr_error_release(err);
2716
+ return;
2717
+ }
2718
+ st->w.prefinished = true;
2719
+ scr_stream_emit0(s, "prefinish");
2720
+ if (scr_exc_pending()) return;
2721
+ scr_stream_finish_maybe(s);
2722
+ }
2723
+
2724
+ void scr_stream_destroy_done(ScrStream *s, ScrError *err /*moves*/) {
2725
+ ScrStreamState *st = s->st;
2726
+ /* Node's onDestroy: 'error' emits only with the error the USER'S
2727
+ * callback passed along — a `cb()` after destroy(err) SWALLOWS the
2728
+ * error (errored stays set, no emission; the default _destroy forwards,
2729
+ * which is the no-destroy-callback path in do_destroy). */
2730
+ if (err) {
2731
+ if (!st->errored) st->errored = scr_error_retain(err);
2732
+ if (!st->error_scheduled) {
2733
+ st->error_scheduled = true;
2734
+ scr_st_tick(s, SCR_ST_ERROR, err, NULL);
2735
+ } else {
2736
+ scr_error_release(err);
2737
+ }
2738
+ }
2739
+ if (!st->close_scheduled) {
2740
+ st->close_scheduled = true;
2741
+ scr_st_tick(s, SCR_ST_CLOSE, NULL, NULL);
2742
+ }
2743
+ }
2744
+
2745
+ void scr_stream_transform_done(ScrStream *s, ScrError *err /*moves*/, ScrBytes *data /*moves*/,
2746
+ ScrStr *data_str /*moves*/) {
2747
+ if (!err) {
2748
+ if (data) {
2749
+ scr_stream_add_chunk(s, data, false);
2750
+ } else if (data_str) {
2751
+ ScrBytes *b = scr_bytes_new(SCR_BYTES_U8, (double)data_str->len);
2752
+ memcpy(b->data, data_str->data, data_str->len);
2753
+ scr_stream_add_chunk(s, b, false);
2754
+ scr_bytes_release(b);
2755
+ }
2756
+ }
2757
+ if (data) scr_bytes_release(data);
2758
+ if (data_str) scr_str_release(data_str);
2759
+ if (scr_exc_pending()) {
2760
+ if (err) scr_error_release(err);
2761
+ return;
2762
+ }
2763
+ scr_stream_write_done(s, err);
2764
+ }
2765
+
2766
+ void scr_stream_flush_done(ScrStream *s, ScrError *err /*moves*/, ScrBytes *data /*moves*/,
2767
+ ScrStr *data_str /*moves*/) {
2768
+ ScrStreamState *st = s->st;
2769
+ if (err) {
2770
+ if (data) scr_bytes_release(data);
2771
+ if (data_str) scr_str_release(data_str);
2772
+ scr_stream_error_or_destroy(s, err);
2773
+ scr_error_release(err);
2774
+ return;
2775
+ }
2776
+ if (data) {
2777
+ scr_stream_add_chunk(s, data, false);
2778
+ scr_bytes_release(data);
2779
+ } else if (data_str) {
2780
+ ScrBytes *b = scr_bytes_new(SCR_BYTES_U8, (double)data_str->len);
2781
+ memcpy(b->data, data_str->data, data_str->len);
2782
+ scr_stream_add_chunk(s, b, false);
2783
+ scr_bytes_release(b);
2784
+ scr_str_release(data_str);
2785
+ }
2786
+ if (scr_exc_pending()) return;
2787
+ scr_stream_push_null(s); /* EOF the readable side after flush */
2788
+ if (scr_exc_pending()) return;
2789
+ scr_stream_finish_maybe(s);
2790
+ }
2791
+
2792
+ /* ── destroy ──────────────────────────────────────────────────────────── */
2793
+
2794
+ static void scr_stream_do_destroy(ScrStream *s, ScrError *err /*borrowed*/) {
2795
+ ScrStreamState *st = s->st;
2796
+ if (st->destroyed || st->destroy_calling) return;
2797
+ st->destroyed = true;
2798
+ if (err && !st->errored) st->errored = scr_error_retain(err);
2799
+ scr_stream_settle_next(s); /* a parked for-await rejects/finishes */
2800
+ if (st->destroy_cb) {
2801
+ st->destroy_calling = true;
2802
+ st->destroy_inv(st->destroy_cb, s, err);
2803
+ st->destroy_calling = false;
2804
+ if (scr_exc_pending()) return;
2805
+ /* the user's destroy must call its callback (destroy_done schedules
2806
+ * 'error'/'close'); a user destroy that never calls back leaves the
2807
+ * stream half-closed, exactly Node */
2808
+ return;
2809
+ }
2810
+ if (err) {
2811
+ if (!st->error_scheduled) {
2812
+ st->error_scheduled = true;
2813
+ scr_st_tick(s, SCR_ST_ERROR, scr_error_retain(err), NULL);
2814
+ }
2815
+ }
2816
+ if (!st->close_scheduled) {
2817
+ st->close_scheduled = true;
2818
+ scr_st_tick(s, SCR_ST_CLOSE, NULL, NULL);
2819
+ }
2820
+ }
2821
+
2822
+ ScrStream *scr_stream_destroy(ScrStream *s, ScrError *err) {
2823
+ scr_stream_do_destroy(s, err);
2824
+ return scr_stream_retain(s);
2825
+ }
2826
+
2827
+ ScrStream *scr_stream_iterator_close(ScrStream *s) {
2828
+ ScrStreamState *st = s->st;
2829
+ if (st->destroyed) return scr_stream_retain(s);
2830
+ ScrStr *message = scr_str_new("The operation was aborted", 25);
2831
+ ScrError *error = scr_error_new(SCR_ERR_ERROR, message);
2832
+ scr_str_release(message);
2833
+ scr_str_release(error->name);
2834
+ error->name = scr_str_new("AbortError", 10);
2835
+ scr_error_set_code(error, "ABORT_ERR");
2836
+ /* Node's iterator registers an internal error listener: the AbortError is
2837
+ * still observable through stream.errored and user listeners, but it does
2838
+ * not become an unhandled 'error' event when nobody subscribed. */
2839
+ st->next_err_consumed = true;
2840
+ scr_stream_do_destroy(s, error);
2841
+ scr_error_release(error);
2842
+ return scr_stream_retain(s);
2843
+ }
2844
+
2845
+ ScrError *scr_stream_errored(ScrStream *s) {
2846
+ return s->st->errored ? scr_error_retain(s->st->errored) : NULL;
2847
+ }
2848
+
2849
+ /* ── properties ───────────────────────────────────────────────────────── */
2850
+
2851
+ double scr_stream_prop(ScrStream *s, const char *name) {
2852
+ ScrStreamState *st = s->st;
2853
+ if (strcmp(name, "readable") == 0) {
2854
+ return st->has_r && !st->destroyed && !st->r.end_emitted && !st->errored;
2855
+ }
2856
+ if (strcmp(name, "readableEnded") == 0) return st->r.end_emitted;
2857
+ if (strcmp(name, "readableLength") == 0) return (double)st->r.length;
2858
+ if (strcmp(name, "readableHighWaterMark") == 0) return (double)st->r.hwm;
2859
+ if (strcmp(name, "readableObjectMode") == 0) return st->r.object_entries;
2860
+ if (strcmp(name, "writable") == 0) {
2861
+ return st->has_w && !st->destroyed && !st->w.ending && !st->errored;
2862
+ }
2863
+ if (strcmp(name, "writableEnded") == 0) return st->w.ending;
2864
+ if (strcmp(name, "writableFinished") == 0) return st->w.finished;
2865
+ if (strcmp(name, "writableNeedDrain") == 0) return st->w.need_drain;
2866
+ if (strcmp(name, "writableLength") == 0) return (double)st->w.length;
2867
+ if (strcmp(name, "writableHighWaterMark") == 0) return (double)st->w.hwm;
2868
+ if (strcmp(name, "writableCorked") == 0) return (double)st->w.corked;
2869
+ if (strcmp(name, "destroyed") == 0) return st->destroyed;
2870
+ if (strcmp(name, "closed") == 0) return st->close_emitted;
2871
+ if (strcmp(name, "allowHalfOpen") == 0) return st->allow_half_open;
2872
+ /* The _readableState/_writableState compat VIEW (read-only): each name
2873
+ * answers from the field the runtime actually keeps. Node's ending/
2874
+ * ended distinction inside end() collapses onto w.ending here. */
2875
+ if (strncmp(name, "rs:", 3) == 0) {
2876
+ const char *p = name + 3;
2877
+ if (strcmp(p, "ended") == 0) return st->r.ended;
2878
+ if (strcmp(p, "endEmitted") == 0) return st->r.end_emitted;
2879
+ if (strcmp(p, "destroyed") == 0) return st->destroyed;
2880
+ if (strcmp(p, "errorEmitted") == 0) return st->error_emitted;
2881
+ if (strcmp(p, "emittedReadable") == 0) return st->r.emitted_readable;
2882
+ if (strcmp(p, "needReadable") == 0) return st->r.need_readable;
2883
+ if (strcmp(p, "reading") == 0) return st->r.reading;
2884
+ if (strcmp(p, "readableListening") == 0) return st->r.readable_listening;
2885
+ if (strcmp(p, "resumeScheduled") == 0) return st->r.resume_scheduled;
2886
+ if (strcmp(p, "objectMode") == 0) return st->r.object_entries;
2887
+ if (strcmp(p, "constructed") == 0) return 1;
2888
+ if (strcmp(p, "closed") == 0) return st->close_emitted;
2889
+ if (strcmp(p, "length") == 0) return (double)st->r.length;
2890
+ if (strcmp(p, "highWaterMark") == 0) return (double)st->r.hwm;
2891
+ return 0;
2892
+ }
2893
+ if (strncmp(name, "ws:", 3) == 0) {
2894
+ const char *p = name + 3;
2895
+ if (strcmp(p, "ended") == 0 || strcmp(p, "ending") == 0) return st->w.ending;
2896
+ if (strcmp(p, "finished") == 0) return st->w.finished;
2897
+ if (strcmp(p, "prefinished") == 0) return st->w.prefinished;
2898
+ if (strcmp(p, "destroyed") == 0) return st->destroyed;
2899
+ if (strcmp(p, "errorEmitted") == 0) return st->error_emitted;
2900
+ if (strcmp(p, "needDrain") == 0) return st->w.need_drain;
2901
+ if (strcmp(p, "objectMode") == 0) return 0;
2902
+ if (strcmp(p, "constructed") == 0) return 1;
2903
+ if (strcmp(p, "closed") == 0) return st->close_emitted;
2904
+ if (strcmp(p, "length") == 0) return (double)st->w.length;
2905
+ if (strcmp(p, "highWaterMark") == 0) return (double)st->w.hwm;
2906
+ if (strcmp(p, "corked") == 0) return (double)st->w.corked;
2907
+ if (strcmp(p, "bufferedRequestCount") == 0) return (double)(st->w.n - st->w.head);
2908
+ return 0;
2909
+ }
2910
+ return 0;
2911
+ }
2912
+
2913
+ /* emitReadable_ — the shared body of the 'readable' tick AND the
2914
+ * synchronous onEofChunk call (Node runs it directly when the eof push
2915
+ * arrives outside a _read call). */
2916
+ static void scr_stream_emit_readable_now(ScrStream *s) {
2917
+ ScrStreamState *st = s->st;
2918
+ /* Node's emitReadable_ clears emittedReadable AFTER the emit (a
2919
+ * 'readable' listener observes true) and only when it really fired. */
2920
+ if (!st->destroyed && !st->errored && (st->r.length > 0 || st->r.ended)) {
2921
+ scr_stream_emit0(s, "readable");
2922
+ if (scr_exc_pending()) return;
2923
+ st->r.emitted_readable = false;
2924
+ }
2925
+ st->r.need_readable = st->r.flowing != 1 && !st->r.ended &&
2926
+ st->r.length <= st->r.hwm;
2927
+ scr_stream_flow(s);
2928
+ if (!scr_exc_pending() && st->r.ended && st->r.length == 0) {
2929
+ scr_stream_end_readable(s);
2930
+ }
2931
+ }
2932
+
2933
+ /* ── tick dispatch ────────────────────────────────────────────────────── */
2934
+
2935
+ static void scr_stream_run_tick(ScrStreamTick *t) {
2936
+ ScrStream *s = t->s;
2937
+ ScrStreamState *st = s->st;
2938
+ switch (t->op) {
2939
+ case SCR_ST_RESUME: {
2940
+ st->r.resume_scheduled = false;
2941
+ if (!st->r.reading && st->r.flowing == 1) {
2942
+ /* read(0) kick: pull the user _read without consuming */
2943
+ st->r.need_readable = st->r.length == 0;
2944
+ if (!st->r.ended && !st->destroyed) scr_stream_call_read(s);
2945
+ if (scr_exc_pending()) break;
2946
+ }
2947
+ scr_stream_emit0(s, "resume");
2948
+ if (scr_exc_pending()) break;
2949
+ scr_stream_flow(s);
2950
+ if (scr_exc_pending()) break;
2951
+ if (st->r.flowing == 1 && !st->r.reading && !st->r.ended && !st->destroyed) {
2952
+ scr_stream_call_read(s);
2953
+ }
2954
+ break;
2955
+ }
2956
+ case SCR_ST_READABLE:
2957
+ scr_stream_emit_readable_now(s);
2958
+ break;
2959
+ case SCR_ST_END: {
2960
+ st->r.end_scheduled = false;
2961
+ if (st->destroyed || st->errored || st->r.end_emitted || st->r.length != 0 || !st->r.ended) break;
2962
+ st->r.end_emitted = true;
2963
+ scr_stream_emit0(s, "end");
2964
+ if (scr_exc_pending()) break;
2965
+ /* pipe end propagation */
2966
+ for (size_t i = 0; i < st->pipes.n; i++) {
2967
+ if (st->pipes.end[i]) {
2968
+ scr_stream_release(scr_stream_end(st->pipes.dst[i], NULL, NULL, NULL));
2969
+ if (scr_exc_pending()) break;
2970
+ }
2971
+ }
2972
+ if (scr_exc_pending()) break;
2973
+ if (st->has_w && !st->allow_half_open && !st->w.ending) {
2974
+ scr_st_tick(s, SCR_ST_END_W, NULL, NULL);
2975
+ break;
2976
+ }
2977
+ if (st->auto_destroy && (!st->has_w || st->w.finished)) {
2978
+ scr_stream_do_destroy(s, NULL);
2979
+ }
2980
+ break;
2981
+ }
2982
+ case SCR_ST_MAYBE_MORE: {
2983
+ st->r.maybe_more_scheduled = false;
2984
+ if (st->destroyed) break;
2985
+ /* loop while synchronous pushes make progress below the hwm */
2986
+ while (!st->r.reading && !st->r.ended && st->r.length < st->r.hwm &&
2987
+ (st->r.flowing == 1 || st->r.need_readable) && !scr_exc_pending()) {
2988
+ size_t before = st->r.length;
2989
+ scr_stream_call_read(s);
2990
+ if (scr_exc_pending() || st->r.length == before) break;
2991
+ }
2992
+ break;
2993
+ }
2994
+ case SCR_ST_AFTER_WRITE: {
2995
+ st->w.after_scheduled = false;
2996
+ ScrClosure *cb = t->cb;
2997
+ t->cb = NULL;
2998
+ if (!st->destroyed) {
2999
+ scr_stream_after_write(s, cb);
3000
+ } else if (cb) {
3001
+ ((void (*)(ScrClosure *))cb->fn)(cb);
3002
+ scr_closure_release(cb);
3003
+ }
3004
+ break;
3005
+ }
3006
+ case SCR_ST_FINISH: {
3007
+ st->w.finish_scheduled = false;
3008
+ if (st->destroyed || st->w.finished) break;
3009
+ st->w.finished = true;
3010
+ /* Node runs the end(cb) callbacks (kOnFinished) BEFORE 'finish'. */
3011
+ while (st->w.end_cbs_n > 0) {
3012
+ ScrClosure *cb = st->w.end_cbs[0];
3013
+ memmove(st->w.end_cbs, st->w.end_cbs + 1, (st->w.end_cbs_n - 1) * sizeof *st->w.end_cbs);
3014
+ st->w.end_cbs_n--;
3015
+ ((void (*)(ScrClosure *))cb->fn)(cb);
3016
+ scr_closure_release(cb);
3017
+ if (scr_exc_pending()) break;
3018
+ }
3019
+ if (scr_exc_pending()) break;
3020
+ scr_stream_emit0(s, "finish");
3021
+ if (scr_exc_pending()) break;
3022
+ if (st->auto_destroy && (!st->has_r || st->r.end_emitted || !st->r.readable_listening)) {
3023
+ /* Node: autoDestroy after finish once the readable half is done
3024
+ * (a half-open duplex with a live readable side stays up) */
3025
+ if (!st->has_r || st->r.end_emitted) scr_stream_do_destroy(s, NULL);
3026
+ }
3027
+ break;
3028
+ }
3029
+ case SCR_ST_ERROR: {
3030
+ st->error_scheduled = false;
3031
+ if (!st->error_emitted && t->err) {
3032
+ st->error_emitted = true;
3033
+ if (st->next_err_consumed && !scr_emitter_has((ScrEmitter *)s, "error")) {
3034
+ /* the for-await's rejection consumed it (Node's iterator
3035
+ * registers its own 'error' handler — no unhandled crash) */
3036
+ break;
3037
+ }
3038
+ if (st->fin.n > 0 && !scr_emitter_has((ScrEmitter *)s, "error")) {
3039
+ /* a finished()/pipeline watcher consumes it (Node's eos and
3040
+ * pipeline register their own 'error' handlers) — the watcher
3041
+ * reports it at the terminal point instead of crashing */
3042
+ break;
3043
+ }
3044
+ scr_stream_emit_error(s, t->err);
3045
+ }
3046
+ break;
3047
+ }
3048
+ case SCR_ST_CLOSE: {
3049
+ st->close_scheduled = false;
3050
+ if (!st->close_emitted) {
3051
+ st->close_emitted = true;
3052
+ if (st->emit_close) scr_stream_emit0(s, "close");
3053
+ /* eos ordering: the finished()/pipeline watchers fire right after
3054
+ * 'close' (Node's willEmitClose stance). */
3055
+ scr_stream_notify_finished(s);
3056
+ /* Fully closed: nothing calls the option callbacks again (Node's
3057
+ * contract), so drop them here — this breaks the reference cycle
3058
+ * a callback capturing its own stream forms, including the dyn-
3059
+ * options closures whose stream edge rides through a dyn function
3060
+ * value the cycle collector cannot traverse. */
3061
+ if (st->r.read_cb) { scr_closure_release(st->r.read_cb); st->r.read_cb = NULL; }
3062
+ if (st->w.write_cb) { scr_closure_release(st->w.write_cb); st->w.write_cb = NULL; }
3063
+ if (st->w.final_cb) { scr_closure_release(st->w.final_cb); st->w.final_cb = NULL; }
3064
+ if (st->transform_cb) { scr_closure_release(st->transform_cb); st->transform_cb = NULL; }
3065
+ if (st->flush_cb) { scr_closure_release(st->flush_cb); st->flush_cb = NULL; }
3066
+ if (st->destroy_cb) { scr_closure_release(st->destroy_cb); st->destroy_cb = NULL; }
3067
+ }
3068
+ break;
3069
+ }
3070
+ case SCR_ST_END_W: {
3071
+ scr_stream_release(scr_stream_end(s, NULL, NULL, NULL));
3072
+ break;
3073
+ }
3074
+ case SCR_ST_WCB_ERR: {
3075
+ ScrClosure *cb = t->cb;
3076
+ t->cb = NULL;
3077
+ if (cb) {
3078
+ ((void (*)(ScrClosure *))cb->fn)(cb);
3079
+ scr_closure_release(cb);
3080
+ }
3081
+ break;
3082
+ }
3083
+ case SCR_ST_FIN: {
3084
+ scr_stream_notify_finished(s);
3085
+ break;
3086
+ }
3087
+ case SCR_ST_NEXT_EOF: {
3088
+ if (st->r.next_waiter && st->r.length == 0 && (st->r.ended || st->destroyed)) {
3089
+ ScrPromise *w = st->r.next_waiter;
3090
+ st->r.next_waiter = NULL;
3091
+ scr_stream_next_fulfill(st, w, NULL);
3092
+ } else if (st->r.next_waiter) {
3093
+ scr_stream_settle_next(s); /* content raced in: deliver it */
3094
+ }
3095
+ break;
3096
+ }
3097
+ }
3098
+ }
3099
+
3100
+ static void scr_stream_dispatch(void);
3101
+
3102
+ /* One tick-marker's dispatch: the queue's FIFO head (markers and entries
3103
+ * are enqueued 1:1 in the same order). After an uncaught throw the
3104
+ * remaining entries drop through the station's exc branch below, keeping
3105
+ * the RC audit clean. */
3106
+ static void scr_stream_dispatch_one(void) {
3107
+ ScrStreamTick *t = scr_st_head;
3108
+ if (t == NULL || scr_exc_pending()) return;
3109
+ scr_st_head = t->next;
3110
+ if (scr_st_head == NULL) scr_st_tail = NULL;
3111
+ scr_stream_run_tick(t);
3112
+ scr_stream_release(t->s);
3113
+ if (t->err) scr_error_release(t->err);
3114
+ if (t->cb) scr_closure_release(t->cb);
3115
+ free(t);
3116
+ if (scr_exc_pending()) scr_stream_dispatch(); /* its exc branch drops the rest */
3117
+ }
3118
+
3119
+ static void scr_stream_dispatch(void) {
3120
+ while (scr_st_head != NULL && !scr_exc_pending() && !scr_loop_has_ready()) {
3121
+ ScrStreamTick *t = scr_st_head;
3122
+ scr_st_head = t->next;
3123
+ if (scr_st_head == NULL) scr_st_tail = NULL;
3124
+ scr_stream_run_tick(t);
3125
+ scr_stream_release(t->s);
3126
+ if (t->err) scr_error_release(t->err);
3127
+ if (t->cb) scr_closure_release(t->cb);
3128
+ free(t);
3129
+ }
3130
+ /* An uncaught throw ends the process (the loop returns to main): the
3131
+ * undelivered ticks are DROPPED — release their references here so the
3132
+ * RC audit stays clean (the children-teardown precedent). */
3133
+ if (scr_exc_pending()) {
3134
+ while (scr_st_head != NULL) {
3135
+ ScrStreamTick *t = scr_st_head;
3136
+ scr_st_head = t->next;
3137
+ scr_stream_release(t->s);
3138
+ if (t->err) scr_error_release(t->err);
3139
+ if (t->cb) scr_closure_release(t->cb);
3140
+ free(t);
3141
+ }
3142
+ scr_st_tail = NULL;
3143
+ }
3144
+ }
3145
+
3146
+ void scr_stream_install(void) {
3147
+ scr_emitter_on_hook = &scr_stream_on_listener;
3148
+ scr_loop_set_stream(&scr_stream_ticks_pending, &scr_stream_dispatch);
3149
+ }