visaljs 0.0.0-stage → 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 (520) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/cli.js +8084 -0
  4. package/node/include/js_node.h +46 -0
  5. package/node/prelude/async_hooks.js +88 -0
  6. package/node/prelude/buffer.js +31 -0
  7. package/node/prelude/crypto.js +114 -0
  8. package/node/prelude/events.js +227 -0
  9. package/node/prelude/fs.js +79 -0
  10. package/node/prelude/http.js +536 -0
  11. package/node/prelude/http2.js +30 -0
  12. package/node/prelude/internal/crypto/asym.js +333 -0
  13. package/node/prelude/internal/crypto/cipher.js +205 -0
  14. package/node/prelude/internal/crypto/hash.js +137 -0
  15. package/node/prelude/internal/crypto/kdf.js +182 -0
  16. package/node/prelude/internal/crypto/keys.js +603 -0
  17. package/node/prelude/internal/crypto/random.js +118 -0
  18. package/node/prelude/internal/crypto/util.js +76 -0
  19. package/node/prelude/internal/errors.js +88 -0
  20. package/node/prelude/internal/querystring.js +105 -0
  21. package/node/prelude/module.js +53 -0
  22. package/node/prelude/net.js +51 -0
  23. package/node/prelude/os.js +129 -0
  24. package/node/prelude/path.js +257 -0
  25. package/node/prelude/process.js +21 -0
  26. package/node/prelude/querystring.js +469 -0
  27. package/node/prelude/stream.js +1327 -0
  28. package/node/prelude/stream_promises.js +7 -0
  29. package/node/prelude/stream_web.js +6 -0
  30. package/node/prelude/string_decoder.js +236 -0
  31. package/node/prelude/tty.js +18 -0
  32. package/node/prelude/url.js +1156 -0
  33. package/node/prelude/util.js +64 -0
  34. package/node/prelude/zlib.js +81 -0
  35. package/node/src/host_fs.c +126 -0
  36. package/node/src/host_http.c +486 -0
  37. package/node/src/host_os.c +505 -0
  38. package/node/src/host_sys.c +78 -0
  39. package/node/third_party/libuv/LICENSE +19 -0
  40. package/node/third_party/libuv/include/uv/aix.h +32 -0
  41. package/node/third_party/libuv/include/uv/bsd.h +34 -0
  42. package/node/third_party/libuv/include/uv/darwin.h +61 -0
  43. package/node/third_party/libuv/include/uv/errno.h +483 -0
  44. package/node/third_party/libuv/include/uv/linux.h +34 -0
  45. package/node/third_party/libuv/include/uv/os390.h +33 -0
  46. package/node/third_party/libuv/include/uv/posix.h +31 -0
  47. package/node/third_party/libuv/include/uv/sunos.h +44 -0
  48. package/node/third_party/libuv/include/uv/threadpool.h +37 -0
  49. package/node/third_party/libuv/include/uv/tree.h +521 -0
  50. package/node/third_party/libuv/include/uv/unix.h +512 -0
  51. package/node/third_party/libuv/include/uv/version.h +43 -0
  52. package/node/third_party/libuv/include/uv/win.h +698 -0
  53. package/node/third_party/libuv/include/uv.h +1990 -0
  54. package/node/third_party/libuv/src/fs-poll.c +290 -0
  55. package/node/third_party/libuv/src/heap-inl.h +245 -0
  56. package/node/third_party/libuv/src/idna.c +560 -0
  57. package/node/third_party/libuv/src/idna.h +31 -0
  58. package/node/third_party/libuv/src/inet.c +298 -0
  59. package/node/third_party/libuv/src/queue.h +90 -0
  60. package/node/third_party/libuv/src/random.c +123 -0
  61. package/node/third_party/libuv/src/strscpy.c +38 -0
  62. package/node/third_party/libuv/src/strscpy.h +39 -0
  63. package/node/third_party/libuv/src/strtok.c +52 -0
  64. package/node/third_party/libuv/src/strtok.h +27 -0
  65. package/node/third_party/libuv/src/thread-common.c +175 -0
  66. package/node/third_party/libuv/src/threadpool.c +419 -0
  67. package/node/third_party/libuv/src/timer.c +200 -0
  68. package/node/third_party/libuv/src/unix/async.c +418 -0
  69. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +164 -0
  70. package/node/third_party/libuv/src/unix/core.c +2104 -0
  71. package/node/third_party/libuv/src/unix/darwin-proctitle.c +176 -0
  72. package/node/third_party/libuv/src/unix/darwin-stub.h +97 -0
  73. package/node/third_party/libuv/src/unix/darwin-syscalls.h +17 -0
  74. package/node/third_party/libuv/src/unix/darwin.c +237 -0
  75. package/node/third_party/libuv/src/unix/dl.c +80 -0
  76. package/node/third_party/libuv/src/unix/fs.c +2303 -0
  77. package/node/third_party/libuv/src/unix/fsevents.c +906 -0
  78. package/node/third_party/libuv/src/unix/getaddrinfo.c +252 -0
  79. package/node/third_party/libuv/src/unix/getnameinfo.c +121 -0
  80. package/node/third_party/libuv/src/unix/internal.h +530 -0
  81. package/node/third_party/libuv/src/unix/kqueue.c +667 -0
  82. package/node/third_party/libuv/src/unix/linux.c +2761 -0
  83. package/node/third_party/libuv/src/unix/loop-watcher.c +68 -0
  84. package/node/third_party/libuv/src/unix/loop.c +240 -0
  85. package/node/third_party/libuv/src/unix/pipe.c +555 -0
  86. package/node/third_party/libuv/src/unix/poll.c +159 -0
  87. package/node/third_party/libuv/src/unix/process.c +1123 -0
  88. package/node/third_party/libuv/src/unix/procfs-exepath.c +45 -0
  89. package/node/third_party/libuv/src/unix/proctitle.c +157 -0
  90. package/node/third_party/libuv/src/unix/random-devurandom.c +93 -0
  91. package/node/third_party/libuv/src/unix/random-getentropy.c +57 -0
  92. package/node/third_party/libuv/src/unix/random-getrandom.c +86 -0
  93. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +99 -0
  94. package/node/third_party/libuv/src/unix/signal.c +581 -0
  95. package/node/third_party/libuv/src/unix/stream.c +1567 -0
  96. package/node/third_party/libuv/src/unix/tcp.c +673 -0
  97. package/node/third_party/libuv/src/unix/thread.c +975 -0
  98. package/node/third_party/libuv/src/unix/tty.c +510 -0
  99. package/node/third_party/libuv/src/unix/udp.c +1434 -0
  100. package/node/third_party/libuv/src/uv-common.c +1051 -0
  101. package/node/third_party/libuv/src/uv-common.h +474 -0
  102. package/node/third_party/libuv/src/uv-data-getter-setters.c +119 -0
  103. package/node/third_party/libuv/src/version.c +45 -0
  104. package/node/third_party/llhttp/LICENSE +22 -0
  105. package/node/third_party/llhttp/api.c +509 -0
  106. package/node/third_party/llhttp/http.c +170 -0
  107. package/node/third_party/llhttp/llhttp.c +10099 -0
  108. package/node/third_party/llhttp/llhttp.h +907 -0
  109. package/package.json +25 -4
  110. package/runtime/include/js_atoms.gen.h +68 -0
  111. package/runtime/include/js_atoms.h +54 -0
  112. package/runtime/include/js_bigint.h +93 -0
  113. package/runtime/include/js_buffer.h +79 -0
  114. package/runtime/include/js_builtins.h +168 -0
  115. package/runtime/include/js_console.h +58 -0
  116. package/runtime/include/js_convert.h +22 -0
  117. package/runtime/include/js_core.def +188 -0
  118. package/runtime/include/js_crypto.h +58 -0
  119. package/runtime/include/js_error.h +37 -0
  120. package/runtime/include/js_exception.h +65 -0
  121. package/runtime/include/js_function.h +167 -0
  122. package/runtime/include/js_gc.h +195 -0
  123. package/runtime/include/js_generator.h +96 -0
  124. package/runtime/include/js_host.h +19 -0
  125. package/runtime/include/js_jobs.h +84 -0
  126. package/runtime/include/js_module.h +16 -0
  127. package/runtime/include/js_object.h +384 -0
  128. package/runtime/include/js_ops.h +111 -0
  129. package/runtime/include/js_promise.h +45 -0
  130. package/runtime/include/js_regexp.h +25 -0
  131. package/runtime/include/js_runtime.h +30 -0
  132. package/runtime/include/js_symbol.h +62 -0
  133. package/runtime/include/js_web.h +110 -0
  134. package/runtime/include/jscell.h +48 -0
  135. package/runtime/include/jscontext.h +240 -0
  136. package/runtime/include/jsnum.h +42 -0
  137. package/runtime/include/jsstring.h +161 -0
  138. package/runtime/include/jsvalue.h +142 -0
  139. package/runtime/src/arguments.c +115 -0
  140. package/runtime/src/array.c +1145 -0
  141. package/runtime/src/arraybuffer.c +608 -0
  142. package/runtime/src/async_iter.c +479 -0
  143. package/runtime/src/atoms.c +157 -0
  144. package/runtime/src/base64.c +107 -0
  145. package/runtime/src/bigint.c +1189 -0
  146. package/runtime/src/blob.c +371 -0
  147. package/runtime/src/buffer.c +1357 -0
  148. package/runtime/src/builtin_table.c +100 -0
  149. package/runtime/src/builtins.c +987 -0
  150. package/runtime/src/builtins_util.h +53 -0
  151. package/runtime/src/collections.c +912 -0
  152. package/runtime/src/components.c +28 -0
  153. package/runtime/src/console.c +637 -0
  154. package/runtime/src/convert.c +82 -0
  155. package/runtime/src/core_all.c +21 -0
  156. package/runtime/src/crypto.c +116 -0
  157. package/runtime/src/crypto_asym.c +644 -0
  158. package/runtime/src/crypto_cipher.c +671 -0
  159. package/runtime/src/crypto_hash.c +260 -0
  160. package/runtime/src/crypto_host.c +414 -0
  161. package/runtime/src/crypto_internal.h +304 -0
  162. package/runtime/src/crypto_kdf.c +143 -0
  163. package/runtime/src/crypto_key.c +171 -0
  164. package/runtime/src/crypto_pkey.c +794 -0
  165. package/runtime/src/crypto_subtle.c +1675 -0
  166. package/runtime/src/date.c +940 -0
  167. package/runtime/src/domexception.c +169 -0
  168. package/runtime/src/elements.c +312 -0
  169. package/runtime/src/elements.h +45 -0
  170. package/runtime/src/encoding.c +485 -0
  171. package/runtime/src/error.c +297 -0
  172. package/runtime/src/events.c +793 -0
  173. package/runtime/src/exception.c +56 -0
  174. package/runtime/src/fetch.c +772 -0
  175. package/runtime/src/function.c +530 -0
  176. package/runtime/src/gc.c +803 -0
  177. package/runtime/src/generator.c +218 -0
  178. package/runtime/src/global.c +119 -0
  179. package/runtime/src/headers.c +557 -0
  180. package/runtime/src/inspect.c +1792 -0
  181. package/runtime/src/internal.h +80 -0
  182. package/runtime/src/iterate.c +94 -0
  183. package/runtime/src/iterator.c +409 -0
  184. package/runtime/src/jobs.c +337 -0
  185. package/runtime/src/jsnum.c +353 -0
  186. package/runtime/src/json.c +1028 -0
  187. package/runtime/src/math.c +243 -0
  188. package/runtime/src/module.c +336 -0
  189. package/runtime/src/number.c +176 -0
  190. package/runtime/src/object.c +1265 -0
  191. package/runtime/src/ops.c +322 -0
  192. package/runtime/src/os.c +196 -0
  193. package/runtime/src/os.h +29 -0
  194. package/runtime/src/process.c +432 -0
  195. package/runtime/src/promise.c +721 -0
  196. package/runtime/src/proxy.c +570 -0
  197. package/runtime/src/reflect.c +194 -0
  198. package/runtime/src/regexp.c +1141 -0
  199. package/runtime/src/regexp_anchor.h +34 -0
  200. package/runtime/src/regexp_message.h +32 -0
  201. package/runtime/src/shape.c +294 -0
  202. package/runtime/src/shape.h +46 -0
  203. package/runtime/src/streams.c +1046 -0
  204. package/runtime/src/streams.h +47 -0
  205. package/runtime/src/string.c +364 -0
  206. package/runtime/src/string_builtins.c +837 -0
  207. package/runtime/src/symbol.c +143 -0
  208. package/runtime/src/test_host.c +59 -0
  209. package/runtime/src/typedarray.c +1330 -0
  210. package/runtime/src/tznames.gen.h +712 -0
  211. package/runtime/src/uri.c +169 -0
  212. package/runtime/src/url.c +2116 -0
  213. package/runtime/src/weak.c +486 -0
  214. package/runtime/src/web.c +214 -0
  215. package/runtime/src/wrapper.c +59 -0
  216. package/runtime/src/writable.c +1486 -0
  217. package/runtime/third_party/ada-idna/LICENSE-MIT +18 -0
  218. package/runtime/third_party/ada-idna/README.md +27 -0
  219. package/runtime/third_party/ada-idna/convert.mjs +83 -0
  220. package/runtime/third_party/ada-idna/idna.c +416 -0
  221. package/runtime/third_party/ada-idna/idna.h +15 -0
  222. package/runtime/third_party/ada-idna/idna_tables.h +2657 -0
  223. package/runtime/third_party/bearssl/LICENSE.txt +21 -0
  224. package/runtime/third_party/bearssl/README.txt +136 -0
  225. package/runtime/third_party/bearssl/VERSION +1 -0
  226. package/runtime/third_party/bearssl/inc/bearssl.h +183 -0
  227. package/runtime/third_party/bearssl/inc/bearssl_aead.h +1059 -0
  228. package/runtime/third_party/bearssl/inc/bearssl_block.h +2618 -0
  229. package/runtime/third_party/bearssl/inc/bearssl_ec.h +967 -0
  230. package/runtime/third_party/bearssl/inc/bearssl_hash.h +1346 -0
  231. package/runtime/third_party/bearssl/inc/bearssl_hmac.h +241 -0
  232. package/runtime/third_party/bearssl/inc/bearssl_kdf.h +284 -0
  233. package/runtime/third_party/bearssl/inc/bearssl_pem.h +294 -0
  234. package/runtime/third_party/bearssl/inc/bearssl_prf.h +150 -0
  235. package/runtime/third_party/bearssl/inc/bearssl_rand.h +397 -0
  236. package/runtime/third_party/bearssl/inc/bearssl_rsa.h +1655 -0
  237. package/runtime/third_party/bearssl/inc/bearssl_ssl.h +4296 -0
  238. package/runtime/third_party/bearssl/inc/bearssl_x509.h +1474 -0
  239. package/runtime/third_party/bearssl/src/aead/ccm.c +346 -0
  240. package/runtime/third_party/bearssl/src/aead/eax.c +525 -0
  241. package/runtime/third_party/bearssl/src/aead/gcm.c +318 -0
  242. package/runtime/third_party/bearssl/src/codec/ccopy.c +44 -0
  243. package/runtime/third_party/bearssl/src/codec/dec16be.c +38 -0
  244. package/runtime/third_party/bearssl/src/codec/dec16le.c +38 -0
  245. package/runtime/third_party/bearssl/src/codec/dec32be.c +38 -0
  246. package/runtime/third_party/bearssl/src/codec/dec32le.c +38 -0
  247. package/runtime/third_party/bearssl/src/codec/dec64be.c +38 -0
  248. package/runtime/third_party/bearssl/src/codec/dec64le.c +38 -0
  249. package/runtime/third_party/bearssl/src/codec/enc16be.c +38 -0
  250. package/runtime/third_party/bearssl/src/codec/enc16le.c +38 -0
  251. package/runtime/third_party/bearssl/src/codec/enc32be.c +38 -0
  252. package/runtime/third_party/bearssl/src/codec/enc32le.c +38 -0
  253. package/runtime/third_party/bearssl/src/codec/enc64be.c +38 -0
  254. package/runtime/third_party/bearssl/src/codec/enc64le.c +38 -0
  255. package/runtime/third_party/bearssl/src/codec/pemdec.c +526 -0
  256. package/runtime/third_party/bearssl/src/codec/pemdec.t0 +314 -0
  257. package/runtime/third_party/bearssl/src/codec/pemenc.c +173 -0
  258. package/runtime/third_party/bearssl/src/config.h +247 -0
  259. package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +121 -0
  260. package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +171 -0
  261. package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +398 -0
  262. package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +390 -0
  263. package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +1478 -0
  264. package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +800 -0
  265. package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +605 -0
  266. package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +831 -0
  267. package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +46 -0
  268. package/runtime/third_party/bearssl/src/ec/ec_default.c +36 -0
  269. package/runtime/third_party/bearssl/src/ec/ec_keygen.c +86 -0
  270. package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +2124 -0
  271. package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +1469 -0
  272. package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +1765 -0
  273. package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +1781 -0
  274. package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +824 -0
  275. package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +826 -0
  276. package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +85 -0
  277. package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +51 -0
  278. package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +57 -0
  279. package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +64 -0
  280. package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +134 -0
  281. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +36 -0
  282. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +36 -0
  283. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +36 -0
  284. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +36 -0
  285. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +47 -0
  286. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +45 -0
  287. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +174 -0
  288. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +48 -0
  289. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +166 -0
  290. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +47 -0
  291. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +45 -0
  292. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +173 -0
  293. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +48 -0
  294. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +165 -0
  295. package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +121 -0
  296. package/runtime/third_party/bearssl/src/hash/dig_oid.c +84 -0
  297. package/runtime/third_party/bearssl/src/hash/dig_size.c +50 -0
  298. package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +345 -0
  299. package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +251 -0
  300. package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +154 -0
  301. package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +389 -0
  302. package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +411 -0
  303. package/runtime/third_party/bearssl/src/hash/md5.c +208 -0
  304. package/runtime/third_party/bearssl/src/hash/md5sha1.c +141 -0
  305. package/runtime/third_party/bearssl/src/hash/mgf1.c +56 -0
  306. package/runtime/third_party/bearssl/src/hash/multihash.c +166 -0
  307. package/runtime/third_party/bearssl/src/hash/sha1.c +191 -0
  308. package/runtime/third_party/bearssl/src/hash/sha2big.c +285 -0
  309. package/runtime/third_party/bearssl/src/hash/sha2small.c +341 -0
  310. package/runtime/third_party/bearssl/src/inner.h +2577 -0
  311. package/runtime/third_party/bearssl/src/int/i15_add.c +46 -0
  312. package/runtime/third_party/bearssl/src/int/i15_bitlen.c +44 -0
  313. package/runtime/third_party/bearssl/src/int/i15_decmod.c +124 -0
  314. package/runtime/third_party/bearssl/src/int/i15_decode.c +56 -0
  315. package/runtime/third_party/bearssl/src/int/i15_decred.c +100 -0
  316. package/runtime/third_party/bearssl/src/int/i15_encode.c +56 -0
  317. package/runtime/third_party/bearssl/src/int/i15_fmont.c +59 -0
  318. package/runtime/third_party/bearssl/src/int/i15_iszero.c +39 -0
  319. package/runtime/third_party/bearssl/src/int/i15_moddiv.c +465 -0
  320. package/runtime/third_party/bearssl/src/int/i15_modpow.c +50 -0
  321. package/runtime/third_party/bearssl/src/int/i15_modpow2.c +160 -0
  322. package/runtime/third_party/bearssl/src/int/i15_montmul.c +184 -0
  323. package/runtime/third_party/bearssl/src/int/i15_mulacc.c +61 -0
  324. package/runtime/third_party/bearssl/src/int/i15_muladd.c +173 -0
  325. package/runtime/third_party/bearssl/src/int/i15_ninv15.c +38 -0
  326. package/runtime/third_party/bearssl/src/int/i15_reduce.c +66 -0
  327. package/runtime/third_party/bearssl/src/int/i15_rshift.c +47 -0
  328. package/runtime/third_party/bearssl/src/int/i15_sub.c +46 -0
  329. package/runtime/third_party/bearssl/src/int/i15_tmont.c +36 -0
  330. package/runtime/third_party/bearssl/src/int/i31_add.c +46 -0
  331. package/runtime/third_party/bearssl/src/int/i31_bitlen.c +44 -0
  332. package/runtime/third_party/bearssl/src/int/i31_decmod.c +124 -0
  333. package/runtime/third_party/bearssl/src/int/i31_decode.c +57 -0
  334. package/runtime/third_party/bearssl/src/int/i31_decred.c +103 -0
  335. package/runtime/third_party/bearssl/src/int/i31_encode.c +79 -0
  336. package/runtime/third_party/bearssl/src/int/i31_fmont.c +60 -0
  337. package/runtime/third_party/bearssl/src/int/i31_iszero.c +39 -0
  338. package/runtime/third_party/bearssl/src/int/i31_moddiv.c +488 -0
  339. package/runtime/third_party/bearssl/src/int/i31_modpow.c +65 -0
  340. package/runtime/third_party/bearssl/src/int/i31_modpow2.c +160 -0
  341. package/runtime/third_party/bearssl/src/int/i31_montmul.c +127 -0
  342. package/runtime/third_party/bearssl/src/int/i31_mulacc.c +74 -0
  343. package/runtime/third_party/bearssl/src/int/i31_muladd.c +157 -0
  344. package/runtime/third_party/bearssl/src/int/i31_ninv31.c +39 -0
  345. package/runtime/third_party/bearssl/src/int/i31_reduce.c +66 -0
  346. package/runtime/third_party/bearssl/src/int/i31_rshift.c +47 -0
  347. package/runtime/third_party/bearssl/src/int/i31_sub.c +46 -0
  348. package/runtime/third_party/bearssl/src/int/i31_tmont.c +36 -0
  349. package/runtime/third_party/bearssl/src/int/i32_add.c +51 -0
  350. package/runtime/third_party/bearssl/src/int/i32_bitlen.c +44 -0
  351. package/runtime/third_party/bearssl/src/int/i32_decmod.c +77 -0
  352. package/runtime/third_party/bearssl/src/int/i32_decode.c +63 -0
  353. package/runtime/third_party/bearssl/src/int/i32_decred.c +107 -0
  354. package/runtime/third_party/bearssl/src/int/i32_div32.c +56 -0
  355. package/runtime/third_party/bearssl/src/int/i32_encode.c +72 -0
  356. package/runtime/third_party/bearssl/src/int/i32_fmont.c +60 -0
  357. package/runtime/third_party/bearssl/src/int/i32_iszero.c +39 -0
  358. package/runtime/third_party/bearssl/src/int/i32_modpow.c +65 -0
  359. package/runtime/third_party/bearssl/src/int/i32_montmul.c +69 -0
  360. package/runtime/third_party/bearssl/src/int/i32_mulacc.c +56 -0
  361. package/runtime/third_party/bearssl/src/int/i32_muladd.c +138 -0
  362. package/runtime/third_party/bearssl/src/int/i32_ninv32.c +39 -0
  363. package/runtime/third_party/bearssl/src/int/i32_reduce.c +66 -0
  364. package/runtime/third_party/bearssl/src/int/i32_sub.c +51 -0
  365. package/runtime/third_party/bearssl/src/int/i32_tmont.c +36 -0
  366. package/runtime/third_party/bearssl/src/int/i62_modpow2.c +493 -0
  367. package/runtime/third_party/bearssl/src/kdf/hkdf.c +107 -0
  368. package/runtime/third_party/bearssl/src/kdf/shake.c +590 -0
  369. package/runtime/third_party/bearssl/src/mac/hmac.c +122 -0
  370. package/runtime/third_party/bearssl/src/mac/hmac_ct.c +193 -0
  371. package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +206 -0
  372. package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +157 -0
  373. package/runtime/third_party/bearssl/src/rand/sysrng.c +252 -0
  374. package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +38 -0
  375. package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +36 -0
  376. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +38 -0
  377. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +38 -0
  378. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +38 -0
  379. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +38 -0
  380. package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +38 -0
  381. package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +36 -0
  382. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +38 -0
  383. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +38 -0
  384. package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +38 -0
  385. package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +36 -0
  386. package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +583 -0
  387. package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +99 -0
  388. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +41 -0
  389. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +44 -0
  390. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +37 -0
  391. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +43 -0
  392. package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +209 -0
  393. package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +320 -0
  394. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +40 -0
  395. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +44 -0
  396. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +113 -0
  397. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +152 -0
  398. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +37 -0
  399. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +608 -0
  400. package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +99 -0
  401. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +41 -0
  402. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +44 -0
  403. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +37 -0
  404. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +43 -0
  405. package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +203 -0
  406. package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +318 -0
  407. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +40 -0
  408. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +44 -0
  409. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +106 -0
  410. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +152 -0
  411. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +41 -0
  412. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +44 -0
  413. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +37 -0
  414. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +43 -0
  415. package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +160 -0
  416. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +40 -0
  417. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +44 -0
  418. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +77 -0
  419. package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +57 -0
  420. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +61 -0
  421. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +64 -0
  422. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +57 -0
  423. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +63 -0
  424. package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +223 -0
  425. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +60 -0
  426. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +64 -0
  427. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +125 -0
  428. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +112 -0
  429. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +145 -0
  430. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
  431. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +121 -0
  432. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +106 -0
  433. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +121 -0
  434. package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +52 -0
  435. package/runtime/third_party/bearssl/src/settings.c +306 -0
  436. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +69 -0
  437. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +67 -0
  438. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +84 -0
  439. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +142 -0
  440. package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +254 -0
  441. package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +157 -0
  442. package/runtime/third_party/bearssl/src/symcipher/aes_common.c +112 -0
  443. package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +328 -0
  444. package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +398 -0
  445. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +104 -0
  446. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +81 -0
  447. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +114 -0
  448. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +433 -0
  449. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +159 -0
  450. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +115 -0
  451. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +111 -0
  452. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +91 -0
  453. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +116 -0
  454. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +422 -0
  455. package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +170 -0
  456. package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +112 -0
  457. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +445 -0
  458. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +670 -0
  459. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +417 -0
  460. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +717 -0
  461. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +946 -0
  462. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +69 -0
  463. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +67 -0
  464. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +84 -0
  465. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +142 -0
  466. package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +176 -0
  467. package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +129 -0
  468. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +240 -0
  469. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +223 -0
  470. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +122 -0
  471. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +211 -0
  472. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +596 -0
  473. package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +106 -0
  474. package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +237 -0
  475. package/runtime/third_party/bearssl/src/symcipher/des_ct.c +411 -0
  476. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +87 -0
  477. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +69 -0
  478. package/runtime/third_party/bearssl/src/symcipher/des_support.c +166 -0
  479. package/runtime/third_party/bearssl/src/symcipher/des_tab.c +310 -0
  480. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +85 -0
  481. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +67 -0
  482. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +260 -0
  483. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +297 -0
  484. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +475 -0
  485. package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +221 -0
  486. package/runtime/third_party/bearssl/src/x509/asn1.t0 +757 -0
  487. package/runtime/third_party/bearssl/src/x509/asn1enc.c +93 -0
  488. package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +110 -0
  489. package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +161 -0
  490. package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +97 -0
  491. package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +96 -0
  492. package/runtime/third_party/bearssl/src/x509/skey_decoder.c +653 -0
  493. package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +376 -0
  494. package/runtime/third_party/bearssl/src/x509/x509_decoder.c +776 -0
  495. package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +324 -0
  496. package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +105 -0
  497. package/runtime/third_party/bearssl/src/x509/x509_minimal.c +1722 -0
  498. package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +1526 -0
  499. package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +59 -0
  500. package/runtime/third_party/quickjs-dtoa/LICENSE +22 -0
  501. package/runtime/third_party/quickjs-dtoa/README.md +23 -0
  502. package/runtime/third_party/quickjs-dtoa/dtoa.c +1640 -0
  503. package/runtime/third_party/quickjs-dtoa/dtoa.h +83 -0
  504. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +89 -0
  505. package/runtime/third_party/quickjs-regexp/LICENSE +22 -0
  506. package/runtime/third_party/quickjs-regexp/README.md +22 -0
  507. package/runtime/third_party/quickjs-regexp/cutils.c +641 -0
  508. package/runtime/third_party/quickjs-regexp/cutils.h +457 -0
  509. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +73 -0
  510. package/runtime/third_party/quickjs-regexp/libregexp.c +3448 -0
  511. package/runtime/third_party/quickjs-regexp/libregexp.h +65 -0
  512. package/runtime/third_party/quickjs-regexp/libunicode-table.h +5206 -0
  513. package/runtime/third_party/quickjs-regexp/libunicode.c +2124 -0
  514. package/runtime/third_party/quickjs-regexp/libunicode.h +196 -0
  515. package/runtime/third_party/v8-ieee754/LICENSE +61 -0
  516. package/runtime/third_party/v8-ieee754/README.md +22 -0
  517. package/runtime/third_party/v8-ieee754/convert.py +84 -0
  518. package/runtime/third_party/v8-ieee754/ieee754.c +3030 -0
  519. package/runtime/third_party/v8-ieee754/ieee754.h +27 -0
  520. package/runtime/tools/regexp_compile.c +90 -0
@@ -0,0 +1,110 @@
1
+ /* js_web.h — the web-standard host layer (ADR 0012, layer 2): what its components share.
2
+ * DOMException is a component of its own (domexception.c); the components that throw one
3
+ * need it. The Node-style errors are web.c's, linked into the programs that throw them. */
4
+ #ifndef JS_WEB_H
5
+ #define JS_WEB_H
6
+
7
+ #include "js_builtins.h"
8
+ #include "js_error.h"
9
+ #include "jscontext.h"
10
+
11
+ /* A Node error: a native error of `kind` with an enumerable own `code` ("ERR_INVALID_THIS"),
12
+ * thrown. Always JS_EXCEPTION. */
13
+ JS_WARN_UNUSED JSValue js_throw_node_error(JSContext *ctx, JSErrorKind kind, const char *code, const char *fmt, ...);
14
+ /* ERR_INVALID_THIS: `Value of "this" must be of type TextDecoder`. */
15
+ JS_WARN_UNUSED JSValue js_throw_invalid_this(JSContext *ctx, const char *type);
16
+ /* ERR_INVALID_ARG_TYPE: `The "dest" argument must be <expected>. Received …` (Node's wording
17
+ * of the value). */
18
+ JS_WARN_UNUSED JSValue js_throw_invalid_arg_type(JSContext *ctx, const char *name, const char *expected, JSValue value);
19
+ /* Node's "Received …" tail for a value: " Received type number (1)", " Received an instance of
20
+ * Array", " Received undefined". */
21
+ void js_node_received(JSContext *ctx, JSValue v, char *buf, size_t cap);
22
+ /* `Class constructor X cannot be invoked without 'new'`, as a call of Node's JS classes throws. */
23
+ JS_WARN_UNUSED JSValue js_throw_class_without_new(JSContext *ctx, const char *name);
24
+
25
+ /* domexception.c: new DOMException(message, name), thrown or not. Needs the domexception component. */
26
+ JS_WARN_UNUSED JSValue js_throw_dom_exception(JSContext *ctx, const char *name, const char *message);
27
+ JS_WARN_UNUSED JSValue js_new_dom_exception(JSContext *ctx, const char *name, const char *message);
28
+
29
+ /* A native closure: `data` (any value) kept in the function, read back with js_closure_data. */
30
+ JSValue js_new_closure_native(JSContext *ctx, JSNativeFn fn, uint32_t length, JSValue data);
31
+ JSValue js_closure_data(JSValue callee);
32
+
33
+ /* Node's inspection of a web class through a plain object: `Name { a: 1 }`, where Name is the
34
+ * receiver's constructor name (`fallback` without one) and the object is inspected with the
35
+ * depth option less one, as Node's do; just `Name` past the depth. A [nodejs.util.inspect.custom](depth, options) body. */
36
+ JS_WARN_UNUSED JSValue js_inspect_as(JSContext *ctx, JSValue self, const char *fallback, JSValue object, JSValue depth, JSValue options);
37
+ /* The same with a fixed name (undici's classes show theirs whatever the subclass). */
38
+ JS_WARN_UNUSED JSValue js_inspect_named(JSContext *ctx, const char *name, JSValue object, JSValue depth, JSValue options);
39
+ /* Defines proto[Symbol.for("nodejs.util.inspect.custom")] = fn and proto[Symbol.toStringTag] = tag. */
40
+ void js_define_inspect(JSContext *ctx, JSValue proto, JSNativeFn fn, const char *tag);
41
+ /* A web class for a component: the constructor, its prototype (inheriting from `parent`, an
42
+ * object) in ctx->intrinsics[slot], and the global binding (writable, configurable). */
43
+ JSValue js_define_web_class(JSContext *ctx, JSObject *global, const char *name, JSNativeFn ctor, uint32_t length,
44
+ JSValue parent, JSIntrinsic slot);
45
+
46
+ /* UTF-8 bytes as a string, decoded as WHATWG decodes them: U+FFFD for each maximal invalid
47
+ * subpart (V8's and TextDecoder's decoding; js_new_string_utf8 replaces byte by byte). */
48
+ JS_WARN_UNUSED JSValue js_decode_utf8_bytes(JSContext *ctx, const uint8_t *p, size_t n);
49
+
50
+ /* buffer.c (the buffer component): a new Buffer holding a copy of the bytes. */
51
+ JS_WARN_UNUSED JSValue js_new_buffer_from_bytes(JSContext *ctx, const uint8_t *p, size_t n);
52
+
53
+ /* events.c (the events component): AbortSignals for the components that make them. */
54
+ JS_WARN_UNUSED JSValue js_new_abort_signal(JSContext *ctx);
55
+ bool js_is_abort_signal(JSValue v);
56
+ /* Aborts a signal (with the default AbortError when reason is undefined); once only. */
57
+ void js_abort_signal_abort(JSContext *ctx, JSValue signal, JSValue reason);
58
+ /* A new signal that aborts when `source` does (AbortSignal.any([source])). */
59
+ JS_WARN_UNUSED JSValue js_abort_signal_follow(JSContext *ctx, JSValue source);
60
+
61
+ /* headers.c (the headers component): Headers for Request and Response. */
62
+ typedef enum JSHeadersGuard { JS_HEADERS_NONE, JS_HEADERS_IMMUTABLE } JSHeadersGuard;
63
+ bool js_is_headers(JSValue v);
64
+ /* new Headers(init); init undefined for none. */
65
+ JS_WARN_UNUSED JSValue js_new_headers_from(JSContext *ctx, JSValue init);
66
+ void js_headers_set_guard(JSValue headers, JSHeadersGuard guard);
67
+ /* Appends name/value (validated, whatever the guard): 0, or -1. */
68
+ JS_WARN_UNUSED int js_headers_append(JSContext *ctx, JSValue headers, JSValue name, JSValue value);
69
+ /* A header's values combined, by its lowercase name: a string, or null. */
70
+ JS_WARN_UNUSED JSValue js_headers_get(JSContext *ctx, JSValue headers, const char *lower);
71
+ uint32_t js_headers_count(JSValue headers);
72
+ void js_headers_at(JSValue headers, uint32_t i, JSValue *lower, JSValue *name, JSValue *value);
73
+
74
+ /* streams.c (the streams component): ReadableStreams for bodies. A C source pulls with the
75
+ * controller and its data (a promise, a value or JS_EXCEPTION) and cancels with a reason. */
76
+ typedef struct JSStreamSource {
77
+ JSValue (*pull)(JSContext *ctx, JSValue controller, JSValue data);
78
+ JSValue (*cancel)(JSContext *ctx, JSValue data, JSValue reason); /* or NULL */
79
+ } JSStreamSource;
80
+ JS_WARN_UNUSED JSValue js_new_readable_stream(JSContext *ctx, const JSStreamSource *source, JSValue data, double high_water_mark);
81
+ /* A byte stream of one chunk (a Uint8Array), or of none (undefined), closed after it. */
82
+ JS_WARN_UNUSED JSValue js_readable_stream_of_bytes(JSContext *ctx, JSValue chunk);
83
+ bool js_is_readable_stream(JSValue v);
84
+ bool js_readable_stream_locked(JSValue v);
85
+ bool js_readable_stream_disturbed(JSValue v);
86
+ JS_WARN_UNUSED int js_readable_stream_enqueue(JSContext *ctx, JSValue controller, JSValue chunk);
87
+ JS_WARN_UNUSED int js_readable_stream_close(JSContext *ctx, JSValue controller);
88
+ void js_readable_stream_error(JSContext *ctx, JSValue controller, JSValue e);
89
+ /* Reads a stream of Uint8Array chunks to the end: a promise of one Uint8Array. */
90
+ JS_WARN_UNUSED JSValue js_readable_stream_read_all(JSContext *ctx, JSValue stream);
91
+ /* ReadableStreamTee: an array of the two branches. */
92
+ JS_WARN_UNUSED JSValue js_readable_stream_tee(JSContext *ctx, JSValue stream);
93
+
94
+ /* blob.c (the blob component) */
95
+ bool js_is_blob(JSValue v);
96
+ void js_blob_bytes(JSValue v, const uint8_t **data, size_t *size, JSValue *type);
97
+ JS_WARN_UNUSED JSValue js_new_blob(JSContext *ctx, const uint8_t *p, size_t n, JSValue type);
98
+
99
+ /* url.c (the url component): the href of a string parsed as an absolute URL, or undefined
100
+ * when it doesn't parse. */
101
+ JS_WARN_UNUSED JSValue js_parse_url_href(JSContext *ctx, JSValue input);
102
+ /* json.c (the json component): JSON.parse(text). */
103
+ JS_WARN_UNUSED JSValue js_json_parse(JSContext *ctx, JSValue text);
104
+
105
+ #define WEBIDL_OPERATION(name, fn, length) \
106
+ { (name), NULL, JS_BUILTIN_KIND_FN, JS_PROP_WRITABLE | JS_PROP_ENUMERABLE | JS_PROP_CONFIGURABLE, (length), (fn), NULL, 0, NULL }
107
+ #define WEBIDL_ATTRIBUTE(name, get, set) \
108
+ { (name), NULL, JS_BUILTIN_KIND_ACCESSOR, JS_PROP_ENUMERABLE | JS_PROP_CONFIGURABLE, 0, (get), (set), 0, NULL }
109
+
110
+ #endif /* JS_WEB_H */
@@ -0,0 +1,48 @@
1
+ /*
2
+ * jscell.h — the header word every heap cell starts with (ADR 0001, 0002).
3
+ */
4
+ #ifndef JSCELL_H
5
+ #define JSCELL_H
6
+
7
+ #include <stdint.h>
8
+
9
+ /* Cell kinds. Each has a JSCellClass (visit, finalize) in the GC.
10
+ * Kinds are added as their ADRs are implemented. */
11
+ typedef enum JSCellKind {
12
+ JS_CELL_INVALID = 0, /* never a live cell */
13
+ JS_CELL_STR_FLAT, /* JSString: inline Latin-1 or UTF-16 characters (ADR 0003) */
14
+ JS_CELL_STR_ROPE, /* JSRope: lazy concatenation (ADR 0003) */
15
+ JS_CELL_STR_SLICE, /* JSSlice: a substring sharing its parent's characters (ADR 0003) */
16
+ JS_CELL_VALUE_ARRAY, /* internal: fixed-length JSValue array (overflow slots, …) */
17
+ JS_CELL_HOST, /* internal: native payload with its own class (ADR 0012) */
18
+ JS_CELL_SHAPE, /* JSShape: hidden class (ADR 0005) */
19
+ JS_CELL_ACCESSOR, /* JSAccessorPair: {get, set} in an accessor property's slot */
20
+ JS_CELL_ELEMENTS, /* JSElements: indexed properties */
21
+ JS_CELL_ENV, /* JSEnv: a scope's captured variables (ADR 0006) */
22
+ JS_CELL_SYMBOL, /* JSSymbol: a symbol primitive (ADR 0001) */
23
+ JS_CELL_BIGINT, /* JSBigInt: a BigInt primitive (ADR 0016) */
24
+ /* Objects: every kind from here on starts with a JSObject (js_is_object). */
25
+ JS_CELL_OBJECT, /* ordinary objects, and exotic ones whose class is in the shape */
26
+ JS_CELL_ARRAY, /* JSArray */
27
+ JS_CELL_FUNCTION, /* JSFunction (ADR 0006) */
28
+ JS_CELL_KIND_COUNT
29
+ } JSCellKind;
30
+
31
+ /* Cell flags. The low byte is kind-specific (e.g. STR_LATIN1, ADR 0003). */
32
+ #define JS_CELL_STATIC 0x8000u /* emitted by the compiler: never marked or swept */
33
+ #define JS_CELL_FINALIZABLE 0x4000u /* the class finalizer must run when it dies */
34
+
35
+ /* 8 bytes, so the fields after it start 8-aligned and a 16-byte header fits two more words. */
36
+ typedef struct JSCell {
37
+ uint8_t kind; /* JSCellKind */
38
+ uint8_t reserved;
39
+ uint16_t flags;
40
+ uint32_t aux; /* kind-specific */
41
+ } JSCell;
42
+
43
+ #define JS_CELL_HEADER(kind, flags) { (uint8_t)(kind), 0, (uint16_t)(flags), 0 }
44
+
45
+ static inline JSCellKind js_cell_kind(const JSCell *c) { return (JSCellKind)c->kind; }
46
+ static inline int js_cell_is_static(const JSCell *c) { return (c->flags & JS_CELL_STATIC) != 0; }
47
+
48
+ #endif /* JSCELL_H */
@@ -0,0 +1,240 @@
1
+ /*
2
+ * jscontext.h — the two runtime handles (ADR 0011).
3
+ *
4
+ * JSRuntime the agent: heap and GC, atoms, pending exception, job queue
5
+ * JSContext a realm: global object and intrinsics. Reaches the agent via ctx->rt.
6
+ *
7
+ * Fields are added as each ADR is implemented.
8
+ */
9
+ #ifndef JSCONTEXT_H
10
+ #define JSCONTEXT_H
11
+
12
+ #include <string.h>
13
+
14
+ #include "js_atoms.h"
15
+ #include "js_bigint.h"
16
+ #include "js_gc.h"
17
+ #include "js_jobs.h"
18
+
19
+ /* Room left below the stack limit for the throw path and for runtime C code
20
+ * called after the last check (ADR 0004). Sanitizers make frames larger. */
21
+ #if defined(__SANITIZE_ADDRESS__)
22
+ #define JS_STACK_MARGIN ((uintptr_t)256 * 1024)
23
+ #elif defined(__has_feature)
24
+ #if __has_feature(address_sanitizer)
25
+ #define JS_STACK_MARGIN ((uintptr_t)256 * 1024)
26
+ #endif
27
+ #endif
28
+ #ifndef JS_STACK_MARGIN
29
+ #define JS_STACK_MARGIN ((uintptr_t)64 * 1024)
30
+ #endif
31
+
32
+ /* Typed array element types (js_buffer.h lists them): one constructor and prototype each. */
33
+ #define JS_TYPED_ARRAY_TYPES 12
34
+
35
+ /* Per-realm objects the runtime needs (ADR 0011). Filled in as the object
36
+ * model and built-ins land (M3); every slot is a GC root. */
37
+ typedef enum JSIntrinsic {
38
+ JS_INTRINSIC_GLOBAL_OBJECT, /* globalThis */
39
+ JS_INTRINSIC_OBJECT_PROTOTYPE, /* %Object.prototype% */
40
+ JS_INTRINSIC_ARRAY_PROTOTYPE, /* %Array.prototype%: itself an array */
41
+ JS_INTRINSIC_FUNCTION_PROTOTYPE, /* %Function.prototype%: itself a function */
42
+ JS_INTRINSIC_THROW_TYPE_ERROR, /* %ThrowTypeError%: strict arguments.callee */
43
+ JS_INTRINSIC_FUNCTION_HAS_INSTANCE,
44
+ JS_INTRINSIC_FUNCTION_SHAPE, /* the shapes new functions start with: length and name in place (js_cached_shape) */
45
+ JS_INTRINSIC_GENERATOR_FUNCTION_SHAPE,
46
+ JS_INTRINSIC_ASYNC_FUNCTION_SHAPE,
47
+ JS_INTRINSIC_ASYNC_GENERATOR_FUNCTION_SHAPE,
48
+ JS_INTRINSIC_ITER_RESULT_SHAPE, /* { value, done } */
49
+ JS_INTRINSIC_PROMISE_SPECIES_GETTER, /* the original Promise[@@species] getter: then's fast path */ /* Function.prototype[@@hasInstance]: instanceof's fast path */
50
+ JS_INTRINSIC_STRING_PROTOTYPE, /* where primitives look up properties */
51
+ JS_INTRINSIC_NUMBER_PROTOTYPE,
52
+ JS_INTRINSIC_BOOLEAN_PROTOTYPE,
53
+ JS_INTRINSIC_SYMBOL_PROTOTYPE,
54
+ JS_INTRINSIC_BIGINT_PROTOTYPE, /* the bigint component */
55
+ JS_INTRINSIC_ITERATOR_PROTOTYPE, /* %IteratorPrototype% */
56
+ JS_INTRINSIC_ARRAY_ITERATOR_PROTOTYPE,
57
+ JS_INTRINSIC_ARRAY_ITERATOR_NEXT, /* the original next: the array fast path checks it */
58
+ JS_INTRINSIC_ARRAY_VALUES, /* %Array.prototype.values%, also Array.prototype[@@iterator] */
59
+ JS_INTRINSIC_STRING_ITERATOR_PROTOTYPE,
60
+ JS_INTRINSIC_STRING_ITERATOR_NEXT,
61
+ JS_INTRINSIC_STRING_ITERATOR, /* the original String.prototype[@@iterator] */
62
+ JS_INTRINSIC_GENERATOR_FUNCTION_PROTOTYPE, /* %GeneratorFunction.prototype% */
63
+ JS_INTRINSIC_GENERATOR_PROTOTYPE, /* %GeneratorPrototype% */
64
+ JS_INTRINSIC_ASYNC_FUNCTION_PROTOTYPE, /* %AsyncFunction.prototype% */
65
+ JS_INTRINSIC_ASYNC_ITERATOR_PROTOTYPE, /* %AsyncIteratorPrototype% */
66
+ JS_INTRINSIC_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE,
67
+ JS_INTRINSIC_ASYNC_GENERATOR_FUNCTION_PROTOTYPE, /* %AsyncGeneratorFunction.prototype% */
68
+ JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE, /* %AsyncGeneratorPrototype% */
69
+ JS_INTRINSIC_WEAK_MAP_PROTOTYPE,
70
+ JS_INTRINSIC_WEAK_SET_PROTOTYPE,
71
+ JS_INTRINSIC_WEAK_REF_PROTOTYPE,
72
+ JS_INTRINSIC_FINALIZATION_REGISTRY_PROTOTYPE,
73
+ JS_INTRINSIC_MAP_PROTOTYPE, /* the collections component (ADR 0014), when installed */
74
+ JS_INTRINSIC_SET_PROTOTYPE,
75
+ JS_INTRINSIC_MAP_ITERATOR_PROTOTYPE,
76
+ JS_INTRINSIC_SET_ITERATOR_PROTOTYPE,
77
+ JS_INTRINSIC_ARRAY_BUFFER_PROTOTYPE, /* the arraybuffer component */
78
+ JS_INTRINSIC_DATA_VIEW_PROTOTYPE,
79
+ JS_INTRINSIC_DATE_PROTOTYPE, /* the date component */
80
+ JS_INTRINSIC_TYPED_ARRAY, /* %TypedArray%, the typedarray component */
81
+ JS_INTRINSIC_TYPED_ARRAY_PROTOTYPE,
82
+ JS_INTRINSIC_TYPED_ARRAY_CTORS, /* then one per element type (js_buffer.h) */
83
+ JS_INTRINSIC_TYPED_ARRAY_PROTOS = JS_INTRINSIC_TYPED_ARRAY_CTORS + JS_TYPED_ARRAY_TYPES,
84
+ JS_INTRINSIC_TYPED_ARRAY_PROTOS_END = JS_INTRINSIC_TYPED_ARRAY_PROTOS + JS_TYPED_ARRAY_TYPES - 1,
85
+ JS_INTRINSIC_PROMISE, /* %Promise%: NewPromiseCapability's fast path checks it */
86
+ JS_INTRINSIC_PROMISE_PROTOTYPE,
87
+ JS_INTRINSIC_ERROR_PROTOTYPE, /* then one per native error, in JSErrorKind order */
88
+ JS_INTRINSIC_EVAL_ERROR_PROTOTYPE,
89
+ JS_INTRINSIC_RANGE_ERROR_PROTOTYPE,
90
+ JS_INTRINSIC_REFERENCE_ERROR_PROTOTYPE,
91
+ JS_INTRINSIC_SYNTAX_ERROR_PROTOTYPE,
92
+ JS_INTRINSIC_TYPE_ERROR_PROTOTYPE,
93
+ JS_INTRINSIC_URI_ERROR_PROTOTYPE,
94
+ JS_INTRINSIC_AGGREGATE_ERROR_PROTOTYPE,
95
+ JS_INTRINSIC_ERROR_STACK_GET, /* every error's `stack` accessor (V8's) */
96
+ JS_INTRINSIC_ERROR_STACK_SET,
97
+ JS_INTRINSIC_ERROR, /* %Error%: Error.captureStackTrace reads its prepareStackTrace and stackTraceLimit */
98
+ JS_INTRINSIC_CALL_SITE_PROTOTYPE, /* the placeholder call sites Error.prepareStackTrace receives */
99
+ JS_INTRINSIC_REGEXP, /* %RegExp%, when the RegExp component is installed (ADR 0015) */
100
+ JS_INTRINSIC_REGEXP_PROTOTYPE,
101
+ JS_INTRINSIC_REGEXP_EXEC, /* the original RegExp.prototype.exec: RegExpExec calls it directly */
102
+ JS_INTRINSIC_REGEXP_STRING_ITERATOR_PROTOTYPE,
103
+ JS_INTRINSIC_DOM_EXCEPTION_PROTOTYPE, /* the web-standard host layer (ADR 0012, layer 2) */
104
+ JS_INTRINSIC_TEXT_ENCODER_PROTOTYPE,
105
+ JS_INTRINSIC_TEXT_DECODER_PROTOTYPE,
106
+ JS_INTRINSIC_URL_PROTOTYPE,
107
+ JS_INTRINSIC_URL_SEARCH_PARAMS_PROTOTYPE,
108
+ JS_INTRINSIC_URL_SEARCH_PARAMS_ITERATOR_PROTOTYPE,
109
+ JS_INTRINSIC_URL_SEARCH_PARAMS_ENTRIES,
110
+ JS_INTRINSIC_EVENT_PROTOTYPE,
111
+ JS_INTRINSIC_EVENT_TARGET_PROTOTYPE,
112
+ JS_INTRINSIC_ABORT_SIGNAL_PROTOTYPE,
113
+ JS_INTRINSIC_ABORT_CONTROLLER_PROTOTYPE,
114
+ JS_INTRINSIC_BUFFER, /* Node's Buffer (ADR 0012, layer 3) */
115
+ JS_INTRINSIC_BUFFER_PROTOTYPE,
116
+ JS_INTRINSIC_HEADERS_PROTOTYPE,
117
+ JS_INTRINSIC_HEADERS_ITERATOR_PROTOTYPE,
118
+ JS_INTRINSIC_READABLE_STREAM_PROTOTYPE,
119
+ JS_INTRINSIC_READABLE_STREAM_READER_PROTOTYPE,
120
+ JS_INTRINSIC_READABLE_STREAM_CONTROLLER_PROTOTYPE,
121
+ JS_INTRINSIC_READABLE_STREAM_ITERATOR_PROTOTYPE,
122
+ JS_INTRINSIC_WRITABLE_STREAM_PROTOTYPE,
123
+ JS_INTRINSIC_WRITABLE_STREAM_WRITER_PROTOTYPE,
124
+ JS_INTRINSIC_WRITABLE_STREAM_CONTROLLER_PROTOTYPE,
125
+ JS_INTRINSIC_TRANSFORM_STREAM_PROTOTYPE,
126
+ JS_INTRINSIC_TRANSFORM_STREAM_CONTROLLER_PROTOTYPE,
127
+ JS_INTRINSIC_BLOB_PROTOTYPE,
128
+ JS_INTRINSIC_FILE_PROTOTYPE,
129
+ JS_INTRINSIC_REQUEST_PROTOTYPE,
130
+ JS_INTRINSIC_RESPONSE_PROTOTYPE, /* the original entries: new URLSearchParams(params) copies directly */
131
+ JS_INTRINSIC_CRYPTO, /* Web Crypto (ADR 0018): the crypto object */
132
+ JS_INTRINSIC_CRYPTO_PROTOTYPE,
133
+ JS_INTRINSIC_SUBTLE_CRYPTO, /* crypto.subtle */
134
+ JS_INTRINSIC_SUBTLE_CRYPTO_PROTOTYPE,
135
+ JS_INTRINSIC_CRYPTO_KEY_PROTOTYPE,
136
+ JS_INTRINSIC_UTIL_INSPECT, /* the util.inspect function custom inspectors receive (ADR 0012) */
137
+ JS_INTRINSIC_CONSOLE_STATE, /* console's counters and timers, by label */
138
+ JS_INTRINSIC_COUNT
139
+ } JSIntrinsic;
140
+
141
+ /* Shapes the GC processes weakly (ADR 0005): root shapes by (class, proto,
142
+ * capacity), and shapes whose transition tables point to children. */
143
+ typedef struct JSShapeRegistry {
144
+ struct JSShape **roots; /* open addressing; NULL = empty */
145
+ size_t root_cap, root_count;
146
+ struct JSShape **parents; /* shapes with transitions */
147
+ size_t parent_count, parent_cap;
148
+ } JSShapeRegistry;
149
+
150
+ /* Registered inline-cache arrays (ADR 0005): reset weakly after marking. */
151
+ typedef struct JSPropCacheTables {
152
+ struct JSPropCacheTable { struct JSPropCache *ics; size_t n; } *tables;
153
+ size_t count, cap;
154
+ } JSPropCacheTables;
155
+
156
+ /* What util.inspect shows of a Map, a Set or their iterators (collection_preview). */
157
+ typedef enum JSCollectionPreview {
158
+ JS_PREVIEW_MAP, JS_PREVIEW_SET, /* the entries */
159
+ JS_PREVIEW_MAP_ITERATOR, JS_PREVIEW_SET_ITERATOR, /* the keys or values left */
160
+ JS_PREVIEW_MAP_ENTRIES, JS_PREVIEW_SET_ENTRIES, /* the [key, value] pairs left */
161
+ } JSCollectionPreview;
162
+
163
+ /* An I/O backend for the event loop (ADR 0008): libuv, set by the host code that first needs it
164
+ * (node:http), so that programs without I/O don't link libuv. */
165
+ typedef struct JSIOBackend {
166
+ bool (*alive)(JSRuntime *rt); /* open handles (servers, sockets) keep the program running */
167
+ /* Waits for I/O at most timeout_ms (-1: until some), running the callbacks it brings: 0, or
168
+ * the exit status after an uncaught error (already reported). */
169
+ int (*run)(JSContext *ctx, int64_t timeout_ms);
170
+ } JSIOBackend;
171
+
172
+ struct JSRuntime {
173
+ JSHeap heap;
174
+ JSShapeRegistry shapes;
175
+ JSPropCacheTables prop_caches;
176
+ /* the shared second-level caches (object.c): get and set entries by (shape, key), for the
177
+ * sites a monomorphic cache misses and C code's lookups; emptied at every collection */
178
+ struct JSMegaEntry *mega_get, *mega_set;
179
+ JSContext *realms; /* every live JSContext, linked through next_realm */
180
+ JSAtomTable atoms; /* weak (ADR 0003) */
181
+ JSValue exception; /* pending exception, JS_EMPTY if none; a GC root (ADR 0004) */
182
+ JSValue symbol_registry; /* Symbol.for's GlobalSymbolRegistry: key -> symbol (a root) */
183
+ uintptr_t stack_limit; /* lowest usable stack address, margin included */
184
+ JSJobQueue jobs; /* microtasks (ADR 0008) */
185
+ JSTimers timers; /* setTimeout / setInterval (ADR 0008) */
186
+ struct JSRejections { JSValue *items; size_t count, cap; } rejections; /* rejected, unhandled promises (roots) */
187
+ struct JSWeakList { struct JSObject **items; size_t count, cap; } weak; /* WeakMap/Set/Ref, registries (ADR 0002) */
188
+ struct JSKeptAlive { JSValue *items; size_t count, cap; } kept_alive; /* [[KeptAlive]]: roots until ClearKeptObjects */
189
+ const struct JSComponent *const *components; /* installed in every realm (ADR 0014) */
190
+ size_t ncomponents;
191
+ const struct JSCoreEntry *core; /* the core methods every realm installs (js_core.def) */
192
+ size_t ncore;
193
+ /* Set by the collections component (ADR 0014: core reaches optional components through
194
+ * hooks): a Map's or Set's entries, or what an iterator has left, as an array (flat
195
+ * [k1, v1, k2, v2, …] for a Map and the entries iterators); EMPTY for other values. */
196
+ JSValue (*collection_preview)(JSContext *ctx, JSValue v, JSCollectionPreview *what);
197
+ bool (*is_typed_array)(JSValue v); /* set by typed arrays: ArrayBuffer.isView */
198
+ /* Set by Date: a Date's ISO string ("Invalid Date" if invalid) for util.inspect; EMPTY otherwise. */
199
+ JSValue (*date_inspect)(JSContext *ctx, JSValue v);
200
+ /* Set by RegExp: a RegExp's "/source/flags" for util.inspect; EMPTY otherwise. */
201
+ JSValue (*regexp_inspect)(JSContext *ctx, JSValue v);
202
+ const JSBigIntOps *bigint; /* set by the bigint component (ADR 0016) */
203
+ /* A typed array's length now: -1 when out of bounds (detached), -2 for anything else. */
204
+ double (*typed_array_length)(JSValue v);
205
+ const JSIOBackend *io; /* the event loop's I/O, once a program uses some */
206
+ uint8_t rejection_mode; /* JSRejectionMode */
207
+ uint8_t in_checkpoint; /* js_run_microtasks is running */
208
+ };
209
+
210
+ struct JSContext {
211
+ JSRuntime *rt;
212
+ uintptr_t stack_limit; /* copy of rt->stack_limit: one load in every function prologue */
213
+ JSValue intrinsics[JS_INTRINSIC_COUNT];
214
+ JSContext *next_realm;
215
+ };
216
+
217
+ JSRuntime *js_runtime_new(void);
218
+ void js_runtime_free(JSRuntime *rt); /* frees every cell, running finalizers */
219
+ JSContext *js_context_new(JSRuntime *rt); /* a new realm; js_runtime_free frees any left */
220
+ void js_context_free(JSContext *ctx);
221
+ /* The test262 host (ADR 0011): defines $262 on ctx's global object and returns it. */
222
+ JSValue js_test_host_init(JSContext *ctx);
223
+
224
+ /* Allocation fast path: pop the class's free list and zero the cell (ADR 0002).
225
+ * Zeroed memory reads as JS_EMPTY, so a half-initialized cell is always safe to trace.
226
+ * GC-stress builds (ADR 0011) always take the slow path, which collects first. */
227
+ static inline void *js_alloc_small(JSContext *ctx, unsigned size_class) {
228
+ #ifdef JS_GC_STRESS
229
+ JSFreeCell *c = (JSFreeCell *)js_alloc_slow(ctx, size_class);
230
+ #else
231
+ JSHeap *h = &ctx->rt->heap;
232
+ JSFreeCell *c = h->free[size_class];
233
+ if (JS_LIKELY(c)) h->free[size_class] = c->next;
234
+ else c = (JSFreeCell *)js_alloc_slow(ctx, size_class);
235
+ #endif
236
+ memset(c, 0, js_size_class_bytes[size_class]);
237
+ return c;
238
+ }
239
+
240
+ #endif /* JSCONTEXT_H */
@@ -0,0 +1,42 @@
1
+ /*
2
+ * jsnum.h — number <-> string conversion (ADR 0013).
3
+ *
4
+ * Digit generation and rounding come from the vendored QuickJS dtoa.c.
5
+ * The JS grammar (StringNumericLiteral) is ours.
6
+ */
7
+ #ifndef JSNUM_H
8
+ #define JSNUM_H
9
+
10
+ #include <stddef.h>
11
+ #include <stdint.h>
12
+
13
+ #include "jsstring.h"
14
+
15
+ /* Fits any output: toString(2) of the smallest subnormal is ~1,080 characters. */
16
+ #define JS_NUM_BUF_SIZE 1100
17
+
18
+ /* All functions write a NUL-terminated ASCII string and return its length. */
19
+
20
+ size_t js_i32_to_cstr(char *buf, int32_t i);
21
+ /* Number::toString(x, 10): shortest round-trip. "NaN", "Infinity", -0 → "0". */
22
+ size_t js_num_to_cstr(char *buf, double d);
23
+ /* Number.prototype.toString(radix), 2 <= radix <= 36. */
24
+ size_t js_num_to_cstr_radix(char *buf, double d, int radix);
25
+
26
+ /* The caller has range-checked `digits` and thrown RangeError if needed. */
27
+ size_t js_num_to_fixed(char *buf, double d, int digits); /* 0..100 */
28
+ size_t js_num_to_precision(char *buf, double d, int digits); /* 1..100 */
29
+ size_t js_num_to_exponential(char *buf, double d, int digits); /* 0..100, or -1: as many as needed */
30
+ /* Number.prototype.toLocaleString until Intl: en-US as ICU prints it ("1,234.568", "-∞"), UTF-8.
31
+ * `buf` holds 512 bytes. */
32
+ size_t js_num_to_locale(char *buf, double d);
33
+
34
+ /* StringToNumber (ToNumber on a string). Never fails: bad input is NaN. */
35
+ double js_str_to_num(JSStrView s);
36
+
37
+ /* parseFloat(s) and parseInt(s, radix): the longest valid prefix after leading
38
+ * whitespace. `radix` is already ToInt32'd; 0 means 10, or 16 after "0x". */
39
+ double js_parse_float(JSStrView s);
40
+ double js_parse_int(JSStrView s, int32_t radix);
41
+
42
+ #endif /* JSNUM_H */
@@ -0,0 +1,161 @@
1
+ /*
2
+ * jsstring.h — strings (ADR 0003).
3
+ *
4
+ * A string is a sequence of UTF-16 code units. Cells are flat (characters
5
+ * inline, Latin-1 when every unit is <= 0xFF, else UTF-16), ropes (lazy
6
+ * concatenations, flattened on first read) or slices (long substrings, which
7
+ * share their parent's characters). Everything that reads characters goes
8
+ * through a JSStrView.
9
+ */
10
+ #ifndef JSSTRING_H
11
+ #define JSSTRING_H
12
+
13
+ #include <stdbool.h>
14
+ #include <stddef.h>
15
+ #include <stdint.h>
16
+
17
+ #include "jscell.h"
18
+ #include "jsvalue.h"
19
+
20
+ typedef struct JSContext JSContext;
21
+
22
+ /* Cell flags (low byte of JSCell.flags) */
23
+ #define JS_STR_LATIN1 0x01u /* flat: 1 byte per unit; rope: both sides are Latin-1; slice: the parent is */
24
+ #define JS_STR_ATOM 0x02u /* the unique interned copy of its content */
25
+ #define JS_STR_PRIVATE 0x04u /* a private name (#x): a property key no key listing shows */
26
+
27
+ #define JS_STRING_MAX_LENGTH ((UINT32_C(1) << 30) - 1)
28
+ #define JS_ROPE_MIN 13 /* shorter concatenations copy instead */
29
+ #define JS_ROPE_MAX_DEPTH 1024 /* deeper concatenations flatten eagerly */
30
+ #define JS_SLICE_MIN 13 /* shorter substrings copy instead */
31
+ #define JS_SLICE_MAX_WASTE 4 /* a slice is at least 1/4 of its parent; smaller ones copy */
32
+
33
+ typedef struct JSString { /* kind = STR_FLAT */
34
+ JSCell cell; /* flags: STR_LATIN1, STR_ATOM, CELL_STATIC */
35
+ uint32_t length; /* UTF-16 code units */
36
+ uint32_t hash; /* 0 = not computed yet; computed hashes are never 0 */
37
+ union { uint8_t latin1[1]; uint16_t utf16[1]; } chars; /* flexible; Latin-1 has a trailing NUL */
38
+ } JSString; /* 16-byte header */
39
+
40
+ typedef struct JSRope { /* kind = STR_ROPE */
41
+ JSCell cell; /* flags: STR_LATIN1 */
42
+ uint32_t length;
43
+ uint16_t depth; /* max(left depth, right depth) + 1 */
44
+ uint16_t reserved;
45
+ JSValue left; /* after flattening: the resulting STR_FLAT */
46
+ JSValue right; /* after flattening: JS_EMPTY */
47
+ } JSRope;
48
+
49
+ typedef struct JSSlice { /* kind = STR_SLICE */
50
+ JSCell cell; /* flags: STR_LATIN1 */
51
+ uint32_t length;
52
+ uint32_t hash; /* as in JSString */
53
+ JSValue parent; /* a STR_FLAT: slices never nest */
54
+ uint32_t offset; /* the first unit, in the parent */
55
+ uint32_t reserved;
56
+ } JSSlice;
57
+
58
+ #define JS_STRING_HEADER_SIZE offsetof(JSString, chars)
59
+
60
+ /* ---- Views ------------------------------------------------------------- */
61
+
62
+ typedef struct {
63
+ const void *chars; /* uint8_t* if latin1, else uint16_t* */
64
+ uint32_t length;
65
+ bool latin1;
66
+ } JSStrView;
67
+
68
+ static inline uint32_t js_view_at(JSStrView v, uint32_t i) {
69
+ return v.latin1 ? ((const uint8_t *)v.chars)[i] : ((const uint16_t *)v.chars)[i];
70
+ }
71
+
72
+ static inline JSStrView js_view_latin1(const char *chars, uint32_t length) {
73
+ return (JSStrView){ chars, length, true };
74
+ }
75
+
76
+ static inline JSStrView js_view_utf16(const uint16_t *chars, uint32_t length) {
77
+ return (JSStrView){ chars, length, false };
78
+ }
79
+
80
+ /* The characters of string `s`, flattening a rope first (which allocates).
81
+ * Valid while `s` is live; the chars pointer itself keeps the cell alive. */
82
+ JSStrView js_string_view(JSContext *ctx, JSValue s);
83
+
84
+ /* ---- Type tests and accessors ----------------------------------------- */
85
+
86
+ static inline bool js_is_string(JSValue v) {
87
+ if (!js_is_cell(v)) return false;
88
+ uint8_t k = js_as_cell(v)->kind;
89
+ return k >= JS_CELL_STR_FLAT && k <= JS_CELL_STR_SLICE;
90
+ }
91
+
92
+ static inline uint32_t js_string_length(JSValue s) {
93
+ JSCell *c = js_as_cell(s);
94
+ switch (c->kind) {
95
+ case JS_CELL_STR_FLAT: return ((JSString *)c)->length;
96
+ case JS_CELL_STR_ROPE: return ((JSRope *)c)->length;
97
+ default: return ((JSSlice *)c)->length;
98
+ }
99
+ }
100
+
101
+ /* ---- Hashing (FNV-1a over UTF-16 code units; the compiler computes the same) ---- */
102
+
103
+ #define JS_HASH_INIT UINT32_C(2166136261)
104
+ #define JS_HASH_PRIME UINT32_C(16777619)
105
+ #define JS_HASH_STEP(h, unit) ((uint32_t)(((h) ^ (uint32_t)(unit)) * JS_HASH_PRIME))
106
+ #define JS_HASH_FIX(h) ((h) ? (h) : UINT32_C(1)) /* 0 means "not computed" */
107
+
108
+ uint32_t js_hash_view(JSStrView v);
109
+ uint32_t js_string_hash(JSContext *ctx, JSValue s); /* cached in the cell (not in static cells) */
110
+
111
+ /* ---- Static strings (compiler-emitted, never collected) ---------------- */
112
+
113
+ #define JS_STATIC_LATIN1_TYPE(n) \
114
+ struct { _Alignas(16) JSCell cell; uint32_t length, hash; uint8_t chars[(n) + 1]; }
115
+ #define JS_STATIC_UTF16_TYPE(n) \
116
+ struct { _Alignas(16) JSCell cell; uint32_t length, hash; uint16_t chars[(n) ? (n) : 1]; }
117
+ #define JS_STATIC_LATIN1_INIT(len, hash, ...) \
118
+ { JS_CELL_HEADER(JS_CELL_STR_FLAT, JS_CELL_STATIC | JS_STR_LATIN1), (len), (hash), __VA_ARGS__ }
119
+ #define JS_STATIC_ATOM_INIT(len, hash, ...) \
120
+ { JS_CELL_HEADER(JS_CELL_STR_FLAT, JS_CELL_STATIC | JS_STR_LATIN1 | JS_STR_ATOM), (len), (hash), __VA_ARGS__ }
121
+ #define JS_STATIC_UTF16_INIT(len, hash, ...) \
122
+ { JS_CELL_HEADER(JS_CELL_STR_FLAT, JS_CELL_STATIC), (len), (hash), __VA_ARGS__ }
123
+ #define JS_STATIC_UTF16_ATOM_INIT(len, hash, ...) \
124
+ { JS_CELL_HEADER(JS_CELL_STR_FLAT, JS_CELL_STATIC | JS_STR_ATOM), (len), (hash), __VA_ARGS__ }
125
+ #define JS_STATIC_STR(s) js_cell((JSCell *)&(s))
126
+
127
+ /* "" and every single code unit 0…255: static atoms, never allocated. */
128
+ JSValue js_empty_string(void);
129
+ JSValue js_char_string(uint8_t unit);
130
+
131
+ /* ---- Creating strings -------------------------------------------------- */
132
+
133
+ /* Each narrows to Latin-1 when it can, and returns the static cells for "" and
134
+ * single units <= 0xFF. Longer than JS_STRING_MAX_LENGTH: RangeError. */
135
+ JS_WARN_UNUSED JSValue js_new_string_latin1(JSContext *ctx, const uint8_t *chars, uint32_t length);
136
+ JS_WARN_UNUSED JSValue js_new_string_utf16(JSContext *ctx, const uint16_t *chars, uint32_t length);
137
+ JS_WARN_UNUSED JSValue js_new_string_view(JSContext *ctx, JSStrView v);
138
+ /* Decodes UTF-8; invalid sequences become U+FFFD. */
139
+ JS_WARN_UNUSED JSValue js_new_string_utf8(JSContext *ctx, const char *s, size_t length);
140
+ JS_WARN_UNUSED JSValue js_new_string_cstr(JSContext *ctx, const char *s); /* UTF-8, NUL-terminated */
141
+
142
+ /* ---- Operations -------------------------------------------------------- */
143
+
144
+ /* RangeError if the result would exceed JS_STRING_MAX_LENGTH. */
145
+ JS_WARN_UNUSED JSValue js_concat(JSContext *ctx, JSValue a, JSValue b);
146
+ /* Code units [start, end) of s; 0 <= start <= end <= length. */
147
+ JSValue js_substring(JSContext *ctx, JSValue s, uint32_t start, uint32_t end);
148
+ bool js_string_equals(JSContext *ctx, JSValue a, JSValue b);
149
+ /* <0, 0, >0 by code units (the relational operators on strings). */
150
+ int js_string_compare(JSContext *ctx, JSValue a, JSValue b);
151
+
152
+ /* Number::toString(n) as a string cell (ADR 0013). `n` is an int32 or a double. */
153
+ JSValue js_number_to_string(JSContext *ctx, JSValue n);
154
+
155
+ /* ---- Output ------------------------------------------------------------ */
156
+
157
+ /* UTF-8 encoding of a view; lone surrogates become U+FFFD. Writes at most `cap`
158
+ * bytes (no NUL) and returns the full length needed. */
159
+ size_t js_view_to_utf8(JSStrView v, char *out, size_t cap);
160
+
161
+ #endif /* JSSTRING_H */