@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
@@ -0,0 +1,29 @@
1
+ /* The parsed-URL layout, shared by the always-linked url unit
2
+ * (scr_url.c) and the link-gated URLSearchParams unit
3
+ * (scr_url_params.c — compiled only when the IR uses the sp surface;
4
+ * the scr_symbol gating precedent). Everything else about the URL
5
+ * stays private to scr_url.c. */
6
+ #ifndef SCR_URL_INTERNAL_H
7
+ #define SCR_URL_INTERNAL_H
8
+
9
+ #include "scr_runtime.h"
10
+
11
+ struct ScrUrl {
12
+ size_t rc;
13
+ ScrStr *scheme; /* lowercase, no ":" */
14
+ ScrStr *userinfo; /* "" or "user[:pw]" (encoded) */
15
+ ScrStr *host; /* "" allowed; includes ":port" never (see port) */
16
+ ScrStr *port; /* "" or digits (defaults stripped) */
17
+ ScrStr *path; /* "/..." rooted, "" (non-special, no path), or opaque */
18
+ ScrStr *query; /* "" or "?..." */
19
+ ScrStr *fragment; /* "" or "#..." */
20
+ bool has_authority;
21
+ /* The LIVE searchParams view (NULL until first read). NON-owning: the
22
+ * view retains its URL, so a URL with a live view never dies; the view
23
+ * clears this back-pointer when it releases. Every `u.searchParams`
24
+ * read answers the SAME view — Node's cached-object identity — and
25
+ * view mutations write back into `query` (sp_sync_owner). */
26
+ struct ScrSearchParams *sp_cache;
27
+ };
28
+
29
+ #endif /* SCR_URL_INTERNAL_H */
@@ -0,0 +1,561 @@
1
+ /* URLSearchParams (scr_runtime.h has the API contract): the WHATWG
2
+ * application/x-www-form-urlencoded list, standalone or as a URL's LIVE
3
+ * query view. LINK-GATED: compiled into the binary only when the IR uses
4
+ * the searchParams surface (moduleUsesSearchParams — the scr_symbol
5
+ * gating precedent), so sp-free programs pay zero bytes; scr_url.c stays
6
+ * always-linked and never references this unit. Shares only the parsed
7
+ * URL layout (scr_url_internal.h) with the url unit — the buffer and
8
+ * hex helpers below are this unit's own statics. */
9
+ #include "scr_runtime.h"
10
+ #include "scr_url_internal.h"
11
+
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+
16
+ /* ── a tiny growable byte buffer (scr_url.c's, redeclared locally) ───── */
17
+
18
+ typedef struct {
19
+ char *data;
20
+ size_t len;
21
+ size_t cap;
22
+ } UrlBuf;
23
+
24
+ static void ub_init(UrlBuf *b) {
25
+ b->cap = 64;
26
+ b->len = 0;
27
+ b->data = malloc(b->cap);
28
+ if (!b->data) {
29
+ fputs("scriptc: out of memory\n", stderr);
30
+ abort();
31
+ }
32
+ }
33
+
34
+ static void ub_append(UrlBuf *b, const char *bytes, size_t n) {
35
+ if (b->len + n > b->cap) {
36
+ while (b->len + n > b->cap) b->cap *= 2;
37
+ char *grown = realloc(b->data, b->cap);
38
+ if (!grown) {
39
+ fputs("scriptc: out of memory\n", stderr);
40
+ abort();
41
+ }
42
+ b->data = grown;
43
+ }
44
+ memcpy(b->data + b->len, bytes, n);
45
+ b->len += n;
46
+ }
47
+
48
+ static void ub_push(UrlBuf *b, char c) { ub_append(b, &c, 1); }
49
+
50
+ static ScrStr *ub_take(UrlBuf *b) {
51
+ ScrStr *s = scr_str_new(b->data, b->len);
52
+ free(b->data);
53
+ return s;
54
+ }
55
+
56
+ static int hex_val(char c) {
57
+ if (c >= '0' && c <= '9') return c - '0';
58
+ if (c >= 'a' && c <= 'f') return c - 'a' + 10;
59
+ if (c >= 'A' && c <= 'F') return c - 'A' + 10;
60
+ return -1;
61
+ }
62
+
63
+ /* ── URLSearchParams (WHATWG application/x-www-form-urlencoded) ───────
64
+ *
65
+ * A refcounted ordered list of (name, value) DECODED pairs. Standalone
66
+ * (`new URLSearchParams(...)`) or the LIVE view of a URL's query
67
+ * (`u.searchParams`): the view retains its URL, the URL caches the view
68
+ * non-owningly (one identity, Node's cached object), and every mutation
69
+ * re-serializes the list into the URL's query — href reflects
70
+ * immediately, and emptying the list drops the '?' entirely (the spec's
71
+ * update steps set a null query for the empty serialization).
72
+ *
73
+ * Parsing and serialization are the URL Standard's urlencoded pair
74
+ * exactly (Node's byte behavior, pinned by the differential corpus):
75
+ * parse splits on '&' (empty segments skipped), first '=' splits the
76
+ * pair, '+' decodes to space, %XX decodes case-insensitively (malformed
77
+ * escapes pass through verbatim), and the decoded BYTES pass through
78
+ * UTF-8 decode-with-replacement (invalid sequences become U+FFFD per
79
+ * maximal subpart — every stored string stays well-formed UTF-8);
80
+ * serialize keeps [A-Za-z0-9*\-._] verbatim, encodes space as '+', and
81
+ * percent-encodes every other byte as uppercase %XX. sort() is a STABLE
82
+ * sort by the name's UTF-16 code units (the spec's order — supplementary
83
+ * code points compare as their surrogate pairs, BELOW U+E000..U+FFFF,
84
+ * where raw UTF-8 byte order would put them above). */
85
+
86
+ struct ScrSearchParams {
87
+ size_t rc;
88
+ size_t len, cap;
89
+ ScrStr **names; /* decoded */
90
+ ScrStr **vals; /* decoded */
91
+ ScrUrl *owner; /* retained; NULL for standalone lists */
92
+ };
93
+
94
+ static ScrSearchParams *sp_alloc(void) {
95
+ ScrSearchParams *sp = malloc(sizeof(ScrSearchParams));
96
+ if (!sp) {
97
+ fputs("scriptc: out of memory\n", stderr);
98
+ abort();
99
+ }
100
+ sp->rc = 1;
101
+ sp->len = 0;
102
+ sp->cap = 8;
103
+ sp->names = malloc(sp->cap * sizeof(ScrStr *));
104
+ sp->vals = malloc(sp->cap * sizeof(ScrStr *));
105
+ if (!sp->names || !sp->vals) {
106
+ fputs("scriptc: out of memory\n", stderr);
107
+ abort();
108
+ }
109
+ sp->owner = NULL;
110
+ return sp;
111
+ }
112
+
113
+ ScrSearchParams *scr_sp_retain(ScrSearchParams *sp) {
114
+ if (sp->rc != SIZE_MAX) sp->rc++;
115
+ return sp;
116
+ }
117
+
118
+ void scr_sp_release(ScrSearchParams *sp) {
119
+ if (!sp || sp->rc == SIZE_MAX) return;
120
+ if (--sp->rc == 0) {
121
+ for (size_t i = 0; i < sp->len; i++) {
122
+ scr_str_release(sp->names[i]);
123
+ scr_str_release(sp->vals[i]);
124
+ }
125
+ free(sp->names);
126
+ free(sp->vals);
127
+ if (sp->owner) {
128
+ sp->owner->sp_cache = NULL;
129
+ scr_url_release(sp->owner);
130
+ }
131
+ free(sp);
132
+ }
133
+ }
134
+
135
+ void *scr_sp_retain_v(void *p) { return scr_sp_retain(p); }
136
+ void scr_sp_release_v(void *p) { scr_sp_release(p); }
137
+
138
+ /* Takes ownership of both strings. */
139
+ static void sp_push(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
140
+ if (sp->len == sp->cap) {
141
+ sp->cap *= 2;
142
+ ScrStr **gn = realloc(sp->names, sp->cap * sizeof(ScrStr *));
143
+ ScrStr **gv = realloc(sp->vals, sp->cap * sizeof(ScrStr *));
144
+ if (!gn || !gv) {
145
+ fputs("scriptc: out of memory\n", stderr);
146
+ abort();
147
+ }
148
+ sp->names = gn;
149
+ sp->vals = gv;
150
+ }
151
+ sp->names[sp->len] = name;
152
+ sp->vals[sp->len] = value;
153
+ sp->len++;
154
+ }
155
+
156
+ /* WHATWG UTF-8 decode with U+FFFD replacement per maximal invalid subpart
157
+ * — percent-decoding produces arbitrary BYTES, and Node runs them through
158
+ * this exact decode (scr_bytes.c's toString("utf8") twin; duplicated so
159
+ * the always-linked url unit stays self-contained). */
160
+ static ScrStr *sp_scrub_utf8(const char *in_c, size_t n) {
161
+ const unsigned char *in = (const unsigned char *)in_c;
162
+ char *out = malloc(n * 3 + 1);
163
+ if (!out) {
164
+ fputs("scriptc: out of memory\n", stderr);
165
+ abort();
166
+ }
167
+ size_t o = 0;
168
+ uint32_t cp = 0;
169
+ int needed = 0;
170
+ unsigned char lower = 0x80, upper = 0xbf;
171
+ for (size_t i = 0; i <= n; i++) {
172
+ if (i == n) {
173
+ if (needed > 0) {
174
+ memcpy(out + o, "\xef\xbf\xbd", 3);
175
+ o += 3;
176
+ }
177
+ break;
178
+ }
179
+ unsigned char byte = in[i];
180
+ if (needed == 0) {
181
+ if (byte <= 0x7f) {
182
+ out[o++] = (char)byte;
183
+ } else if (byte >= 0xc2 && byte <= 0xdf) {
184
+ needed = 1; cp = byte & 0x1fu;
185
+ } else if (byte >= 0xe0 && byte <= 0xef) {
186
+ if (byte == 0xe0) lower = 0xa0;
187
+ if (byte == 0xed) upper = 0x9f;
188
+ needed = 2; cp = byte & 0xfu;
189
+ } else if (byte >= 0xf0 && byte <= 0xf4) {
190
+ if (byte == 0xf0) lower = 0x90;
191
+ if (byte == 0xf4) upper = 0x8f;
192
+ needed = 3; cp = byte & 0x7u;
193
+ } else {
194
+ memcpy(out + o, "\xef\xbf\xbd", 3);
195
+ o += 3;
196
+ }
197
+ continue;
198
+ }
199
+ if (byte < lower || byte > upper) {
200
+ memcpy(out + o, "\xef\xbf\xbd", 3);
201
+ o += 3;
202
+ needed = 0; lower = 0x80; upper = 0xbf;
203
+ i--;
204
+ continue;
205
+ }
206
+ lower = 0x80; upper = 0xbf;
207
+ cp = (cp << 6) | (byte & 0x3fu);
208
+ if (--needed == 0) {
209
+ if (cp <= 0x7f) {
210
+ out[o++] = (char)cp;
211
+ } else if (cp <= 0x7ff) {
212
+ out[o++] = (char)(0xc0 | (cp >> 6));
213
+ out[o++] = (char)(0x80 | (cp & 0x3f));
214
+ } else if (cp <= 0xffff) {
215
+ out[o++] = (char)(0xe0 | (cp >> 12));
216
+ out[o++] = (char)(0x80 | ((cp >> 6) & 0x3f));
217
+ out[o++] = (char)(0x80 | (cp & 0x3f));
218
+ } else {
219
+ out[o++] = (char)(0xf0 | (cp >> 18));
220
+ out[o++] = (char)(0x80 | ((cp >> 12) & 0x3f));
221
+ out[o++] = (char)(0x80 | ((cp >> 6) & 0x3f));
222
+ out[o++] = (char)(0x80 | (cp & 0x3f));
223
+ }
224
+ }
225
+ }
226
+ ScrStr *s = scr_str_new(out, o);
227
+ free(out);
228
+ return s;
229
+ }
230
+
231
+ /* One urlencoded piece → decoded string: '+' is space, %XX decodes
232
+ * (malformed escapes pass through verbatim), then the UTF-8 scrub. */
233
+ static ScrStr *sp_decode_piece(const char *s, size_t len) {
234
+ UrlBuf b;
235
+ ub_init(&b);
236
+ for (size_t i = 0; i < len; i++) {
237
+ char c = s[i];
238
+ if (c == '+') {
239
+ ub_push(&b, ' ');
240
+ } else if (c == '%' && i + 2 < len && hex_val(s[i + 1]) >= 0 && hex_val(s[i + 2]) >= 0) {
241
+ ub_push(&b, (char)((hex_val(s[i + 1]) << 4) | hex_val(s[i + 2])));
242
+ i += 2;
243
+ } else {
244
+ ub_push(&b, c);
245
+ }
246
+ }
247
+ ScrStr *out = sp_scrub_utf8(b.data, b.len);
248
+ free(b.data);
249
+ return out;
250
+ }
251
+
252
+ /* The urlencoded serializer's byte set: [A-Za-z0-9*\-._] verbatim, space
253
+ * as '+', everything else uppercase %XX. */
254
+ static void sp_encode_piece(UrlBuf *b, const ScrStr *s) {
255
+ for (size_t i = 0; i < s->len; i++) {
256
+ unsigned char c = (unsigned char)s->data[i];
257
+ if (c == ' ') {
258
+ ub_push(b, '+');
259
+ } else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') ||
260
+ c == '*' || c == '-' || c == '.' || c == '_') {
261
+ ub_push(b, (char)c);
262
+ } else {
263
+ char hex[4];
264
+ snprintf(hex, sizeof hex, "%%%02X", c);
265
+ ub_append(b, hex, 3);
266
+ }
267
+ }
268
+ }
269
+
270
+ /* Parses an urlencoded body into the list (no leading '?' here). */
271
+ static void sp_parse_into(ScrSearchParams *sp, const char *s, size_t len) {
272
+ size_t start = 0;
273
+ for (size_t i = 0; i <= len; i++) {
274
+ if (i < len && s[i] != '&') continue;
275
+ if (i > start) {
276
+ size_t eq = i; /* first '=' inside [start, i) */
277
+ for (size_t j = start; j < i; j++) {
278
+ if (s[j] == '=') {
279
+ eq = j;
280
+ break;
281
+ }
282
+ }
283
+ ScrStr *name = sp_decode_piece(s + start, eq - start);
284
+ ScrStr *value = eq < i ? sp_decode_piece(s + eq + 1, i - eq - 1) : scr_str_new("", 0);
285
+ sp_push(sp, name, value);
286
+ }
287
+ start = i + 1;
288
+ }
289
+ }
290
+
291
+ ScrStr *scr_sp_to_string(ScrSearchParams *sp) {
292
+ UrlBuf b;
293
+ ub_init(&b);
294
+ for (size_t i = 0; i < sp->len; i++) {
295
+ if (i > 0) ub_push(&b, '&');
296
+ sp_encode_piece(&b, sp->names[i]);
297
+ ub_push(&b, '=');
298
+ sp_encode_piece(&b, sp->vals[i]);
299
+ }
300
+ return ub_take(&b);
301
+ }
302
+
303
+ /* The live view's write-back: re-serialize the list into the owner's
304
+ * query ("?..." or "", the spec's null-query for an empty serialization).
305
+ * href/search read the field directly, so the update is visible at once. */
306
+ static void sp_sync_owner(ScrSearchParams *sp) {
307
+ if (!sp->owner) return;
308
+ scr_str_release(sp->owner->query);
309
+ if (sp->len == 0) {
310
+ sp->owner->query = scr_str_new("", 0);
311
+ return;
312
+ }
313
+ UrlBuf b;
314
+ ub_init(&b);
315
+ ub_push(&b, '?');
316
+ for (size_t i = 0; i < sp->len; i++) {
317
+ if (i > 0) ub_push(&b, '&');
318
+ sp_encode_piece(&b, sp->names[i]);
319
+ ub_push(&b, '=');
320
+ sp_encode_piece(&b, sp->vals[i]);
321
+ }
322
+ sp->owner->query = ub_take(&b);
323
+ }
324
+
325
+ ScrSearchParams *scr_sp_new(void) { return sp_alloc(); }
326
+
327
+ ScrSearchParams *scr_sp_parse(ScrStr *init) {
328
+ ScrSearchParams *sp = sp_alloc();
329
+ const char *s = init->data;
330
+ size_t len = init->len;
331
+ if (len > 0 && s[0] == '?') {
332
+ s++;
333
+ len--;
334
+ }
335
+ sp_parse_into(sp, s, len);
336
+ return sp;
337
+ }
338
+
339
+ ScrSearchParams *scr_sp_copy(ScrSearchParams *src) {
340
+ ScrSearchParams *sp = sp_alloc();
341
+ for (size_t i = 0; i < src->len; i++) {
342
+ sp_push(sp, scr_str_retain(src->names[i]), scr_str_retain(src->vals[i]));
343
+ }
344
+ return sp;
345
+ }
346
+
347
+ /* string[][] init: each row must be a [name, value] pair — Node's
348
+ * ERR_INVALID_TUPLE TypeError otherwise. */
349
+ ScrSearchParams *scr_sp_from_pairs(ScrArr *pairs) {
350
+ size_t n = (size_t)scr_arr_len(pairs);
351
+ for (size_t i = 0; i < n; i++) {
352
+ ScrArr *row = scr_arr_get_ref(pairs, (double)i);
353
+ double rl = scr_arr_len(row);
354
+ scr_arr_release(row);
355
+ if (rl != 2) {
356
+ static const char tuple_msg[] = "Each query pair must be an iterable [name, value] tuple";
357
+ scr_throw_error_msg_code(SCR_ERR_TYPE, tuple_msg, sizeof tuple_msg - 1,
358
+ "ERR_INVALID_TUPLE");
359
+ return NULL;
360
+ }
361
+ }
362
+ ScrSearchParams *sp = sp_alloc();
363
+ for (size_t i = 0; i < n; i++) {
364
+ ScrArr *row = scr_arr_get_ref(pairs, (double)i);
365
+ ScrStr *name = scr_arr_get_ref(row, 0);
366
+ ScrStr *value = scr_arr_get_ref(row, 1);
367
+ scr_arr_release(row);
368
+ sp_push(sp, name, value); /* ownership of the +1 reads passes in */
369
+ }
370
+ return sp;
371
+ }
372
+
373
+ /* The record-literal init desugar: append one pair, answer the SAME list
374
+ * +1 (`new URLSearchParams({a: "1", b: "2"})` folds to a with-chain). */
375
+ ScrSearchParams *scr_sp_with(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
376
+ sp_push(sp, scr_str_retain(name), scr_str_retain(value));
377
+ return scr_sp_retain(sp);
378
+ }
379
+
380
+ ScrSearchParams *scr_url_search_params(ScrUrl *u) {
381
+ if (u->sp_cache) return scr_sp_retain(u->sp_cache);
382
+ ScrSearchParams *sp = sp_alloc();
383
+ if (u->query->len > 1) sp_parse_into(sp, u->query->data + 1, u->query->len - 1);
384
+ sp->owner = scr_url_retain(u);
385
+ u->sp_cache = sp;
386
+ return sp;
387
+ }
388
+
389
+ void scr_sp_append(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
390
+ sp_push(sp, scr_str_retain(name), scr_str_retain(value));
391
+ sp_sync_owner(sp);
392
+ }
393
+
394
+ static bool sp_str_eq(const ScrStr *a, const ScrStr *b) {
395
+ return a->len == b->len && memcmp(a->data, b->data, a->len) == 0;
396
+ }
397
+
398
+ void scr_sp_set(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
399
+ size_t w = 0;
400
+ bool replaced = false;
401
+ for (size_t i = 0; i < sp->len; i++) {
402
+ if (sp_str_eq(sp->names[i], name)) {
403
+ if (!replaced) {
404
+ replaced = true;
405
+ scr_str_release(sp->vals[i]);
406
+ sp->vals[i] = scr_str_retain(value);
407
+ sp->names[w] = sp->names[i];
408
+ sp->vals[w] = sp->vals[i];
409
+ w++;
410
+ } else {
411
+ scr_str_release(sp->names[i]);
412
+ scr_str_release(sp->vals[i]);
413
+ }
414
+ } else {
415
+ sp->names[w] = sp->names[i];
416
+ sp->vals[w] = sp->vals[i];
417
+ w++;
418
+ }
419
+ }
420
+ sp->len = w;
421
+ if (!replaced) sp_push(sp, scr_str_retain(name), scr_str_retain(value));
422
+ sp_sync_owner(sp);
423
+ }
424
+
425
+ static void sp_delete_impl(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
426
+ size_t w = 0;
427
+ for (size_t i = 0; i < sp->len; i++) {
428
+ bool drop = sp_str_eq(sp->names[i], name) && (!value || sp_str_eq(sp->vals[i], value));
429
+ if (drop) {
430
+ scr_str_release(sp->names[i]);
431
+ scr_str_release(sp->vals[i]);
432
+ } else {
433
+ sp->names[w] = sp->names[i];
434
+ sp->vals[w] = sp->vals[i];
435
+ w++;
436
+ }
437
+ }
438
+ sp->len = w;
439
+ sp_sync_owner(sp);
440
+ }
441
+
442
+ void scr_sp_delete(ScrSearchParams *sp, ScrStr *name) { sp_delete_impl(sp, name, NULL); }
443
+ void scr_sp_delete_value(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
444
+ sp_delete_impl(sp, name, value);
445
+ }
446
+
447
+ ScrStr *scr_sp_get(ScrSearchParams *sp, ScrStr *name) {
448
+ for (size_t i = 0; i < sp->len; i++) {
449
+ if (sp_str_eq(sp->names[i], name)) return scr_str_retain(sp->vals[i]);
450
+ }
451
+ return NULL;
452
+ }
453
+
454
+ ScrArr *scr_sp_get_all(ScrSearchParams *sp, ScrStr *name) {
455
+ ScrArr *out = scr_arr_new(SCR_ELEM_STR, 4);
456
+ for (size_t i = 0; i < sp->len; i++) {
457
+ if (sp_str_eq(sp->names[i], name)) scr_arr_push_ref(out, scr_str_retain(sp->vals[i]));
458
+ }
459
+ return out;
460
+ }
461
+
462
+ bool scr_sp_has(ScrSearchParams *sp, ScrStr *name) {
463
+ for (size_t i = 0; i < sp->len; i++) {
464
+ if (sp_str_eq(sp->names[i], name)) return true;
465
+ }
466
+ return false;
467
+ }
468
+
469
+ bool scr_sp_has_value(ScrSearchParams *sp, ScrStr *name, ScrStr *value) {
470
+ for (size_t i = 0; i < sp->len; i++) {
471
+ if (sp_str_eq(sp->names[i], name) && sp_str_eq(sp->vals[i], value)) return true;
472
+ }
473
+ return false;
474
+ }
475
+
476
+ /* UTF-16 code-unit comparison over well-formed UTF-8 (the spec's sort
477
+ * order). Byte order ALMOST matches — the exception is U+E000..U+FFFF
478
+ * (3-byte UTF-8, single high code units) vs supplementary code points
479
+ * (4-byte UTF-8, surrogate pairs 0xD800..0xDFFF): bytes put the 4-byte
480
+ * form last, code units put it first. Decode code points and compare
481
+ * their leading UTF-16 units. */
482
+ static uint32_t sp_lead_unit(const unsigned char *s, size_t len, size_t *adv) {
483
+ unsigned char b = s[0];
484
+ uint32_t cp;
485
+ size_t n;
486
+ if (b < 0x80) {
487
+ cp = b; n = 1;
488
+ } else if ((b & 0xe0) == 0xc0) {
489
+ cp = b & 0x1fu; n = 2;
490
+ } else if ((b & 0xf0) == 0xe0) {
491
+ cp = b & 0x0fu; n = 3;
492
+ } else {
493
+ cp = b & 0x07u; n = 4;
494
+ }
495
+ if (n > len) n = len; /* defensive: strings are well-formed by contract */
496
+ for (size_t i = 1; i < n; i++) cp = (cp << 6) | (s[i] & 0x3fu);
497
+ *adv = n;
498
+ if (cp >= 0x10000) return 0xd800 + ((cp - 0x10000) >> 10); /* high surrogate leads */
499
+ return cp;
500
+ }
501
+
502
+ static int sp_cmp_u16(const ScrStr *a, const ScrStr *b) {
503
+ size_t ia = 0, ib = 0;
504
+ while (ia < a->len && ib < b->len) {
505
+ size_t na, nb;
506
+ uint32_t ua = sp_lead_unit((const unsigned char *)a->data + ia, a->len - ia, &na);
507
+ uint32_t ub = sp_lead_unit((const unsigned char *)b->data + ib, b->len - ib, &nb);
508
+ if (ua != ub) return ua < ub ? -1 : 1;
509
+ /* Equal LEADING units: equal whole code points (both single units or
510
+ * both pairs with equal highs — lows only differ if cps differ). */
511
+ if (na == 4 && nb == 4) {
512
+ uint32_t cpa = 0, cpb = 0;
513
+ for (size_t i = 0; i < 4; i++) {
514
+ cpa = (cpa << 6) | ((i == 0 ? a->data[ia] & 0x07 : a->data[ia + i] & 0x3f));
515
+ cpb = (cpb << 6) | ((i == 0 ? b->data[ib] & 0x07 : b->data[ib + i] & 0x3f));
516
+ }
517
+ if (cpa != cpb) return cpa < cpb ? -1 : 1;
518
+ }
519
+ ia += na;
520
+ ib += nb;
521
+ }
522
+ if (ia < a->len) return 1;
523
+ if (ib < b->len) return -1;
524
+ return 0;
525
+ }
526
+
527
+ /* Stable insertion sort by name (lists are small; equal names keep their
528
+ * relative order — the spec's stability requirement). */
529
+ void scr_sp_sort(ScrSearchParams *sp) {
530
+ for (size_t i = 1; i < sp->len; i++) {
531
+ ScrStr *n = sp->names[i];
532
+ ScrStr *v = sp->vals[i];
533
+ size_t j = i;
534
+ while (j > 0 && sp_cmp_u16(sp->names[j - 1], n) > 0) {
535
+ sp->names[j] = sp->names[j - 1];
536
+ sp->vals[j] = sp->vals[j - 1];
537
+ j--;
538
+ }
539
+ sp->names[j] = n;
540
+ sp->vals[j] = v;
541
+ }
542
+ sp_sync_owner(sp);
543
+ }
544
+
545
+ double scr_sp_size(ScrSearchParams *sp) { return (double)sp->len; }
546
+
547
+ /* Iteration primitives: the desugared for-of/forEach walk re-reads the
548
+ * count every pass (the spec's index-based live iteration — entries
549
+ * appended mid-walk are visited, deletions shift). The index is guarded
550
+ * by the loop condition; out-of-range reads answer "" defensively. */
551
+ ScrStr *scr_sp_key_at(ScrSearchParams *sp, double i) {
552
+ size_t idx = (size_t)i;
553
+ if (idx >= sp->len) return scr_str_new("", 0);
554
+ return scr_str_retain(sp->names[idx]);
555
+ }
556
+
557
+ ScrStr *scr_sp_val_at(ScrSearchParams *sp, double i) {
558
+ size_t idx = (size_t)i;
559
+ if (idx >= sp->len) return scr_str_new("", 0);
560
+ return scr_str_retain(sp->vals[idx]);
561
+ }