@scriptc/runtime 0.0.0 → 0.0.1

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 (416) hide show
  1. package/LICENSE +202 -0
  2. package/package.json +16 -6
  3. package/src/scr_array.c +488 -0
  4. package/src/scr_assert.c +1393 -0
  5. package/src/scr_async.c +2593 -0
  6. package/src/scr_async_dyn.c +607 -0
  7. package/src/scr_bytes.c +1425 -0
  8. package/src/scr_bytes_io.c +161 -0
  9. package/src/scr_child.c +3587 -0
  10. package/src/scr_closure.c +214 -0
  11. package/src/scr_console.c +143 -0
  12. package/src/scr_cycle.c +218 -0
  13. package/src/scr_dc.c +805 -0
  14. package/src/scr_dgram.c +1007 -0
  15. package/src/scr_dyn_handle.c +154 -0
  16. package/src/scr_dyn_invoke.c +644 -0
  17. package/src/scr_error.c +332 -0
  18. package/src/scr_events.c +714 -0
  19. package/src/scr_events_emitter.c +699 -0
  20. package/src/scr_exception.c +242 -0
  21. package/src/scr_fetch.c +1130 -0
  22. package/src/scr_fetch_curl.c +654 -0
  23. package/src/scr_http.c +3482 -0
  24. package/src/scr_http2.c +3030 -0
  25. package/src/scr_inspect.c +803 -0
  26. package/src/scr_inspect_island.c +51 -0
  27. package/src/scr_island.c +9363 -0
  28. package/src/scr_json.c +2151 -0
  29. package/src/scr_lib.c +3612 -0
  30. package/src/scr_loop_epoll.c +241 -0
  31. package/src/scr_loop_kqueue.c +121 -0
  32. package/src/scr_loop_wsapoll.c +208 -0
  33. package/src/scr_map.c +591 -0
  34. package/src/scr_net.c +3017 -0
  35. package/src/scr_net_island.c +458 -0
  36. package/src/scr_number.c +115 -0
  37. package/src/scr_object.c +25 -0
  38. package/src/scr_path.c +1266 -0
  39. package/src/scr_platform.h +119 -0
  40. package/src/scr_readline.c +287 -0
  41. package/src/scr_regex.c +1080 -0
  42. package/src/scr_runtime.h +5036 -0
  43. package/src/scr_stream.c +2877 -0
  44. package/src/scr_string.c +1176 -0
  45. package/src/scr_symbol.c +132 -0
  46. package/src/scr_test.c +662 -0
  47. package/src/scr_tls.c +1520 -0
  48. package/src/scr_union.c +105 -0
  49. package/src/scr_url.c +911 -0
  50. package/src/scr_url_internal.h +29 -0
  51. package/src/scr_url_params.c +561 -0
  52. package/src/scr_watch.c +568 -0
  53. package/src/scr_web.c +1778 -0
  54. package/src/scr_win.c +76 -0
  55. package/src/scr_zlib.c +197 -0
  56. package/src/scr_zlib_island.c +15 -0
  57. package/vendor/README.md +52 -0
  58. package/vendor/curl/COPYRIGHT +534 -0
  59. package/vendor/curl/include/curl/curl.h +3214 -0
  60. package/vendor/curl/include/curl/curlver.h +79 -0
  61. package/vendor/curl/include/curl/easy.h +125 -0
  62. package/vendor/curl/include/curl/header.h +74 -0
  63. package/vendor/curl/include/curl/mprintf.h +52 -0
  64. package/vendor/curl/include/curl/multi.h +460 -0
  65. package/vendor/curl/include/curl/options.h +70 -0
  66. package/vendor/curl/include/curl/stdcheaders.h +35 -0
  67. package/vendor/curl/include/curl/system.h +508 -0
  68. package/vendor/curl/include/curl/typecheck-gcc.h +716 -0
  69. package/vendor/curl/include/curl/urlapi.h +149 -0
  70. package/vendor/curl/include/curl/websockets.h +84 -0
  71. package/vendor/mbedtls/LICENSE +553 -0
  72. package/vendor/mbedtls/include/CMakeLists.txt +22 -0
  73. package/vendor/mbedtls/include/mbedtls/aes.h +631 -0
  74. package/vendor/mbedtls/include/mbedtls/aria.h +343 -0
  75. package/vendor/mbedtls/include/mbedtls/asn1.h +642 -0
  76. package/vendor/mbedtls/include/mbedtls/asn1write.h +390 -0
  77. package/vendor/mbedtls/include/mbedtls/base64.h +82 -0
  78. package/vendor/mbedtls/include/mbedtls/bignum.h +1088 -0
  79. package/vendor/mbedtls/include/mbedtls/block_cipher.h +76 -0
  80. package/vendor/mbedtls/include/mbedtls/build_info.h +194 -0
  81. package/vendor/mbedtls/include/mbedtls/camellia.h +305 -0
  82. package/vendor/mbedtls/include/mbedtls/ccm.h +526 -0
  83. package/vendor/mbedtls/include/mbedtls/chacha20.h +209 -0
  84. package/vendor/mbedtls/include/mbedtls/chachapoly.h +351 -0
  85. package/vendor/mbedtls/include/mbedtls/check_config.h +1149 -0
  86. package/vendor/mbedtls/include/mbedtls/cipher.h +1250 -0
  87. package/vendor/mbedtls/include/mbedtls/cmac.h +246 -0
  88. package/vendor/mbedtls/include/mbedtls/compat-2.x.h +46 -0
  89. package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_crypto.h +578 -0
  90. package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_from_psa.h +873 -0
  91. package/vendor/mbedtls/include/mbedtls/config_adjust_psa_from_legacy.h +359 -0
  92. package/vendor/mbedtls/include/mbedtls/config_adjust_psa_superset_legacy.h +145 -0
  93. package/vendor/mbedtls/include/mbedtls/config_adjust_ssl.h +91 -0
  94. package/vendor/mbedtls/include/mbedtls/config_adjust_x509.h +35 -0
  95. package/vendor/mbedtls/include/mbedtls/config_psa.h +61 -0
  96. package/vendor/mbedtls/include/mbedtls/constant_time.h +36 -0
  97. package/vendor/mbedtls/include/mbedtls/ctr_drbg.h +596 -0
  98. package/vendor/mbedtls/include/mbedtls/debug.h +156 -0
  99. package/vendor/mbedtls/include/mbedtls/des.h +385 -0
  100. package/vendor/mbedtls/include/mbedtls/dhm.h +972 -0
  101. package/vendor/mbedtls/include/mbedtls/ecdh.h +455 -0
  102. package/vendor/mbedtls/include/mbedtls/ecdsa.h +674 -0
  103. package/vendor/mbedtls/include/mbedtls/ecjpake.h +298 -0
  104. package/vendor/mbedtls/include/mbedtls/ecp.h +1517 -0
  105. package/vendor/mbedtls/include/mbedtls/entropy.h +274 -0
  106. package/vendor/mbedtls/include/mbedtls/error.h +201 -0
  107. package/vendor/mbedtls/include/mbedtls/gcm.h +387 -0
  108. package/vendor/mbedtls/include/mbedtls/hkdf.h +124 -0
  109. package/vendor/mbedtls/include/mbedtls/hmac_drbg.h +434 -0
  110. package/vendor/mbedtls/include/mbedtls/lms.h +440 -0
  111. package/vendor/mbedtls/include/mbedtls/mbedtls_config.h +4446 -0
  112. package/vendor/mbedtls/include/mbedtls/md.h +526 -0
  113. package/vendor/mbedtls/include/mbedtls/md5.h +190 -0
  114. package/vendor/mbedtls/include/mbedtls/memory_buffer_alloc.h +142 -0
  115. package/vendor/mbedtls/include/mbedtls/net_sockets.h +299 -0
  116. package/vendor/mbedtls/include/mbedtls/nist_kw.h +166 -0
  117. package/vendor/mbedtls/include/mbedtls/oid.h +727 -0
  118. package/vendor/mbedtls/include/mbedtls/pem.h +160 -0
  119. package/vendor/mbedtls/include/mbedtls/pk.h +1303 -0
  120. package/vendor/mbedtls/include/mbedtls/pkcs12.h +186 -0
  121. package/vendor/mbedtls/include/mbedtls/pkcs5.h +198 -0
  122. package/vendor/mbedtls/include/mbedtls/pkcs7.h +252 -0
  123. package/vendor/mbedtls/include/mbedtls/platform.h +516 -0
  124. package/vendor/mbedtls/include/mbedtls/platform_time.h +79 -0
  125. package/vendor/mbedtls/include/mbedtls/platform_util.h +247 -0
  126. package/vendor/mbedtls/include/mbedtls/poly1305.h +168 -0
  127. package/vendor/mbedtls/include/mbedtls/private_access.h +20 -0
  128. package/vendor/mbedtls/include/mbedtls/psa_util.h +207 -0
  129. package/vendor/mbedtls/include/mbedtls/ripemd160.h +136 -0
  130. package/vendor/mbedtls/include/mbedtls/rsa.h +1170 -0
  131. package/vendor/mbedtls/include/mbedtls/sha1.h +219 -0
  132. package/vendor/mbedtls/include/mbedtls/sha256.h +200 -0
  133. package/vendor/mbedtls/include/mbedtls/sha3.h +172 -0
  134. package/vendor/mbedtls/include/mbedtls/sha512.h +208 -0
  135. package/vendor/mbedtls/include/mbedtls/ssl.h +5887 -0
  136. package/vendor/mbedtls/include/mbedtls/ssl_cache.h +187 -0
  137. package/vendor/mbedtls/include/mbedtls/ssl_ciphersuites.h +482 -0
  138. package/vendor/mbedtls/include/mbedtls/ssl_cookie.h +106 -0
  139. package/vendor/mbedtls/include/mbedtls/ssl_ticket.h +199 -0
  140. package/vendor/mbedtls/include/mbedtls/threading.h +167 -0
  141. package/vendor/mbedtls/include/mbedtls/timing.h +94 -0
  142. package/vendor/mbedtls/include/mbedtls/version.h +78 -0
  143. package/vendor/mbedtls/include/mbedtls/x509.h +500 -0
  144. package/vendor/mbedtls/include/mbedtls/x509_crl.h +184 -0
  145. package/vendor/mbedtls/include/mbedtls/x509_crt.h +1208 -0
  146. package/vendor/mbedtls/include/mbedtls/x509_csr.h +382 -0
  147. package/vendor/mbedtls/include/psa/build_info.h +20 -0
  148. package/vendor/mbedtls/include/psa/crypto.h +4998 -0
  149. package/vendor/mbedtls/include/psa/crypto_adjust_auto_enabled.h +31 -0
  150. package/vendor/mbedtls/include/psa/crypto_adjust_config_dependencies.h +51 -0
  151. package/vendor/mbedtls/include/psa/crypto_adjust_config_key_pair_types.h +101 -0
  152. package/vendor/mbedtls/include/psa/crypto_adjust_config_synonyms.h +49 -0
  153. package/vendor/mbedtls/include/psa/crypto_builtin_composites.h +214 -0
  154. package/vendor/mbedtls/include/psa/crypto_builtin_key_derivation.h +118 -0
  155. package/vendor/mbedtls/include/psa/crypto_builtin_primitives.h +114 -0
  156. package/vendor/mbedtls/include/psa/crypto_compat.h +230 -0
  157. package/vendor/mbedtls/include/psa/crypto_config.h +145 -0
  158. package/vendor/mbedtls/include/psa/crypto_driver_common.h +44 -0
  159. package/vendor/mbedtls/include/psa/crypto_driver_contexts_composites.h +151 -0
  160. package/vendor/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h +52 -0
  161. package/vendor/mbedtls/include/psa/crypto_driver_contexts_primitives.h +105 -0
  162. package/vendor/mbedtls/include/psa/crypto_extra.h +2145 -0
  163. package/vendor/mbedtls/include/psa/crypto_legacy.h +88 -0
  164. package/vendor/mbedtls/include/psa/crypto_platform.h +102 -0
  165. package/vendor/mbedtls/include/psa/crypto_se_driver.h +1383 -0
  166. package/vendor/mbedtls/include/psa/crypto_sizes.h +1319 -0
  167. package/vendor/mbedtls/include/psa/crypto_struct.h +527 -0
  168. package/vendor/mbedtls/include/psa/crypto_types.h +508 -0
  169. package/vendor/mbedtls/include/psa/crypto_values.h +2782 -0
  170. package/vendor/mbedtls/library/aes.c +2294 -0
  171. package/vendor/mbedtls/library/aesce.c +624 -0
  172. package/vendor/mbedtls/library/aesce.h +136 -0
  173. package/vendor/mbedtls/library/aesni.c +846 -0
  174. package/vendor/mbedtls/library/aesni.h +162 -0
  175. package/vendor/mbedtls/library/alignment.h +704 -0
  176. package/vendor/mbedtls/library/aria.c +969 -0
  177. package/vendor/mbedtls/library/asn1parse.c +468 -0
  178. package/vendor/mbedtls/library/asn1write.c +440 -0
  179. package/vendor/mbedtls/library/base64.c +322 -0
  180. package/vendor/mbedtls/library/base64_internal.h +45 -0
  181. package/vendor/mbedtls/library/bignum.c +2583 -0
  182. package/vendor/mbedtls/library/bignum_core.c +1240 -0
  183. package/vendor/mbedtls/library/bignum_core.h +872 -0
  184. package/vendor/mbedtls/library/bignum_core_invasive.h +38 -0
  185. package/vendor/mbedtls/library/bignum_internal.h +122 -0
  186. package/vendor/mbedtls/library/bignum_mod.c +394 -0
  187. package/vendor/mbedtls/library/bignum_mod.h +452 -0
  188. package/vendor/mbedtls/library/bignum_mod_raw.c +276 -0
  189. package/vendor/mbedtls/library/bignum_mod_raw.h +416 -0
  190. package/vendor/mbedtls/library/bignum_mod_raw_invasive.h +34 -0
  191. package/vendor/mbedtls/library/block_cipher.c +207 -0
  192. package/vendor/mbedtls/library/block_cipher_internal.h +99 -0
  193. package/vendor/mbedtls/library/bn_mul.h +1094 -0
  194. package/vendor/mbedtls/library/camellia.c +1058 -0
  195. package/vendor/mbedtls/library/ccm.c +777 -0
  196. package/vendor/mbedtls/library/chacha20.c +563 -0
  197. package/vendor/mbedtls/library/chacha20_internal.h +23 -0
  198. package/vendor/mbedtls/library/chachapoly.c +487 -0
  199. package/vendor/mbedtls/library/check_crypto_config.h +136 -0
  200. package/vendor/mbedtls/library/cipher.c +1712 -0
  201. package/vendor/mbedtls/library/cipher_invasive.h +28 -0
  202. package/vendor/mbedtls/library/cipher_wrap.c +2482 -0
  203. package/vendor/mbedtls/library/cipher_wrap.h +178 -0
  204. package/vendor/mbedtls/library/cmac.c +1067 -0
  205. package/vendor/mbedtls/library/common.h +487 -0
  206. package/vendor/mbedtls/library/constant_time.c +247 -0
  207. package/vendor/mbedtls/library/constant_time_impl.h +541 -0
  208. package/vendor/mbedtls/library/constant_time_internal.h +579 -0
  209. package/vendor/mbedtls/library/ctr.h +35 -0
  210. package/vendor/mbedtls/library/ctr_drbg.c +1016 -0
  211. package/vendor/mbedtls/library/debug.c +475 -0
  212. package/vendor/mbedtls/library/debug_internal.h +185 -0
  213. package/vendor/mbedtls/library/des.c +1042 -0
  214. package/vendor/mbedtls/library/dhm.c +700 -0
  215. package/vendor/mbedtls/library/ecdh.c +696 -0
  216. package/vendor/mbedtls/library/ecdsa.c +858 -0
  217. package/vendor/mbedtls/library/ecjpake.c +1216 -0
  218. package/vendor/mbedtls/library/ecp.c +3674 -0
  219. package/vendor/mbedtls/library/ecp_curves.c +6125 -0
  220. package/vendor/mbedtls/library/ecp_curves_new.c +9 -0
  221. package/vendor/mbedtls/library/ecp_internal_alt.h +287 -0
  222. package/vendor/mbedtls/library/ecp_invasive.h +305 -0
  223. package/vendor/mbedtls/library/entropy.c +680 -0
  224. package/vendor/mbedtls/library/entropy_poll.c +233 -0
  225. package/vendor/mbedtls/library/entropy_poll.h +64 -0
  226. package/vendor/mbedtls/library/error.c +878 -0
  227. package/vendor/mbedtls/library/gcm.c +1330 -0
  228. package/vendor/mbedtls/library/hkdf.c +161 -0
  229. package/vendor/mbedtls/library/hmac_drbg.c +633 -0
  230. package/vendor/mbedtls/library/lmots.c +789 -0
  231. package/vendor/mbedtls/library/lmots.h +288 -0
  232. package/vendor/mbedtls/library/lms.c +778 -0
  233. package/vendor/mbedtls/library/md.c +1108 -0
  234. package/vendor/mbedtls/library/md5.c +426 -0
  235. package/vendor/mbedtls/library/md_psa.h +26 -0
  236. package/vendor/mbedtls/library/md_wrap.h +46 -0
  237. package/vendor/mbedtls/library/memory_buffer_alloc.c +751 -0
  238. package/vendor/mbedtls/library/mps_common.h +181 -0
  239. package/vendor/mbedtls/library/mps_error.h +89 -0
  240. package/vendor/mbedtls/library/mps_reader.c +538 -0
  241. package/vendor/mbedtls/library/mps_reader.h +366 -0
  242. package/vendor/mbedtls/library/mps_trace.c +112 -0
  243. package/vendor/mbedtls/library/mps_trace.h +154 -0
  244. package/vendor/mbedtls/library/net_sockets.c +694 -0
  245. package/vendor/mbedtls/library/nist_kw.c +729 -0
  246. package/vendor/mbedtls/library/oid.c +1166 -0
  247. package/vendor/mbedtls/library/padlock.c +157 -0
  248. package/vendor/mbedtls/library/padlock.h +111 -0
  249. package/vendor/mbedtls/library/pem.c +554 -0
  250. package/vendor/mbedtls/library/pk.c +1602 -0
  251. package/vendor/mbedtls/library/pk_ecc.c +261 -0
  252. package/vendor/mbedtls/library/pk_internal.h +241 -0
  253. package/vendor/mbedtls/library/pk_wrap.c +1618 -0
  254. package/vendor/mbedtls/library/pk_wrap.h +138 -0
  255. package/vendor/mbedtls/library/pkcs12.c +437 -0
  256. package/vendor/mbedtls/library/pkcs5.c +500 -0
  257. package/vendor/mbedtls/library/pkcs7.c +787 -0
  258. package/vendor/mbedtls/library/pkparse.c +1392 -0
  259. package/vendor/mbedtls/library/pkwrite.c +631 -0
  260. package/vendor/mbedtls/library/pkwrite.h +121 -0
  261. package/vendor/mbedtls/library/platform.c +402 -0
  262. package/vendor/mbedtls/library/platform_util.c +258 -0
  263. package/vendor/mbedtls/library/poly1305.c +492 -0
  264. package/vendor/mbedtls/library/psa_crypto.c +9532 -0
  265. package/vendor/mbedtls/library/psa_crypto_aead.c +646 -0
  266. package/vendor/mbedtls/library/psa_crypto_aead.h +499 -0
  267. package/vendor/mbedtls/library/psa_crypto_cipher.c +747 -0
  268. package/vendor/mbedtls/library/psa_crypto_cipher.h +316 -0
  269. package/vendor/mbedtls/library/psa_crypto_client.c +22 -0
  270. package/vendor/mbedtls/library/psa_crypto_core.h +983 -0
  271. package/vendor/mbedtls/library/psa_crypto_core_common.h +52 -0
  272. package/vendor/mbedtls/library/psa_crypto_driver_wrappers.h +2896 -0
  273. package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.c +256 -0
  274. package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.h +31 -0
  275. package/vendor/mbedtls/library/psa_crypto_ecp.c +594 -0
  276. package/vendor/mbedtls/library/psa_crypto_ecp.h +267 -0
  277. package/vendor/mbedtls/library/psa_crypto_ffdh.c +361 -0
  278. package/vendor/mbedtls/library/psa_crypto_ffdh.h +131 -0
  279. package/vendor/mbedtls/library/psa_crypto_hash.c +470 -0
  280. package/vendor/mbedtls/library/psa_crypto_hash.h +211 -0
  281. package/vendor/mbedtls/library/psa_crypto_invasive.h +92 -0
  282. package/vendor/mbedtls/library/psa_crypto_its.h +131 -0
  283. package/vendor/mbedtls/library/psa_crypto_mac.c +505 -0
  284. package/vendor/mbedtls/library/psa_crypto_mac.h +264 -0
  285. package/vendor/mbedtls/library/psa_crypto_pake.c +571 -0
  286. package/vendor/mbedtls/library/psa_crypto_pake.h +159 -0
  287. package/vendor/mbedtls/library/psa_crypto_random.c +181 -0
  288. package/vendor/mbedtls/library/psa_crypto_random.h +72 -0
  289. package/vendor/mbedtls/library/psa_crypto_random_impl.h +200 -0
  290. package/vendor/mbedtls/library/psa_crypto_rsa.c +714 -0
  291. package/vendor/mbedtls/library/psa_crypto_rsa.h +321 -0
  292. package/vendor/mbedtls/library/psa_crypto_se.c +373 -0
  293. package/vendor/mbedtls/library/psa_crypto_se.h +192 -0
  294. package/vendor/mbedtls/library/psa_crypto_slot_management.c +1137 -0
  295. package/vendor/mbedtls/library/psa_crypto_slot_management.h +344 -0
  296. package/vendor/mbedtls/library/psa_crypto_storage.c +481 -0
  297. package/vendor/mbedtls/library/psa_crypto_storage.h +392 -0
  298. package/vendor/mbedtls/library/psa_its_file.c +254 -0
  299. package/vendor/mbedtls/library/psa_util.c +614 -0
  300. package/vendor/mbedtls/library/psa_util_internal.h +100 -0
  301. package/vendor/mbedtls/library/ripemd160.c +490 -0
  302. package/vendor/mbedtls/library/rsa.c +3121 -0
  303. package/vendor/mbedtls/library/rsa_alt_helpers.c +455 -0
  304. package/vendor/mbedtls/library/rsa_alt_helpers.h +209 -0
  305. package/vendor/mbedtls/library/rsa_internal.h +188 -0
  306. package/vendor/mbedtls/library/sha1.c +480 -0
  307. package/vendor/mbedtls/library/sha256.c +983 -0
  308. package/vendor/mbedtls/library/sha3.c +721 -0
  309. package/vendor/mbedtls/library/sha512.c +1115 -0
  310. package/vendor/mbedtls/library/ssl_cache.c +410 -0
  311. package/vendor/mbedtls/library/ssl_ciphersuites.c +2050 -0
  312. package/vendor/mbedtls/library/ssl_ciphersuites_internal.h +154 -0
  313. package/vendor/mbedtls/library/ssl_client.c +1023 -0
  314. package/vendor/mbedtls/library/ssl_client.h +22 -0
  315. package/vendor/mbedtls/library/ssl_cookie.c +384 -0
  316. package/vendor/mbedtls/library/ssl_debug_helpers.h +85 -0
  317. package/vendor/mbedtls/library/ssl_debug_helpers_generated.c +251 -0
  318. package/vendor/mbedtls/library/ssl_misc.h +3198 -0
  319. package/vendor/mbedtls/library/ssl_msg.c +6619 -0
  320. package/vendor/mbedtls/library/ssl_ticket.c +556 -0
  321. package/vendor/mbedtls/library/ssl_tls.c +10234 -0
  322. package/vendor/mbedtls/library/ssl_tls12_client.c +3688 -0
  323. package/vendor/mbedtls/library/ssl_tls12_server.c +4311 -0
  324. package/vendor/mbedtls/library/ssl_tls13_client.c +3208 -0
  325. package/vendor/mbedtls/library/ssl_tls13_generic.c +1793 -0
  326. package/vendor/mbedtls/library/ssl_tls13_invasive.h +23 -0
  327. package/vendor/mbedtls/library/ssl_tls13_keys.c +1918 -0
  328. package/vendor/mbedtls/library/ssl_tls13_keys.h +668 -0
  329. package/vendor/mbedtls/library/ssl_tls13_server.c +3624 -0
  330. package/vendor/mbedtls/library/threading.c +193 -0
  331. package/vendor/mbedtls/library/threading_internal.h +28 -0
  332. package/vendor/mbedtls/library/timing.c +152 -0
  333. package/vendor/mbedtls/library/version.c +32 -0
  334. package/vendor/mbedtls/library/version_features.c +856 -0
  335. package/vendor/mbedtls/library/x509.c +1776 -0
  336. package/vendor/mbedtls/library/x509_create.c +570 -0
  337. package/vendor/mbedtls/library/x509_crl.c +708 -0
  338. package/vendor/mbedtls/library/x509_crt.c +3311 -0
  339. package/vendor/mbedtls/library/x509_csr.c +648 -0
  340. package/vendor/mbedtls/library/x509_internal.h +101 -0
  341. package/vendor/mbedtls/library/x509write.c +174 -0
  342. package/vendor/mbedtls/library/x509write_crt.c +688 -0
  343. package/vendor/mbedtls/library/x509write_csr.c +336 -0
  344. package/vendor/quickjs-ng/CMakeLists.txt +566 -0
  345. package/vendor/quickjs-ng/LICENSE +24 -0
  346. package/vendor/quickjs-ng/README.md +24 -0
  347. package/vendor/quickjs-ng/api-test.c +1195 -0
  348. package/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
  349. package/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
  350. package/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
  351. package/vendor/quickjs-ng/cutils.h +1998 -0
  352. package/vendor/quickjs-ng/dtoa.c +1619 -0
  353. package/vendor/quickjs-ng/dtoa.h +87 -0
  354. package/vendor/quickjs-ng/gen/function_source.c +81 -0
  355. package/vendor/quickjs-ng/gen/hello.c +53 -0
  356. package/vendor/quickjs-ng/gen/hello_module.c +106 -0
  357. package/vendor/quickjs-ng/gen/repl.c +3036 -0
  358. package/vendor/quickjs-ng/gen/standalone.c +323 -0
  359. package/vendor/quickjs-ng/gen/test_fib.c +81 -0
  360. package/vendor/quickjs-ng/libregexp-opcode.h +73 -0
  361. package/vendor/quickjs-ng/libregexp.c +3474 -0
  362. package/vendor/quickjs-ng/libregexp.h +101 -0
  363. package/vendor/quickjs-ng/libunicode-table.h +5173 -0
  364. package/vendor/quickjs-ng/libunicode.c +2069 -0
  365. package/vendor/quickjs-ng/libunicode.h +172 -0
  366. package/vendor/quickjs-ng/list.h +107 -0
  367. package/vendor/quickjs-ng/lre-test.c +52 -0
  368. package/vendor/quickjs-ng/qjs.c +762 -0
  369. package/vendor/quickjs-ng/qjsc.c +673 -0
  370. package/vendor/quickjs-ng/quickjs-atom.h +280 -0
  371. package/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
  372. package/vendor/quickjs-ng/quickjs-libc.c +5037 -0
  373. package/vendor/quickjs-ng/quickjs-libc.h +87 -0
  374. package/vendor/quickjs-ng/quickjs-opcode.h +377 -0
  375. package/vendor/quickjs-ng/quickjs.c +64041 -0
  376. package/vendor/quickjs-ng/quickjs.h +1447 -0
  377. package/vendor/quickjs-ng/run-test262.c +2374 -0
  378. package/vendor/quickjs-ng/unicode_gen.c +3121 -0
  379. package/vendor/quickjs-ng/unicode_gen_def.h +310 -0
  380. package/vendor/ryu/LICENSE-Boost +23 -0
  381. package/vendor/ryu/common.h +114 -0
  382. package/vendor/ryu/d2s.c +509 -0
  383. package/vendor/ryu/d2s_full_table.h +367 -0
  384. package/vendor/ryu/d2s_intrinsics.h +357 -0
  385. package/vendor/ryu/d2s_small_table.h +186 -0
  386. package/vendor/ryu/digit_table.h +35 -0
  387. package/vendor/ryu/ryu.h +46 -0
  388. package/vendor/zlib/LICENSE +22 -0
  389. package/vendor/zlib/adler32.c +164 -0
  390. package/vendor/zlib/compress.c +75 -0
  391. package/vendor/zlib/crc32.c +1049 -0
  392. package/vendor/zlib/crc32.h +9446 -0
  393. package/vendor/zlib/deflate.c +2139 -0
  394. package/vendor/zlib/deflate.h +377 -0
  395. package/vendor/zlib/gzclose.c +23 -0
  396. package/vendor/zlib/gzguts.h +214 -0
  397. package/vendor/zlib/gzlib.c +582 -0
  398. package/vendor/zlib/gzread.c +602 -0
  399. package/vendor/zlib/gzwrite.c +631 -0
  400. package/vendor/zlib/infback.c +628 -0
  401. package/vendor/zlib/inffast.c +320 -0
  402. package/vendor/zlib/inffast.h +11 -0
  403. package/vendor/zlib/inffixed.h +94 -0
  404. package/vendor/zlib/inflate.c +1526 -0
  405. package/vendor/zlib/inflate.h +126 -0
  406. package/vendor/zlib/inftrees.c +299 -0
  407. package/vendor/zlib/inftrees.h +62 -0
  408. package/vendor/zlib/trees.c +1117 -0
  409. package/vendor/zlib/trees.h +128 -0
  410. package/vendor/zlib/uncompr.c +85 -0
  411. package/vendor/zlib/zconf.h +543 -0
  412. package/vendor/zlib/zlib.h +1938 -0
  413. package/vendor/zlib/zutil.c +299 -0
  414. package/vendor/zlib/zutil.h +254 -0
  415. package/README.md +0 -3
  416. package/index.js +0 -2
@@ -0,0 +1,119 @@
1
+ /* The platform readiness contract — ONE interface both event backends
2
+ * implement (kqueue on macOS/BSD, epoll on Linux), designed from how
3
+ * scr_net.c / scr_dgram.c / scr_child.c use kqueue TODAY. Design notes and
4
+ * the full macOS-ism audit live in docs/linux-port.md.
5
+ *
6
+ * Scope, deliberately: the loop CORE (scr_async.c) is already portable —
7
+ * its idle sleep is poll(2)/nanosleep over fds the optional units hand it
8
+ * via the pending/dispatch/pollfd hook triple, and that hook contract is
9
+ * platform-neutral (an epoll fd polls readable while events pend, exactly
10
+ * like a kqueue fd). What is NOT portable is the plumbing INSIDE each
11
+ * unit: kqueue creation, filter add/remove, the idle-timer filter, the
12
+ * child-exit filter, and the zero-timeout drains. This header names that
13
+ * plumbing so each unit can call one spelling and link either backend.
14
+ *
15
+ * STATUS: LIVE. scr_net.c and scr_dgram.c call this contract; cc.ts
16
+ * links BOTH backends whenever either unit compiles (scr_loop_kqueue.c —
17
+ * a stateless spelling of the units' historical inline syscall
18
+ * sequences, byte-identical on macOS by construction — and
19
+ * scr_loop_epoll.c; each TU is empty off its platform). The mapping each
20
+ * backend owes:
21
+ *
22
+ * contract kqueue backend epoll backend
23
+ * ------------------ --------------------------- -------------------------------
24
+ * poller fd the kqueue() fd the epoll_create1() fd
25
+ * watch read on/off EVFILT_READ EV_ADD/EV_DELETE EPOLLIN via ADD/MOD/DEL + fd table
26
+ * watch write on/off EVFILT_WRITE EV_ADD/EV_DELETE EPOLLOUT via ADD/MOD/DEL + fd table
27
+ * one-shot timer(key) EVFILT_TIMER ident=key, one timerfd_create per armed key,
28
+ * EV_ONESHOT, NOTE_* default ms TFD_NONBLOCK, registered EPOLLIN
29
+ * drain (zero timeout) kevent(evs, N, {0,0}) epoll_wait(evs, N, 0)
30
+ * EOF/error delivery EV_EOF on the read filter EPOLLHUP/EPOLLERR/EPOLLRDHUP
31
+ * reported as READABLE (+WRITABLE
32
+ * when write interest is armed) —
33
+ * units learn the truth from
34
+ * read()==0 / errno, as today
35
+ *
36
+ * (Child-exit wakeups live inline in scr_child.c — see the note at the
37
+ * bottom of this header.)
38
+ *
39
+ * Two epoll-only obligations the kqueue side never had, called out so the
40
+ * extraction cannot fudge them: (1) epoll keys interest by fd with
41
+ * ONE mask, so read+write interest on the same fd must merge into a MOD —
42
+ * the backend keeps a private fd -> (mask, udata) table; kqueue's separate
43
+ * filters need no such state. (2) closing an fd does NOT reliably remove
44
+ * it from an epoll set while dup'd references exist — units must call
45
+ * scrp_forget BEFORE close(2). kqueue drops filters on close, so today's
46
+ * units don't always bother; the extraction adds the forget calls (a
47
+ * no-op wrapper on the kqueue side keeps macOS byte-identical in
48
+ * behavior; the corpus proves it). */
49
+ #ifndef SCR_PLATFORM_H
50
+ #define SCR_PLATFORM_H
51
+
52
+ #include <stdbool.h>
53
+ #include <stddef.h>
54
+
55
+ /* ── the fd/timer poller (scr_net.c's and scr_dgram.c's unit kqueues) ── */
56
+
57
+ typedef struct ScrPoller ScrPoller;
58
+
59
+ enum {
60
+ SCRP_READABLE = 1u << 0,
61
+ SCRP_WRITABLE = 1u << 1,
62
+ SCRP_TIMER = 1u << 2,
63
+ };
64
+
65
+ typedef struct {
66
+ void *udata; /* the pointer registered at watch/arm time; routing is
67
+ * the caller's business (scr_net routes on a leading
68
+ * `kind` int, exactly as its kevent udata does today) */
69
+ unsigned events; /* SCRP_* bits OR'd */
70
+ } ScrPollerEvent;
71
+
72
+ /* NULL on resource exhaustion — callers report and disable the unit, the
73
+ * historical kqueue() failure path. */
74
+ ScrPoller *scrp_poller_new(void);
75
+ void scrp_poller_free(ScrPoller *p);
76
+
77
+ /* The fd the LOOP sleeps on (poll(2), POLLIN): readable while any event
78
+ * pends, the property both kqueue and epoll fds share. Owned by the
79
+ * poller — never closed or drained by the caller. */
80
+ int scrp_poller_fd(const ScrPoller *p);
81
+
82
+ /* Watch/unwatch one direction on an fd. `udata` tags every delivery for
83
+ * this fd (the LAST registration wins across both directions — matching
84
+ * how the units pass the same socket pointer to both filters today).
85
+ * Unwatching a direction that isn't armed is a no-op, like EV_DELETE on a
86
+ * missing filter is ignored by today's code. */
87
+ bool scrp_watch_read(ScrPoller *p, int fd, void *udata, bool on);
88
+ bool scrp_watch_write(ScrPoller *p, int fd, void *udata, bool on);
89
+
90
+ /* Drop every registration for fd. MUST precede close(2) of a watched fd
91
+ * (see the epoll obligation above); safe on unwatched fds. */
92
+ void scrp_forget(ScrPoller *p, int fd);
93
+
94
+ /* One-shot timer keyed by an arbitrary pointer (scr_net's idle timers:
95
+ * ident = the socket pointer). Re-arming an armed key replaces its
96
+ * deadline; delivery reports SCRP_TIMER with udata = key. Cancel of an
97
+ * unarmed/already-fired key is a no-op (the timer "may already have
98
+ * fired" comment in scr_net.c today). */
99
+ bool scrp_timer_arm(ScrPoller *p, void *key, double ms, void *udata);
100
+ void scrp_timer_cancel(ScrPoller *p, void *key);
101
+
102
+ /* Zero-timeout drain of everything pending, at most `max` events (the
103
+ * units' dispatch-top drains: kevent/epoll_wait with a zero timeout).
104
+ * Returns the count; EINTR reads as 0 (a spurious pass, as today). */
105
+ int scrp_drain(ScrPoller *p, ScrPollerEvent *out, int max);
106
+
107
+ /* ── child-exit wakeups: NOT here, deliberately ───────────────────────
108
+ * scr_child.c keeps its narrow seam INLINE (scr_child_watch /
109
+ * scr_children_wait / scr_children_wake_fd, plus the stream read-fd
110
+ * arm/dearm): kqueue EVFILT_PROC NOTE_EXIT + EVFILT_READ on BSD,
111
+ * pidfd_open + a dedicated epoll on Linux, and the portable
112
+ * waitpid(WNOHANG)-under-a-~1ms-cap fallback everywhere else. That unit
113
+ * links into EVERY binary, so routing it through this contract would put
114
+ * both backends on every link line; its plumbing (wakeups-only, events
115
+ * discarded, the unit's own unwatched-children accounting) also never
116
+ * matched the fd/timer poller shape above. Reaping stays the WNOHANG
117
+ * sweep on every platform — exit events are wakeups only. */
118
+
119
+ #endif /* SCR_PLATFORM_H */
@@ -0,0 +1,287 @@
1
+ /* node:readline — the question/close slice over the stdin unit
2
+ * (scr_events.c), linked exactly when the program uses it (the events
3
+ * gating; rl.* libCalls imply events).
4
+ *
5
+ * Model, pinned against Node under pipes (SEMANTICS.md + corpus 1475):
6
+ * - createInterface({ input: process.stdin, output: process.stdout })
7
+ * registers this unit's ONE shared stdin data listener (a consumer: the
8
+ * loop watches fd 0 and the process stays alive while any interface is
9
+ * open, exactly Node's un-closed readline) and a global 'end' listener.
10
+ * - Lines split on \n and \r\n (and a bare \r followed by more input);
11
+ * a trailing \r holds until the next chunk decides \r\n vs \r.
12
+ * - question(query, cb) writes the query to stdout (Node writes it under
13
+ * pipes too) and delivers the NEXT line's text; a line arriving with no
14
+ * pending question is DROPPED (Node emits 'line' that nobody hears).
15
+ * - close() removes the consumer (the loop stops waiting on fd 0), drops
16
+ * a pending question (its callback never fires), and fires the 'close'
17
+ * listeners SYNCHRONOUSLY — Node's close() emits inline, which is why
18
+ * the portless prompt's close-listener resolve wins over the question
19
+ * callback's (oracle-pinned).
20
+ * - stdin EOF closes every open interface the same way: the buffered
21
+ * partial line is DISCARDED (Node), then 'close' fires.
22
+ * - question() after close() throws Node's ERR_USE_AFTER_CLOSE message.
23
+ * - An interface created AFTER stdin ended is DEAD (pinned against
24
+ * Node): a question still writes its prompt, but nothing ever answers
25
+ * and 'close' never fires — Node's process exits with the question
26
+ * pending, and the loop exhausts the same way here. */
27
+ #include "scr_runtime.h"
28
+
29
+ #include <stdio.h>
30
+ #include <stdlib.h>
31
+ #include <string.h>
32
+
33
+ static void scr_rl_oom(void) {
34
+ fputs("scriptc: out of memory\n", stderr);
35
+ abort();
36
+ }
37
+
38
+ typedef struct ScrRl {
39
+ double id;
40
+ bool closed;
41
+ bool dead; /* created after stdin ended: close fires at question() */
42
+ ScrClosure *q_cb; /* pending question's callback (owned), or NULL */
43
+ void (*q_fn)(ScrClosure *, ScrStr *);
44
+ ScrClosure **close_cbs; /* owned zero-arg listeners */
45
+ size_t n_close, cap_close;
46
+ char *buf; /* undelivered stdin bytes */
47
+ size_t len, cap;
48
+ struct ScrRl *next;
49
+ } ScrRl;
50
+
51
+ static ScrRl *scr_rls = NULL;
52
+ static double scr_rl_next_id = 1;
53
+ static size_t scr_rl_open = 0; /* un-closed, un-dead interfaces */
54
+ static ScrClosure *scr_rl_data_cb = NULL; /* the shared consumer (borrowed
55
+ * mirror; the registry owns) */
56
+ static bool scr_rl_end_registered = false;
57
+
58
+ static ScrRl *scr_rl_find(double id) {
59
+ for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
60
+ if (rl->id == id) return rl;
61
+ }
62
+ return NULL;
63
+ }
64
+
65
+ /* Fires the close listeners (snapshot; synchronous, like Node's emit) and
66
+ * releases everything the interface holds. */
67
+ static void scr_rl_settle_close(ScrRl *rl) {
68
+ if (rl->closed) return;
69
+ rl->closed = true;
70
+ if (!rl->dead && scr_rl_open > 0) scr_rl_open--;
71
+ if (rl->q_cb) {
72
+ scr_closure_release(rl->q_cb); /* a pending question never answers */
73
+ rl->q_cb = NULL;
74
+ }
75
+ /* The last open interface leaving detaches the shared consumer so the
76
+ * loop stops waiting on fd 0 (Node's pause-on-close). */
77
+ if (scr_rl_open == 0 && scr_rl_data_cb != NULL) {
78
+ scr_stdin_remove_data(scr_rl_data_cb);
79
+ scr_rl_data_cb = NULL;
80
+ }
81
+ size_t n = rl->n_close;
82
+ ScrClosure **snap = rl->close_cbs;
83
+ rl->close_cbs = NULL;
84
+ rl->n_close = rl->cap_close = 0;
85
+ for (size_t i = 0; i < n; i++) {
86
+ if (!scr_exc_pending()) {
87
+ ((void (*)(ScrClosure *))snap[i]->fn)(snap[i]);
88
+ }
89
+ scr_closure_release(snap[i]);
90
+ }
91
+ free(snap);
92
+ free(rl->buf);
93
+ rl->buf = NULL;
94
+ rl->len = rl->cap = 0;
95
+ }
96
+
97
+ /* One complete line off the front of the buffer: *adv is the byte count
98
+ * consumed (terminator included), *line_len the line's length. False when
99
+ * no complete line is buffered (a trailing \r holds for the \r\n
100
+ * decision). */
101
+ static bool scr_rl_scan(const ScrRl *rl, size_t *line_len, size_t *adv) {
102
+ for (size_t i = 0; i < rl->len; i++) {
103
+ char c = rl->buf[i];
104
+ if (c == '\n') {
105
+ *line_len = i;
106
+ *adv = i + 1;
107
+ return true;
108
+ }
109
+ if (c == '\r') {
110
+ if (i + 1 >= rl->len) return false; /* hold: \r\n may straddle chunks */
111
+ *line_len = i;
112
+ *adv = rl->buf[i + 1] == '\n' ? i + 2 : i + 1;
113
+ return true;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+
119
+ static void scr_rl_drain(ScrRl *rl) {
120
+ size_t line_len, adv;
121
+ while (!rl->closed && scr_rl_scan(rl, &line_len, &adv)) {
122
+ ScrStr *line = NULL;
123
+ ScrClosure *cb = rl->q_cb;
124
+ void (*fn)(ScrClosure *, ScrStr *) = rl->q_fn;
125
+ if (cb) line = scr_str_new(rl->buf, line_len);
126
+ memmove(rl->buf, rl->buf + adv, rl->len - adv);
127
+ rl->len -= adv;
128
+ if (cb) {
129
+ rl->q_cb = NULL; /* consumed BEFORE the callback runs (once) */
130
+ fn(cb, line); /* the adapter owns the +1 line */
131
+ scr_closure_release(cb);
132
+ if (scr_exc_pending()) return;
133
+ }
134
+ /* No pending question: the line drops, exactly Node's unheard 'line'. */
135
+ }
136
+ }
137
+
138
+ /* The shared stdin data consumer: appends and drains every open
139
+ * interface (chunks broadcast, like any stdin listener set). */
140
+ static void scr_rl_data_adapter(ScrClosure *cb, ScrBytes *chunk) {
141
+ (void)cb;
142
+ for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
143
+ if (rl->closed || rl->dead) continue;
144
+ if (rl->len + chunk->len > rl->cap) {
145
+ rl->cap = (rl->len + chunk->len) * 2 + 64;
146
+ rl->buf = realloc(rl->buf, rl->cap);
147
+ if (!rl->buf) scr_rl_oom();
148
+ }
149
+ memcpy(rl->buf + rl->len, chunk->data, chunk->len);
150
+ rl->len += chunk->len;
151
+ scr_rl_drain(rl);
152
+ if (scr_exc_pending()) return;
153
+ }
154
+ }
155
+
156
+ /* stdin EOF: every open interface closes — the buffered partial line is
157
+ * DISCARDED (Node; a trailing held \r still terminates its line first). */
158
+ static void scr_rl_end_thunk(ScrClosure *cb) {
159
+ (void)cb;
160
+ scr_rl_data_cb = NULL; /* the stdin unit dropped its listeners itself */
161
+ for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
162
+ if (rl->closed || rl->dead) continue;
163
+ if (rl->len > 0 && rl->buf[rl->len - 1] == '\r' && rl->q_cb) {
164
+ /* "a\r" then EOF: the \r terminates the line (Node's crlfDelay
165
+ * expiry collapsed to EOF time). */
166
+ ScrStr *line = scr_str_new(rl->buf, rl->len - 1);
167
+ ScrClosure *qcb = rl->q_cb;
168
+ void (*fn)(ScrClosure *, ScrStr *) = rl->q_fn;
169
+ rl->q_cb = NULL;
170
+ rl->len = 0;
171
+ fn(qcb, line);
172
+ scr_closure_release(qcb);
173
+ if (scr_exc_pending()) return;
174
+ }
175
+ scr_rl_settle_close(rl);
176
+ if (scr_exc_pending()) return;
177
+ }
178
+ }
179
+
180
+ /* Exit-time cleanup (the events-unit precedent, before the RC audit):
181
+ * whatever an interface still holds — a parked question, close listeners
182
+ * on a dead interface that never asked — releases here. */
183
+ static void scr_rl_cleanup_atexit(void) {
184
+ for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
185
+ if (rl->q_cb) {
186
+ scr_closure_release(rl->q_cb);
187
+ rl->q_cb = NULL;
188
+ }
189
+ for (size_t i = 0; i < rl->n_close; i++) scr_closure_release(rl->close_cbs[i]);
190
+ free(rl->close_cbs);
191
+ rl->close_cbs = NULL;
192
+ rl->n_close = rl->cap_close = 0;
193
+ free(rl->buf);
194
+ rl->buf = NULL;
195
+ rl->len = rl->cap = 0;
196
+ }
197
+ }
198
+
199
+ double scr_rl_create(void) {
200
+ static bool cleanup_registered = false;
201
+ if (!cleanup_registered) {
202
+ cleanup_registered = true;
203
+ atexit(scr_rl_cleanup_atexit);
204
+ }
205
+ ScrRl *rl = calloc(1, sizeof *rl);
206
+ if (!rl) scr_rl_oom();
207
+ rl->id = scr_rl_next_id++;
208
+ rl->next = scr_rls;
209
+ scr_rls = rl;
210
+ if (scr_stdin_ended()) {
211
+ rl->dead = true; /* close fires when a question is asked */
212
+ return rl->id;
213
+ }
214
+ scr_rl_open++;
215
+ if (scr_rl_data_cb == NULL) {
216
+ /* One shared consumer + one global end hook. The closures carry no
217
+ * captures; their fn slots are never invoked directly for the data
218
+ * one (the registered adapter is), and the end one IS its thunk. */
219
+ scr_rl_data_cb = scr_closure_new((void *)&scr_rl_data_adapter, 0);
220
+ scr_stdin_on_data(scr_rl_data_cb, &scr_rl_data_adapter, false);
221
+ }
222
+ if (!scr_rl_end_registered) {
223
+ scr_rl_end_registered = true;
224
+ scr_stdin_on_end(scr_closure_new((void *)&scr_rl_end_thunk, 0), false);
225
+ }
226
+ return rl->id;
227
+ }
228
+
229
+ void scr_rl_question(double id, const ScrStr *query, ScrClosure *cb /*moves*/,
230
+ void (*fn)(ScrClosure *, ScrStr *)) {
231
+ ScrRl *rl = scr_rl_find(id);
232
+ if (!rl || rl->closed) {
233
+ scr_closure_release(cb);
234
+ /* Node's ERR_USE_AFTER_CLOSE. */
235
+ scr_throw_error_msg(SCR_ERR_ERROR, "readline was closed", 19);
236
+ return;
237
+ }
238
+ /* The prompt writes to stdout under pipes too (Node's question does);
239
+ * same stream and buffer as console.log, so ordering holds. */
240
+ fwrite(query->data, 1, query->len, stdout);
241
+ if (rl->dead) {
242
+ /* Created after stdin ended: pinned against Node — the prompt still
243
+ * writes, but the DESTROYED stream delivers nothing and 'close'
244
+ * never fires (Node's process exits with the question pending; the
245
+ * loop exhausts the same way here). The callback releases now. */
246
+ scr_closure_release(cb);
247
+ return;
248
+ }
249
+ if (rl->q_cb) scr_closure_release(rl->q_cb); /* re-ask replaces (Node) */
250
+ rl->q_cb = cb;
251
+ rl->q_fn = fn;
252
+ scr_rl_drain(rl); /* an already-buffered line answers immediately */
253
+ }
254
+
255
+ void scr_rl_close(double id) {
256
+ ScrRl *rl = scr_rl_find(id);
257
+ if (!rl) return;
258
+ scr_rl_settle_close(rl); /* twice is a no-op, like Node */
259
+ }
260
+
261
+ void scr_rl_on_close(double id, ScrClosure *cb /*moves*/) {
262
+ ScrRl *rl = scr_rl_find(id);
263
+ if (!rl || rl->closed) {
264
+ scr_closure_release(cb); /* after 'close' emitted: never fires */
265
+ return;
266
+ }
267
+ if (rl->n_close == rl->cap_close) {
268
+ rl->cap_close = rl->cap_close ? rl->cap_close * 2 : 2;
269
+ rl->close_cbs = realloc(rl->close_cbs, rl->cap_close * sizeof *rl->close_cbs);
270
+ if (!rl->close_cbs) scr_rl_oom();
271
+ }
272
+ rl->close_cbs[rl->n_close++] = cb;
273
+ }
274
+
275
+ /* ── the runtime-provided answer adapters ────────────────────────────── */
276
+
277
+ /* A zero-param question callback: the answer is ignored. */
278
+ void scr_rl_answer_thunk0(ScrClosure *cb, ScrStr *answer) {
279
+ scr_str_release(answer);
280
+ ((void (*)(ScrClosure *))cb->fn)(cb);
281
+ }
282
+
283
+ /* An (answer: string) callback — owns the +1 answer per the universal
284
+ * convention. */
285
+ void scr_rl_answer_thunk_str(ScrClosure *cb, ScrStr *answer) {
286
+ ((void (*)(ScrClosure *, ScrStr *))cb->fn)(cb, answer);
287
+ }