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.
- package/LICENSE +21 -0
- package/README.md +45 -2
- package/cli.js +8084 -0
- package/node/include/js_node.h +46 -0
- package/node/prelude/async_hooks.js +88 -0
- package/node/prelude/buffer.js +31 -0
- package/node/prelude/crypto.js +114 -0
- package/node/prelude/events.js +227 -0
- package/node/prelude/fs.js +79 -0
- package/node/prelude/http.js +536 -0
- package/node/prelude/http2.js +30 -0
- package/node/prelude/internal/crypto/asym.js +333 -0
- package/node/prelude/internal/crypto/cipher.js +205 -0
- package/node/prelude/internal/crypto/hash.js +137 -0
- package/node/prelude/internal/crypto/kdf.js +182 -0
- package/node/prelude/internal/crypto/keys.js +603 -0
- package/node/prelude/internal/crypto/random.js +118 -0
- package/node/prelude/internal/crypto/util.js +76 -0
- package/node/prelude/internal/errors.js +88 -0
- package/node/prelude/internal/querystring.js +105 -0
- package/node/prelude/module.js +53 -0
- package/node/prelude/net.js +51 -0
- package/node/prelude/os.js +129 -0
- package/node/prelude/path.js +257 -0
- package/node/prelude/process.js +21 -0
- package/node/prelude/querystring.js +469 -0
- package/node/prelude/stream.js +1327 -0
- package/node/prelude/stream_promises.js +7 -0
- package/node/prelude/stream_web.js +6 -0
- package/node/prelude/string_decoder.js +236 -0
- package/node/prelude/tty.js +18 -0
- package/node/prelude/url.js +1156 -0
- package/node/prelude/util.js +64 -0
- package/node/prelude/zlib.js +81 -0
- package/node/src/host_fs.c +126 -0
- package/node/src/host_http.c +486 -0
- package/node/src/host_os.c +505 -0
- package/node/src/host_sys.c +78 -0
- package/node/third_party/libuv/LICENSE +19 -0
- package/node/third_party/libuv/include/uv/aix.h +32 -0
- package/node/third_party/libuv/include/uv/bsd.h +34 -0
- package/node/third_party/libuv/include/uv/darwin.h +61 -0
- package/node/third_party/libuv/include/uv/errno.h +483 -0
- package/node/third_party/libuv/include/uv/linux.h +34 -0
- package/node/third_party/libuv/include/uv/os390.h +33 -0
- package/node/third_party/libuv/include/uv/posix.h +31 -0
- package/node/third_party/libuv/include/uv/sunos.h +44 -0
- package/node/third_party/libuv/include/uv/threadpool.h +37 -0
- package/node/third_party/libuv/include/uv/tree.h +521 -0
- package/node/third_party/libuv/include/uv/unix.h +512 -0
- package/node/third_party/libuv/include/uv/version.h +43 -0
- package/node/third_party/libuv/include/uv/win.h +698 -0
- package/node/third_party/libuv/include/uv.h +1990 -0
- package/node/third_party/libuv/src/fs-poll.c +290 -0
- package/node/third_party/libuv/src/heap-inl.h +245 -0
- package/node/third_party/libuv/src/idna.c +560 -0
- package/node/third_party/libuv/src/idna.h +31 -0
- package/node/third_party/libuv/src/inet.c +298 -0
- package/node/third_party/libuv/src/queue.h +90 -0
- package/node/third_party/libuv/src/random.c +123 -0
- package/node/third_party/libuv/src/strscpy.c +38 -0
- package/node/third_party/libuv/src/strscpy.h +39 -0
- package/node/third_party/libuv/src/strtok.c +52 -0
- package/node/third_party/libuv/src/strtok.h +27 -0
- package/node/third_party/libuv/src/thread-common.c +175 -0
- package/node/third_party/libuv/src/threadpool.c +419 -0
- package/node/third_party/libuv/src/timer.c +200 -0
- package/node/third_party/libuv/src/unix/async.c +418 -0
- package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +164 -0
- package/node/third_party/libuv/src/unix/core.c +2104 -0
- package/node/third_party/libuv/src/unix/darwin-proctitle.c +176 -0
- package/node/third_party/libuv/src/unix/darwin-stub.h +97 -0
- package/node/third_party/libuv/src/unix/darwin-syscalls.h +17 -0
- package/node/third_party/libuv/src/unix/darwin.c +237 -0
- package/node/third_party/libuv/src/unix/dl.c +80 -0
- package/node/third_party/libuv/src/unix/fs.c +2303 -0
- package/node/third_party/libuv/src/unix/fsevents.c +906 -0
- package/node/third_party/libuv/src/unix/getaddrinfo.c +252 -0
- package/node/third_party/libuv/src/unix/getnameinfo.c +121 -0
- package/node/third_party/libuv/src/unix/internal.h +530 -0
- package/node/third_party/libuv/src/unix/kqueue.c +667 -0
- package/node/third_party/libuv/src/unix/linux.c +2761 -0
- package/node/third_party/libuv/src/unix/loop-watcher.c +68 -0
- package/node/third_party/libuv/src/unix/loop.c +240 -0
- package/node/third_party/libuv/src/unix/pipe.c +555 -0
- package/node/third_party/libuv/src/unix/poll.c +159 -0
- package/node/third_party/libuv/src/unix/process.c +1123 -0
- package/node/third_party/libuv/src/unix/procfs-exepath.c +45 -0
- package/node/third_party/libuv/src/unix/proctitle.c +157 -0
- package/node/third_party/libuv/src/unix/random-devurandom.c +93 -0
- package/node/third_party/libuv/src/unix/random-getentropy.c +57 -0
- package/node/third_party/libuv/src/unix/random-getrandom.c +86 -0
- package/node/third_party/libuv/src/unix/random-sysctl-linux.c +99 -0
- package/node/third_party/libuv/src/unix/signal.c +581 -0
- package/node/third_party/libuv/src/unix/stream.c +1567 -0
- package/node/third_party/libuv/src/unix/tcp.c +673 -0
- package/node/third_party/libuv/src/unix/thread.c +975 -0
- package/node/third_party/libuv/src/unix/tty.c +510 -0
- package/node/third_party/libuv/src/unix/udp.c +1434 -0
- package/node/third_party/libuv/src/uv-common.c +1051 -0
- package/node/third_party/libuv/src/uv-common.h +474 -0
- package/node/third_party/libuv/src/uv-data-getter-setters.c +119 -0
- package/node/third_party/libuv/src/version.c +45 -0
- package/node/third_party/llhttp/LICENSE +22 -0
- package/node/third_party/llhttp/api.c +509 -0
- package/node/third_party/llhttp/http.c +170 -0
- package/node/third_party/llhttp/llhttp.c +10099 -0
- package/node/third_party/llhttp/llhttp.h +907 -0
- package/package.json +25 -4
- package/runtime/include/js_atoms.gen.h +68 -0
- package/runtime/include/js_atoms.h +54 -0
- package/runtime/include/js_bigint.h +93 -0
- package/runtime/include/js_buffer.h +79 -0
- package/runtime/include/js_builtins.h +168 -0
- package/runtime/include/js_console.h +58 -0
- package/runtime/include/js_convert.h +22 -0
- package/runtime/include/js_core.def +188 -0
- package/runtime/include/js_crypto.h +58 -0
- package/runtime/include/js_error.h +37 -0
- package/runtime/include/js_exception.h +65 -0
- package/runtime/include/js_function.h +167 -0
- package/runtime/include/js_gc.h +195 -0
- package/runtime/include/js_generator.h +96 -0
- package/runtime/include/js_host.h +19 -0
- package/runtime/include/js_jobs.h +84 -0
- package/runtime/include/js_module.h +16 -0
- package/runtime/include/js_object.h +384 -0
- package/runtime/include/js_ops.h +111 -0
- package/runtime/include/js_promise.h +45 -0
- package/runtime/include/js_regexp.h +25 -0
- package/runtime/include/js_runtime.h +30 -0
- package/runtime/include/js_symbol.h +62 -0
- package/runtime/include/js_web.h +110 -0
- package/runtime/include/jscell.h +48 -0
- package/runtime/include/jscontext.h +240 -0
- package/runtime/include/jsnum.h +42 -0
- package/runtime/include/jsstring.h +161 -0
- package/runtime/include/jsvalue.h +142 -0
- package/runtime/src/arguments.c +115 -0
- package/runtime/src/array.c +1145 -0
- package/runtime/src/arraybuffer.c +608 -0
- package/runtime/src/async_iter.c +479 -0
- package/runtime/src/atoms.c +157 -0
- package/runtime/src/base64.c +107 -0
- package/runtime/src/bigint.c +1189 -0
- package/runtime/src/blob.c +371 -0
- package/runtime/src/buffer.c +1357 -0
- package/runtime/src/builtin_table.c +100 -0
- package/runtime/src/builtins.c +987 -0
- package/runtime/src/builtins_util.h +53 -0
- package/runtime/src/collections.c +912 -0
- package/runtime/src/components.c +28 -0
- package/runtime/src/console.c +637 -0
- package/runtime/src/convert.c +82 -0
- package/runtime/src/core_all.c +21 -0
- package/runtime/src/crypto.c +116 -0
- package/runtime/src/crypto_asym.c +644 -0
- package/runtime/src/crypto_cipher.c +671 -0
- package/runtime/src/crypto_hash.c +260 -0
- package/runtime/src/crypto_host.c +414 -0
- package/runtime/src/crypto_internal.h +304 -0
- package/runtime/src/crypto_kdf.c +143 -0
- package/runtime/src/crypto_key.c +171 -0
- package/runtime/src/crypto_pkey.c +794 -0
- package/runtime/src/crypto_subtle.c +1675 -0
- package/runtime/src/date.c +940 -0
- package/runtime/src/domexception.c +169 -0
- package/runtime/src/elements.c +312 -0
- package/runtime/src/elements.h +45 -0
- package/runtime/src/encoding.c +485 -0
- package/runtime/src/error.c +297 -0
- package/runtime/src/events.c +793 -0
- package/runtime/src/exception.c +56 -0
- package/runtime/src/fetch.c +772 -0
- package/runtime/src/function.c +530 -0
- package/runtime/src/gc.c +803 -0
- package/runtime/src/generator.c +218 -0
- package/runtime/src/global.c +119 -0
- package/runtime/src/headers.c +557 -0
- package/runtime/src/inspect.c +1792 -0
- package/runtime/src/internal.h +80 -0
- package/runtime/src/iterate.c +94 -0
- package/runtime/src/iterator.c +409 -0
- package/runtime/src/jobs.c +337 -0
- package/runtime/src/jsnum.c +353 -0
- package/runtime/src/json.c +1028 -0
- package/runtime/src/math.c +243 -0
- package/runtime/src/module.c +336 -0
- package/runtime/src/number.c +176 -0
- package/runtime/src/object.c +1265 -0
- package/runtime/src/ops.c +322 -0
- package/runtime/src/os.c +196 -0
- package/runtime/src/os.h +29 -0
- package/runtime/src/process.c +432 -0
- package/runtime/src/promise.c +721 -0
- package/runtime/src/proxy.c +570 -0
- package/runtime/src/reflect.c +194 -0
- package/runtime/src/regexp.c +1141 -0
- package/runtime/src/regexp_anchor.h +34 -0
- package/runtime/src/regexp_message.h +32 -0
- package/runtime/src/shape.c +294 -0
- package/runtime/src/shape.h +46 -0
- package/runtime/src/streams.c +1046 -0
- package/runtime/src/streams.h +47 -0
- package/runtime/src/string.c +364 -0
- package/runtime/src/string_builtins.c +837 -0
- package/runtime/src/symbol.c +143 -0
- package/runtime/src/test_host.c +59 -0
- package/runtime/src/typedarray.c +1330 -0
- package/runtime/src/tznames.gen.h +712 -0
- package/runtime/src/uri.c +169 -0
- package/runtime/src/url.c +2116 -0
- package/runtime/src/weak.c +486 -0
- package/runtime/src/web.c +214 -0
- package/runtime/src/wrapper.c +59 -0
- package/runtime/src/writable.c +1486 -0
- package/runtime/third_party/ada-idna/LICENSE-MIT +18 -0
- package/runtime/third_party/ada-idna/README.md +27 -0
- package/runtime/third_party/ada-idna/convert.mjs +83 -0
- package/runtime/third_party/ada-idna/idna.c +416 -0
- package/runtime/third_party/ada-idna/idna.h +15 -0
- package/runtime/third_party/ada-idna/idna_tables.h +2657 -0
- package/runtime/third_party/bearssl/LICENSE.txt +21 -0
- package/runtime/third_party/bearssl/README.txt +136 -0
- package/runtime/third_party/bearssl/VERSION +1 -0
- package/runtime/third_party/bearssl/inc/bearssl.h +183 -0
- package/runtime/third_party/bearssl/inc/bearssl_aead.h +1059 -0
- package/runtime/third_party/bearssl/inc/bearssl_block.h +2618 -0
- package/runtime/third_party/bearssl/inc/bearssl_ec.h +967 -0
- package/runtime/third_party/bearssl/inc/bearssl_hash.h +1346 -0
- package/runtime/third_party/bearssl/inc/bearssl_hmac.h +241 -0
- package/runtime/third_party/bearssl/inc/bearssl_kdf.h +284 -0
- package/runtime/third_party/bearssl/inc/bearssl_pem.h +294 -0
- package/runtime/third_party/bearssl/inc/bearssl_prf.h +150 -0
- package/runtime/third_party/bearssl/inc/bearssl_rand.h +397 -0
- package/runtime/third_party/bearssl/inc/bearssl_rsa.h +1655 -0
- package/runtime/third_party/bearssl/inc/bearssl_ssl.h +4296 -0
- package/runtime/third_party/bearssl/inc/bearssl_x509.h +1474 -0
- package/runtime/third_party/bearssl/src/aead/ccm.c +346 -0
- package/runtime/third_party/bearssl/src/aead/eax.c +525 -0
- package/runtime/third_party/bearssl/src/aead/gcm.c +318 -0
- package/runtime/third_party/bearssl/src/codec/ccopy.c +44 -0
- package/runtime/third_party/bearssl/src/codec/dec16be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec16le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec32be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec32le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec64be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/dec64le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc16be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc16le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc32be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc32le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc64be.c +38 -0
- package/runtime/third_party/bearssl/src/codec/enc64le.c +38 -0
- package/runtime/third_party/bearssl/src/codec/pemdec.c +526 -0
- package/runtime/third_party/bearssl/src/codec/pemdec.t0 +314 -0
- package/runtime/third_party/bearssl/src/codec/pemenc.c +173 -0
- package/runtime/third_party/bearssl/src/config.h +247 -0
- package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +121 -0
- package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +171 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +398 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +390 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +1478 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +800 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +605 -0
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +831 -0
- package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +46 -0
- package/runtime/third_party/bearssl/src/ec/ec_default.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ec_keygen.c +86 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +2124 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +1469 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +1765 -0
- package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +1781 -0
- package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +824 -0
- package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +826 -0
- package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +85 -0
- package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +51 -0
- package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +57 -0
- package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +64 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +134 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +36 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +47 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +45 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +174 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +48 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +166 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +47 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +45 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +173 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +48 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +165 -0
- package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +121 -0
- package/runtime/third_party/bearssl/src/hash/dig_oid.c +84 -0
- package/runtime/third_party/bearssl/src/hash/dig_size.c +50 -0
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +345 -0
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +251 -0
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +154 -0
- package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +389 -0
- package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +411 -0
- package/runtime/third_party/bearssl/src/hash/md5.c +208 -0
- package/runtime/third_party/bearssl/src/hash/md5sha1.c +141 -0
- package/runtime/third_party/bearssl/src/hash/mgf1.c +56 -0
- package/runtime/third_party/bearssl/src/hash/multihash.c +166 -0
- package/runtime/third_party/bearssl/src/hash/sha1.c +191 -0
- package/runtime/third_party/bearssl/src/hash/sha2big.c +285 -0
- package/runtime/third_party/bearssl/src/hash/sha2small.c +341 -0
- package/runtime/third_party/bearssl/src/inner.h +2577 -0
- package/runtime/third_party/bearssl/src/int/i15_add.c +46 -0
- package/runtime/third_party/bearssl/src/int/i15_bitlen.c +44 -0
- package/runtime/third_party/bearssl/src/int/i15_decmod.c +124 -0
- package/runtime/third_party/bearssl/src/int/i15_decode.c +56 -0
- package/runtime/third_party/bearssl/src/int/i15_decred.c +100 -0
- package/runtime/third_party/bearssl/src/int/i15_encode.c +56 -0
- package/runtime/third_party/bearssl/src/int/i15_fmont.c +59 -0
- package/runtime/third_party/bearssl/src/int/i15_iszero.c +39 -0
- package/runtime/third_party/bearssl/src/int/i15_moddiv.c +465 -0
- package/runtime/third_party/bearssl/src/int/i15_modpow.c +50 -0
- package/runtime/third_party/bearssl/src/int/i15_modpow2.c +160 -0
- package/runtime/third_party/bearssl/src/int/i15_montmul.c +184 -0
- package/runtime/third_party/bearssl/src/int/i15_mulacc.c +61 -0
- package/runtime/third_party/bearssl/src/int/i15_muladd.c +173 -0
- package/runtime/third_party/bearssl/src/int/i15_ninv15.c +38 -0
- package/runtime/third_party/bearssl/src/int/i15_reduce.c +66 -0
- package/runtime/third_party/bearssl/src/int/i15_rshift.c +47 -0
- package/runtime/third_party/bearssl/src/int/i15_sub.c +46 -0
- package/runtime/third_party/bearssl/src/int/i15_tmont.c +36 -0
- package/runtime/third_party/bearssl/src/int/i31_add.c +46 -0
- package/runtime/third_party/bearssl/src/int/i31_bitlen.c +44 -0
- package/runtime/third_party/bearssl/src/int/i31_decmod.c +124 -0
- package/runtime/third_party/bearssl/src/int/i31_decode.c +57 -0
- package/runtime/third_party/bearssl/src/int/i31_decred.c +103 -0
- package/runtime/third_party/bearssl/src/int/i31_encode.c +79 -0
- package/runtime/third_party/bearssl/src/int/i31_fmont.c +60 -0
- package/runtime/third_party/bearssl/src/int/i31_iszero.c +39 -0
- package/runtime/third_party/bearssl/src/int/i31_moddiv.c +488 -0
- package/runtime/third_party/bearssl/src/int/i31_modpow.c +65 -0
- package/runtime/third_party/bearssl/src/int/i31_modpow2.c +160 -0
- package/runtime/third_party/bearssl/src/int/i31_montmul.c +127 -0
- package/runtime/third_party/bearssl/src/int/i31_mulacc.c +74 -0
- package/runtime/third_party/bearssl/src/int/i31_muladd.c +157 -0
- package/runtime/third_party/bearssl/src/int/i31_ninv31.c +39 -0
- package/runtime/third_party/bearssl/src/int/i31_reduce.c +66 -0
- package/runtime/third_party/bearssl/src/int/i31_rshift.c +47 -0
- package/runtime/third_party/bearssl/src/int/i31_sub.c +46 -0
- package/runtime/third_party/bearssl/src/int/i31_tmont.c +36 -0
- package/runtime/third_party/bearssl/src/int/i32_add.c +51 -0
- package/runtime/third_party/bearssl/src/int/i32_bitlen.c +44 -0
- package/runtime/third_party/bearssl/src/int/i32_decmod.c +77 -0
- package/runtime/third_party/bearssl/src/int/i32_decode.c +63 -0
- package/runtime/third_party/bearssl/src/int/i32_decred.c +107 -0
- package/runtime/third_party/bearssl/src/int/i32_div32.c +56 -0
- package/runtime/third_party/bearssl/src/int/i32_encode.c +72 -0
- package/runtime/third_party/bearssl/src/int/i32_fmont.c +60 -0
- package/runtime/third_party/bearssl/src/int/i32_iszero.c +39 -0
- package/runtime/third_party/bearssl/src/int/i32_modpow.c +65 -0
- package/runtime/third_party/bearssl/src/int/i32_montmul.c +69 -0
- package/runtime/third_party/bearssl/src/int/i32_mulacc.c +56 -0
- package/runtime/third_party/bearssl/src/int/i32_muladd.c +138 -0
- package/runtime/third_party/bearssl/src/int/i32_ninv32.c +39 -0
- package/runtime/third_party/bearssl/src/int/i32_reduce.c +66 -0
- package/runtime/third_party/bearssl/src/int/i32_sub.c +51 -0
- package/runtime/third_party/bearssl/src/int/i32_tmont.c +36 -0
- package/runtime/third_party/bearssl/src/int/i62_modpow2.c +493 -0
- package/runtime/third_party/bearssl/src/kdf/hkdf.c +107 -0
- package/runtime/third_party/bearssl/src/kdf/shake.c +590 -0
- package/runtime/third_party/bearssl/src/mac/hmac.c +122 -0
- package/runtime/third_party/bearssl/src/mac/hmac_ct.c +193 -0
- package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +206 -0
- package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +157 -0
- package/runtime/third_party/bearssl/src/rand/sysrng.c +252 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +36 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +36 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +38 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +36 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +583 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +99 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +41 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +43 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +209 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +320 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +40 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +113 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +152 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +608 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +99 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +41 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +43 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +203 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +318 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +40 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +106 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +152 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +41 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +37 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +43 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +160 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +40 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +44 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +77 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +57 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +61 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +64 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +57 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +63 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +223 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +60 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +64 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +125 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +112 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +145 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +121 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +106 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +121 -0
- package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +52 -0
- package/runtime/third_party/bearssl/src/settings.c +306 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +69 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +67 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +84 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +142 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +254 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +157 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_common.c +112 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +328 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +398 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +104 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +81 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +114 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +433 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +159 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +115 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +111 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +91 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +116 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +422 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +170 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +112 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +445 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +670 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +417 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +717 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +946 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +69 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +67 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +84 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +142 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +176 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +129 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +240 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +223 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +122 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +211 -0
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +596 -0
- package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +106 -0
- package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +237 -0
- package/runtime/third_party/bearssl/src/symcipher/des_ct.c +411 -0
- package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +87 -0
- package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +69 -0
- package/runtime/third_party/bearssl/src/symcipher/des_support.c +166 -0
- package/runtime/third_party/bearssl/src/symcipher/des_tab.c +310 -0
- package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +85 -0
- package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +67 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +260 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +297 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +475 -0
- package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +221 -0
- package/runtime/third_party/bearssl/src/x509/asn1.t0 +757 -0
- package/runtime/third_party/bearssl/src/x509/asn1enc.c +93 -0
- package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +110 -0
- package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +161 -0
- package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +97 -0
- package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +96 -0
- package/runtime/third_party/bearssl/src/x509/skey_decoder.c +653 -0
- package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +376 -0
- package/runtime/third_party/bearssl/src/x509/x509_decoder.c +776 -0
- package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +324 -0
- package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +105 -0
- package/runtime/third_party/bearssl/src/x509/x509_minimal.c +1722 -0
- package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +1526 -0
- package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +59 -0
- package/runtime/third_party/quickjs-dtoa/LICENSE +22 -0
- package/runtime/third_party/quickjs-dtoa/README.md +23 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.c +1640 -0
- package/runtime/third_party/quickjs-dtoa/dtoa.h +83 -0
- package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +89 -0
- package/runtime/third_party/quickjs-regexp/LICENSE +22 -0
- package/runtime/third_party/quickjs-regexp/README.md +22 -0
- package/runtime/third_party/quickjs-regexp/cutils.c +641 -0
- package/runtime/third_party/quickjs-regexp/cutils.h +457 -0
- package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +73 -0
- package/runtime/third_party/quickjs-regexp/libregexp.c +3448 -0
- package/runtime/third_party/quickjs-regexp/libregexp.h +65 -0
- package/runtime/third_party/quickjs-regexp/libunicode-table.h +5206 -0
- package/runtime/third_party/quickjs-regexp/libunicode.c +2124 -0
- package/runtime/third_party/quickjs-regexp/libunicode.h +196 -0
- package/runtime/third_party/v8-ieee754/LICENSE +61 -0
- package/runtime/third_party/v8-ieee754/README.md +22 -0
- package/runtime/third_party/v8-ieee754/convert.py +84 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +3030 -0
- package/runtime/third_party/v8-ieee754/ieee754.h +27 -0
- package/runtime/tools/regexp_compile.c +90 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
/* Async generators (ECMAScript §27.6) and async iteration (§27.1.4–6): the request queue
|
|
2
|
+
* and its driver, %AsyncIteratorPrototype%, the async-from-sync iterator, for await, and
|
|
3
|
+
* yield* in async generators (§15.5.5). ADR 0007. */
|
|
4
|
+
#include "internal.h"
|
|
5
|
+
#include "js_atoms.h"
|
|
6
|
+
#include "js_error.h"
|
|
7
|
+
#include "js_function.h"
|
|
8
|
+
#include "js_generator.h"
|
|
9
|
+
#include "js_ops.h"
|
|
10
|
+
#include "js_promise.h"
|
|
11
|
+
#include "js_symbol.h"
|
|
12
|
+
#include "jscontext.h"
|
|
13
|
+
|
|
14
|
+
#define ARG(i) ((i) < argc ? argv[i] : JS_UNDEFINED)
|
|
15
|
+
#define BUILTIN(fn) \
|
|
16
|
+
static JSValue fn(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, \
|
|
17
|
+
const JSValue *argv, JSValue new_target)
|
|
18
|
+
|
|
19
|
+
/* A builtin closure: `data` kept in its home_object slot (as in promise.c). */
|
|
20
|
+
static JSValue native_with(JSContext *ctx, JSNativeFn fn, uint32_t length, JSValue data) {
|
|
21
|
+
JSValue f = js_new_native(ctx, fn, js_empty_string(), length, JS_FN_STRICT);
|
|
22
|
+
js_store(ctx, &js_as_function(f)->obj.cell, &js_as_function(f)->home_object, data);
|
|
23
|
+
return f;
|
|
24
|
+
}
|
|
25
|
+
static JSValue data_of(JSValue callee) { return js_as_function(callee)->home_object; }
|
|
26
|
+
|
|
27
|
+
/* GetMethod (§7.3.10): undefined for null or undefined, a TypeError if not callable. */
|
|
28
|
+
static JSValue get_method(JSContext *ctx, JSValue v, JSValue key, const char *what) {
|
|
29
|
+
JSValue m = js_get_value(ctx, v, key);
|
|
30
|
+
if (js_is_exception(m) || js_is_callable(m)) return m;
|
|
31
|
+
if (js_is_nullish(m)) return JS_UNDEFINED;
|
|
32
|
+
return js_throw_type_error(ctx, "%s is not a function", what);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Rejects `promise` with the pending exception (IfAbruptRejectPromise) and returns it. */
|
|
36
|
+
static JSValue reject_pending(JSContext *ctx, JSValue promise) {
|
|
37
|
+
js_promise_reject_internal(ctx, promise, js_take_exception(ctx));
|
|
38
|
+
return promise;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* ---- The async generator's request queue (§27.6.3) ------------------------------------- */
|
|
42
|
+
|
|
43
|
+
typedef struct Request {
|
|
44
|
+
JSHostCell host;
|
|
45
|
+
int32_t mode; /* JS_RESUME_NEXT / THROW / RETURN */
|
|
46
|
+
JSValue value;
|
|
47
|
+
JSValue promise; /* what next/throw/return returned */
|
|
48
|
+
JSValue next;
|
|
49
|
+
} Request;
|
|
50
|
+
|
|
51
|
+
static void request_visit(JSCell *c, JSTracer *trc) {
|
|
52
|
+
Request *r = (Request *)c;
|
|
53
|
+
js_trace_value(trc, r->value);
|
|
54
|
+
js_trace_value(trc, r->promise);
|
|
55
|
+
js_trace_value(trc, r->next);
|
|
56
|
+
}
|
|
57
|
+
static const JSCellClass request_class = { "AsyncGeneratorRequest", request_visit, NULL };
|
|
58
|
+
|
|
59
|
+
static const JSClass async_generator_class = { "AsyncGenerator", sizeof(JSGenerator), NULL, NULL, NULL, NULL, js_generator_visit, NULL, NULL };
|
|
60
|
+
|
|
61
|
+
JSValue js_async_generator_new(JSContext *ctx, JSValue callee, JSGeneratorResume resume, uint32_t slots) {
|
|
62
|
+
JSValue proto = js_generator_proto(ctx, callee, JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE);
|
|
63
|
+
if (js_is_exception(proto)) return JS_EXCEPTION;
|
|
64
|
+
JSGenerator *g = js_generator_alloc(ctx, &async_generator_class, proto, resume, slots);
|
|
65
|
+
g->kind = JS_GEN_ASYNC_GENERATOR; /* driver: the queue's first request, or undefined */
|
|
66
|
+
return js_object_value(&g->obj);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static Request *head_of(JSGenerator *g) { return js_is_cell(g->driver) ? (Request *)js_as_cell(g->driver) : NULL; }
|
|
70
|
+
|
|
71
|
+
/* AsyncGeneratorEnqueue */
|
|
72
|
+
static void enqueue(JSContext *ctx, JSGenerator *g, int mode, JSValue value, JSValue promise) {
|
|
73
|
+
Request *r = (Request *)js_alloc_host_cell(ctx, &request_class, sizeof(Request));
|
|
74
|
+
r->mode = mode;
|
|
75
|
+
js_init_slot(&r->value, value);
|
|
76
|
+
js_init_slot(&r->promise, promise);
|
|
77
|
+
js_init_slot(&r->next, JS_UNDEFINED);
|
|
78
|
+
JSValue rv = js_cell(&r->host.cell);
|
|
79
|
+
Request *tail = head_of(g);
|
|
80
|
+
if (!tail) {
|
|
81
|
+
js_store(ctx, &g->obj.cell, &g->driver, rv);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
while (js_is_cell(tail->next)) tail = (Request *)js_as_cell(tail->next);
|
|
85
|
+
js_store(ctx, &tail->host.cell, &tail->next, rv);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* AsyncGeneratorCompleteStep: settles the first request's promise and removes it. */
|
|
89
|
+
static void complete_step(JSContext *ctx, JSGenerator *g, bool threw, JSValue value, bool done) {
|
|
90
|
+
Request *r = head_of(g);
|
|
91
|
+
JSValue promise = r->promise;
|
|
92
|
+
js_store(ctx, &g->obj.cell, &g->driver, r->next);
|
|
93
|
+
if (threw) js_promise_reject_internal(ctx, promise, value);
|
|
94
|
+
else js_promise_resolve_internal(ctx, promise, js_iter_result(ctx, value, done));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static void finish(JSContext *ctx, JSGenerator *g) {
|
|
98
|
+
g->status = JS_GEN_COMPLETED;
|
|
99
|
+
js_store(ctx, &g->obj.cell, &g->frame, JS_UNDEFINED);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* AsyncGeneratorAwaitReturn: return(v) on a finished generator awaits v first. */
|
|
103
|
+
static void await_return(JSContext *ctx, JSGenerator *g) {
|
|
104
|
+
g->status = JS_GEN_AWAITING_RETURN;
|
|
105
|
+
JSValue promise = js_promise_resolve(ctx, head_of(g)->value);
|
|
106
|
+
if (js_is_exception(promise)) {
|
|
107
|
+
g->status = JS_GEN_COMPLETED;
|
|
108
|
+
complete_step(ctx, g, true, js_take_exception(ctx), true);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
js_promise_await(ctx, promise, js_object_value(&g->obj));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* Runs the body from where it paused to its next pause point (AsyncGeneratorResume). */
|
|
115
|
+
static void resume_body(JSContext *ctx, JSGenerator *g, JSValue value, int mode) {
|
|
116
|
+
g->status = JS_GEN_EXECUTING;
|
|
117
|
+
g->raw = 0;
|
|
118
|
+
JSValue r = g->resume(ctx, g, value, mode);
|
|
119
|
+
if (g->status == JS_GEN_AWAITING) return;
|
|
120
|
+
if (g->status == JS_GEN_SUSPENDED) { /* AsyncGeneratorYield: still running while the request settles */
|
|
121
|
+
g->status = JS_GEN_EXECUTING;
|
|
122
|
+
complete_step(ctx, g, false, r, false);
|
|
123
|
+
g->status = JS_GEN_SUSPENDED;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
finish(ctx, g);
|
|
127
|
+
if (js_is_exception(r)) complete_step(ctx, g, true, js_take_exception(ctx), true);
|
|
128
|
+
else complete_step(ctx, g, false, r, true);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* Serves queued requests while the generator can take one (AsyncGeneratorDrainQueue and the
|
|
132
|
+
* resumes the methods start): a finished generator answers next() with done, throw() with a
|
|
133
|
+
* rejection, and awaits return()'s value. */
|
|
134
|
+
static void drain(JSContext *ctx, JSGenerator *g) {
|
|
135
|
+
for (Request *r; (r = head_of(g));) {
|
|
136
|
+
uint8_t s = g->status;
|
|
137
|
+
if (s == JS_GEN_EXECUTING || s == JS_GEN_AWAITING || s == JS_GEN_AWAITING_RETURN) return;
|
|
138
|
+
if (s == JS_GEN_START && r->mode != JS_RESUME_NEXT) { /* never started: the body never runs */
|
|
139
|
+
finish(ctx, g);
|
|
140
|
+
s = JS_GEN_COMPLETED;
|
|
141
|
+
}
|
|
142
|
+
if (s == JS_GEN_COMPLETED) {
|
|
143
|
+
if (r->mode == JS_RESUME_RETURN) await_return(ctx, g);
|
|
144
|
+
else if (r->mode == JS_RESUME_THROW) complete_step(ctx, g, true, r->value, true);
|
|
145
|
+
else complete_step(ctx, g, false, JS_UNDEFINED, true);
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
resume_body(ctx, g, r->value, r->mode);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* An await in the body settled, or return()'s value did. */
|
|
153
|
+
void js_async_generator_resume(JSContext *ctx, JSGenerator *g, JSValue value, int mode) {
|
|
154
|
+
if (g->status == JS_GEN_AWAITING_RETURN) {
|
|
155
|
+
g->status = JS_GEN_COMPLETED;
|
|
156
|
+
complete_step(ctx, g, mode == JS_RESUME_THROW, value, true);
|
|
157
|
+
} else {
|
|
158
|
+
resume_body(ctx, g, value, mode);
|
|
159
|
+
}
|
|
160
|
+
drain(ctx, g);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* %AsyncGeneratorPrototype%.next / return / throw (§27.6.1.2–4) */
|
|
164
|
+
static JSValue request(JSContext *ctx, JSValue callee, JSValue this_val, JSValue value, int mode, const char *name) {
|
|
165
|
+
JSValue promise = js_new_promise(js_as_function(callee)->realm);
|
|
166
|
+
if (!js_is_object(this_val) || js_as_object(this_val)->shape->cls != &async_generator_class) {
|
|
167
|
+
js_discard(js_throw_type_error(ctx, "%s method called on incompatible receiver (not an async generator)", name));
|
|
168
|
+
return reject_pending(ctx, promise);
|
|
169
|
+
}
|
|
170
|
+
JSGenerator *g = js_as_generator(this_val);
|
|
171
|
+
enqueue(ctx, g, mode, value, promise);
|
|
172
|
+
drain(ctx, g);
|
|
173
|
+
return promise;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#define METHOD(fn, mode, name) \
|
|
177
|
+
BUILTIN(fn) { \
|
|
178
|
+
(void)new_target; \
|
|
179
|
+
return request(ctx, callee, this_val, ARG(0), mode, name); \
|
|
180
|
+
}
|
|
181
|
+
METHOD(async_generator_next, JS_RESUME_NEXT, "next")
|
|
182
|
+
METHOD(async_generator_return, JS_RESUME_RETURN, "return")
|
|
183
|
+
METHOD(async_generator_throw, JS_RESUME_THROW, "throw")
|
|
184
|
+
|
|
185
|
+
/* ---- The async-from-sync iterator (§27.1.6) ------------------------------------------------ */
|
|
186
|
+
|
|
187
|
+
typedef struct AsyncFromSync {
|
|
188
|
+
JSObject obj;
|
|
189
|
+
JSValue iterator; /* the sync iterator record */
|
|
190
|
+
JSValue next;
|
|
191
|
+
} AsyncFromSync;
|
|
192
|
+
|
|
193
|
+
static void afs_visit(JSCell *c, JSTracer *trc) {
|
|
194
|
+
js_trace_value(trc, ((AsyncFromSync *)c)->iterator);
|
|
195
|
+
js_trace_value(trc, ((AsyncFromSync *)c)->next);
|
|
196
|
+
}
|
|
197
|
+
static const JSClass afs_class = { "AsyncFromSyncIterator", sizeof(AsyncFromSync), NULL, NULL, NULL, NULL, afs_visit, NULL, NULL };
|
|
198
|
+
|
|
199
|
+
static JSValue create_async_from_sync(JSContext *ctx, JSValue iterator, JSValue next) {
|
|
200
|
+
JSShape *shape = js_shape_root(ctx, &afs_class, ctx->intrinsics[JS_INTRINSIC_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE], 0);
|
|
201
|
+
AsyncFromSync *a = (AsyncFromSync *)js_alloc_object(ctx, JS_CELL_OBJECT, shape);
|
|
202
|
+
js_init_slot(&a->iterator, iterator);
|
|
203
|
+
js_init_slot(&a->next, next);
|
|
204
|
+
return js_object_value(&a->obj);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* IteratorClose(sync, throw completion): return() runs, its errors are ignored. */
|
|
208
|
+
static void close_sync_quietly(JSContext *ctx, JSValue iterator) {
|
|
209
|
+
JSValue ret = js_get_value(ctx, iterator, JS_ATOM(return));
|
|
210
|
+
if (!js_is_exception(ret) && js_is_callable(ret)) ret = js_call(ctx, ret, iterator, 0, NULL);
|
|
211
|
+
if (js_is_exception(ret)) js_discard(js_take_exception(ctx));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
BUILTIN(unwrap_fulfilled) {
|
|
215
|
+
(void)this_val, (void)new_target;
|
|
216
|
+
return js_iter_result(ctx, ARG(0), js_truthy(data_of(callee)));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
BUILTIN(unwrap_rejected) { /* closes the sync iterator, then rejects with the same reason */
|
|
220
|
+
(void)this_val, (void)new_target;
|
|
221
|
+
close_sync_quietly(ctx, data_of(callee));
|
|
222
|
+
return js_throw(ctx, ARG(0));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/* AsyncFromSyncIteratorContinuation: the result's value is awaited before it is handed on. */
|
|
226
|
+
static JSValue continuation(JSContext *ctx, JSValue result, JSValue promise, JSValue iterator, bool close_on_rejection) {
|
|
227
|
+
JSValue done_value = js_get_value(ctx, result, JS_ATOM(done));
|
|
228
|
+
if (js_is_exception(done_value)) return reject_pending(ctx, promise);
|
|
229
|
+
bool done = js_truthy(done_value);
|
|
230
|
+
JSValue value = js_get_value(ctx, result, JS_ATOM(value));
|
|
231
|
+
if (js_is_exception(value)) return reject_pending(ctx, promise);
|
|
232
|
+
JSValue wrapper = js_promise_resolve(ctx, value);
|
|
233
|
+
if (js_is_exception(wrapper)) {
|
|
234
|
+
if (!done && close_on_rejection) {
|
|
235
|
+
JSValue e = js_take_exception(ctx);
|
|
236
|
+
close_sync_quietly(ctx, iterator);
|
|
237
|
+
js_discard(js_throw(ctx, e));
|
|
238
|
+
}
|
|
239
|
+
return reject_pending(ctx, promise);
|
|
240
|
+
}
|
|
241
|
+
JSValue on_fulfilled = native_with(ctx, unwrap_fulfilled, 1, js_bool(done));
|
|
242
|
+
JSValue on_rejected = done || !close_on_rejection ? JS_UNDEFINED : native_with(ctx, unwrap_rejected, 1, iterator);
|
|
243
|
+
js_promise_then_internal(ctx, wrapper, on_fulfilled, on_rejected, promise);
|
|
244
|
+
return promise;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
static AsyncFromSync *afs_this(JSContext *ctx, JSValue this_val) {
|
|
248
|
+
if (js_is_object(this_val) && js_as_object(this_val)->shape->cls == &afs_class) return (AsyncFromSync *)js_as_object(this_val);
|
|
249
|
+
js_discard(js_throw_type_error(ctx, "not an async-from-sync iterator"));
|
|
250
|
+
return NULL;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* A sync result that must be an object, or a rejection. */
|
|
254
|
+
static bool result_is_object(JSContext *ctx, JSValue result) {
|
|
255
|
+
if (js_is_exception(result)) return false;
|
|
256
|
+
if (js_is_object(result)) return true;
|
|
257
|
+
js_discard(js_throw_type_error(ctx, "Iterator result is not an object"));
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
BUILTIN(afs_next) {
|
|
262
|
+
(void)new_target;
|
|
263
|
+
JSValue promise = js_new_promise(js_as_function(callee)->realm);
|
|
264
|
+
AsyncFromSync *a = afs_this(ctx, this_val);
|
|
265
|
+
if (!a) return reject_pending(ctx, promise);
|
|
266
|
+
JSValue result = js_call(ctx, a->next, a->iterator, argc ? 1 : 0, argv);
|
|
267
|
+
if (!result_is_object(ctx, result)) return reject_pending(ctx, promise);
|
|
268
|
+
return continuation(ctx, result, promise, a->iterator, true);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
BUILTIN(afs_return) {
|
|
272
|
+
(void)new_target;
|
|
273
|
+
JSValue promise = js_new_promise(js_as_function(callee)->realm);
|
|
274
|
+
AsyncFromSync *a = afs_this(ctx, this_val);
|
|
275
|
+
if (!a) return reject_pending(ctx, promise);
|
|
276
|
+
JSValue ret = get_method(ctx, a->iterator, JS_ATOM(return), "The iterator's 'return' method");
|
|
277
|
+
if (js_is_exception(ret)) return reject_pending(ctx, promise);
|
|
278
|
+
if (js_is_undefined(ret)) {
|
|
279
|
+
js_promise_resolve_internal(ctx, promise, js_iter_result(ctx, ARG(0), true));
|
|
280
|
+
return promise;
|
|
281
|
+
}
|
|
282
|
+
JSValue result = js_call(ctx, ret, a->iterator, argc ? 1 : 0, argv);
|
|
283
|
+
if (!result_is_object(ctx, result)) return reject_pending(ctx, promise);
|
|
284
|
+
return continuation(ctx, result, promise, a->iterator, false);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
BUILTIN(afs_throw) {
|
|
288
|
+
(void)new_target;
|
|
289
|
+
JSValue promise = js_new_promise(js_as_function(callee)->realm);
|
|
290
|
+
AsyncFromSync *a = afs_this(ctx, this_val);
|
|
291
|
+
if (!a) return reject_pending(ctx, promise);
|
|
292
|
+
JSValue thr = get_method(ctx, a->iterator, js_atom_from_cstr(ctx, "throw"), "The iterator's 'throw' method");
|
|
293
|
+
if (js_is_exception(thr)) return reject_pending(ctx, promise);
|
|
294
|
+
if (js_is_undefined(thr)) { /* close the sync iterator (normally: its errors win), then a TypeError */
|
|
295
|
+
JSValue ret = get_method(ctx, a->iterator, JS_ATOM(return), "The iterator's 'return' method");
|
|
296
|
+
if (js_is_exception(ret)) return reject_pending(ctx, promise);
|
|
297
|
+
if (!js_is_undefined(ret) && !result_is_object(ctx, js_call(ctx, ret, a->iterator, 0, NULL))) return reject_pending(ctx, promise);
|
|
298
|
+
js_discard(js_throw_type_error(ctx, "The iterator does not provide a 'throw' method"));
|
|
299
|
+
return reject_pending(ctx, promise);
|
|
300
|
+
}
|
|
301
|
+
JSValue value = ARG(0);
|
|
302
|
+
JSValue result = js_call(ctx, thr, a->iterator, 1, &value);
|
|
303
|
+
if (!result_is_object(ctx, result)) return reject_pending(ctx, promise);
|
|
304
|
+
return continuation(ctx, result, promise, a->iterator, true);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* ---- for await and yield*: the async iterator record -------------------------------------- */
|
|
308
|
+
|
|
309
|
+
enum { PHASE_CALL, PHASE_CLOSE, PHASE_RETURN_VALUE }; /* what yield*'s awaited value is */
|
|
310
|
+
enum { AYS_YIELD, AYS_DONE, AYS_RETURN, AYS_AWAIT };
|
|
311
|
+
|
|
312
|
+
typedef struct AsyncIter {
|
|
313
|
+
JSHostCell host;
|
|
314
|
+
JSValue iterator;
|
|
315
|
+
JSValue next;
|
|
316
|
+
int32_t phase;
|
|
317
|
+
int32_t mode;
|
|
318
|
+
int32_t status;
|
|
319
|
+
bool done; /* exhausted, or closed */
|
|
320
|
+
} AsyncIter;
|
|
321
|
+
|
|
322
|
+
static void async_iter_visit(JSCell *c, JSTracer *trc) {
|
|
323
|
+
js_trace_value(trc, ((AsyncIter *)c)->iterator);
|
|
324
|
+
js_trace_value(trc, ((AsyncIter *)c)->next);
|
|
325
|
+
}
|
|
326
|
+
static const JSCellClass async_iter_class = { "AsyncIteratorRecord", async_iter_visit, NULL };
|
|
327
|
+
|
|
328
|
+
static AsyncIter *rec_of(JSValue rec) { return (AsyncIter *)js_as_cell(rec); }
|
|
329
|
+
|
|
330
|
+
/* GetIterator(v, async) (§7.4.3): v[@@asyncIterator](), else v[@@iterator]() wrapped. */
|
|
331
|
+
JSValue js_async_iter_start(JSContext *ctx, JSValue v) {
|
|
332
|
+
if (js_is_nullish(v)) return js_throw_type_error(ctx, "%s is not async iterable", js_is_null(v) ? "null" : "undefined");
|
|
333
|
+
JSValue method = get_method(ctx, v, JS_SYMBOL(asyncIterator), "Symbol.asyncIterator");
|
|
334
|
+
if (js_is_exception(method)) return JS_EXCEPTION;
|
|
335
|
+
JSValue iterator;
|
|
336
|
+
if (js_is_undefined(method)) {
|
|
337
|
+
JSValue sync = get_method(ctx, v, JS_SYMBOL(iterator), "Symbol.iterator");
|
|
338
|
+
if (js_is_exception(sync)) return JS_EXCEPTION;
|
|
339
|
+
if (js_is_undefined(sync)) return js_throw_type_error(ctx, "object is not async iterable");
|
|
340
|
+
JSValue it = js_call(ctx, sync, v, 0, NULL);
|
|
341
|
+
if (js_is_exception(it)) return JS_EXCEPTION;
|
|
342
|
+
if (!js_is_object(it)) return js_throw_type_error(ctx, "Result of the Symbol.iterator method is not an object");
|
|
343
|
+
JSValue next = js_get_value(ctx, it, JS_ATOM(next));
|
|
344
|
+
if (js_is_exception(next)) return JS_EXCEPTION;
|
|
345
|
+
iterator = create_async_from_sync(ctx, it, next);
|
|
346
|
+
} else {
|
|
347
|
+
iterator = js_call(ctx, method, v, 0, NULL);
|
|
348
|
+
if (js_is_exception(iterator)) return JS_EXCEPTION;
|
|
349
|
+
if (!js_is_object(iterator)) return js_throw_type_error(ctx, "Result of the Symbol.asyncIterator method is not an object");
|
|
350
|
+
}
|
|
351
|
+
JSValue next = js_get_value(ctx, iterator, JS_ATOM(next));
|
|
352
|
+
if (js_is_exception(next)) return JS_EXCEPTION;
|
|
353
|
+
AsyncIter *r = (AsyncIter *)js_alloc_host_cell(ctx, &async_iter_class, sizeof(AsyncIter));
|
|
354
|
+
js_init_slot(&r->iterator, iterator);
|
|
355
|
+
js_init_slot(&r->next, next);
|
|
356
|
+
return js_cell(&r->host.cell);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
JSValue js_async_iter_next(JSContext *ctx, JSValue rec) {
|
|
360
|
+
AsyncIter *r = rec_of(rec);
|
|
361
|
+
return js_call(ctx, r->next, r->iterator, 0, NULL);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
JSValue js_async_iter_value(JSContext *ctx, JSValue rec, JSValue result) {
|
|
365
|
+
AsyncIter *r = rec_of(rec);
|
|
366
|
+
if (!js_is_object(result)) return js_throw_type_error(ctx, "Iterator result is not an object");
|
|
367
|
+
JSValue done = js_get_value(ctx, result, JS_ATOM(done));
|
|
368
|
+
if (js_is_exception(done)) return JS_EXCEPTION;
|
|
369
|
+
if (js_truthy(done)) {
|
|
370
|
+
r->done = true;
|
|
371
|
+
return JS_EMPTY;
|
|
372
|
+
}
|
|
373
|
+
return js_get_value(ctx, result, JS_ATOM(value));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* AsyncIteratorClose's call: once only (a failed close isn't retried by the loop's handler). */
|
|
377
|
+
JSValue js_async_iter_return(JSContext *ctx, JSValue rec) {
|
|
378
|
+
AsyncIter *r = rec_of(rec);
|
|
379
|
+
if (r->done) return JS_EMPTY;
|
|
380
|
+
r->done = true;
|
|
381
|
+
JSValue ret = get_method(ctx, r->iterator, JS_ATOM(return), "The iterator's 'return' method");
|
|
382
|
+
if (js_is_exception(ret)) return JS_EXCEPTION;
|
|
383
|
+
if (js_is_undefined(ret)) return JS_EMPTY;
|
|
384
|
+
return js_call(ctx, ret, r->iterator, 0, NULL);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
JSValue js_async_iter_check(JSContext *ctx, JSValue result) {
|
|
388
|
+
if (js_is_object(result)) return JS_UNDEFINED;
|
|
389
|
+
return js_throw_type_error(ctx, "The iterator's 'return' method returned a non-object");
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/* yield* (§15.5.5, async): one step, forwarding how the generator was resumed. */
|
|
393
|
+
JSValue js_async_yield_star_step(JSContext *ctx, JSValue rec, JSValue received, JSValue mode_value) {
|
|
394
|
+
AsyncIter *r = rec_of(rec);
|
|
395
|
+
int mode = js_as_int32(mode_value);
|
|
396
|
+
r->mode = mode;
|
|
397
|
+
r->phase = PHASE_CALL;
|
|
398
|
+
if (mode == JS_RESUME_NEXT) return js_call(ctx, r->next, r->iterator, 1, &received);
|
|
399
|
+
if (mode == JS_RESUME_THROW) {
|
|
400
|
+
JSValue thr = get_method(ctx, r->iterator, js_atom_from_cstr(ctx, "throw"), "The iterator's 'throw' method");
|
|
401
|
+
if (js_is_exception(thr)) return JS_EXCEPTION;
|
|
402
|
+
if (!js_is_undefined(thr)) return js_call(ctx, thr, r->iterator, 1, &received);
|
|
403
|
+
/* no throw(): AsyncIteratorClose (awaiting return()), then a TypeError */
|
|
404
|
+
JSValue ret = get_method(ctx, r->iterator, JS_ATOM(return), "The iterator's 'return' method");
|
|
405
|
+
if (js_is_exception(ret)) return JS_EXCEPTION;
|
|
406
|
+
if (js_is_undefined(ret)) return js_throw_type_error(ctx, "The iterator does not provide a 'throw' method");
|
|
407
|
+
r->phase = PHASE_CLOSE;
|
|
408
|
+
return js_call(ctx, ret, r->iterator, 0, NULL);
|
|
409
|
+
}
|
|
410
|
+
JSValue ret = get_method(ctx, r->iterator, JS_ATOM(return), "The iterator's 'return' method");
|
|
411
|
+
if (js_is_exception(ret)) return JS_EXCEPTION;
|
|
412
|
+
if (js_is_undefined(ret)) { /* this generator returns the (awaited) value itself */
|
|
413
|
+
r->phase = PHASE_RETURN_VALUE;
|
|
414
|
+
return received;
|
|
415
|
+
}
|
|
416
|
+
return js_call(ctx, ret, r->iterator, 1, &received);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
JSValue js_async_yield_star_settled(JSContext *ctx, JSValue rec, JSValue awaited) {
|
|
420
|
+
AsyncIter *r = rec_of(rec);
|
|
421
|
+
if (r->phase == PHASE_RETURN_VALUE) {
|
|
422
|
+
r->status = AYS_RETURN;
|
|
423
|
+
return awaited;
|
|
424
|
+
}
|
|
425
|
+
if (r->phase == PHASE_CLOSE) {
|
|
426
|
+
if (!js_is_object(awaited)) return js_throw_type_error(ctx, "The iterator's 'return' method returned a non-object");
|
|
427
|
+
return js_throw_type_error(ctx, "The iterator does not provide a 'throw' method");
|
|
428
|
+
}
|
|
429
|
+
if (!js_is_object(awaited)) return js_throw_type_error(ctx, "Iterator result is not an object");
|
|
430
|
+
JSValue done = js_get_value(ctx, awaited, JS_ATOM(done));
|
|
431
|
+
if (js_is_exception(done)) return JS_EXCEPTION;
|
|
432
|
+
JSValue value = js_get_value(ctx, awaited, JS_ATOM(value));
|
|
433
|
+
if (js_is_exception(value)) return JS_EXCEPTION;
|
|
434
|
+
if (!js_truthy(done)) r->status = AYS_YIELD;
|
|
435
|
+
else if (r->mode != JS_RESUME_RETURN) r->status = AYS_DONE;
|
|
436
|
+
else { /* the inner iterator finished a return(): await its value, then return it */
|
|
437
|
+
r->phase = PHASE_RETURN_VALUE;
|
|
438
|
+
r->status = AYS_AWAIT;
|
|
439
|
+
}
|
|
440
|
+
return value;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
JSValue js_async_yield_star_status(JSValue rec) { return js_int32(rec_of(rec)->status); }
|
|
444
|
+
|
|
445
|
+
/* ---- Realm (§27.1.3, §27.1.6, §27.4, §27.6) ------------------------------------------------ */
|
|
446
|
+
|
|
447
|
+
BUILTIN(async_iterator_proto_iterator) {
|
|
448
|
+
(void)ctx, (void)callee, (void)argc, (void)argv, (void)new_target;
|
|
449
|
+
return this_val;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
void js_async_iter_realm_init(JSContext *ctx) {
|
|
453
|
+
JSValue *in = ctx->intrinsics;
|
|
454
|
+
const uint8_t wc = JS_PROP_WRITABLE | JS_PROP_CONFIGURABLE;
|
|
455
|
+
/* %AsyncIteratorPrototype%: [Symbol.asyncIterator]() returns this */
|
|
456
|
+
in[JS_INTRINSIC_ASYNC_ITERATOR_PROTOTYPE] = js_new_object_proto(ctx, in[JS_INTRINSIC_OBJECT_PROTOTYPE], 4);
|
|
457
|
+
JSObject *aip = js_as_object(in[JS_INTRINSIC_ASYNC_ITERATOR_PROTOTYPE]);
|
|
458
|
+
JSValue f = js_new_native(ctx, async_iterator_proto_iterator, js_atom_from_cstr(ctx, "[Symbol.asyncIterator]"), 0, JS_FN_STRICT);
|
|
459
|
+
js_define_data(ctx, aip, JS_SYMBOL(asyncIterator), f, wc);
|
|
460
|
+
|
|
461
|
+
in[JS_INTRINSIC_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE] = js_new_object_proto(ctx, in[JS_INTRINSIC_ASYNC_ITERATOR_PROTOTYPE], 4);
|
|
462
|
+
JSObject *afs = js_as_object(in[JS_INTRINSIC_ASYNC_FROM_SYNC_ITERATOR_PROTOTYPE]);
|
|
463
|
+
(void)js_define_method(ctx, afs, "next", afs_next, 1);
|
|
464
|
+
(void)js_define_method(ctx, afs, "return", afs_return, 1);
|
|
465
|
+
(void)js_define_method(ctx, afs, "throw", afs_throw, 1);
|
|
466
|
+
|
|
467
|
+
/* %AsyncGeneratorFunction.prototype% and %AsyncGeneratorPrototype% */
|
|
468
|
+
in[JS_INTRINSIC_ASYNC_GENERATOR_FUNCTION_PROTOTYPE] = js_new_object_proto(ctx, in[JS_INTRINSIC_FUNCTION_PROTOTYPE], 4);
|
|
469
|
+
JSObject *agfp = js_as_object(in[JS_INTRINSIC_ASYNC_GENERATOR_FUNCTION_PROTOTYPE]);
|
|
470
|
+
in[JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE] = js_new_object_proto(ctx, in[JS_INTRINSIC_ASYNC_ITERATOR_PROTOTYPE], 8);
|
|
471
|
+
JSObject *agp = js_as_object(in[JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE]);
|
|
472
|
+
js_define_data(ctx, agfp, JS_ATOM(prototype), in[JS_INTRINSIC_ASYNC_GENERATOR_PROTOTYPE], JS_PROP_CONFIGURABLE);
|
|
473
|
+
js_define_data(ctx, agfp, JS_SYMBOL(toStringTag), js_atom_from_cstr(ctx, "AsyncGeneratorFunction"), JS_PROP_CONFIGURABLE);
|
|
474
|
+
js_define_data(ctx, agp, JS_ATOM(constructor), in[JS_INTRINSIC_ASYNC_GENERATOR_FUNCTION_PROTOTYPE], JS_PROP_CONFIGURABLE);
|
|
475
|
+
(void)js_define_method(ctx, agp, "next", async_generator_next, 1);
|
|
476
|
+
(void)js_define_method(ctx, agp, "return", async_generator_return, 1);
|
|
477
|
+
(void)js_define_method(ctx, agp, "throw", async_generator_throw, 1);
|
|
478
|
+
js_define_data(ctx, agp, JS_SYMBOL(toStringTag), js_atom_from_cstr(ctx, "AsyncGenerator"), JS_PROP_CONFIGURABLE);
|
|
479
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/* Atoms: interned strings, held weakly (ADR 0003). */
|
|
2
|
+
#include "js_atoms.h"
|
|
3
|
+
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
|
|
7
|
+
#include "internal.h"
|
|
8
|
+
#include "jscontext.h"
|
|
9
|
+
|
|
10
|
+
/* The runtime's predefined atoms, generated with precomputed hashes. */
|
|
11
|
+
#define JS_ATOM_DEF(id, len, hash, chars) const js_atom_##id##_t js_atom_##id = JS_STATIC_ATOM_INIT(len, hash, chars);
|
|
12
|
+
#include "js_atoms.gen.h"
|
|
13
|
+
#undef JS_ATOM_DEF
|
|
14
|
+
|
|
15
|
+
static JSStrView view_of(const JSString *s) {
|
|
16
|
+
return (JSStrView){ s->chars.latin1, s->length, (s->cell.flags & JS_STR_LATIN1) != 0 };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static bool same_content(JSStrView a, JSStrView b) {
|
|
20
|
+
if (a.length != b.length) return false;
|
|
21
|
+
if (a.latin1 == b.latin1) return memcmp(a.chars, b.chars, (size_t)a.length * (a.latin1 ? 1 : 2)) == 0;
|
|
22
|
+
for (uint32_t i = 0; i < a.length; i++)
|
|
23
|
+
if (js_view_at(a, i) != js_view_at(b, i)) return false;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* ---- Open-addressing table --------------------------------------------- */
|
|
28
|
+
|
|
29
|
+
static JSString *find(const JSAtomTable *t, JSStrView v, uint32_t hash) {
|
|
30
|
+
size_t mask = t->cap - 1;
|
|
31
|
+
for (size_t i = hash & mask; t->entries[i].str; i = (i + 1) & mask)
|
|
32
|
+
if (t->entries[i].hash == hash && same_content(view_of(t->entries[i].str), v)) return t->entries[i].str;
|
|
33
|
+
return NULL;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static void put(struct JSAtomEntry *entries, size_t cap, JSString *s, uint32_t hash) {
|
|
37
|
+
size_t i = hash & (cap - 1);
|
|
38
|
+
while (entries[i].str) i = (i + 1) & (cap - 1);
|
|
39
|
+
entries[i] = (struct JSAtomEntry){ s, hash };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* Rebuilds the table at `cap`, keeping the entries `keep` accepts. */
|
|
43
|
+
static void rebuild(JSAtomTable *t, size_t cap, bool (*keep)(const JSString *)) {
|
|
44
|
+
struct JSAtomEntry *entries = calloc(cap, sizeof *entries);
|
|
45
|
+
if (!entries) js_fatal("out of memory growing the atom table");
|
|
46
|
+
size_t count = 0;
|
|
47
|
+
for (size_t i = 0; i < t->cap; i++) {
|
|
48
|
+
JSString *s = t->entries[i].str;
|
|
49
|
+
if (s && (!keep || keep(s))) {
|
|
50
|
+
put(entries, cap, s, t->entries[i].hash);
|
|
51
|
+
count++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
free(t->entries);
|
|
55
|
+
t->entries = entries;
|
|
56
|
+
t->cap = cap;
|
|
57
|
+
t->count = count;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static void insert(JSAtomTable *t, JSString *s, uint32_t hash) {
|
|
61
|
+
if (2 * (t->count + 1) > t->cap) rebuild(t, t->cap * 2, NULL); /* load factor <= 1/2 */
|
|
62
|
+
put(t->entries, t->cap, s, hash);
|
|
63
|
+
t->count++;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* ---- Lifecycle --------------------------------------------------------- */
|
|
67
|
+
|
|
68
|
+
void js_register_static_atoms(JSRuntime *rt, const JSString *const *cells, size_t n) {
|
|
69
|
+
for (size_t i = 0; i < n; i++) {
|
|
70
|
+
JSString *s = (JSString *)cells[i];
|
|
71
|
+
if ((s->cell.flags & (JS_CELL_STATIC | JS_STR_ATOM)) != (JS_CELL_STATIC | JS_STR_ATOM))
|
|
72
|
+
js_fatal("js_register_static_atoms: not a static atom");
|
|
73
|
+
uint32_t hash = s->hash ? s->hash : js_hash_view(view_of(s));
|
|
74
|
+
if (find(&rt->atoms, view_of(s), hash)) js_fatal("duplicate static atom (%u units)", s->length);
|
|
75
|
+
insert(&rt->atoms, s, hash);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void js_atoms_init(JSRuntime *rt) {
|
|
80
|
+
rt->atoms.cap = 512;
|
|
81
|
+
rt->atoms.entries = calloc(rt->atoms.cap, sizeof *rt->atoms.entries);
|
|
82
|
+
if (!rt->atoms.entries) js_fatal("out of memory creating the atom table");
|
|
83
|
+
|
|
84
|
+
const JSString *builtin[257];
|
|
85
|
+
builtin[0] = (const JSString *)js_as_cell(js_empty_string());
|
|
86
|
+
for (unsigned u = 0; u < 256; u++) builtin[u + 1] = (const JSString *)js_as_cell(js_char_string((uint8_t)u));
|
|
87
|
+
js_register_static_atoms(rt, builtin, 257);
|
|
88
|
+
|
|
89
|
+
#define JS_ATOM_DEF(id, len, hash, chars) (const JSString *)&js_atom_##id,
|
|
90
|
+
static const JSString *const predefined[] = {
|
|
91
|
+
#include "js_atoms.gen.h"
|
|
92
|
+
};
|
|
93
|
+
#undef JS_ATOM_DEF
|
|
94
|
+
js_register_static_atoms(rt, predefined, sizeof predefined / sizeof predefined[0]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static bool survives(const JSString *s) { return js_gc_is_marked(&s->cell); }
|
|
98
|
+
|
|
99
|
+
/* Drops unmarked atoms and resizes for the survivors: load <= 1/2, shrinking
|
|
100
|
+
* after mass death (dynamic keys), never below 512 entries. */
|
|
101
|
+
void js_atoms_sweep(JSRuntime *rt) {
|
|
102
|
+
JSAtomTable *t = &rt->atoms;
|
|
103
|
+
size_t live = 0;
|
|
104
|
+
for (size_t i = 0; i < t->cap; i++) live += t->entries[i].str && survives(t->entries[i].str);
|
|
105
|
+
size_t cap = 512;
|
|
106
|
+
while (cap < 4 * live) cap *= 2; /* room to grow before the next resize */
|
|
107
|
+
rebuild(t, cap, survives);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void js_atoms_free(JSRuntime *rt) {
|
|
111
|
+
free(rt->atoms.entries);
|
|
112
|
+
rt->atoms.entries = NULL;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
size_t js_atom_count(const JSRuntime *rt) {
|
|
116
|
+
return rt->atoms.count;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* ---- Atomizing --------------------------------------------------------- */
|
|
120
|
+
|
|
121
|
+
JSValue js_atomize(JSContext *ctx, JSValue s) {
|
|
122
|
+
if (js_is_atom(s)) return s;
|
|
123
|
+
JSStrView v = js_string_view(ctx, s); /* flattens a rope */
|
|
124
|
+
uint32_t hash = js_string_hash(ctx, s);
|
|
125
|
+
JSAtomTable *t = &ctx->rt->atoms;
|
|
126
|
+
JSString *found = find(t, v, hash);
|
|
127
|
+
if (found) return js_cell(&found->cell);
|
|
128
|
+
|
|
129
|
+
JSCell *c = js_as_cell(s);
|
|
130
|
+
JSString *flat = c->kind == JS_CELL_STR_ROPE ? (JSString *)js_as_cell(((JSRope *)c)->left) : (JSString *)c;
|
|
131
|
+
if (c->kind == JS_CELL_STR_SLICE || js_cell_is_static(&flat->cell)) {
|
|
132
|
+
/* A slice, or static but not an atom (e.g. an error message): intern a heap copy.
|
|
133
|
+
* Length >= 2 here: "" and single units are atoms already. */
|
|
134
|
+
JSValue copy = js_new_string_view(ctx, v);
|
|
135
|
+
flat = (JSString *)js_as_cell(copy);
|
|
136
|
+
}
|
|
137
|
+
flat->cell.flags |= JS_STR_ATOM; /* immutable content: becoming the atom changes nothing else */
|
|
138
|
+
flat->hash = hash;
|
|
139
|
+
insert(t, flat, hash);
|
|
140
|
+
return js_cell(&flat->cell);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
JSValue js_atom_from_cstr(JSContext *ctx, const char *utf8) {
|
|
144
|
+
/* an ASCII name already interned (the usual case: C code naming properties) is found
|
|
145
|
+
* without making a string */
|
|
146
|
+
size_t n = 0;
|
|
147
|
+
bool ascii = true;
|
|
148
|
+
for (; utf8[n]; n++) ascii &= (uint8_t)utf8[n] < 0x80;
|
|
149
|
+
if (ascii && n <= UINT32_MAX) {
|
|
150
|
+
JSStrView v = js_view_latin1(utf8, (uint32_t)n);
|
|
151
|
+
JSString *found = find(&ctx->rt->atoms, v, js_hash_view(v));
|
|
152
|
+
if (found) return js_cell(&found->cell);
|
|
153
|
+
}
|
|
154
|
+
JSValue s = js_new_string_cstr(ctx, utf8);
|
|
155
|
+
if (js_is_exception(s)) return JS_EXCEPTION;
|
|
156
|
+
return js_atomize(ctx, s);
|
|
157
|
+
}
|