@scriptc/runtime 0.0.0 → 0.0.2

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 +5046 -0
  43. package/src/scr_stream.c +2877 -0
  44. package/src/scr_string.c +1264 -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
package/src/scr_dc.c ADDED
@@ -0,0 +1,805 @@
1
+ /* node:diagnostics_channel — the in-process pub/sub core (scr_runtime.h
2
+ * has the API contract). Linked only when the IR carries dc.* libCalls
3
+ * (cc.ts; the zlib gating precedent), pure data structure over the DOM —
4
+ * no loop hooks, no platform seams, cross-compiles everywhere.
5
+ *
6
+ * - The registry is process-global and append-only (Node's channels are
7
+ * process-lived too — its WeakRefMap only collects channels nothing
8
+ * references, which a compiled program cannot observe). Handles are
9
+ * 1-based indexes so a zeroed f64 can never alias channel 0.
10
+ * - Subscribers are DOM FUNCTION values. unsubscribe matches by the
11
+ * UNDERLYING closure when both sides are functions (boxing one function
12
+ * twice yields distinct ScrDyn nodes sharing one ScrClosure, and JS has
13
+ * ONE function object), falling back to node identity.
14
+ * - publish iterates a SNAPSHOT of the subscriber list: a subscriber
15
+ * unsubscribing itself mid-publish still lets its siblings fire (the
16
+ * test suite's sync-unsubscribe shape, Node's behavior). A subscriber's
17
+ * throw PROPAGATES out of publish — catchable there — where Node routes
18
+ * it to triggerUncaughtException (SEMANTICS.md divergence).
19
+ * - The atexit teardown releases names and subscribers before the RC
20
+ * audit runs (atexit is LIFO; scr_init registered the audit first), so
21
+ * registry-held values never count as leaks.
22
+ */
23
+ #include "scr_runtime.h"
24
+
25
+ #include <stdio.h>
26
+ #include <stdlib.h>
27
+ #include <string.h>
28
+
29
+ typedef struct {
30
+ double als_id; /* the bound AsyncLocalStorage handle */
31
+ ScrDyn *transform; /* owned FUNC, or NULL (identity — Node's default) */
32
+ } ScrDcBinding;
33
+
34
+ typedef struct {
35
+ ScrStr *name; /* owned */
36
+ ScrDyn **subs; /* owned entries */
37
+ size_t nsubs, cap;
38
+ /* bindStore entries: set semantics per store (a re-bind replaces the
39
+ * transform), entered around every publish that flows through
40
+ * runStores (and the tracing choreography's runStores points). */
41
+ ScrDcBinding *binds;
42
+ size_t nbinds, binds_cap;
43
+ } ScrDcChannel;
44
+
45
+ static ScrDcChannel *dc_channels = NULL;
46
+ static size_t dc_nchannels = 0, dc_cap = 0;
47
+ static bool dc_teardown_registered = false;
48
+
49
+ static void scr_dc_teardown(void) {
50
+ for (size_t i = 0; i < dc_nchannels; i++) {
51
+ ScrDcChannel *ch = &dc_channels[i];
52
+ scr_str_release(ch->name);
53
+ for (size_t j = 0; j < ch->nsubs; j++) scr_dyn_release(ch->subs[j]);
54
+ free(ch->subs);
55
+ for (size_t j = 0; j < ch->nbinds; j++) scr_dyn_release(ch->binds[j].transform);
56
+ free(ch->binds);
57
+ }
58
+ free(dc_channels);
59
+ dc_channels = NULL;
60
+ dc_nchannels = dc_cap = 0;
61
+ }
62
+
63
+ /* Get-or-create by name; returns the channel's index. Borrows name. */
64
+ static size_t dc_intern(ScrStr *name) {
65
+ for (size_t i = 0; i < dc_nchannels; i++) {
66
+ if (scr_str_eq(dc_channels[i].name, name)) return i;
67
+ }
68
+ if (dc_nchannels == dc_cap) {
69
+ dc_cap = dc_cap ? dc_cap * 2 : 8;
70
+ dc_channels = realloc(dc_channels, dc_cap * sizeof *dc_channels);
71
+ if (!dc_channels) {
72
+ fputs("scriptc: out of memory\n", stderr);
73
+ abort();
74
+ }
75
+ }
76
+ if (!dc_teardown_registered) {
77
+ dc_teardown_registered = true;
78
+ atexit(scr_dc_teardown);
79
+ }
80
+ ScrDcChannel *ch = &dc_channels[dc_nchannels];
81
+ ch->name = scr_str_retain(name);
82
+ ch->subs = NULL;
83
+ ch->nsubs = ch->cap = 0;
84
+ ch->binds = NULL;
85
+ ch->nbinds = ch->binds_cap = 0;
86
+ return dc_nchannels++;
87
+ }
88
+
89
+ static ScrDcChannel *dc_of(double handle) {
90
+ size_t i = (size_t)handle;
91
+ if (i < 1 || i > dc_nchannels) {
92
+ /* Compiled code can only hold handles dc_intern minted — anything
93
+ * else is a compiler bug, never user-reachable. */
94
+ fputs("scriptc: invalid diagnostics_channel handle\n", stderr);
95
+ abort();
96
+ }
97
+ return &dc_channels[i - 1];
98
+ }
99
+
100
+ /* Node's ERR_INVALID_ARG_TYPE for a non-function subscriber — the
101
+ * "Received ..." tail covers the DOM kinds (determineSpecificType lite;
102
+ * scr_dyn_handle.c's full renderer is not linked here). */
103
+ static void dc_throw_bad_fn_arg(const ScrDyn *cb, const char *arg_name) {
104
+ const char *received = "an instance of Object";
105
+ char detail[64];
106
+ if (cb == NULL) {
107
+ received = "undefined";
108
+ char buf[160];
109
+ int n = snprintf(buf, sizeof buf, "The \"%s\" argument must be of type function. Received %s",
110
+ arg_name, received);
111
+ scr_throw_error_msg_code(SCR_ERR_TYPE, buf, (size_t)n, "ERR_INVALID_ARG_TYPE");
112
+ return;
113
+ }
114
+ switch (cb->kind) {
115
+ case SCR_DYN_NULL: received = "null"; break;
116
+ case SCR_DYN_UNDEF: received = "undefined"; break;
117
+ case SCR_DYN_ARR: received = "an instance of Array"; break;
118
+ case SCR_DYN_BYTES: received = "an instance of Uint8Array"; break;
119
+ case SCR_DYN_BOOL:
120
+ snprintf(detail, sizeof detail, "type boolean (%s)", cb->v.b ? "true" : "false");
121
+ received = detail;
122
+ break;
123
+ case SCR_DYN_NUM: {
124
+ char num[32];
125
+ size_t n = scr_f64_to_str(cb->v.num, num);
126
+ snprintf(detail, sizeof detail, "type number (%.*s)", (int)n, num);
127
+ received = detail;
128
+ break;
129
+ }
130
+ case SCR_DYN_STR:
131
+ snprintf(detail, sizeof detail, "type string ('%.*s')",
132
+ (int)(cb->v.str->len < 28 ? cb->v.str->len : 28), cb->v.str->data);
133
+ received = detail;
134
+ break;
135
+ default: break;
136
+ }
137
+ char buf[160];
138
+ int n = snprintf(buf, sizeof buf,
139
+ "The \"%s\" argument must be of type function. Received %s",
140
+ arg_name, received);
141
+ scr_throw_error_msg_code(SCR_ERR_TYPE, buf, (size_t)n, "ERR_INVALID_ARG_TYPE");
142
+ }
143
+
144
+ static void dc_throw_bad_subscriber(const ScrDyn *cb) {
145
+ dc_throw_bad_fn_arg(cb, "subscription");
146
+ }
147
+
148
+ /* Subscriber identity: the underlying closure for FUNC pairs, node
149
+ * identity otherwise. */
150
+ static bool dc_sub_matches(const ScrDyn *a, const ScrDyn *b) {
151
+ if (a == b) return true;
152
+ return a->kind == SCR_DYN_FUNC && b->kind == SCR_DYN_FUNC && a->v.fn.clo == b->v.fn.clo;
153
+ }
154
+
155
+ static void dc_sub_add(ScrDcChannel *ch, ScrDyn *cb) {
156
+ if (ch->nsubs == ch->cap) {
157
+ ch->cap = ch->cap ? ch->cap * 2 : 4;
158
+ ch->subs = realloc(ch->subs, ch->cap * sizeof *ch->subs);
159
+ if (!ch->subs) {
160
+ fputs("scriptc: out of memory\n", stderr);
161
+ abort();
162
+ }
163
+ }
164
+ ch->subs[ch->nsubs++] = scr_dyn_retain(cb);
165
+ }
166
+
167
+ static bool dc_sub_remove(ScrDcChannel *ch, const ScrDyn *cb) {
168
+ for (size_t i = 0; i < ch->nsubs; i++) {
169
+ if (dc_sub_matches(ch->subs[i], cb)) {
170
+ scr_dyn_release(ch->subs[i]);
171
+ memmove(ch->subs + i, ch->subs + i + 1, (ch->nsubs - i - 1) * sizeof *ch->subs);
172
+ ch->nsubs--;
173
+ return true;
174
+ }
175
+ }
176
+ return false;
177
+ }
178
+
179
+ double scr_dc_channel(ScrStr *name) { return (double)(dc_intern(name) + 1); }
180
+
181
+ void scr_dc_chan_subscribe(double handle, ScrDyn *cb) {
182
+ if (cb->kind != SCR_DYN_FUNC) {
183
+ dc_throw_bad_subscriber(cb);
184
+ return;
185
+ }
186
+ dc_sub_add(dc_of(handle), cb);
187
+ }
188
+
189
+ bool scr_dc_chan_unsubscribe(double handle, ScrDyn *cb) {
190
+ if (cb->kind != SCR_DYN_FUNC) {
191
+ dc_throw_bad_subscriber(cb);
192
+ return false;
193
+ }
194
+ return dc_sub_remove(dc_of(handle), cb);
195
+ }
196
+
197
+ /* Node's Channel is ACTIVE with subscribers OR bound stores (bindStore
198
+ * marks active through the same prototype swap subscribe uses), and
199
+ * hasSubscribers answers activeness — so the tracing early exits keep
200
+ * running the store choreography for subscriber-less bound channels. */
201
+ static bool dc_chan_active(const ScrDcChannel *ch) { return ch->nsubs > 0 || ch->nbinds > 0; }
202
+
203
+ bool scr_dc_chan_has_subscribers(double handle) { return dc_chan_active(dc_of(handle)); }
204
+
205
+ ScrStr *scr_dc_chan_name(double handle) { return scr_str_retain(dc_of(handle)->name); }
206
+
207
+ void scr_dc_subscribe(ScrStr *name, ScrDyn *cb) {
208
+ scr_dc_chan_subscribe((double)(dc_intern(name) + 1), cb);
209
+ }
210
+
211
+ bool scr_dc_unsubscribe(ScrStr *name, ScrDyn *cb) {
212
+ /* Node's module-level unsubscribe of a never-created channel answers
213
+ * false without creating it; matching an existing list needs no
214
+ * creation either — probe without interning. */
215
+ if (cb->kind != SCR_DYN_FUNC) {
216
+ dc_throw_bad_subscriber(cb);
217
+ return false;
218
+ }
219
+ for (size_t i = 0; i < dc_nchannels; i++) {
220
+ if (scr_str_eq(dc_channels[i].name, name)) return dc_sub_remove(&dc_channels[i], cb);
221
+ }
222
+ return false;
223
+ }
224
+
225
+ bool scr_dc_has_subscribers(ScrStr *name) {
226
+ for (size_t i = 0; i < dc_nchannels; i++) {
227
+ if (scr_str_eq(dc_channels[i].name, name)) return dc_chan_active(&dc_channels[i]);
228
+ }
229
+ return false;
230
+ }
231
+
232
+ /* ── bindStore / runStores (the AsyncLocalStorage integration) ─────────
233
+ * bindStore is per-store SET semantics (a re-bind replaces the
234
+ * transform); runStores enters every bound store with transform(data)
235
+ * (identity without a transform), publishes INSIDE the entered contexts
236
+ * (subscribers observe getStore(), Node's shape), runs fn with thisArg
237
+ * bound and the arguments forwarded, and restores in reverse — the
238
+ * finally, so a throw still restores. A transform throw propagates
239
+ * (Node defers it to reportError and skips the store — SEMANTICS.md). */
240
+
241
+ void scr_dc_chan_bind_store(double handle, double als_id, ScrDyn *transform) {
242
+ ScrDcChannel *ch = dc_of(handle);
243
+ ScrDyn *t = (transform != NULL && transform->kind == SCR_DYN_FUNC)
244
+ ? scr_dyn_retain(transform)
245
+ : NULL;
246
+ for (size_t i = 0; i < ch->nbinds; i++) {
247
+ if (ch->binds[i].als_id == als_id) {
248
+ scr_dyn_release(ch->binds[i].transform);
249
+ ch->binds[i].transform = t;
250
+ return;
251
+ }
252
+ }
253
+ if (ch->nbinds == ch->binds_cap) {
254
+ ch->binds_cap = ch->binds_cap ? ch->binds_cap * 2 : 4;
255
+ ch->binds = realloc(ch->binds, ch->binds_cap * sizeof *ch->binds);
256
+ if (!ch->binds) {
257
+ fputs("scriptc: out of memory\n", stderr);
258
+ abort();
259
+ }
260
+ }
261
+ ch->binds[ch->nbinds].als_id = als_id;
262
+ ch->binds[ch->nbinds].transform = t;
263
+ ch->nbinds++;
264
+ }
265
+
266
+ bool scr_dc_chan_unbind_store(double handle, double als_id) {
267
+ ScrDcChannel *ch = dc_of(handle);
268
+ for (size_t i = 0; i < ch->nbinds; i++) {
269
+ if (ch->binds[i].als_id == als_id) {
270
+ scr_dyn_release(ch->binds[i].transform);
271
+ memmove(ch->binds + i, ch->binds + i + 1, (ch->nbinds - i - 1) * sizeof *ch->binds);
272
+ ch->nbinds--;
273
+ return true;
274
+ }
275
+ }
276
+ return false;
277
+ }
278
+
279
+ /* Enter every bound store (transform(data) or data itself); the returned
280
+ * malloc'd array of PREVIOUS snapshots restores in reverse. On a
281
+ * transform throw the already-entered stores restore here and the
282
+ * exception stays pending (*n_out counts the entered prefix). */
283
+ static ScrAlsCtx **dc_stores_enter(ScrDcChannel *ch, ScrDyn *data, size_t *n_out) {
284
+ *n_out = 0;
285
+ if (ch->nbinds == 0) return NULL;
286
+ ScrAlsCtx **prevs = malloc(ch->nbinds * sizeof *prevs);
287
+ if (!prevs) {
288
+ fputs("scriptc: out of memory\n", stderr);
289
+ abort();
290
+ }
291
+ for (size_t i = 0; i < ch->nbinds; i++) {
292
+ ScrDyn *value;
293
+ if (ch->binds[i].transform != NULL) {
294
+ ScrDyn *args[1] = {data};
295
+ value = scr_dyn_call(ch->binds[i].transform, args, 1, "transform");
296
+ if (value == NULL) return prevs; /* pending; entered prefix restores */
297
+ } else {
298
+ value = scr_dyn_retain(data);
299
+ }
300
+ prevs[i] = scr_als_enter(ch->binds[i].als_id, value);
301
+ scr_dyn_release(value);
302
+ (*n_out)++;
303
+ }
304
+ return prevs;
305
+ }
306
+
307
+ static void dc_stores_restore(ScrAlsCtx **prevs, size_t n) {
308
+ if (prevs == NULL) return;
309
+ for (size_t i = n; i > 0; i--) scr_als_restore(prevs[i - 1]);
310
+ free(prevs);
311
+ }
312
+
313
+ ScrDyn *scr_dc_chan_run_stores(double handle, ScrDyn *data, ScrDyn *fn, ScrDyn *this_arg,
314
+ ScrDyn *args) {
315
+ ScrDcChannel *ch = dc_of(handle);
316
+ size_t entered = 0;
317
+ ScrAlsCtx **prevs = dc_stores_enter(ch, data, &entered);
318
+ if (scr_exc_pending()) {
319
+ dc_stores_restore(prevs, entered);
320
+ return NULL;
321
+ }
322
+ scr_dc_publish(handle, data);
323
+ ScrDyn *r = NULL;
324
+ if (!scr_exc_pending()) {
325
+ size_t argc = args->kind == SCR_DYN_ARR ? args->v.arr.len : 0;
326
+ ScrDyn *const *items = args->kind == SCR_DYN_ARR ? args->v.arr.items : NULL;
327
+ scr_dyn_this_push_dyn(this_arg);
328
+ r = scr_dyn_call(fn, items, argc, "runStores");
329
+ scr_dyn_this_pop();
330
+ }
331
+ dc_stores_restore(prevs, entered);
332
+ return r;
333
+ }
334
+
335
+ /* ── TracingChannel ────────────────────────────────────────────────────
336
+ * A registry entry of five channel indexes (start/end/asyncStart/asyncEnd/
337
+ * error), handled as a 1-based f64 like Channel. The trace choreography
338
+ * lives here in C over the DOM: publishes stash the pending traced-call /
339
+ * subscriber exception in a ScrCaught box first (compiled subscriber
340
+ * bodies run with a CLEAR cell — a pending flag would unwind them at
341
+ * their first call) and re-raise after, so throws propagate exactly like
342
+ * scr_dc_publish's documented divergence. */
343
+
344
+ typedef struct {
345
+ size_t ch[5]; /* dc_channels indexes: start, end, asyncStart, asyncEnd, error */
346
+ } ScrDcTracing;
347
+
348
+ enum { DC_TC_START, DC_TC_END, DC_TC_ASYNC_START, DC_TC_ASYNC_END, DC_TC_ERROR };
349
+
350
+ static const char *const dc_trace_events[5] = {"start", "end", "asyncStart", "asyncEnd", "error"};
351
+
352
+ static ScrDcTracing *dc_tracings = NULL;
353
+ static size_t dc_ntracings = 0, dc_tracings_cap = 0;
354
+ static bool dc_tracings_teardown_registered = false;
355
+
356
+ static void scr_dc_tracings_teardown(void) {
357
+ free(dc_tracings);
358
+ dc_tracings = NULL;
359
+ dc_ntracings = dc_tracings_cap = 0;
360
+ }
361
+
362
+ static double dc_tracing_register(const size_t ch[5]) {
363
+ if (dc_ntracings == dc_tracings_cap) {
364
+ dc_tracings_cap = dc_tracings_cap ? dc_tracings_cap * 2 : 4;
365
+ dc_tracings = realloc(dc_tracings, dc_tracings_cap * sizeof *dc_tracings);
366
+ if (!dc_tracings) {
367
+ fputs("scriptc: out of memory\n", stderr);
368
+ abort();
369
+ }
370
+ }
371
+ if (!dc_tracings_teardown_registered) {
372
+ dc_tracings_teardown_registered = true;
373
+ atexit(scr_dc_tracings_teardown);
374
+ }
375
+ for (size_t i = 0; i < 5; i++) dc_tracings[dc_ntracings].ch[i] = ch[i];
376
+ dc_ntracings++;
377
+ return (double)dc_ntracings;
378
+ }
379
+
380
+ static ScrDcTracing *dc_tc_of(double handle) {
381
+ size_t i = (size_t)handle;
382
+ if (i < 1 || i > dc_ntracings) {
383
+ fputs("scriptc: invalid tracingChannel handle\n", stderr);
384
+ abort();
385
+ }
386
+ return &dc_tracings[i - 1];
387
+ }
388
+
389
+ double scr_dc_tracing_channel(ScrStr *name) {
390
+ size_t ch[5];
391
+ for (size_t i = 0; i < 5; i++) {
392
+ /* "tracing:<name>:<event>" */
393
+ size_t evlen = strlen(dc_trace_events[i]);
394
+ size_t len = 8 + name->len + 1 + evlen;
395
+ char *buf = malloc(len + 1);
396
+ if (!buf) {
397
+ fputs("scriptc: out of memory\n", stderr);
398
+ abort();
399
+ }
400
+ memcpy(buf, "tracing:", 8);
401
+ memcpy(buf + 8, name->data, name->len);
402
+ buf[8 + name->len] = ':';
403
+ memcpy(buf + 8 + name->len + 1, dc_trace_events[i], evlen);
404
+ buf[len] = '\0';
405
+ ScrStr *s = scr_str_new(buf, len);
406
+ free(buf);
407
+ ch[i] = dc_intern(s);
408
+ scr_str_release(s);
409
+ }
410
+ return dc_tracing_register(ch);
411
+ }
412
+
413
+ double scr_dc_tracing_channel_of(double start, double end, double async_start,
414
+ double async_end, double error) {
415
+ size_t ch[5];
416
+ /* dc_of validates each handle (compiled code only holds minted ones). */
417
+ ch[DC_TC_START] = (size_t)(dc_of(start) - dc_channels);
418
+ ch[DC_TC_END] = (size_t)(dc_of(end) - dc_channels);
419
+ ch[DC_TC_ASYNC_START] = (size_t)(dc_of(async_start) - dc_channels);
420
+ ch[DC_TC_ASYNC_END] = (size_t)(dc_of(async_end) - dc_channels);
421
+ ch[DC_TC_ERROR] = (size_t)(dc_of(error) - dc_channels);
422
+ return dc_tracing_register(ch);
423
+ }
424
+
425
+ double scr_dc_tc_channel(double h, double idx) {
426
+ ScrDcTracing *tc = dc_tc_of(h);
427
+ size_t i = (size_t)idx;
428
+ if (i > 4) {
429
+ fputs("scriptc: invalid tracingChannel event index\n", stderr);
430
+ abort();
431
+ }
432
+ return (double)(tc->ch[i] + 1);
433
+ }
434
+
435
+ bool scr_dc_tc_has_subscribers(double h) {
436
+ ScrDcTracing *tc = dc_tc_of(h);
437
+ for (size_t i = 0; i < 5; i++) {
438
+ if (dc_chan_active(&dc_channels[tc->ch[i]])) return true;
439
+ }
440
+ return false;
441
+ }
442
+
443
+ void scr_dc_tc_subscribe(double h, ScrDyn *handlers) {
444
+ ScrDcTracing *tc = dc_tc_of(h);
445
+ for (size_t i = 0; i < 5; i++) {
446
+ ScrDyn *cb = scr_dyn_obj_get(handlers, dc_trace_events[i], strlen(dc_trace_events[i]));
447
+ if (cb == NULL || !scr_dyn_truthy(cb)) continue; /* falsy slots skip, Node */
448
+ scr_dc_chan_subscribe((double)(tc->ch[i] + 1), cb);
449
+ if (scr_exc_pending()) return; /* a non-function slot threw */
450
+ }
451
+ }
452
+
453
+ bool scr_dc_tc_unsubscribe(double h, ScrDyn *handlers) {
454
+ ScrDcTracing *tc = dc_tc_of(h);
455
+ bool done = true;
456
+ for (size_t i = 0; i < 5; i++) {
457
+ ScrDyn *cb = scr_dyn_obj_get(handlers, dc_trace_events[i], strlen(dc_trace_events[i]));
458
+ if (cb == NULL || !scr_dyn_truthy(cb)) continue;
459
+ if (!scr_dc_chan_unsubscribe((double)(tc->ch[i] + 1), cb)) done = false;
460
+ if (scr_exc_pending()) return false;
461
+ }
462
+ return done;
463
+ }
464
+
465
+ /* The pending exception as a DOM value for ctx.error: scr_caught_to_dyn
466
+ * (scr_json.c) — identity-preserving for DOM payloads and %Error
467
+ * instances (the identity-cached crossing: the stamped ctx.error compares
468
+ * reference-equal to the thrown error's other boxings). */
469
+
470
+ /* publish while an exception snapshot is parked: the cell is already
471
+ * clear (scr_exc_take), subscribers run normally; a SUBSCRIBER throw
472
+ * replaces the parked one (JS's finally-throw rule) — the caller checks
473
+ * pending after. */
474
+ static void dc_tc_publish(ScrDcTracing *tc, int ev, ScrDyn *ctx) {
475
+ scr_dc_publish((double)(tc->ch[ev] + 1), ctx);
476
+ }
477
+
478
+ /* The traced call: thisArg bound as the ambient receiver. Result +1 or
479
+ * NULL with the exception pending. */
480
+ static ScrDyn *dc_tc_apply(ScrDyn *fn, ScrDyn *this_arg, ScrDyn *const *items, size_t n,
481
+ const char *what) {
482
+ scr_dyn_this_push_dyn(this_arg);
483
+ ScrDyn *r = scr_dyn_call(fn, items, n, what);
484
+ scr_dyn_this_pop();
485
+ return r;
486
+ }
487
+
488
+ /* The choreography body, run inside the start channel's entered stores
489
+ * (start.runStores — Node wraps the WHOLE body: the start publish, the
490
+ * traced call, and the finally end publish). */
491
+ static ScrDyn *dc_tc_trace_sync_body(ScrDcTracing *tc, ScrDyn *fn, ScrDyn *ctx,
492
+ ScrDyn *this_arg, ScrDyn *const *items, size_t argc) {
493
+ dc_tc_publish(tc, DC_TC_START, ctx);
494
+ if (scr_exc_pending()) return NULL;
495
+ ScrDyn *r = dc_tc_apply(fn, this_arg, items, argc, "traceSync");
496
+ if (r == NULL) {
497
+ /* context.error = err; error.publish; end.publish (finally); rethrow */
498
+ ScrCaught *c = scr_exc_take();
499
+ if (ctx->kind == SCR_DYN_OBJ) scr_dyn_obj_set(ctx, "error", 5, scr_caught_to_dyn(c));
500
+ dc_tc_publish(tc, DC_TC_ERROR, ctx);
501
+ if (!scr_exc_pending()) dc_tc_publish(tc, DC_TC_END, ctx);
502
+ if (!scr_exc_pending()) scr_rethrow(c);
503
+ scr_caught_release(c);
504
+ return NULL;
505
+ }
506
+ /* context.result = result; end.publish (finally); return result */
507
+ if (ctx->kind == SCR_DYN_OBJ) scr_dyn_obj_set(ctx, "result", 6, scr_dyn_retain(r));
508
+ dc_tc_publish(tc, DC_TC_END, ctx);
509
+ if (scr_exc_pending()) {
510
+ scr_dyn_release(r);
511
+ return NULL;
512
+ }
513
+ return r;
514
+ }
515
+
516
+ ScrDyn *scr_dc_tc_trace_sync(double h, ScrDyn *fn, ScrDyn *ctx, ScrDyn *this_arg, ScrDyn *args) {
517
+ ScrDcTracing *tc = dc_tc_of(h);
518
+ size_t argc = args->kind == SCR_DYN_ARR ? args->v.arr.len : 0;
519
+ ScrDyn *const *items = args->kind == SCR_DYN_ARR ? args->v.arr.items : NULL;
520
+ if (!scr_dc_tc_has_subscribers(h)) {
521
+ return dc_tc_apply(fn, this_arg, items, argc, "traceSync");
522
+ }
523
+ /* start.runStores: the body runs inside the start channel's stores. */
524
+ size_t entered = 0;
525
+ ScrAlsCtx **prevs = dc_stores_enter(&dc_channels[tc->ch[DC_TC_START]], ctx, &entered);
526
+ ScrDyn *r = scr_exc_pending() ? NULL
527
+ : dc_tc_trace_sync_body(tc, fn, ctx, this_arg, items, argc);
528
+ dc_stores_restore(prevs, entered);
529
+ return r;
530
+ }
531
+
532
+ /* ── tracePromise ──────────────────────────────────────────────────────
533
+ * Node's choreography: start.runStores(ctx, body) where body calls the
534
+ * traced fn, wraps a non-promise result in a resolved promise, registers
535
+ * the resolve/reject reactions, and publishes end in the finally. The
536
+ * reactions run one microtask later: resolve stamps ctx.result and
537
+ * publishes asyncStart + asyncEnd (plain publishes — promises have no
538
+ * "after" point for a runStores, Node's comment); reject stamps
539
+ * ctx.error, publishes error then asyncStart + asyncEnd, and passes the
540
+ * rejection through. The returned promise is the REACTION's (a rejection
541
+ * nobody observes is the unhandled one, exactly Node's then-chain). A
542
+ * reaction fiber gives the microtask ordering for free. */
543
+ typedef struct {
544
+ ScrPromise *src, *dst; /* owned */
545
+ double h;
546
+ ScrDyn *ctx; /* owned */
547
+ } DcTracePromisePack;
548
+
549
+ static void dc_tp_entry(ScrFiber *self, void *ap) {
550
+ (void)self;
551
+ DcTracePromisePack *a = (DcTracePromisePack *)ap;
552
+ ScrDcTracing *tc = dc_tc_of(a->h);
553
+ ScrDyn *v = scr_await_dyn(a->src);
554
+ if (scr_exc_pending()) {
555
+ ScrCaught *c = scr_exc_take();
556
+ if (a->ctx->kind == SCR_DYN_OBJ) scr_dyn_obj_set(a->ctx, "error", 5, scr_caught_to_dyn(c));
557
+ dc_tc_publish(tc, DC_TC_ERROR, a->ctx);
558
+ if (!scr_exc_pending()) dc_tc_publish(tc, DC_TC_ASYNC_START, a->ctx);
559
+ if (!scr_exc_pending()) dc_tc_publish(tc, DC_TC_ASYNC_END, a->ctx);
560
+ /* A subscriber throw replaced the parked rejection (the finally-throw
561
+ * rule; Node routes it to triggerUncaughtException) — either way the
562
+ * pending exception is what dst rejects with. */
563
+ if (!scr_exc_pending()) scr_rethrow(c);
564
+ scr_promise_reject_pending(a->dst);
565
+ scr_caught_release(c);
566
+ } else {
567
+ if (a->ctx->kind == SCR_DYN_OBJ) scr_dyn_obj_set(a->ctx, "result", 6, scr_dyn_retain(v));
568
+ dc_tc_publish(tc, DC_TC_ASYNC_START, a->ctx);
569
+ if (!scr_exc_pending()) dc_tc_publish(tc, DC_TC_ASYNC_END, a->ctx);
570
+ if (scr_exc_pending()) {
571
+ scr_promise_reject_pending(a->dst); /* the subscriber throw */
572
+ scr_dyn_release(v);
573
+ } else {
574
+ scr_promise_fulfill_ref(a->dst, v, scr_dyn_retain_v, scr_dyn_release_v, NULL);
575
+ }
576
+ }
577
+ scr_dyn_release(a->ctx);
578
+ scr_promise_release(a->src);
579
+ scr_promise_release(a->dst);
580
+ free(a);
581
+ }
582
+
583
+ /* The traced result as a promise (+1): a DOM promise unwraps, anything
584
+ * else is PromiseResolve'd (Node converts non-promise returns; a raw
585
+ * non-promise return on the NO-SUBSCRIBER path wraps too — the lowering
586
+ * types the result Promise<unknown>, a wrap Node skips, SEMANTICS.md). */
587
+ static ScrPromise *dc_tp_promise_of(ScrDyn *r) {
588
+ ScrPromise *p = scr_dyn_promise_of(r);
589
+ if (p != NULL) return scr_promise_retain(p);
590
+ ScrPromise *fresh = scr_promise_new();
591
+ scr_promise_fulfill_ref(fresh, scr_dyn_retain(r), scr_dyn_retain_v, scr_dyn_release_v, NULL);
592
+ return fresh;
593
+ }
594
+
595
+ ScrPromise *scr_dc_tc_trace_promise(double h, ScrDyn *fn, ScrDyn *ctx, ScrDyn *this_arg,
596
+ ScrDyn *args) {
597
+ ScrDcTracing *tc = dc_tc_of(h);
598
+ size_t argc = args->kind == SCR_DYN_ARR ? args->v.arr.len : 0;
599
+ ScrDyn *const *items = args->kind == SCR_DYN_ARR ? args->v.arr.items : NULL;
600
+ if (!scr_dc_tc_has_subscribers(h)) {
601
+ ScrDyn *r = dc_tc_apply(fn, this_arg, items, argc, "tracePromise");
602
+ if (r == NULL) return NULL;
603
+ ScrPromise *p = dc_tp_promise_of(r);
604
+ scr_dyn_release(r);
605
+ return p;
606
+ }
607
+ /* start.runStores: the start publish, the traced call, the reaction
608
+ * registration, and the finally end publish run inside the start
609
+ * channel's entered stores — the traced async body's fiber INHERITS
610
+ * them at spawn, so getStore() inside the traced function answers
611
+ * across its awaits (the run-stores suite's shape). The reactions
612
+ * publish OUTSIDE any store (promises have no "after" runStores point,
613
+ * Node's comment). */
614
+ size_t entered = 0;
615
+ ScrAlsCtx **prevs = dc_stores_enter(&dc_channels[tc->ch[DC_TC_START]], ctx, &entered);
616
+ ScrPromise *out = NULL;
617
+ if (!scr_exc_pending()) {
618
+ dc_tc_publish(tc, DC_TC_START, ctx);
619
+ if (!scr_exc_pending()) {
620
+ ScrDyn *r = dc_tc_apply(fn, this_arg, items, argc, "tracePromise");
621
+ if (r == NULL) {
622
+ /* ctx.error = err; error.publish; end.publish (finally); rethrow */
623
+ ScrCaught *c = scr_exc_take();
624
+ if (ctx->kind == SCR_DYN_OBJ) scr_dyn_obj_set(ctx, "error", 5, scr_caught_to_dyn(c));
625
+ dc_tc_publish(tc, DC_TC_ERROR, ctx);
626
+ if (!scr_exc_pending()) dc_tc_publish(tc, DC_TC_END, ctx);
627
+ if (!scr_exc_pending()) scr_rethrow(c);
628
+ scr_caught_release(c);
629
+ } else {
630
+ ScrPromise *src = dc_tp_promise_of(r);
631
+ scr_dyn_release(r);
632
+ DcTracePromisePack *a = malloc(sizeof *a);
633
+ if (!a) {
634
+ fputs("scriptc: out of memory\n", stderr);
635
+ abort();
636
+ }
637
+ a->src = src; /* the +1 moves in */
638
+ a->dst = scr_promise_new();
639
+ a->h = h;
640
+ a->ctx = scr_dyn_retain(ctx);
641
+ out = scr_promise_retain(a->dst);
642
+ ScrPromise *waiter = scr_async_spawn(dc_tp_entry, a);
643
+ scr_promise_release(waiter); /* the entry never rejects; nobody awaits it */
644
+ dc_tc_publish(tc, DC_TC_END, ctx); /* finally */
645
+ if (scr_exc_pending()) {
646
+ scr_promise_release(out);
647
+ out = NULL;
648
+ }
649
+ }
650
+ }
651
+ }
652
+ dc_stores_restore(prevs, entered);
653
+ return out;
654
+ }
655
+
656
+ /* traceCallback's wrapped callback: caps[0] = the tracing handle (f64),
657
+ * caps[1] = ctx (dyn), caps[2] = the original callback (dyn). Publishes
658
+ * error/result off the (err, res) convention, then asyncStart, runs the
659
+ * original with the ambient receiver and ALL arguments forwarded, then
660
+ * asyncEnd (finally — also on a callback throw). */
661
+ static ScrDyn *dc_tc_wrapped_cb(ScrClosure *clo, ScrDyn *const *cbargs, size_t cbargc) {
662
+ double h = scr_box_get_f64(clo->caps[0]);
663
+ ScrDcTracing *tc = dc_tc_of(h);
664
+ ScrDyn *ctx = scr_box_get_ref(clo->caps[1]);
665
+ ScrDyn *cb = scr_box_get_ref(clo->caps[2]);
666
+ ScrDyn *err = cbargc >= 1 ? cbargs[0] : NULL;
667
+ if (err != NULL && scr_dyn_truthy(err)) {
668
+ if (ctx->kind == SCR_DYN_OBJ) scr_dyn_obj_set(ctx, "error", 5, scr_dyn_retain(err));
669
+ dc_tc_publish(tc, DC_TC_ERROR, ctx);
670
+ } else if (ctx->kind == SCR_DYN_OBJ) {
671
+ ScrDyn *res = cbargc >= 2 ? scr_dyn_retain(cbargs[1]) : scr_dyn_undefined();
672
+ scr_dyn_obj_set(ctx, "result", 6, res);
673
+ }
674
+ ScrDyn *r = NULL;
675
+ if (!scr_exc_pending()) {
676
+ /* asyncStart.runStores: the asyncStart publish, the original
677
+ * callback, and the finally asyncEnd all run inside the asyncStart
678
+ * channel's entered stores (Node's manual context-recovery point). */
679
+ size_t entered = 0;
680
+ ScrAlsCtx **prevs = dc_stores_enter(&dc_channels[tc->ch[DC_TC_ASYNC_START]], ctx, &entered);
681
+ if (!scr_exc_pending()) dc_tc_publish(tc, DC_TC_ASYNC_START, ctx);
682
+ if (!scr_exc_pending()) {
683
+ ScrDyn *this_arg = scr_dyn_this_get();
684
+ scr_dyn_this_push_dyn(this_arg);
685
+ r = scr_dyn_call(cb, cbargs, cbargc, "callback");
686
+ scr_dyn_this_pop();
687
+ scr_dyn_release(this_arg);
688
+ /* finally: asyncEnd fires on the throw path too, exception parked */
689
+ if (r == NULL) {
690
+ ScrCaught *c = scr_exc_take();
691
+ dc_tc_publish(tc, DC_TC_ASYNC_END, ctx);
692
+ if (!scr_exc_pending()) scr_rethrow(c);
693
+ scr_caught_release(c);
694
+ } else {
695
+ dc_tc_publish(tc, DC_TC_ASYNC_END, ctx);
696
+ if (scr_exc_pending()) {
697
+ scr_dyn_release(r);
698
+ r = NULL;
699
+ }
700
+ }
701
+ }
702
+ dc_stores_restore(prevs, entered);
703
+ }
704
+ scr_dyn_release(ctx);
705
+ scr_dyn_release(cb);
706
+ return r;
707
+ }
708
+
709
+ ScrDyn *scr_dc_tc_trace_callback(double h, ScrDyn *fn, double position, ScrDyn *ctx,
710
+ ScrDyn *this_arg, ScrDyn *args) {
711
+ ScrDcTracing *tc = dc_tc_of(h);
712
+ size_t argc = args->kind == SCR_DYN_ARR ? args->v.arr.len : 0;
713
+ ScrDyn *const *items = args->kind == SCR_DYN_ARR ? args->v.arr.items : NULL;
714
+ if (!scr_dc_tc_has_subscribers(h)) {
715
+ return dc_tc_apply(fn, this_arg, items, argc, "traceCallback");
716
+ }
717
+ /* args.at(position), JS-style negative indexing */
718
+ double pos = position < 0 ? (double)argc + position : position;
719
+ size_t idx = (size_t)pos;
720
+ ScrDyn *cb = (pos >= 0 && idx < argc) ? items[idx] : NULL;
721
+ if (cb == NULL || cb->kind != SCR_DYN_FUNC) {
722
+ dc_throw_bad_fn_arg(cb, "callback");
723
+ return NULL;
724
+ }
725
+ /* Splice the wrapper in (a fresh argument vector; the DOM array is
726
+ * borrowed and Node's splice mutation is unobservable through it — the
727
+ * caller rebuilt it from the call site's arguments). */
728
+ ScrClosure *clo = scr_closure_new((void *)dc_tc_wrapped_cb, 3);
729
+ clo->caps[0] = scr_box_new(SCR_BOX_F64);
730
+ scr_box_set_f64(clo->caps[0], h);
731
+ clo->caps[1] = scr_box_new_obj(scr_dyn_retain_v, scr_dyn_release_v, NULL);
732
+ scr_box_set_ref(clo->caps[1], scr_dyn_retain(ctx));
733
+ clo->caps[2] = scr_box_new_obj(scr_dyn_retain_v, scr_dyn_release_v, NULL);
734
+ scr_box_set_ref(clo->caps[2], scr_dyn_retain(cb));
735
+ ScrDyn *wrapped = scr_dyn_new_func(clo, dc_tc_wrapped_cb, 2, "(err,res)", "wrappedCallback");
736
+ ScrDyn **call_items = NULL;
737
+ if (argc > 0) {
738
+ call_items = malloc(argc * sizeof *call_items);
739
+ if (!call_items) {
740
+ fputs("scriptc: out of memory\n", stderr);
741
+ abort();
742
+ }
743
+ for (size_t i = 0; i < argc; i++) call_items[i] = i == idx ? wrapped : items[i];
744
+ }
745
+ /* start.runStores: the start publish, the traced call, and the finally
746
+ * end publish run inside the start channel's entered stores. */
747
+ size_t entered = 0;
748
+ ScrAlsCtx **prevs = dc_stores_enter(&dc_channels[tc->ch[DC_TC_START]], ctx, &entered);
749
+ ScrDyn *r = NULL;
750
+ if (!scr_exc_pending()) {
751
+ dc_tc_publish(tc, DC_TC_START, ctx);
752
+ if (!scr_exc_pending()) {
753
+ r = dc_tc_apply(fn, this_arg, call_items, argc, "traceCallback");
754
+ if (r == NULL) {
755
+ ScrCaught *c = scr_exc_take();
756
+ if (ctx->kind == SCR_DYN_OBJ) scr_dyn_obj_set(ctx, "error", 5, scr_caught_to_dyn(c));
757
+ dc_tc_publish(tc, DC_TC_ERROR, ctx);
758
+ if (!scr_exc_pending()) dc_tc_publish(tc, DC_TC_END, ctx);
759
+ if (!scr_exc_pending()) scr_rethrow(c);
760
+ scr_caught_release(c);
761
+ } else {
762
+ /* No result stamping here — the traced fn's return value is not the
763
+ * traced RESULT (the callback's res is; wrappedCallback stamps it). */
764
+ dc_tc_publish(tc, DC_TC_END, ctx); /* finally */
765
+ if (scr_exc_pending()) {
766
+ scr_dyn_release(r);
767
+ r = NULL;
768
+ }
769
+ }
770
+ }
771
+ }
772
+ dc_stores_restore(prevs, entered);
773
+ free(call_items);
774
+ scr_dyn_release(wrapped);
775
+ return r;
776
+ }
777
+
778
+ void scr_dc_publish(double handle, ScrDyn *message) {
779
+ ScrDcChannel *ch = dc_of(handle);
780
+ if (ch->nsubs == 0) return;
781
+ /* Snapshot: subscribe/unsubscribe during dispatch affect LATER
782
+ * publishes only (a self-unsubscribing subscriber's siblings still
783
+ * fire this round). */
784
+ size_t n = ch->nsubs;
785
+ ScrDyn **snap = malloc(n * sizeof *snap);
786
+ if (!snap) {
787
+ fputs("scriptc: out of memory\n", stderr);
788
+ abort();
789
+ }
790
+ for (size_t i = 0; i < n; i++) snap[i] = scr_dyn_retain(ch->subs[i]);
791
+ ScrDyn *namev = scr_dyn_new_str(ch->name);
792
+ bool threw = false;
793
+ for (size_t i = 0; i < n && !threw; i++) {
794
+ ScrDyn *args[2] = {message, namev};
795
+ ScrDyn *r = scr_dyn_call(snap[i], args, 2, "onMessage");
796
+ if (r == NULL) {
797
+ threw = true; /* pending exception propagates out of publish */
798
+ } else {
799
+ scr_dyn_release(r);
800
+ }
801
+ }
802
+ scr_dyn_release(namev);
803
+ for (size_t i = 0; i < n; i++) scr_dyn_release(snap[i]);
804
+ free(snap);
805
+ }