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,384 @@
1
+ /*
2
+ * js_object.h — the object model (ADR 0005): shapes, objects, property keys,
3
+ * and the ordinary internal methods ([[Get]], [[Set]], [[DefineOwnProperty]], …).
4
+ *
5
+ * Named properties (atoms, symbols) live in shape-described slots; indexed
6
+ * properties (array indices, int32 keys) live in the elements store.
7
+ */
8
+ #ifndef JS_OBJECT_H
9
+ #define JS_OBJECT_H
10
+
11
+ #include "js_exception.h"
12
+ #include "jsstring.h"
13
+
14
+ /* ---- Property attributes ------------------------------------------------ */
15
+
16
+ #define JS_PROP_WRITABLE 0x01u
17
+ #define JS_PROP_ENUMERABLE 0x02u
18
+ #define JS_PROP_CONFIGURABLE 0x04u
19
+ #define JS_PROP_ACCESSOR 0x08u /* the slot holds a JSAccessorPair */
20
+ #define JS_PROP_DEFAULT (JS_PROP_WRITABLE | JS_PROP_ENUMERABLE | JS_PROP_CONFIGURABLE)
21
+
22
+ /* A property descriptor (§6.2.6): which fields are present, and their values. */
23
+ #define JS_DESC_VALUE 0x01u
24
+ #define JS_DESC_GET 0x02u
25
+ #define JS_DESC_SET 0x04u
26
+ #define JS_DESC_WRITABLE 0x08u
27
+ #define JS_DESC_ENUMERABLE 0x10u
28
+ #define JS_DESC_CONFIGURABLE 0x20u
29
+
30
+ typedef struct JSPropertyDescriptor {
31
+ uint8_t has; /* JS_DESC_* */
32
+ uint8_t attrs; /* JS_PROP_WRITABLE/ENUMERABLE/CONFIGURABLE, meaningful where `has` says so */
33
+ JSValue value;
34
+ JSValue get; /* undefined or a function */
35
+ JSValue set;
36
+ } JSPropertyDescriptor;
37
+
38
+ /* A data property with the given attributes. */
39
+ static inline JSPropertyDescriptor js_data_descriptor(JSValue value, uint8_t attrs) {
40
+ JSPropertyDescriptor d = { JS_DESC_VALUE | JS_DESC_WRITABLE | JS_DESC_ENUMERABLE | JS_DESC_CONFIGURABLE,
41
+ (uint8_t)(attrs & JS_PROP_DEFAULT), value, JS_UNDEFINED, JS_UNDEFINED };
42
+ return d;
43
+ }
44
+
45
+ /* ---- Cells ---------------------------------------------------------------- */
46
+
47
+ typedef struct JSObject JSObject;
48
+ typedef struct JSShape JSShape;
49
+ typedef struct JSPropTable JSPropTable;
50
+ typedef struct JSTransitions JSTransitions;
51
+
52
+ /* A class hook returns this to fall back to the ordinary algorithm for a key. */
53
+ #define JS_ORDINARY 2
54
+ /* JS_ORDINARY, but the answer for this key isn't a function of the shape: caches don't remember it. */
55
+ #define JS_ORDINARY_UNCACHED 3
56
+
57
+ /* Exotic behavior (ADR 0005, "class hooks"). NULL hooks mean ordinary behavior.
58
+ * Grows as exotic objects arrive (Function, arguments, Proxy…). Inline caches rely on
59
+ * this: whether a hook takes over a named key depends only on the object's shape, or
60
+ * the hook changes the shape (Function's lazy `prototype`). */
61
+ /* The internal methods an object overrides (Proxy §10.5, typed arrays §10.4.5): the core calls
62
+ * these instead of the ordinary algorithms, also when the object is on a prototype chain. A NULL
63
+ * entry is the ordinary method. [[GetOwnProperty]], [[DefineOwnProperty]] and [[Delete]] are the
64
+ * class hooks above. Results as the core functions: 1/0/-1, or a value / JS_EXCEPTION. */
65
+ typedef struct JSObjectMethods {
66
+ JSValue (*get_prototype_of)(JSContext *ctx, JSObject *o);
67
+ int (*set_prototype_of)(JSContext *ctx, JSObject *o, JSValue proto);
68
+ int (*is_extensible)(JSContext *ctx, JSObject *o);
69
+ int (*prevent_extensions)(JSContext *ctx, JSObject *o);
70
+ int (*has_property)(JSContext *ctx, JSObject *o, JSValue key);
71
+ JSValue (*get)(JSContext *ctx, JSObject *o, JSValue key, JSValue receiver);
72
+ int (*set)(JSContext *ctx, JSObject *o, JSValue key, JSValue v, JSValue receiver, bool throw_on_fail);
73
+ JSValue (*own_keys)(JSContext *ctx, JSObject *o); /* a JSValueArray cell of property keys */
74
+ /* Proxies only: the target without running traps (IsArray, util.inspect), JS_NULL once
75
+ * revoked. Inline caches never remember a lookup that meets an object with it. */
76
+ JSValue (*target)(JSObject *o);
77
+ } JSObjectMethods;
78
+
79
+ typedef struct JSClass {
80
+ const char *name;
81
+ /* Bytes before the inline slots: sizeof(JSObject) plus the class's own fields. */
82
+ uint16_t instance_size;
83
+ int (*get_own_property)(JSContext *ctx, JSObject *o, JSValue key, JSPropertyDescriptor *out);
84
+ int (*define_own_property)(JSContext *ctx, JSObject *o, JSValue key, const JSPropertyDescriptor *desc, bool throw_on_fail);
85
+ int (*delete_property)(JSContext *ctx, JSObject *o, JSValue key, bool throw_on_fail);
86
+ /* Own string keys that come before the shape's (Array: "length"); count returned, keys written to out[]. */
87
+ uint32_t (*extra_keys)(JSContext *ctx, JSObject *o, JSValue *out);
88
+ void (*visit)(JSCell *cell, JSTracer *trc); /* fields beyond JSObject */
89
+ void (*finalize)(JSRuntime *rt, JSCell *cell);
90
+ const JSObjectMethods *methods; /* NULL: the ordinary internal methods */
91
+ } JSClass;
92
+
93
+ extern const JSClass js_class_object; /* ordinary objects */
94
+ extern const JSClass js_class_array; /* Array exotic objects (§10.4.2) */
95
+
96
+ #define JS_SHAPE_EXTENSIBLE 0x01u
97
+ #define JS_SHAPE_DICTIONARY 0x02u /* private to one object; its table is the mutable truth */
98
+
99
+ struct JSShape { /* kind = SHAPE */
100
+ JSCell cell;
101
+ const JSClass *cls;
102
+ JSValue proto; /* an object or null */
103
+ JSShape *parent; /* the shape before `key` was added; NULL for roots and dictionaries */
104
+ JSValue key; /* added by this transition; EMPTY for roots */
105
+ uint8_t attrs; /* of `key` */
106
+ uint8_t flags; /* JS_SHAPE_* */
107
+ uint16_t inline_cap; /* inline slots of objects with this shape */
108
+ uint32_t prop_count; /* named properties = slots in use */
109
+ uint16_t slot_offset; /* where inline slots start in the object: cls->instance_size */
110
+ uint16_t pad_;
111
+ JSPropTable *table; /* key → (slot, attrs): lazy for shared shapes, the truth for dictionaries */
112
+ JSTransitions *transitions; /* (key, attrs) → child shape; weak */
113
+ };
114
+
115
+ /* The slot of an accessor property holds one of these. */
116
+ typedef struct JSAccessorPair { /* kind = ACCESSOR */
117
+ JSCell cell;
118
+ JSValue get; /* a function or undefined */
119
+ JSValue set;
120
+ } JSAccessorPair;
121
+
122
+ #define JS_ELEMENTS_DENSE 0
123
+ #define JS_ELEMENTS_SPARSE 1 /* a JSSparseElements (elements.h) */
124
+
125
+ typedef struct JSElements { /* kind = ELEMENTS */
126
+ JSCell cell;
127
+ uint8_t kind; /* JS_ELEMENTS_DENSE / SPARSE */
128
+ uint8_t flags;
129
+ uint16_t pad_;
130
+ uint32_t length; /* DENSE: slots in use (index of the last present element + 1, at most) */
131
+ uint32_t capacity; /* DENSE: allocated slots */
132
+ uint32_t pad2_;
133
+ JSValue data[]; /* DENSE: values; EMPTY = hole (and zero-filled memory is EMPTY) */
134
+ } JSElements;
135
+
136
+ /* The header of every object. The class's own fields (if any) follow it, then
137
+ * shape->inline_cap inline named slots, at shape->slot_offset. */
138
+ struct JSObject { /* kind >= JS_CELL_OBJECT */
139
+ JSCell cell; /* arrays: aux = length */
140
+ JSShape *shape;
141
+ JSValueArray *ool; /* overflow named slots, NULL until needed */
142
+ JSElements *elements; /* never NULL: the static empty store at first */
143
+ };
144
+
145
+ static inline JSValue *js_object_slots(JSObject *o) {
146
+ return (JSValue *)((char *)o + o->shape->slot_offset);
147
+ }
148
+
149
+ #define JS_DEFAULT_INLINE_SLOTS 4
150
+ #define JS_MAX_INLINE_SLOTS 64
151
+ #define JS_DICTIONARY_THRESHOLD 128 /* named properties before an object becomes a dictionary */
152
+
153
+ static inline bool js_is_object(JSValue v) {
154
+ return js_is_cell(v) && js_as_cell(v)->kind >= JS_CELL_OBJECT;
155
+ }
156
+
157
+ static inline JSObject *js_as_object(JSValue v) { return (JSObject *)js_as_cell(v); }
158
+ static inline JSValue js_object_value(JSObject *o) { return js_cell(&o->cell); }
159
+
160
+ /* The shared, static, empty elements store (ADR 0005, "never NULL"). */
161
+ extern const JSElements js_empty_elements;
162
+
163
+ /* ---- Shapes ----------------------------------------------------------------- */
164
+
165
+ /* The root shape for (class, proto, inline capacity): shared, weakly held. */
166
+ JSShape *js_shape_root(JSContext *ctx, const JSClass *cls, JSValue proto, uint16_t inline_cap);
167
+ /* The shape after adding `key` with `attrs` (a shared transition). */
168
+ JSShape *js_shape_add(JSContext *ctx, JSShape *shape, JSValue key, uint8_t attrs);
169
+ /* The shape of (cls, proto, inline_cap) with `n` keys added (each with `attrs`), cached in the
170
+ * realm's intrinsic `slot`: objects every program makes many of (functions, iterator results)
171
+ * start with their properties in place, their slots filled directly, no transitions. */
172
+ JSShape *js_cached_shape(JSContext *ctx, JSIntrinsic slot, const JSClass *cls, JSValue proto, uint16_t inline_cap,
173
+ uint32_t n, const JSValue *keys, uint8_t attrs);
174
+ /* Finds `key`: its slot, and attrs in *attrs; -1 if absent. */
175
+ int32_t js_shape_find(JSShape *shape, JSValue key, uint8_t *attrs);
176
+
177
+ /* ---- Objects ----------------------------------------------------------------- */
178
+
179
+ /* A new object of `kind` with `shape`: header, class fields, inline slots (undefined), empty elements. */
180
+ JSObject *js_alloc_object(JSContext *ctx, JSCellKind kind, JSShape *shape);
181
+ /* {} with Object.prototype. */
182
+ JSValue js_new_object(JSContext *ctx);
183
+ /* An ordinary object with the given prototype (an object or null). */
184
+ JSValue js_new_object_proto(JSContext *ctx, JSValue proto, uint16_t inline_cap);
185
+
186
+ /* The value in slot `n` of `o`, inline or overflow. */
187
+ static inline JSValue *js_object_slot(JSObject *o, uint32_t n) {
188
+ uint16_t cap = o->shape->inline_cap;
189
+ return n < cap ? &js_object_slots(o)[n] : &o->ool->values[n - cap];
190
+ }
191
+
192
+ /* ---- Property keys --------------------------------------------------------------- */
193
+
194
+ /* A key: an array index (a number: int32 below 2^31, a double up to 2^32 - 2), an atom,
195
+ * or a symbol (ADR 0005). JS_EXCEPTION on failure. */
196
+ JS_WARN_UNUSED JSValue js_to_property_key(JSContext *ctx, JSValue v);
197
+ static inline bool js_key_is_index(JSValue key) { return js_is_number(key); }
198
+ static inline uint32_t js_key_index(JSValue key) {
199
+ return js_is_int32(key) ? (uint32_t)js_as_int32(key) : (uint32_t)js_as_double(key);
200
+ }
201
+ /* The key for array index i. */
202
+ static inline JSValue js_index_key(uint32_t i) {
203
+ return i < 2147483647u ? js_int32((int32_t)i) : js_double((double)i);
204
+ }
205
+
206
+ /* ---- Arrays ------------------------------------------------------------------------- */
207
+
208
+ #define JS_MAX_ARRAY_LENGTH 4294967295.0
209
+
210
+ static inline bool js_is_array(JSValue v) {
211
+ return js_is_cell(v) && js_as_cell(v)->kind == JS_CELL_ARRAY;
212
+ }
213
+ static inline uint32_t js_array_length(JSObject *a) { return a->cell.aux; }
214
+
215
+ /* A new dense array: length 0, room for `capacity` elements. */
216
+ JSValue js_new_array(JSContext *ctx, uint32_t capacity);
217
+ /* A new array holding `n` values. */
218
+ JSValue js_new_array_from(JSContext *ctx, const JSValue *values, uint32_t n);
219
+ JS_WARN_UNUSED int js_array_push(JSContext *ctx, JSObject *a, JSValue v);
220
+ /* Generated code building a list with spreads (array literals, arguments): appends v
221
+ * (EMPTY: a hole), or every element of an iterable. 0, or -1 on exception. */
222
+ JS_WARN_UNUSED int js_array_append(JSContext *ctx, JSValue arr, JSValue v);
223
+ JS_WARN_UNUSED int js_array_spread(JSContext *ctx, JSValue arr, JSValue iterable);
224
+ /* An object literal's getter or setter (the other, EMPTY, is left as it is): enumerable, configurable. */
225
+ void js_define_accessor(JSContext *ctx, JSObject *o, JSValue key, JSValue get, JSValue set);
226
+
227
+ /* ---- Internal methods (ordinary objects; exotic hooks arrive with their classes) ---- */
228
+
229
+ /* Results: 1 true, 0 false, -1 exception (ADR 0004). */
230
+ JS_WARN_UNUSED int js_get_own_property(JSContext *ctx, JSObject *o, JSValue key, JSPropertyDescriptor *out);
231
+ JS_WARN_UNUSED int js_define_own_property(JSContext *ctx, JSObject *o, JSValue key, const JSPropertyDescriptor *desc, bool throw_on_fail);
232
+ JS_WARN_UNUSED int js_has_property(JSContext *ctx, JSObject *o, JSValue key);
233
+ JS_WARN_UNUSED int js_delete_property(JSContext *ctx, JSObject *o, JSValue key, bool throw_on_fail);
234
+ JS_WARN_UNUSED JSValue js_get(JSContext *ctx, JSObject *o, JSValue key, JSValue receiver);
235
+ JS_WARN_UNUSED int js_set(JSContext *ctx, JSObject *o, JSValue key, JSValue v, JSValue receiver, bool throw_on_fail);
236
+ /* The ordinary [[GetPrototypeOf]]: no user code (a proxy answers null). */
237
+ JSValue js_get_prototype_of(JSObject *o);
238
+ /* [[GetPrototypeOf]] and [[IsExtensible]] of any object, proxies' traps included. */
239
+ JS_WARN_UNUSED JSValue js_object_get_prototype_of(JSContext *ctx, JSObject *o);
240
+ JS_WARN_UNUSED int js_object_is_extensible(JSContext *ctx, JSObject *o);
241
+ /* IsArray (§7.2.2): through proxies; 1, 0, or -1 for a revoked one. */
242
+ JS_WARN_UNUSED int js_is_array_spec(JSContext *ctx, JSValue v);
243
+ /* A proxy's target without running traps (JS_NULL once revoked); EMPTY if v isn't a proxy. */
244
+ JSValue js_proxy_target(JSValue v);
245
+ /* The prototype a primitive's properties come from (ToObject(v).[[Prototype]]); v not nullish. */
246
+ JSObject *js_primitive_prototype(JSContext *ctx, JSValue v);
247
+
248
+ /* ---- Primitive wrappers (wrapper.c) --------------------------------------------------- */
249
+
250
+ extern const JSClass js_class_primitive_wrapper;
251
+ /* A wrapper for a non-nullish primitive, with `proto` (or the primitive's prototype if
252
+ * `proto` isn't an object): new Number(1), Object("ab"). */
253
+ JSValue js_new_wrapper(JSContext *ctx, JSValue prim, JSValue proto);
254
+ /* ToObject (§7.1.18): objects as they are, primitives wrapped, a TypeError for null/undefined. */
255
+ JS_WARN_UNUSED JSValue js_to_object(JSContext *ctx, JSValue v);
256
+ bool js_is_wrapper(JSValue v);
257
+ JSValue js_wrapped_value(JSValue wrapper);
258
+ /* thisNumberValue and the like: v if `is_type(v)`, a wrapper's primitive if it is, else EMPTY. */
259
+ JSValue js_this_primitive(JSValue v, bool (*is_type)(JSValue));
260
+ JS_WARN_UNUSED int js_set_prototype_of(JSContext *ctx, JSObject *o, JSValue proto);
261
+ /* The ordinary [[IsExtensible]] (a proxy answers from its own shape: use js_object_is_extensible). */
262
+ bool js_is_extensible(JSObject *o);
263
+ JS_WARN_UNUSED int js_prevent_extensions(JSContext *ctx, JSObject *o);
264
+ /* Iterators (§7.4): GetIterator as a record, its next value (JS_EMPTY when done), and
265
+ * IteratorClose after a normal completion (0 or -1) or a throw (the exception stays). */
266
+ JSValue js_iter_start(JSContext *ctx, JSValue v);
267
+ JSValue js_iter_next(JSContext *ctx, JSValue rec);
268
+ JS_WARN_UNUSED int js_iter_close(JSContext *ctx, JSValue rec);
269
+ void js_iter_close_throw(JSContext *ctx, JSValue rec);
270
+ /* Destructuring: an array pattern's next value (undefined when done) and rest array; an
271
+ * object pattern's RequireObjectCoercible and rest object (all own enumerable properties
272
+ * but the keys in the array `excluded`). */
273
+ JSValue js_iter_value(JSContext *ctx, JSValue rec);
274
+ JSValue js_iter_rest(JSContext *ctx, JSValue rec);
275
+ JSValue js_require_coercible(JSContext *ctx, JSValue v);
276
+ JSValue js_object_rest(JSContext *ctx, JSValue source, JSValue excluded);
277
+ /* `{ ...source }`: CopyDataProperties onto an object literal. 0, or -1 on exception. */
278
+ JS_WARN_UNUSED int js_object_spread(JSContext *ctx, JSValue target, JSValue source);
279
+ /* CreateIterResultObject: { value, done }. */
280
+ JSValue js_iter_result(JSContext *ctx, JSValue value, bool done);
281
+ /* LengthOfArrayLike: ToLength(obj.length) (§7.3.18); 0 or -1. */
282
+ JS_WARN_UNUSED int js_length_of_array_like(JSContext *ctx, JSValue obj, double *out);
283
+ void js_iterator_realm_init(JSContext *ctx);
284
+ /* for…in (§14.7.5): an iterator over v's enumerable string keys, prototypes included, and
285
+ * its next key (a string; undefined when done; JS_EXCEPTION). */
286
+ JSValue js_for_in_start(JSContext *ctx, JSValue v);
287
+ JSValue js_for_in_next(JSContext *ctx, JSValue it);
288
+ /* The own keys in spec order (indices ascending, then strings, then symbols, by insertion). */
289
+ JS_WARN_UNUSED JSValue js_own_keys(JSContext *ctx, JSObject *o);
290
+
291
+ /* ---- Inline caches (ADR 0005) ---------------------------------------------------- */
292
+
293
+ #define JS_IC_EMPTY 0
294
+ #define JS_IC_OWN 1 /* get: an own data property; set: an own writable data property */
295
+ #define JS_IC_PROTO 2 /* get: a data property of `holder`, `depth` prototypes up */
296
+ #define JS_IC_ADD 3 /* set: adding the key takes the receiver from `shape` to `next` */
297
+ #define JS_IC_GETTER 4 /* get: an accessor of `holder` (NULL: the receiver), `depth` prototypes up */
298
+ #define JS_IC_ABSENT 5 /* get: no such property on the receiver or its `depth` prototypes (the last's proto is null) */
299
+ #define JS_IC_MAX_DEPTH 4
300
+
301
+ /* One per property access site with a constant named key; a site is either a get or a
302
+ * set. Monomorphic: a miss refills it. Never caches dictionary shapes (their layout
303
+ * changes under the same pointer). Weak: the GC resets a cache whose shapes or holder
304
+ * die, so every cache must be registered (js_register_prop_caches). */
305
+ typedef struct JSPropCache {
306
+ JSShape *shape; /* receiver shape; NULL = empty */
307
+ uint32_t slot; /* OWN, PROTO: the slot */
308
+ uint8_t kind; /* JS_IC_* */
309
+ uint8_t depth; /* PROTO: hops to the holder; ADD: prototypes up to null */
310
+ uint16_t pad_;
311
+ JSObject *holder; /* PROTO */
312
+ JSShape *next; /* ADD */
313
+ JSShape *chain[JS_IC_MAX_DEPTH]; /* PROTO, ADD: the prototypes' shapes, checked on a hit */
314
+ } JSPropCache;
315
+
316
+ /* A module's caches, once at startup (the GC resets them weakly). */
317
+ void js_register_prop_caches(JSRuntime *rt, JSPropCache *ics, size_t n);
318
+
319
+ JS_WARN_UNUSED JSValue js_get_prop_slow(JSContext *ctx, JSValue obj, JSValue key, JSPropCache *ic);
320
+ JS_WARN_UNUSED int js_set_prop_slow(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict, JSPropCache *ic);
321
+
322
+ /* obj.key with a named key (an atom). A hit is a type check, a shape compare and a load. */
323
+ static inline JSValue js_get_prop(JSContext *ctx, JSValue obj, JSValue key, JSPropCache *ic) {
324
+ if (JS_LIKELY(js_is_object(obj))) {
325
+ JSObject *o = js_as_object(obj);
326
+ if (o->shape == ic->shape && ic->kind == JS_IC_OWN) return *js_object_slot(o, ic->slot);
327
+ }
328
+ return js_get_prop_slow(ctx, obj, key, ic);
329
+ }
330
+
331
+ /* obj.key = v with a named key: 1 done, 0 failed (sloppy), -1 exception. */
332
+ static inline int js_set_prop(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict, JSPropCache *ic) {
333
+ if (JS_LIKELY(js_is_object(obj))) {
334
+ JSObject *o = js_as_object(obj);
335
+ if (o->shape == ic->shape && ic->kind == JS_IC_OWN) {
336
+ js_store(ctx, &o->cell, js_object_slot(o, ic->slot), v);
337
+ return 1;
338
+ }
339
+ }
340
+ return js_set_prop_slow(ctx, obj, key, v, strict, ic);
341
+ }
342
+
343
+ /* Convenience: the value of `obj.key` / `obj.key = v` for any value (ToObject rules). */
344
+ JS_WARN_UNUSED JSValue js_get_value(JSContext *ctx, JSValue obj, JSValue key);
345
+ JS_WARN_UNUSED int js_set_value(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict);
346
+ /* ---- Generated code (ADR 0010): property operators on any value ---------------------- */
347
+
348
+ /* obj[key] and obj[key] = v with a computed key: ToPropertyKey after the nullish check. */
349
+ JS_WARN_UNUSED JSValue js_get_elem(JSContext *ctx, JSValue obj, JSValue key);
350
+ JS_WARN_UNUSED int js_set_elem(JSContext *ctx, JSValue obj, JSValue key, JSValue v, bool strict);
351
+ /* delete obj[key]: true or false (sloppy), a TypeError when strict and not deletable.
352
+ * `key` is a property key; js_delete_elem converts it first. */
353
+ JS_WARN_UNUSED JSValue js_delete_value(JSContext *ctx, JSValue obj, JSValue key, bool strict);
354
+ JS_WARN_UNUSED JSValue js_delete_elem(JSContext *ctx, JSValue obj, JSValue key, bool strict);
355
+ /* `{ __proto__: v }`: sets the prototype when v is an object or null, else nothing. */
356
+ void js_literal_set_proto(JSContext *ctx, JSValue obj, JSValue v);
357
+ /* SameValue (§7.2.10): NaN is NaN, +0 isn't -0. */
358
+ bool js_same_value(JSContext *ctx, JSValue a, JSValue b);
359
+ /* Object.freeze's SetIntegrityLevel(o, frozen): 0, or -1 with an exception. */
360
+ JS_WARN_UNUSED int js_freeze(JSContext *ctx, JSObject *o);
361
+ /* A tagged template's object (§13.2.8.4), created once per site and kept in *cache. */
362
+ JS_WARN_UNUSED JSValue js_template_object(JSContext *ctx, JSValue *cache, uint32_t n, const JSValue *cooked, const JSValue *raw);
363
+
364
+ /* ---- Private names (#x): keys only their class can name -------------------------------- */
365
+
366
+ /* A new private name (a fresh, never interned string flagged JS_STR_PRIVATE). */
367
+ JS_WARN_UNUSED JSValue js_new_private_name(JSContext *ctx, JSValue description);
368
+ static inline bool js_is_private_name(JSValue key) {
369
+ return js_is_cell(key) && js_as_cell(key)->kind == JS_CELL_STR_FLAT && (js_as_cell(key)->flags & JS_STR_PRIVATE);
370
+ }
371
+ /* Adds a private element: kind 0 field, 1 method, 2 getter, 3 setter. 0, or -1 (TypeError: already there). */
372
+ JS_WARN_UNUSED int js_private_add(JSContext *ctx, JSValue obj, JSValue name, JSValue v, int kind);
373
+ JS_WARN_UNUSED JSValue js_private_get(JSContext *ctx, JSValue obj, JSValue name);
374
+ JS_WARN_UNUSED int js_private_set(JSContext *ctx, JSValue obj, JSValue name, JSValue v);
375
+ /* `#x in obj`. */
376
+ JS_WARN_UNUSED JSValue js_private_in(JSContext *ctx, JSValue name, JSValue obj);
377
+
378
+ /* A class field (§7.3.33 DefineField: CreateDataPropertyOrThrow). 0, or -1 on exception. */
379
+ JS_WARN_UNUSED int js_define_field(JSContext *ctx, JSValue obj, JSValue key, JSValue v);
380
+
381
+ /* Defines a builtin-style data property (e.g. while building intrinsics); never fails. */
382
+ void js_define_data(JSContext *ctx, JSObject *o, JSValue key, JSValue value, uint8_t attrs);
383
+
384
+ #endif /* JS_OBJECT_H */
@@ -0,0 +1,111 @@
1
+ /*
2
+ * js_ops.h — the JS operators generated code calls (ADR 0010: generic
3
+ * operators on boxed JSValues; specialized unboxed ones come with M10).
4
+ *
5
+ * Primitives only for now: objects (ToPrimitive, valueOf) arrive in M3.
6
+ * Every function that can fail returns JS_EXCEPTION with the error pending (ADR 0004).
7
+ */
8
+ #ifndef JS_OPS_H
9
+ #define JS_OPS_H
10
+
11
+ #include "js_bigint.h"
12
+ #include "js_exception.h"
13
+ #include "js_object.h"
14
+ #include "jsstring.h"
15
+
16
+ /* ---- Arithmetic and bitwise ------------------------------------------- */
17
+
18
+ JS_WARN_UNUSED JSValue js_add(JSContext *ctx, JSValue a, JSValue b);
19
+ JS_WARN_UNUSED JSValue js_sub(JSContext *ctx, JSValue a, JSValue b);
20
+ JS_WARN_UNUSED JSValue js_mul(JSContext *ctx, JSValue a, JSValue b);
21
+ JS_WARN_UNUSED JSValue js_div(JSContext *ctx, JSValue a, JSValue b);
22
+ JS_WARN_UNUSED JSValue js_mod(JSContext *ctx, JSValue a, JSValue b);
23
+ JS_WARN_UNUSED JSValue js_exp(JSContext *ctx, JSValue a, JSValue b);
24
+ JS_WARN_UNUSED JSValue js_shl(JSContext *ctx, JSValue a, JSValue b);
25
+ JS_WARN_UNUSED JSValue js_sar(JSContext *ctx, JSValue a, JSValue b);
26
+ JS_WARN_UNUSED JSValue js_shr(JSContext *ctx, JSValue a, JSValue b);
27
+ JS_WARN_UNUSED JSValue js_bitand(JSContext *ctx, JSValue a, JSValue b);
28
+ JS_WARN_UNUSED JSValue js_bitor(JSContext *ctx, JSValue a, JSValue b);
29
+ JS_WARN_UNUSED JSValue js_bitxor(JSContext *ctx, JSValue a, JSValue b);
30
+
31
+ JS_WARN_UNUSED JSValue js_neg(JSContext *ctx, JSValue v);
32
+ JS_WARN_UNUSED JSValue js_bitnot(JSContext *ctx, JSValue v);
33
+ JS_WARN_UNUSED JSValue js_to_number_value(JSContext *ctx, JSValue v); /* unary + */
34
+ JS_WARN_UNUSED JSValue js_to_numeric(JSContext *ctx, JSValue v); /* ++/-- operand */
35
+ JS_WARN_UNUSED JSValue js_inc(JSContext *ctx, JSValue v); /* v is numeric */
36
+ JS_WARN_UNUSED JSValue js_dec(JSContext *ctx, JSValue v);
37
+
38
+ /* ---- Comparison ---------------------------------------------------------- */
39
+
40
+ JS_WARN_UNUSED JSValue js_eq(JSContext *ctx, JSValue a, JSValue b); /* == */
41
+ JS_WARN_UNUSED JSValue js_ne(JSContext *ctx, JSValue a, JSValue b);
42
+ JS_WARN_UNUSED JSValue js_lt(JSContext *ctx, JSValue a, JSValue b);
43
+ JS_WARN_UNUSED JSValue js_le(JSContext *ctx, JSValue a, JSValue b);
44
+ JS_WARN_UNUSED JSValue js_gt(JSContext *ctx, JSValue a, JSValue b);
45
+ JS_WARN_UNUSED JSValue js_ge(JSContext *ctx, JSValue a, JSValue b);
46
+
47
+ /* ===, !==: never throw (strings compare by content). */
48
+ bool js_strict_equals(JSContext *ctx, JSValue a, JSValue b);
49
+ static inline JSValue js_strict_eq(JSContext *ctx, JSValue a, JSValue b) { return js_bool(js_strict_equals(ctx, a, b)); }
50
+ static inline JSValue js_strict_ne(JSContext *ctx, JSValue a, JSValue b) { return js_bool(!js_strict_equals(ctx, a, b)); }
51
+
52
+ /* ---- Never throw -------------------------------------------------------- */
53
+
54
+ /* ToBoolean, as a C bool: branches test this. */
55
+ /* for…of: whether iter_next produced a value (EMPTY: the iterator is done). */
56
+ static inline JSValue js_not_empty(JSValue v) { return js_bool(!js_is_empty(v)); }
57
+
58
+ static inline bool js_truthy(JSValue v) {
59
+ if (js_is_bool(v)) return js_as_bool(v);
60
+ if (js_is_int32(v)) return js_as_int32(v) != 0;
61
+ if (js_is_number(v)) {
62
+ double d = js_as_double(v);
63
+ return d == d && d != 0;
64
+ }
65
+ if (js_is_nullish(v)) return false;
66
+ if (js_is_string(v)) return js_string_length(v) != 0;
67
+ if (js_is_bigint(v)) return !js_bigint_is_zero(v);
68
+ return true; /* symbols and objects */
69
+ }
70
+
71
+ static inline JSValue js_to_boolean(JSValue v) { return js_bool(js_truthy(v)); }
72
+ static inline JSValue js_not(JSValue v) { return js_bool(!js_truthy(v)); }
73
+ static inline JSValue js_is_nullish_value(JSValue v) { return js_bool(js_is_nullish(v)); }
74
+
75
+ /* typeof: an atom ("undefined", "number", …). */
76
+ JSValue js_typeof(JSContext *ctx, JSValue v);
77
+
78
+ /* ---- Bindings -------------------------------------------------------------- */
79
+
80
+ /* v itself, or a ReferenceError if it's still uninitialized (JS_EMPTY: the TDZ). */
81
+ static inline JSValue js_check_tdz(JSContext *ctx, JSValue v, const char *name) {
82
+ if (JS_UNLIKELY(js_is_empty(v)))
83
+ return js_throw_reference_error(ctx, "Cannot access '%s' before initialization", name);
84
+ return v;
85
+ }
86
+
87
+ /* A name no declaration binds: the global object's property, or a ReferenceError (global.c). */
88
+ JS_WARN_UNUSED JSValue js_global_name(JSContext *ctx, const char *name);
89
+ /* A sloppy function's `this` (ADR 0006 prologue, §10.2.1.2): undefined and null become the
90
+ * global object, other primitives their wrapper (ToObject). */
91
+ static inline JSValue js_sloppy_this(JSContext *ctx, JSValue v) {
92
+ if (js_is_nullish(v)) return ctx->intrinsics[JS_INTRINSIC_GLOBAL_OBJECT];
93
+ return js_is_object(v) ? v : js_new_wrapper(ctx, v, JS_UNDEFINED);
94
+ }
95
+
96
+ /* A classic script's top-level `var` and function declarations (§16.1.7): properties of the
97
+ * global object, not configurable. 0, or -1 on exception (a TypeError: can't declare it). */
98
+ JS_WARN_UNUSED int js_declare_global_var(JSContext *ctx, JSValue key);
99
+ JS_WARN_UNUSED int js_declare_global_function(JSContext *ctx, JSValue key, JSValue fn);
100
+ /* `name = v` where no declaration binds name: a global property (sloppy), or a
101
+ * ReferenceError if strict code names one that doesn't exist. 1/0 like js_set, -1. */
102
+ JS_WARN_UNUSED int js_set_global_name(JSContext *ctx, JSValue key, JSValue v, bool strict);
103
+
104
+ /* The same for `typeof name`: undefined instead of the ReferenceError. */
105
+ JS_WARN_UNUSED JSValue js_global_typeof_name(JSContext *ctx, const char *name);
106
+ JS_WARN_UNUSED JSValue js_throw_const_assign(JSContext *ctx);
107
+
108
+ /* ToInt32 / ToUint32 of a number (ECMAScript §7.1.6). */
109
+ int32_t js_double_to_int32(double d);
110
+
111
+ #endif /* JS_OPS_H */
@@ -0,0 +1,45 @@
1
+ /*
2
+ * js_promise.h — promises (ECMAScript §27.2; ADR 0008).
3
+ *
4
+ * A promise keeps its reactions in a list until it settles; settling queues one
5
+ * microtask per reaction (js_jobs.h). Async functions (ADR 0007) build on these.
6
+ */
7
+ #ifndef JS_PROMISE_H
8
+ #define JS_PROMISE_H
9
+
10
+ #include "js_object.h"
11
+
12
+ enum { JS_PROMISE_PENDING, JS_PROMISE_FULFILLED, JS_PROMISE_REJECTED };
13
+
14
+ typedef struct JSPromise {
15
+ JSObject obj;
16
+ JSValue result; /* the value or reason once settled */
17
+ JSValue reactions; /* while pending: reaction records, newest first; else undefined */
18
+ uint8_t state; /* JS_PROMISE_* */
19
+ uint8_t is_handled; /* [[PromiseIsHandled]]: rejection tracking */
20
+ uint8_t already_resolved; /* settled through the runtime (no resolving functions) */
21
+ } JSPromise;
22
+
23
+ bool js_is_promise(JSValue v);
24
+ static inline JSPromise *js_as_promise(JSValue v) { return (JSPromise *)js_as_object(v); }
25
+
26
+ /* A new pending promise of ctx's realm, settled only through the two calls below. */
27
+ JSValue js_new_promise(JSContext *ctx);
28
+ /* Resolves it (a thenable is followed) or rejects it; once only, later calls do nothing. */
29
+ void js_promise_resolve_internal(JSContext *ctx, JSValue promise, JSValue resolution);
30
+ void js_promise_reject_internal(JSContext *ctx, JSValue promise, JSValue reason);
31
+ /* PromiseResolve(%Promise%, v) (§27.2.4.7.1): v if it is a native promise of this realm. */
32
+ JS_WARN_UNUSED JSValue js_promise_resolve(JSContext *ctx, JSValue v);
33
+
34
+ /* await (ADR 0007): when the promise settles, a job resumes the async state `gen` (a
35
+ * reaction with no derived promise and no JS closure); marks the promise handled. */
36
+ void js_promise_await(JSContext *ctx, JSValue promise, JSValue gen);
37
+
38
+ /* The jobs (js_jobs.h) run these. 0, or -1 with an exception that is uncaught. */
39
+ int js_promise_reaction_job(JSContext *ctx, JSValue reaction, JSValue argument, JSValue state);
40
+ int js_promise_thenable_job(JSContext *ctx, JSValue promise, JSValue thenable, JSValue then);
41
+
42
+ struct JSObject;
43
+ void js_promise_realm_init(JSContext *ctx, struct JSObject *global);
44
+
45
+ #endif /* JS_PROMISE_H */
@@ -0,0 +1,25 @@
1
+ /*
2
+ * js_regexp.h — regular expression literals (ADR 0015), for generated code.
3
+ *
4
+ * The compiler compiles each literal when the program is built (QuickJS's libregexp, run as the
5
+ * regexp-compile tool) and emits its bytecode as static data; evaluating the literal creates a
6
+ * new RegExp object that points at it (§13.2.7.3).
7
+ */
8
+ #ifndef JS_REGEXP_H
9
+ #define JS_REGEXP_H
10
+
11
+ #include <stdint.h>
12
+
13
+ #include "jsstring.h"
14
+ #include "jsvalue.h"
15
+
16
+ typedef struct JSRegExpLiteral {
17
+ const uint8_t *bytecode; /* libregexp bytecode; NULL: compiled at run time, at each evaluation */
18
+ const JSString *source; /* the pattern as written between the slashes */
19
+ uint16_t flags; /* LRE_FLAG_* (for compiling at run time) */
20
+ } JSRegExpLiteral;
21
+
22
+ /* A new RegExp for a literal (the regexp component). */
23
+ JS_WARN_UNUSED JSValue js_regexp_literal(JSContext *ctx, const JSRegExpLiteral *lit);
24
+
25
+ #endif /* JS_REGEXP_H */
@@ -0,0 +1,30 @@
1
+ /*
2
+ * js_runtime.h — the single header generated code includes (libjsrt).
3
+ */
4
+ #ifndef JS_RUNTIME_H
5
+ #define JS_RUNTIME_H
6
+
7
+ #include "jsvalue.h"
8
+ #include "jscontext.h"
9
+ #include "js_gc.h"
10
+ #include "js_exception.h"
11
+ #include "jsstring.h"
12
+ #include "js_atoms.h"
13
+ #include "js_symbol.h"
14
+ #include "js_bigint.h"
15
+ #include "jsnum.h"
16
+ #include "js_convert.h"
17
+ #include "js_console.h"
18
+ #include "js_ops.h"
19
+ #include "js_object.h"
20
+ #include "js_function.h"
21
+ #include "js_error.h"
22
+ #include "js_generator.h"
23
+ #include "js_jobs.h"
24
+ #include "js_promise.h"
25
+ #include "js_builtins.h"
26
+ #include "js_host.h"
27
+ #include "js_module.h"
28
+ #include "js_regexp.h"
29
+
30
+ #endif /* JS_RUNTIME_H */
@@ -0,0 +1,62 @@
1
+ /*
2
+ * js_symbol.h — symbols (ECMAScript §6.1.5, §20.4; ADR 0001, 0005).
3
+ *
4
+ * A symbol is a heap cell compared by identity; as a property key it is used as is. The
5
+ * well-known symbols are static cells, like the predefined atoms: JS_SYMBOL(iterator).
6
+ */
7
+ #ifndef JS_SYMBOL_H
8
+ #define JS_SYMBOL_H
9
+
10
+ #include "js_atoms.h"
11
+
12
+ typedef struct JSSymbol {
13
+ JSCell cell;
14
+ const JSCell *description; /* a string cell, or NULL for undefined */
15
+ } JSSymbol;
16
+
17
+ #define JS_SYM_REGISTERED 0x01u /* cell flags: made by Symbol.for; the description is its key */
18
+
19
+ static inline bool js_is_symbol(JSValue v) {
20
+ return js_is_cell(v) && js_as_cell(v)->kind == JS_CELL_SYMBOL;
21
+ }
22
+ static inline JSSymbol *js_as_symbol(JSValue v) { return (JSSymbol *)js_as_cell(v); }
23
+
24
+ /* The well-known symbols (§6.1.5.1). */
25
+ #define JS_WELL_KNOWN_SYMBOLS(X) \
26
+ X(asyncIterator) \
27
+ X(hasInstance) \
28
+ X(isConcatSpreadable) \
29
+ X(iterator) \
30
+ X(match) \
31
+ X(matchAll) \
32
+ X(replace) \
33
+ X(search) \
34
+ X(species) \
35
+ X(split) \
36
+ X(toPrimitive) \
37
+ X(toStringTag) \
38
+ X(unscopables) \
39
+ X(dispose) \
40
+ X(asyncDispose)
41
+
42
+ #define JS_SYMBOL_DECL(id) extern const JSSymbol js_symbol_##id;
43
+ JS_WELL_KNOWN_SYMBOLS(JS_SYMBOL_DECL)
44
+ #undef JS_SYMBOL_DECL
45
+ #define JS_SYMBOL(id) js_cell((JSCell *)&js_symbol_##id)
46
+
47
+ /* A new symbol; `description` is a string or undefined. */
48
+ JSValue js_new_symbol(JSContext *ctx, JSValue description);
49
+ /* [[Description]]: a string or undefined. */
50
+ static inline JSValue js_symbol_description(JSValue sym) {
51
+ const JSCell *d = js_as_symbol(sym)->description;
52
+ return d ? js_cell((JSCell *)d) : JS_UNDEFINED;
53
+ }
54
+ /* SymbolDescriptiveString (§20.4.3.3.1): "Symbol(description)". */
55
+ JSValue js_symbol_descriptive_string(JSContext *ctx, JSValue sym);
56
+ /* Symbol.for(key): the registered symbol for a string key, created on first use. */
57
+ JS_WARN_UNUSED JSValue js_symbol_for(JSContext *ctx, JSValue key);
58
+
59
+ struct JSObject;
60
+ void js_symbol_realm_init(JSContext *ctx, struct JSObject *global);
61
+
62
+ #endif /* JS_SYMBOL_H */