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,608 @@
1
+ /* ArrayBuffer and DataView (ECMAScript §25.1, §25.3), the arraybuffer component (ADR 0014):
2
+ * resizable buffers, transfer, and the immutable-ArrayBuffer proposal; DataView with Float16.
3
+ * The BigInt64 accessors exist when the bigint component does (ADR 0016).
4
+ *
5
+ * A buffer's bytes are malloc'd and freed by its finalizer. A detached buffer has no bytes and
6
+ * length 0. Views read the buffer's current data pointer and length on every access, since a
7
+ * resize or a transfer may move or drop the bytes. */
8
+ #include <math.h>
9
+ #include <stdio.h>
10
+ #include <stdlib.h>
11
+ #include <string.h>
12
+
13
+ #include "internal.h"
14
+ #include "builtins_util.h"
15
+ #include "js_atoms.h"
16
+ #include "js_buffer.h"
17
+ #include "js_convert.h"
18
+ #include "js_error.h"
19
+ #include "js_function.h"
20
+ #include "js_ops.h"
21
+ #include "jscontext.h"
22
+
23
+ #define MAX_INDEX 9007199254740991.0 /* 2^53 - 1 */
24
+ #define MAX_ALLOC ((size_t)1 << 34) /* larger buffers fail as V8's do: "Array buffer allocation failed" */
25
+ #define MAX_RESERVE 140737488355328.0 /* 2^47: a larger maxByteLength fails, as V8 can't reserve it */
26
+
27
+ /* ---- ArrayBuffer objects --------------------------------------------------------------------- */
28
+
29
+ static void buffer_finalize(JSRuntime *rt, JSCell *c) {
30
+ (void)rt;
31
+ free(((JSArrayBuffer *)c)->data);
32
+ }
33
+
34
+ static const JSClass array_buffer_class = { "ArrayBuffer", sizeof(JSArrayBuffer), NULL, NULL, NULL, NULL, NULL, buffer_finalize, NULL };
35
+
36
+ static void data_view_visit(JSCell *c, JSTracer *trc) { js_trace_value(trc, ((JSDataView *)c)->buffer); }
37
+
38
+ static const JSClass data_view_class = { "DataView", sizeof(JSDataView), NULL, NULL, NULL, NULL, data_view_visit, NULL, NULL };
39
+
40
+ /* ToIndex (§7.1.22): 0, or -1 with a RangeError saying `what`. */
41
+ static int to_index(JSContext *ctx, JSValue v, double *out, const char *what) {
42
+ if (js_is_undefined(v)) {
43
+ *out = 0;
44
+ return 0;
45
+ }
46
+ double d;
47
+ if (js_to_integer_or_infinity(ctx, &d, v) < 0) return -1;
48
+ if (d < 0 || d > MAX_INDEX) {
49
+ js_discard(js_throw_range_error(ctx, "%s", what));
50
+ return -1;
51
+ }
52
+ *out = d;
53
+ return 0;
54
+ }
55
+
56
+ /* Zeroed bytes, or NULL with a RangeError. Zero bytes need no memory. */
57
+ static int alloc_bytes(JSContext *ctx, double length, uint8_t **out) {
58
+ *out = NULL;
59
+ if (length == 0) return 0;
60
+ if (length > (double)MAX_ALLOC || !(*out = calloc(1, (size_t)length))) {
61
+ js_discard(js_throw_range_error(ctx, "Array buffer allocation failed"));
62
+ return -1;
63
+ }
64
+ return 0;
65
+ }
66
+
67
+ /* AllocateArrayBuffer (§25.1.3.1): the prototype first, then the bytes. max < 0: not resizable. */
68
+ static JSValue allocate(JSContext *ctx, JSValue new_target, double length, double max) {
69
+ if (max >= 0 && length > max) return js_throw_range_error(ctx, "Invalid array buffer max length");
70
+ JSValue proto = js_is_undefined(new_target) ? ctx->intrinsics[JS_INTRINSIC_ARRAY_BUFFER_PROTOTYPE]
71
+ : js_get_prototype_from_constructor(ctx, new_target, JS_INTRINSIC_ARRAY_BUFFER_PROTOTYPE);
72
+ if (js_is_exception(proto)) return proto;
73
+ uint8_t *data;
74
+ if (alloc_bytes(ctx, length, &data) < 0) return JS_EXCEPTION;
75
+ JSArrayBuffer *b = (JSArrayBuffer *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &array_buffer_class, proto, 0));
76
+ b->data = data;
77
+ b->byte_length = (size_t)length;
78
+ b->max_byte_length = max >= 0 ? (size_t)max : (size_t)length;
79
+ b->flags = max >= 0 ? JS_BUFFER_RESIZABLE : 0;
80
+ return js_object_value(&b->obj);
81
+ }
82
+
83
+ JSValue js_new_array_buffer(JSContext *ctx, size_t length) {
84
+ return allocate(ctx, JS_UNDEFINED, (double)length, -1);
85
+ }
86
+
87
+ int js_array_buffer_detach(JSContext *ctx, JSValue buffer) {
88
+ JSArrayBuffer *b = js_as_array_buffer(buffer);
89
+ if (b->flags & JS_BUFFER_IMMUTABLE) {
90
+ js_discard(js_throw_type_error(ctx, "Cannot detach an immutable ArrayBuffer"));
91
+ return -1;
92
+ }
93
+ free(b->data);
94
+ b->data = NULL;
95
+ b->byte_length = 0;
96
+ b->max_byte_length = 0;
97
+ b->flags |= JS_BUFFER_DETACHED;
98
+ return 0;
99
+ }
100
+
101
+ static JSArrayBuffer *this_buffer(JSContext *ctx, JSValue v, const char *method) {
102
+ if (js_is_object(v) && js_as_object(v)->shape->cls == &array_buffer_class) return js_as_array_buffer(v);
103
+ char what[128];
104
+ js_describe_value(ctx, v, what, sizeof what);
105
+ js_discard(js_throw_type_error(ctx, "Method %s called on incompatible receiver %s", method, what));
106
+ return NULL;
107
+ }
108
+
109
+ #define THIS_BUFFER(method) \
110
+ JSArrayBuffer *b = this_buffer(ctx, this_val, method); \
111
+ if (!b) return JS_EXCEPTION
112
+
113
+ static JSValue throw_incompatible_buffer(JSContext *ctx, const char *method, JSValue v) {
114
+ char what[128];
115
+ js_describe_value(ctx, v, what, sizeof what);
116
+ return js_throw_type_error(ctx, "Method %s called on incompatible receiver %s", method, what);
117
+ }
118
+
119
+ static JSValue throw_detached(JSContext *ctx, const char *method) {
120
+ return js_throw_type_error(ctx, "Cannot perform %s on a detached ArrayBuffer", method);
121
+ }
122
+
123
+ /* new ArrayBuffer(length, options) (§25.1.4.1) */
124
+ BUILTIN(array_buffer_ctor) {
125
+ (void)callee, (void)this_val;
126
+ if (js_is_undefined(new_target)) return js_throw_type_error(ctx, "Constructor ArrayBuffer requires 'new'");
127
+ double length, max = -1;
128
+ if (to_index(ctx, ARG(0), &length, "Invalid array buffer length") < 0) return JS_EXCEPTION;
129
+ if (js_is_object(ARG(1))) { /* GetArrayBufferMaxByteLengthOption */
130
+ JSValue m = js_get_value(ctx, ARG(1), js_atom_from_cstr(ctx, "maxByteLength"));
131
+ if (js_is_exception(m)) return m;
132
+ if (!js_is_undefined(m) && to_index(ctx, m, &max, "Invalid array buffer max length") < 0) return JS_EXCEPTION;
133
+ if (max > MAX_RESERVE) return js_throw_range_error(ctx, "Invalid array buffer max length");
134
+ }
135
+ return allocate(ctx, new_target, length, max);
136
+ }
137
+
138
+ /* ArrayBuffer.isView(arg) */
139
+ BUILTIN(array_buffer_is_view) {
140
+ UNUSED_ARGS;
141
+ JSValue v = ARG(0);
142
+ if (!js_is_object(v)) return JS_FALSE;
143
+ const JSClass *cls = js_as_object(v)->shape->cls;
144
+ return js_bool(cls == &data_view_class || (ctx->rt->is_typed_array && ctx->rt->is_typed_array(v)));
145
+ }
146
+
147
+ BUILTIN(get_species) {
148
+ UNUSED_ARGS;
149
+ return this_val;
150
+ }
151
+
152
+ BUILTIN(array_buffer_byte_length) {
153
+ UNUSED_ARGS;
154
+ THIS_BUFFER("get ArrayBuffer.prototype.byteLength");
155
+ return js_number((double)b->byte_length);
156
+ }
157
+
158
+ BUILTIN(array_buffer_max_byte_length) {
159
+ UNUSED_ARGS;
160
+ THIS_BUFFER("get ArrayBuffer.prototype.maxByteLength");
161
+ return js_number((double)(js_buffer_is_detached(b) ? 0 : b->max_byte_length));
162
+ }
163
+
164
+ BUILTIN(array_buffer_resizable) {
165
+ UNUSED_ARGS;
166
+ THIS_BUFFER("get ArrayBuffer.prototype.resizable");
167
+ return js_bool(b->flags & JS_BUFFER_RESIZABLE);
168
+ }
169
+
170
+ BUILTIN(array_buffer_detached) {
171
+ UNUSED_ARGS;
172
+ THIS_BUFFER("get ArrayBuffer.prototype.detached");
173
+ return js_bool(js_buffer_is_detached(b));
174
+ }
175
+
176
+ BUILTIN(array_buffer_immutable) {
177
+ UNUSED_ARGS;
178
+ THIS_BUFFER("get ArrayBuffer.prototype.immutable");
179
+ return js_bool(b->flags & JS_BUFFER_IMMUTABLE);
180
+ }
181
+
182
+ /* resize(newLength) (§25.1.6.6) */
183
+ BUILTIN(array_buffer_resize) {
184
+ UNUSED_ARGS;
185
+ THIS_BUFFER("ArrayBuffer.prototype.resize");
186
+ if (!(b->flags & JS_BUFFER_RESIZABLE)) return throw_incompatible_buffer(ctx, "ArrayBuffer.prototype.resize", this_val);
187
+ double length;
188
+ if (to_index(ctx, ARG(0), &length, "ArrayBuffer.prototype.resize: Invalid length parameter") < 0) return JS_EXCEPTION;
189
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, "ArrayBuffer.prototype.resize");
190
+ if (length > (double)b->max_byte_length) return js_throw_range_error(ctx, "ArrayBuffer.prototype.resize: Invalid length parameter");
191
+ size_t n = (size_t)length;
192
+ if (n == 0) {
193
+ free(b->data);
194
+ b->data = NULL;
195
+ } else if (n != b->byte_length) {
196
+ uint8_t *data = realloc(b->data, n);
197
+ if (!data) return js_throw_range_error(ctx, "Array buffer allocation failed");
198
+ if (n > b->byte_length) memset(data + b->byte_length, 0, n - b->byte_length);
199
+ b->data = data;
200
+ }
201
+ b->byte_length = n;
202
+ return JS_UNDEFINED;
203
+ }
204
+
205
+ /* SpeciesConstructor(o, %ArrayBuffer%) (§7.3.22) */
206
+ static JSValue species_constructor(JSContext *ctx, JSValue o) {
207
+ JSValue dflt = js_get_value(ctx, ctx->intrinsics[JS_INTRINSIC_ARRAY_BUFFER_PROTOTYPE], JS_ATOM(constructor));
208
+ JSValue c = js_get_value(ctx, o, JS_ATOM(constructor));
209
+ if (js_is_exception(c)) return c;
210
+ if (js_is_undefined(c)) return dflt;
211
+ if (!js_is_object(c)) return js_throw_type_error(ctx, "object.constructor is not an object");
212
+ JSValue s = js_get_value(ctx, c, JS_SYMBOL(species));
213
+ if (js_is_exception(s)) return s;
214
+ if (js_is_nullish(s)) return dflt;
215
+ if (!js_is_constructor(s)) return js_throw_type_error(ctx, "object.constructor[Symbol.species] is not a constructor");
216
+ return s;
217
+ }
218
+
219
+ /* ResolveBounds: a relative start and end, clamped to 0..len. */
220
+ static int resolve_bounds(JSContext *ctx, JSValue start, JSValue end, double len, double *from, double *to) {
221
+ double s, e = len;
222
+ if (js_to_integer_or_infinity(ctx, &s, start) < 0) return -1;
223
+ if (!js_is_undefined(end) && js_to_integer_or_infinity(ctx, &e, end) < 0) return -1;
224
+ *from = s < 0 ? fmax(len + s, 0) : fmin(s, len);
225
+ *to = e < 0 ? fmax(len + e, 0) : fmin(e, len);
226
+ return 0;
227
+ }
228
+
229
+ /* slice(start, end) (§25.1.6.7) */
230
+ BUILTIN(array_buffer_slice) {
231
+ UNUSED_ARGS;
232
+ THIS_BUFFER("ArrayBuffer.prototype.slice");
233
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, "ArrayBuffer.prototype.slice");
234
+ double first, final;
235
+ if (resolve_bounds(ctx, ARG(0), ARG(1), (double)b->byte_length, &first, &final) < 0) return JS_EXCEPTION;
236
+ double new_len = fmax(final - first, 0);
237
+ JSValue c = species_constructor(ctx, this_val);
238
+ if (js_is_exception(c)) return c;
239
+ JSValue arg = js_number(new_len);
240
+ JSValue r = js_construct(ctx, c, 1, &arg, JS_UNDEFINED, NULL);
241
+ if (js_is_exception(r)) return r;
242
+ if (!js_is_object(r) || js_as_object(r)->shape->cls != &array_buffer_class)
243
+ return throw_incompatible_buffer(ctx, "ArrayBuffer.prototype.slice", r);
244
+ JSArrayBuffer *nb = js_as_array_buffer(r);
245
+ if (nb->flags & JS_BUFFER_IMMUTABLE) return js_throw_type_error(ctx, "ArrayBuffer.prototype.slice: the new ArrayBuffer is immutable");
246
+ if (js_buffer_is_detached(nb)) return throw_detached(ctx, "ArrayBuffer.prototype.slice");
247
+ if (nb == b) return js_throw_type_error(ctx, "ArrayBuffer subclass returned this from species constructor");
248
+ if ((double)nb->byte_length < new_len) return js_throw_type_error(ctx, "Derived ArrayBuffer constructor created a buffer which was too small");
249
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, "ArrayBuffer.prototype.slice");
250
+ double current = (double)b->byte_length; /* the species constructor may have shrunk it */
251
+ if (first < current) {
252
+ size_t count = (size_t)fmin(new_len, current - first);
253
+ if (count) memcpy(nb->data, b->data + (size_t)first, count);
254
+ }
255
+ return r;
256
+ }
257
+
258
+ /* sliceToImmutable(start, end): an immutable copy of the range. */
259
+ BUILTIN(array_buffer_slice_to_immutable) {
260
+ UNUSED_ARGS;
261
+ THIS_BUFFER("ArrayBuffer.prototype.sliceToImmutable");
262
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, "ArrayBuffer.prototype.sliceToImmutable");
263
+ double first, final;
264
+ if (resolve_bounds(ctx, ARG(0), ARG(1), (double)b->byte_length, &first, &final) < 0) return JS_EXCEPTION;
265
+ double new_len = fmax(final - first, 0);
266
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, "ArrayBuffer.prototype.sliceToImmutable");
267
+ if ((double)b->byte_length < final) return js_throw_range_error(ctx, "ArrayBuffer.prototype.sliceToImmutable: the buffer shrank");
268
+ JSValue r = allocate(ctx, JS_UNDEFINED, new_len, -1);
269
+ if (js_is_exception(r)) return r;
270
+ JSArrayBuffer *nb = js_as_array_buffer(r);
271
+ if (new_len) memcpy(nb->data, b->data + (size_t)first, (size_t)new_len);
272
+ nb->flags |= JS_BUFFER_IMMUTABLE;
273
+ return r;
274
+ }
275
+
276
+ enum { KEEP_RESIZABLE, FIXED_LENGTH, IMMUTABLE };
277
+
278
+ /* ArrayBufferCopyAndDetach (§25.1.3.3): the bytes move to a new buffer, this one is detached. */
279
+ static JSValue copy_and_detach(JSContext *ctx, JSValue this_val, JSValue new_length, int mode, const char *method) {
280
+ THIS_BUFFER(method);
281
+ double length = (double)b->byte_length;
282
+ if (!js_is_undefined(new_length) && to_index(ctx, new_length, &length, "Invalid array buffer length") < 0) return JS_EXCEPTION;
283
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, method);
284
+ if (b->flags & JS_BUFFER_IMMUTABLE) return js_throw_type_error(ctx, "Cannot perform %s on an immutable ArrayBuffer", method);
285
+ double max = mode == KEEP_RESIZABLE && (b->flags & JS_BUFFER_RESIZABLE) ? (double)b->max_byte_length : -1;
286
+ if (max >= 0 && length > max) return js_throw_range_error(ctx, "%s: Invalid length parameter", method);
287
+ if (length > (double)MAX_ALLOC) return js_throw_range_error(ctx, "Array buffer allocation failed");
288
+ size_t n = (size_t)length;
289
+ uint8_t *data = b->data; /* the bytes move: grow or shrink them in place */
290
+ if (n == 0) {
291
+ free(data);
292
+ data = NULL;
293
+ } else if (n != b->byte_length) {
294
+ data = realloc(data, n);
295
+ if (!data) return js_throw_range_error(ctx, "Array buffer allocation failed");
296
+ if (n > b->byte_length) memset(data + b->byte_length, 0, n - b->byte_length);
297
+ }
298
+ b->data = NULL; /* allocate() may collect: b must not free them */
299
+ JSValue r = allocate(ctx, JS_UNDEFINED, 0, max);
300
+ JSArrayBuffer *nb = js_as_array_buffer(r);
301
+ nb->data = data;
302
+ nb->byte_length = n;
303
+ if (mode == IMMUTABLE) nb->flags |= JS_BUFFER_IMMUTABLE;
304
+ b->byte_length = b->max_byte_length = 0;
305
+ b->flags |= JS_BUFFER_DETACHED;
306
+ return r;
307
+ }
308
+
309
+ BUILTIN(array_buffer_transfer) {
310
+ UNUSED_ARGS;
311
+ return copy_and_detach(ctx, this_val, ARG(0), KEEP_RESIZABLE, "ArrayBuffer.prototype.transfer");
312
+ }
313
+
314
+ BUILTIN(array_buffer_transfer_to_fixed_length) {
315
+ UNUSED_ARGS;
316
+ return copy_and_detach(ctx, this_val, ARG(0), FIXED_LENGTH, "ArrayBuffer.prototype.transferToFixedLength");
317
+ }
318
+
319
+ BUILTIN(array_buffer_transfer_to_immutable) {
320
+ UNUSED_ARGS;
321
+ return copy_and_detach(ctx, this_val, ARG(0), IMMUTABLE, "ArrayBuffer.prototype.transferToImmutable");
322
+ }
323
+
324
+ /* ---- DataView ----------------------------------------------------------------------------------- */
325
+
326
+ /* The view's length now, or -1 if it is out of bounds (or its buffer detached). */
327
+ static double view_length(const JSDataView *v) {
328
+ const JSArrayBuffer *b = js_as_array_buffer(v->buffer);
329
+ if (js_buffer_is_detached(b)) return -1;
330
+ if (v->byte_offset > b->byte_length) return -1;
331
+ if (v->length_tracking) return (double)(b->byte_length - v->byte_offset);
332
+ if (v->byte_offset + v->byte_length > b->byte_length) return -1;
333
+ return (double)v->byte_length;
334
+ }
335
+
336
+ /* new DataView(buffer, byteOffset, byteLength) (§25.3.2.1) */
337
+ BUILTIN(data_view_ctor) {
338
+ (void)callee, (void)this_val;
339
+ if (js_is_undefined(new_target)) return js_throw_type_error(ctx, "Constructor DataView requires 'new'");
340
+ JSValue buffer = ARG(0);
341
+ if (!js_is_object(buffer) || js_as_object(buffer)->shape->cls != &array_buffer_class)
342
+ return js_throw_type_error(ctx, "First argument to DataView constructor must be an ArrayBuffer");
343
+ char msg[96];
344
+ double offset;
345
+ if (!js_is_undefined(ARG(1)) && js_is_number(ARG(1)))
346
+ snprintf(msg, sizeof msg, "Start offset %.17g is outside the bounds of the buffer", js_as_number(ARG(1)));
347
+ else
348
+ snprintf(msg, sizeof msg, "Start offset is outside the bounds of the buffer");
349
+ if (to_index(ctx, ARG(1), &offset, msg) < 0) return JS_EXCEPTION;
350
+ JSArrayBuffer *b = js_as_array_buffer(buffer);
351
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, "DataView constructor");
352
+ double buffer_len = (double)b->byte_length;
353
+ if (offset > buffer_len) return js_throw_range_error(ctx, "Start offset %.17g is outside the bounds of the buffer", offset);
354
+ bool tracking = js_is_undefined(ARG(2)) && (b->flags & JS_BUFFER_RESIZABLE);
355
+ double length = 0;
356
+ if (js_is_undefined(ARG(2))) {
357
+ length = buffer_len - offset;
358
+ } else {
359
+ if (to_index(ctx, ARG(2), &length, "Invalid DataView length") < 0) return JS_EXCEPTION;
360
+ if (offset + length > buffer_len) return js_throw_range_error(ctx, "Invalid DataView length %.17g", length);
361
+ }
362
+ JSValue proto = js_get_prototype_from_constructor(ctx, new_target, JS_INTRINSIC_DATA_VIEW_PROTOTYPE);
363
+ if (js_is_exception(proto)) return proto;
364
+ /* the prototype lookup ran user code: check the buffer again */
365
+ if (js_buffer_is_detached(b)) return throw_detached(ctx, "DataView constructor");
366
+ buffer_len = (double)b->byte_length;
367
+ if (offset > buffer_len) return js_throw_range_error(ctx, "Start offset %.17g is outside the bounds of the buffer", offset);
368
+ if (!js_is_undefined(ARG(2)) && offset + length > buffer_len) return js_throw_range_error(ctx, "Invalid DataView length %.17g", length);
369
+ JSDataView *v = (JSDataView *)js_alloc_object(ctx, JS_CELL_OBJECT, js_shape_root(ctx, &data_view_class, proto, 0));
370
+ js_store(ctx, &v->obj.cell, &v->buffer, buffer);
371
+ v->byte_offset = (size_t)offset;
372
+ v->byte_length = tracking ? 0 : (size_t)length;
373
+ v->length_tracking = tracking;
374
+ return js_object_value(&v->obj);
375
+ }
376
+
377
+ static JSDataView *this_view(JSContext *ctx, JSValue v, const char *method) {
378
+ if (js_is_object(v) && js_as_object(v)->shape->cls == &data_view_class) return (JSDataView *)js_as_object(v);
379
+ char what[128];
380
+ js_describe_value(ctx, v, what, sizeof what);
381
+ js_discard(js_throw_type_error(ctx, "Method %s called on incompatible receiver %s", method, what));
382
+ return NULL;
383
+ }
384
+
385
+ #define THIS_VIEW(method) \
386
+ JSDataView *dv = this_view(ctx, this_val, method); \
387
+ if (!dv) return JS_EXCEPTION
388
+
389
+ BUILTIN(data_view_buffer) {
390
+ UNUSED_ARGS;
391
+ THIS_VIEW("get DataView.prototype.buffer");
392
+ return dv->buffer;
393
+ }
394
+
395
+ BUILTIN(data_view_byte_length) {
396
+ UNUSED_ARGS;
397
+ THIS_VIEW("get DataView.prototype.byteLength");
398
+ double len = view_length(dv);
399
+ return len < 0 ? throw_detached(ctx, "get DataView.prototype.byteLength") : js_number(len);
400
+ }
401
+
402
+ BUILTIN(data_view_byte_offset) {
403
+ UNUSED_ARGS;
404
+ THIS_VIEW("get DataView.prototype.byteOffset");
405
+ return view_length(dv) < 0 ? throw_detached(ctx, "get DataView.prototype.byteOffset") : js_number((double)dv->byte_offset);
406
+ }
407
+
408
+ /* Float16 (IEEE 754 binary16) from a double, rounding to nearest, ties to even; and back. */
409
+ uint16_t js_to_float16(double d) {
410
+ uint16_t sign = signbit(d) ? 0x8000 : 0;
411
+ if (isnan(d)) return 0x7E00;
412
+ double a = fabs(d);
413
+ if (a >= 65520.0) return sign | 0x7C00; /* past the largest finite half (65504) */
414
+ if (a < 0x1p-14) return sign | (uint16_t)nearbyint(a * 0x1p24); /* subnormal: m × 2^-24 */
415
+ int e;
416
+ double f = frexp(a, &e); /* a = f × 2^e, f in [0.5, 1) */
417
+ double m = nearbyint((f * 2 - 1) * 1024);
418
+ int exp = e - 1 + 15;
419
+ if (m == 1024) {
420
+ m = 0;
421
+ exp++;
422
+ }
423
+ if (exp >= 31) return sign | 0x7C00;
424
+ return (uint16_t)(sign | (exp << 10) | (uint16_t)m);
425
+ }
426
+
427
+ double js_from_float16(uint16_t h) {
428
+ int exp = (h >> 10) & 0x1F, m = h & 0x3FF;
429
+ double v = exp == 0 ? ldexp(m, -24) : exp == 31 ? (m ? NAN : INFINITY) : ldexp(m + 1024, exp - 25);
430
+ return (h & 0x8000) ? -v : v;
431
+ }
432
+
433
+ enum { T_INT8, T_UINT8, T_INT16, T_UINT16, T_INT32, T_UINT32, T_FLOAT16, T_FLOAT32, T_FLOAT64, T_BIGINT64, T_BIGUINT64 };
434
+ static const uint8_t type_size[] = { 1, 1, 2, 2, 4, 4, 2, 4, 8, 8, 8 };
435
+
436
+ static bool host_little_endian(void) {
437
+ const uint16_t one = 1;
438
+ return *(const uint8_t *)&one == 1;
439
+ }
440
+
441
+ static void copy_ordered(uint8_t *dst, const uint8_t *src, size_t n, bool little) {
442
+ if (little == host_little_endian()) {
443
+ memcpy(dst, src, n);
444
+ } else {
445
+ for (size_t i = 0; i < n; i++) dst[i] = src[n - 1 - i];
446
+ }
447
+ }
448
+
449
+ /* GetViewValue (§25.3.1.5) */
450
+ static JSValue get_view_value(JSContext *ctx, JSValue this_val, JSValue request, JSValue little_endian, int type, const char *method) {
451
+ THIS_VIEW(method);
452
+ double index;
453
+ if (to_index(ctx, request, &index, "Offset is outside the bounds of the DataView") < 0) return JS_EXCEPTION;
454
+ bool little = js_truthy(little_endian);
455
+ double len = view_length(dv);
456
+ if (len < 0) return throw_detached(ctx, method);
457
+ if (index + type_size[type] > len) return js_throw_range_error(ctx, "Offset is outside the bounds of the DataView");
458
+ union { uint8_t b[8]; int8_t i8; uint8_t u8; int16_t i16; uint16_t u16; int32_t i32; uint32_t u32; float f32; double f64; int64_t i64; uint64_t u64; } u;
459
+ const uint8_t *p = js_as_array_buffer(dv->buffer)->data + dv->byte_offset + (size_t)index;
460
+ copy_ordered(u.b, p, type_size[type], little);
461
+ switch (type) {
462
+ case T_BIGINT64: return ctx->rt->bigint->from_int64(ctx, u.i64);
463
+ case T_BIGUINT64: return ctx->rt->bigint->from_uint64(ctx, u.u64);
464
+ case T_INT8: return js_int32(u.i8);
465
+ case T_UINT8: return js_int32(u.u8);
466
+ case T_INT16: return js_int32(u.i16);
467
+ case T_UINT16: return js_int32(u.u16);
468
+ case T_INT32: return js_int32(u.i32);
469
+ case T_UINT32: return js_number(u.u32);
470
+ case T_FLOAT16: return js_number(js_from_float16(u.u16));
471
+ case T_FLOAT32: return js_number(u.f32);
472
+ default: return js_number(u.f64);
473
+ }
474
+ }
475
+
476
+ /* SetViewValue (§25.3.1.6) */
477
+ static JSValue set_view_value(JSContext *ctx, JSValue this_val, JSValue request, JSValue value, JSValue little_endian, int type, const char *method) {
478
+ THIS_VIEW(method);
479
+ if (js_as_array_buffer(dv->buffer)->flags & JS_BUFFER_IMMUTABLE)
480
+ return js_throw_type_error(ctx, "Cannot perform %s on an immutable ArrayBuffer", method);
481
+ double index, d = 0;
482
+ uint64_t big = 0;
483
+ if (to_index(ctx, request, &index, "Offset is outside the bounds of the DataView") < 0) return JS_EXCEPTION;
484
+ if (type == T_BIGINT64 || type == T_BIGUINT64) { /* ToBigInt, then its value modulo 2^64 */
485
+ JSValue b = ctx->rt->bigint->to_bigint(ctx, value);
486
+ if (js_is_exception(b)) return b;
487
+ big = ctx->rt->bigint->to_uint64(b);
488
+ } else if (js_to_number(ctx, &d, value) < 0) {
489
+ return JS_EXCEPTION;
490
+ }
491
+ bool little = js_truthy(little_endian);
492
+ double len = view_length(dv);
493
+ if (len < 0) return throw_detached(ctx, method);
494
+ if (index + type_size[type] > len) return js_throw_range_error(ctx, "Offset is outside the bounds of the DataView");
495
+ union { uint8_t b[8]; int8_t i8; uint8_t u8; int16_t i16; uint16_t u16; int32_t i32; uint32_t u32; float f32; double f64; uint64_t u64; } u;
496
+ switch (type) {
497
+ case T_BIGINT64: case T_BIGUINT64: u.u64 = big; break;
498
+ case T_INT8: case T_UINT8: u.u8 = (uint8_t)(uint32_t)js_double_to_int32(d); break;
499
+ case T_INT16: case T_UINT16: u.u16 = (uint16_t)(uint32_t)js_double_to_int32(d); break;
500
+ case T_INT32: case T_UINT32: u.u32 = (uint32_t)js_double_to_int32(d); break;
501
+ case T_FLOAT16: u.u16 = js_to_float16(d); break;
502
+ case T_FLOAT32: u.f32 = (float)d; break;
503
+ default: u.f64 = d; break;
504
+ }
505
+ uint8_t *p = js_as_array_buffer(dv->buffer)->data + dv->byte_offset + (size_t)index;
506
+ copy_ordered(p, u.b, type_size[type], little);
507
+ return JS_UNDEFINED;
508
+ }
509
+
510
+ #define VIEW_ACCESSORS(Name, type) \
511
+ BUILTIN(data_view_get_##Name) { \
512
+ (void)callee, (void)new_target; \
513
+ return get_view_value(ctx, this_val, ARG(0), ARG(1), type, "DataView.prototype.get" #Name); \
514
+ } \
515
+ BUILTIN(data_view_set_##Name) { \
516
+ (void)callee, (void)new_target; \
517
+ return set_view_value(ctx, this_val, ARG(0), ARG(1), ARG(2), type, "DataView.prototype.set" #Name); \
518
+ }
519
+ VIEW_ACCESSORS(Int8, T_INT8)
520
+ VIEW_ACCESSORS(Uint8, T_UINT8)
521
+ VIEW_ACCESSORS(Int16, T_INT16)
522
+ VIEW_ACCESSORS(Uint16, T_UINT16)
523
+ VIEW_ACCESSORS(Int32, T_INT32)
524
+ VIEW_ACCESSORS(Uint32, T_UINT32)
525
+ VIEW_ACCESSORS(Float16, T_FLOAT16)
526
+ VIEW_ACCESSORS(Float32, T_FLOAT32)
527
+ VIEW_ACCESSORS(Float64, T_FLOAT64)
528
+ VIEW_ACCESSORS(BigInt64, T_BIGINT64)
529
+ VIEW_ACCESSORS(BigUint64, T_BIGUINT64)
530
+
531
+ /* ---- Realm ----------------------------------------------------------------------------------- */
532
+
533
+ static const JSBuiltin array_buffer_statics[] = {
534
+ JS_BUILTIN_FN("isView", array_buffer_is_view, 1),
535
+ JS_BUILTIN_SYMBOL_GETTER(species, get_species),
536
+ };
537
+
538
+ static const JSBuiltin array_buffer_proto[] = { /* V8's order, then the immutable proposal */
539
+ JS_BUILTIN_GETTER("byteLength", array_buffer_byte_length),
540
+ JS_BUILTIN_FN("slice", array_buffer_slice, 2),
541
+ JS_BUILTIN_GETTER("maxByteLength", array_buffer_max_byte_length),
542
+ JS_BUILTIN_GETTER("resizable", array_buffer_resizable),
543
+ JS_BUILTIN_FN("resize", array_buffer_resize, 1),
544
+ JS_BUILTIN_FN("transfer", array_buffer_transfer, 0),
545
+ JS_BUILTIN_FN("transferToFixedLength", array_buffer_transfer_to_fixed_length, 0),
546
+ JS_BUILTIN_GETTER("detached", array_buffer_detached),
547
+ JS_BUILTIN_GETTER("immutable", array_buffer_immutable),
548
+ JS_BUILTIN_FN("sliceToImmutable", array_buffer_slice_to_immutable, 2),
549
+ JS_BUILTIN_FN("transferToImmutable", array_buffer_transfer_to_immutable, 0),
550
+ JS_BUILTIN_SYMBOL_STRING(toStringTag, "ArrayBuffer", JS_PROP_CONFIGURABLE),
551
+ };
552
+
553
+ static const JSBuiltin data_view_proto[] = {
554
+ JS_BUILTIN_GETTER("buffer", data_view_buffer),
555
+ JS_BUILTIN_GETTER("byteLength", data_view_byte_length),
556
+ JS_BUILTIN_GETTER("byteOffset", data_view_byte_offset),
557
+ JS_BUILTIN_FN("getInt8", data_view_get_Int8, 1),
558
+ JS_BUILTIN_FN("setInt8", data_view_set_Int8, 2),
559
+ JS_BUILTIN_FN("getUint8", data_view_get_Uint8, 1),
560
+ JS_BUILTIN_FN("setUint8", data_view_set_Uint8, 2),
561
+ JS_BUILTIN_FN("getInt16", data_view_get_Int16, 1),
562
+ JS_BUILTIN_FN("setInt16", data_view_set_Int16, 2),
563
+ JS_BUILTIN_FN("getUint16", data_view_get_Uint16, 1),
564
+ JS_BUILTIN_FN("setUint16", data_view_set_Uint16, 2),
565
+ JS_BUILTIN_FN("getInt32", data_view_get_Int32, 1),
566
+ JS_BUILTIN_FN("setInt32", data_view_set_Int32, 2),
567
+ JS_BUILTIN_FN("getUint32", data_view_get_Uint32, 1),
568
+ JS_BUILTIN_FN("setUint32", data_view_set_Uint32, 2),
569
+ JS_BUILTIN_FN("getFloat16", data_view_get_Float16, 1),
570
+ JS_BUILTIN_FN("setFloat16", data_view_set_Float16, 2),
571
+ JS_BUILTIN_FN("getFloat32", data_view_get_Float32, 1),
572
+ JS_BUILTIN_FN("setFloat32", data_view_set_Float32, 2),
573
+ JS_BUILTIN_FN("getFloat64", data_view_get_Float64, 1),
574
+ JS_BUILTIN_FN("setFloat64", data_view_set_Float64, 2),
575
+ JS_BUILTIN_SYMBOL_STRING(toStringTag, "DataView", JS_PROP_CONFIGURABLE),
576
+ };
577
+
578
+ /* with BigInt (ADR 0016): the bigint component is installed first when the program reaches it */
579
+ static const JSBuiltin data_view_bigint_proto[] = {
580
+ JS_BUILTIN_FN("getBigInt64", data_view_get_BigInt64, 1),
581
+ JS_BUILTIN_FN("setBigInt64", data_view_set_BigInt64, 2),
582
+ JS_BUILTIN_FN("getBigUint64", data_view_get_BigUint64, 1),
583
+ JS_BUILTIN_FN("setBigUint64", data_view_set_BigUint64, 2),
584
+ };
585
+
586
+ static JSValue define_class(JSContext *ctx, JSObject *global, const char *name, JSNativeFn ctor, uint32_t length, JSIntrinsic proto_slot,
587
+ const JSBuiltin *statics, size_t nstatics, const JSBuiltin *methods, size_t n) {
588
+ JSValue proto = js_new_object_proto(ctx, ctx->intrinsics[JS_INTRINSIC_OBJECT_PROTOTYPE], 8);
589
+ ctx->intrinsics[proto_slot] = proto;
590
+ JSValue key = js_atom_from_cstr(ctx, name);
591
+ JSValue c = js_new_native(ctx, ctor, key, length, JS_FN_STRICT | JS_FN_CONSTRUCTOR);
592
+ js_define_data(ctx, js_as_object(c), JS_ATOM(prototype), proto, 0);
593
+ js_define_builtins(ctx, js_as_object(c), statics, nstatics);
594
+ js_define_data(ctx, js_as_object(proto), JS_ATOM(constructor), c, JS_BUILTIN_METHOD_ATTRS);
595
+ js_define_builtins(ctx, js_as_object(proto), methods, n);
596
+ js_define_data(ctx, global, key, c, JS_BUILTIN_METHOD_ATTRS);
597
+ return c;
598
+ }
599
+
600
+ static void install_arraybuffer(JSContext *ctx, JSObject *global) {
601
+ define_class(ctx, global, "ArrayBuffer", array_buffer_ctor, 1, JS_INTRINSIC_ARRAY_BUFFER_PROTOTYPE,
602
+ array_buffer_statics, JS_COUNTOF(array_buffer_statics), array_buffer_proto, JS_COUNTOF(array_buffer_proto));
603
+ define_class(ctx, global, "DataView", data_view_ctor, 1, JS_INTRINSIC_DATA_VIEW_PROTOTYPE, NULL, 0, data_view_proto, JS_COUNTOF(data_view_proto));
604
+ if (ctx->rt->bigint)
605
+ js_define_builtins(ctx, js_as_object(ctx->intrinsics[JS_INTRINSIC_DATA_VIEW_PROTOTYPE]), data_view_bigint_proto, JS_COUNTOF(data_view_bigint_proto));
606
+ }
607
+
608
+ const JSComponent js_component_arraybuffer = { "arraybuffer", install_arraybuffer };