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,28 @@
|
|
|
1
|
+
/* Every component (ADR 0014): the test host installs them all. Programs name only the ones
|
|
2
|
+
* they reach, so nothing in a program's binary references this list. */
|
|
3
|
+
#include "js_builtins.h"
|
|
4
|
+
|
|
5
|
+
const JSComponent *const js_all_components[] = {
|
|
6
|
+
&js_component_math,
|
|
7
|
+
&js_component_json,
|
|
8
|
+
&js_component_collections,
|
|
9
|
+
&js_component_reflect,
|
|
10
|
+
&js_component_proxy,
|
|
11
|
+
&js_component_bigint,
|
|
12
|
+
&js_component_arraybuffer,
|
|
13
|
+
&js_component_typedarray,
|
|
14
|
+
&js_component_date,
|
|
15
|
+
&js_component_regexp,
|
|
16
|
+
&js_component_domexception,
|
|
17
|
+
&js_component_encoding,
|
|
18
|
+
&js_component_base64,
|
|
19
|
+
&js_component_url,
|
|
20
|
+
&js_component_events,
|
|
21
|
+
&js_component_buffer,
|
|
22
|
+
&js_component_crypto,
|
|
23
|
+
&js_component_headers,
|
|
24
|
+
&js_component_streams,
|
|
25
|
+
&js_component_blob,
|
|
26
|
+
&js_component_fetch,
|
|
27
|
+
};
|
|
28
|
+
const size_t js_all_components_count = JS_COUNTOF(js_all_components);
|
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
/* The global console (ADR 0012), natively: Node's methods and output, formatted by
|
|
2
|
+
* inspect.c. Also the test host's print and the uncaught-error report. */
|
|
3
|
+
#include "js_console.h"
|
|
4
|
+
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
|
|
9
|
+
#include "internal.h"
|
|
10
|
+
#include "js_atoms.h"
|
|
11
|
+
#include "js_convert.h"
|
|
12
|
+
#include "js_error.h"
|
|
13
|
+
#include "js_exception.h"
|
|
14
|
+
#include "js_host.h"
|
|
15
|
+
#include "js_ops.h"
|
|
16
|
+
#include "js_symbol.h"
|
|
17
|
+
#include "jsnum.h"
|
|
18
|
+
#include "jsstring.h"
|
|
19
|
+
#include "os.h"
|
|
20
|
+
|
|
21
|
+
#define NATIVE(name) static JSValue name(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, \
|
|
22
|
+
const JSValue *argv, JSValue new_target)
|
|
23
|
+
#define UNUSED_ARGS (void)callee, (void)this_val, (void)new_target
|
|
24
|
+
#define ARG(i) ((i) < argc ? argv[i] : JS_UNDEFINED)
|
|
25
|
+
|
|
26
|
+
/* ---- Output -------------------------------------------------------------------- */
|
|
27
|
+
|
|
28
|
+
/* A string as UTF-8, lone surrogates as U+FFFD; *out is malloc'd unless it is `small`. */
|
|
29
|
+
static size_t utf8_of(JSContext *ctx, JSValue s, char *small, size_t cap, char **out) {
|
|
30
|
+
JSStrView v = js_string_view(ctx, s);
|
|
31
|
+
size_t n = js_view_to_utf8(v, small, cap);
|
|
32
|
+
*out = small;
|
|
33
|
+
if (n > cap) {
|
|
34
|
+
*out = malloc(n);
|
|
35
|
+
if (!*out) js_fatal("out of memory writing output");
|
|
36
|
+
js_view_to_utf8(v, *out, n);
|
|
37
|
+
}
|
|
38
|
+
return n;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static FILE *stream(int fd) {
|
|
42
|
+
if (fd == 2) {
|
|
43
|
+
fflush(stdout);
|
|
44
|
+
return stderr;
|
|
45
|
+
}
|
|
46
|
+
return stdout;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void js_write_output(JSContext *ctx, int fd, JSValue s) {
|
|
50
|
+
char small[1024], *buf;
|
|
51
|
+
size_t n = utf8_of(ctx, s, small, sizeof small, &buf);
|
|
52
|
+
fwrite(buf, 1, n, stream(fd));
|
|
53
|
+
if (buf != small) free(buf);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* console.group's indentation, in spaces */
|
|
57
|
+
static size_t group_indent;
|
|
58
|
+
|
|
59
|
+
/* One line of console output: every line indented by the groups, then a newline. stdio
|
|
60
|
+
* buffers it (fully when redirected, by line on a terminal) and flushes at exit and before the
|
|
61
|
+
* event loop waits (js_run_event_loop). */
|
|
62
|
+
static void emit(int fd, const char *s, size_t n) {
|
|
63
|
+
FILE *out = stream(fd);
|
|
64
|
+
size_t start = 0;
|
|
65
|
+
for (size_t i = 0; i <= n; i++) {
|
|
66
|
+
if (i < n && s[i] != '\n') continue;
|
|
67
|
+
for (size_t k = 0; k < group_indent; k++) fputc(' ', out);
|
|
68
|
+
fwrite(s + start, 1, i - start + (i < n), out);
|
|
69
|
+
start = i + 1;
|
|
70
|
+
}
|
|
71
|
+
fputc('\n', out);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static void emit_string(JSContext *ctx, int fd, JSValue s) {
|
|
75
|
+
char small[1024], *buf;
|
|
76
|
+
size_t n = utf8_of(ctx, s, small, sizeof small, &buf);
|
|
77
|
+
emit(fd, buf, n);
|
|
78
|
+
if (buf != small) free(buf);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* console.log's line: util.format of the arguments. */
|
|
82
|
+
static JSValue print_args(JSContext *ctx, int fd, uint32_t argc, const JSValue *argv) {
|
|
83
|
+
JSValue s = js_format(ctx, argc, argv);
|
|
84
|
+
if (js_is_exception(s)) return s;
|
|
85
|
+
emit_string(ctx, fd, s);
|
|
86
|
+
return JS_UNDEFINED;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ---- console's methods ---------------------------------------------------------------- */
|
|
90
|
+
|
|
91
|
+
NATIVE(console_log) {
|
|
92
|
+
UNUSED_ARGS;
|
|
93
|
+
return print_args(ctx, 1, argc, argv);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
NATIVE(console_error) {
|
|
97
|
+
UNUSED_ARGS;
|
|
98
|
+
return print_args(ctx, 2, argc, argv);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
NATIVE(console_dir) {
|
|
102
|
+
UNUSED_ARGS;
|
|
103
|
+
JSInspectOptions o = js_inspect_defaults;
|
|
104
|
+
o.custom_inspect = false;
|
|
105
|
+
if (js_inspect_options_from(ctx, ARG(1), &o) < 0) return JS_EXCEPTION;
|
|
106
|
+
JSValue s = js_inspect_with(ctx, ARG(0), &o);
|
|
107
|
+
if (js_is_exception(s)) return s;
|
|
108
|
+
emit_string(ctx, 1, s);
|
|
109
|
+
return JS_UNDEFINED;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
NATIVE(console_assert) {
|
|
113
|
+
UNUSED_ARGS;
|
|
114
|
+
if (js_truthy(ARG(0))) return JS_UNDEFINED;
|
|
115
|
+
uint32_t n = argc > 1 ? argc - 1 : 0;
|
|
116
|
+
JSValue *args = malloc((n + 1) * sizeof *args);
|
|
117
|
+
if (!args) js_fatal("out of memory");
|
|
118
|
+
JSValue failed = js_new_string_cstr(ctx, "Assertion failed");
|
|
119
|
+
JSValue r = failed;
|
|
120
|
+
if (!js_is_exception(failed)) {
|
|
121
|
+
if (n && js_is_string(argv[1])) {
|
|
122
|
+
/* "Assertion failed: " + the message, which can hold format specifiers */
|
|
123
|
+
JSValue colon = js_new_string_cstr(ctx, "Assertion failed: ");
|
|
124
|
+
args[0] = js_is_exception(colon) ? colon : js_concat(ctx, colon, argv[1]);
|
|
125
|
+
for (uint32_t i = 1; i < n; i++) args[i] = argv[i + 1];
|
|
126
|
+
} else {
|
|
127
|
+
args[0] = failed;
|
|
128
|
+
for (uint32_t i = 0; i < n; i++) args[i + 1] = argv[i + 1];
|
|
129
|
+
n++;
|
|
130
|
+
}
|
|
131
|
+
JSValue first = args[0];
|
|
132
|
+
r = js_is_exception(first) ? first : print_args(ctx, 2, n ? n : 1, args);
|
|
133
|
+
js_keep_alive(first); /* args is malloc'd: the scan doesn't see it */
|
|
134
|
+
}
|
|
135
|
+
free(args);
|
|
136
|
+
return r;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* A key in console's state for `label`: "count:" or "time:" and the label. */
|
|
140
|
+
static JSValue state_key(JSContext *ctx, const char *kind, JSValue label) {
|
|
141
|
+
JSValue l = js_is_undefined(label) ? js_new_string_cstr(ctx, "default") : js_to_string(ctx, label);
|
|
142
|
+
if (js_is_exception(l)) return l;
|
|
143
|
+
JSValue prefix = js_new_string_cstr(ctx, kind);
|
|
144
|
+
if (js_is_exception(prefix)) return prefix;
|
|
145
|
+
JSValue k = js_concat(ctx, prefix, l);
|
|
146
|
+
return js_is_exception(k) ? k : js_to_property_key(ctx, k);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static JSObject *state(JSContext *ctx) {
|
|
150
|
+
JSValue *slot = &ctx->intrinsics[JS_INTRINSIC_CONSOLE_STATE];
|
|
151
|
+
if (!js_is_object(*slot)) *slot = js_new_object_proto(ctx, JS_NULL, JS_DEFAULT_INLINE_SLOTS);
|
|
152
|
+
return js_as_object(*slot);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* The label as console prints it: String(label), "default" when absent. */
|
|
156
|
+
static JSValue label_string(JSContext *ctx, JSValue label) {
|
|
157
|
+
return js_is_undefined(label) ? js_new_string_cstr(ctx, "default") : js_to_string(ctx, label);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
NATIVE(console_count) {
|
|
161
|
+
UNUSED_ARGS;
|
|
162
|
+
JSValue key = state_key(ctx, "count:", ARG(0));
|
|
163
|
+
JSValue label = label_string(ctx, ARG(0));
|
|
164
|
+
if (js_is_exception(key) || js_is_exception(label)) return JS_EXCEPTION;
|
|
165
|
+
JSObject *st = state(ctx);
|
|
166
|
+
JSValue n = js_get(ctx, st, key, js_object_value(st));
|
|
167
|
+
if (js_is_exception(n)) return n;
|
|
168
|
+
int32_t count = js_is_int32(n) ? js_as_int32(n) + 1 : 1;
|
|
169
|
+
js_define_data(ctx, st, key, js_int32(count), JS_PROP_DEFAULT);
|
|
170
|
+
char suffix[24];
|
|
171
|
+
snprintf(suffix, sizeof suffix, ": %d", count);
|
|
172
|
+
JSValue s = js_new_string_cstr(ctx, suffix);
|
|
173
|
+
if (js_is_exception(s)) return s;
|
|
174
|
+
s = js_concat(ctx, label, s);
|
|
175
|
+
if (js_is_exception(s)) return s;
|
|
176
|
+
emit_string(ctx, 1, s);
|
|
177
|
+
return JS_UNDEFINED;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
NATIVE(console_count_reset) {
|
|
181
|
+
UNUSED_ARGS;
|
|
182
|
+
JSValue key = state_key(ctx, "count:", ARG(0));
|
|
183
|
+
if (js_is_exception(key)) return key;
|
|
184
|
+
JSObject *st = state(ctx);
|
|
185
|
+
JSValue n = js_get(ctx, st, key, js_object_value(st));
|
|
186
|
+
if (js_is_exception(n)) return n;
|
|
187
|
+
if (js_is_int32(n)) js_define_data(ctx, st, key, js_int32(0), JS_PROP_DEFAULT);
|
|
188
|
+
return JS_UNDEFINED;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
NATIVE(console_group) {
|
|
192
|
+
UNUSED_ARGS;
|
|
193
|
+
if (argc) {
|
|
194
|
+
JSValue r = print_args(ctx, 1, argc, argv);
|
|
195
|
+
if (js_is_exception(r)) return r;
|
|
196
|
+
}
|
|
197
|
+
group_indent += 2;
|
|
198
|
+
return JS_UNDEFINED;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
NATIVE(console_group_end) {
|
|
202
|
+
(void)ctx, (void)argc, (void)argv;
|
|
203
|
+
UNUSED_ARGS;
|
|
204
|
+
group_indent = group_indent >= 2 ? group_indent - 2 : 0;
|
|
205
|
+
return JS_UNDEFINED;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/* Node's formatTime: "12.345ms", "1.500s", "1:02.003 (m:ss.mmm)". */
|
|
209
|
+
static void format_time(char *out, size_t cap, double ms) {
|
|
210
|
+
double hours = 0, minutes = 0, seconds = 0;
|
|
211
|
+
if (ms >= 1000) {
|
|
212
|
+
if (ms >= 60000) {
|
|
213
|
+
if (ms >= 3600000) {
|
|
214
|
+
hours = floor(ms / 3600000);
|
|
215
|
+
ms = fmod(ms, 3600000);
|
|
216
|
+
}
|
|
217
|
+
minutes = floor(ms / 60000);
|
|
218
|
+
ms = fmod(ms, 60000);
|
|
219
|
+
}
|
|
220
|
+
seconds = ms / 1000;
|
|
221
|
+
}
|
|
222
|
+
if (hours != 0 || minutes != 0) {
|
|
223
|
+
char sec[32];
|
|
224
|
+
snprintf(sec, sizeof sec, "%06.3f", seconds); /* ss.mmm */
|
|
225
|
+
if (hours != 0) snprintf(out, cap, "%.0f:%02.0f:%s (h:mm:ss.mmm)", hours, minutes, sec);
|
|
226
|
+
else snprintf(out, cap, "%.0f:%s (m:ss.mmm)", minutes, sec);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (seconds != 0) {
|
|
230
|
+
snprintf(out, cap, "%.3fs", seconds);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
/* Number(ms.toFixed(3)): no trailing zeros */
|
|
234
|
+
char fixed[48];
|
|
235
|
+
snprintf(fixed, sizeof fixed, "%.3f", ms);
|
|
236
|
+
char num[JS_NUM_BUF_SIZE];
|
|
237
|
+
js_num_to_cstr(num, strtod(fixed, NULL));
|
|
238
|
+
snprintf(out, cap, "%.*sms", (int)(cap > 3 ? cap - 3 : 0), num);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/* "label: 1.234ms", then any data (console.timeLog), on stdout. */
|
|
242
|
+
static JSValue print_time(JSContext *ctx, JSValue label, double start, uint32_t extra, const JSValue *data) {
|
|
243
|
+
char t[96];
|
|
244
|
+
format_time(t, sizeof t, js_os_now_ms_precise() - start);
|
|
245
|
+
JSValue *args = malloc((3 + extra) * sizeof *args);
|
|
246
|
+
if (!args) js_fatal("out of memory");
|
|
247
|
+
args[0] = js_new_string_cstr(ctx, "%s: %s");
|
|
248
|
+
args[1] = label;
|
|
249
|
+
args[2] = js_new_string_cstr(ctx, t);
|
|
250
|
+
for (uint32_t i = 0; i < extra; i++) args[3 + i] = data[i];
|
|
251
|
+
JSValue fmt = args[0], elapsed = args[2];
|
|
252
|
+
JSValue r = js_is_exception(fmt) || js_is_exception(elapsed) ? JS_EXCEPTION : print_args(ctx, 1, 3 + extra, args);
|
|
253
|
+
js_keep_alive(fmt); /* args is malloc'd: the scan doesn't see it */
|
|
254
|
+
js_keep_alive(elapsed);
|
|
255
|
+
js_keep_alive(label);
|
|
256
|
+
free(args);
|
|
257
|
+
return r;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* The timer's start, or a warning (Node's process.emitWarning) and -1. */
|
|
261
|
+
static int timer_start(JSContext *ctx, JSValue label_arg, const char *method, JSValue *key, JSValue *label, double *start) {
|
|
262
|
+
*key = state_key(ctx, "time:", label_arg);
|
|
263
|
+
*label = label_string(ctx, label_arg);
|
|
264
|
+
if (js_is_exception(*key) || js_is_exception(*label)) return -2;
|
|
265
|
+
JSObject *st = state(ctx);
|
|
266
|
+
JSValue v = js_get(ctx, st, *key, js_object_value(st));
|
|
267
|
+
if (js_is_exception(v)) return -2;
|
|
268
|
+
if (!js_is_number(v)) {
|
|
269
|
+
char prefix[64];
|
|
270
|
+
snprintf(prefix, sizeof prefix, "No such label '");
|
|
271
|
+
JSValue a = js_new_string_cstr(ctx, prefix);
|
|
272
|
+
JSValue b = js_new_string_cstr(ctx, method);
|
|
273
|
+
if (js_is_exception(a) || js_is_exception(b)) return -2;
|
|
274
|
+
JSValue m = js_concat(ctx, a, *label);
|
|
275
|
+
if (js_is_exception(m)) return -2;
|
|
276
|
+
m = js_concat(ctx, m, b);
|
|
277
|
+
if (js_is_exception(m)) return -2;
|
|
278
|
+
js_emit_warning(ctx, m, "Warning", NULL);
|
|
279
|
+
return -1;
|
|
280
|
+
}
|
|
281
|
+
*start = js_as_number(v);
|
|
282
|
+
return 0;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
NATIVE(console_time) {
|
|
286
|
+
UNUSED_ARGS;
|
|
287
|
+
JSValue key = state_key(ctx, "time:", ARG(0));
|
|
288
|
+
JSValue label = label_string(ctx, ARG(0));
|
|
289
|
+
if (js_is_exception(key) || js_is_exception(label)) return JS_EXCEPTION;
|
|
290
|
+
JSObject *st = state(ctx);
|
|
291
|
+
JSValue v = js_get(ctx, st, key, js_object_value(st));
|
|
292
|
+
if (js_is_exception(v)) return v;
|
|
293
|
+
if (js_is_number(v)) {
|
|
294
|
+
JSValue a = js_new_string_cstr(ctx, "Label '");
|
|
295
|
+
JSValue b = js_new_string_cstr(ctx, "' already exists for console.time()");
|
|
296
|
+
if (js_is_exception(a) || js_is_exception(b)) return JS_EXCEPTION;
|
|
297
|
+
JSValue m = js_concat(ctx, a, label);
|
|
298
|
+
if (!js_is_exception(m)) m = js_concat(ctx, m, b);
|
|
299
|
+
if (js_is_exception(m)) return m;
|
|
300
|
+
js_emit_warning(ctx, m, "Warning", NULL);
|
|
301
|
+
return JS_UNDEFINED;
|
|
302
|
+
}
|
|
303
|
+
js_define_data(ctx, st, key, js_number(js_os_now_ms_precise()), JS_PROP_DEFAULT);
|
|
304
|
+
return JS_UNDEFINED;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
NATIVE(console_time_log) {
|
|
308
|
+
UNUSED_ARGS;
|
|
309
|
+
JSValue key, label;
|
|
310
|
+
double start;
|
|
311
|
+
int r = timer_start(ctx, ARG(0), "' for console.timeLog()", &key, &label, &start);
|
|
312
|
+
if (r == -2) return JS_EXCEPTION;
|
|
313
|
+
if (r == -1) return JS_UNDEFINED;
|
|
314
|
+
return print_time(ctx, label, start, argc > 1 ? argc - 1 : 0, argv + 1);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
NATIVE(console_time_end) {
|
|
318
|
+
UNUSED_ARGS;
|
|
319
|
+
JSValue key, label;
|
|
320
|
+
double start;
|
|
321
|
+
int r = timer_start(ctx, ARG(0), "' for console.timeEnd()", &key, &label, &start);
|
|
322
|
+
if (r == -2) return JS_EXCEPTION;
|
|
323
|
+
if (r == -1) return JS_UNDEFINED;
|
|
324
|
+
JSValue printed = print_time(ctx, label, start, 0, NULL);
|
|
325
|
+
if (js_is_exception(printed)) return printed;
|
|
326
|
+
if (js_delete_property(ctx, state(ctx), key, false) < 0) return JS_EXCEPTION;
|
|
327
|
+
return JS_UNDEFINED;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/* Node adds the stack's frames, which visaljs doesn't record (plan/unsupported.md). */
|
|
331
|
+
NATIVE(console_trace) {
|
|
332
|
+
UNUSED_ARGS;
|
|
333
|
+
JSValue message = js_format(ctx, argc, argv);
|
|
334
|
+
if (js_is_exception(message)) return message;
|
|
335
|
+
JSValue trace = js_new_string_cstr(ctx, js_string_length(message) ? "Trace: " : "Trace");
|
|
336
|
+
if (js_is_exception(trace)) return trace;
|
|
337
|
+
JSValue s = js_concat(ctx, trace, message);
|
|
338
|
+
if (js_is_exception(s)) return s;
|
|
339
|
+
emit_string(ctx, 2, s);
|
|
340
|
+
return JS_UNDEFINED;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* ---- console.table (Node's internal/cli_table.js) --------------------------------------------- */
|
|
344
|
+
|
|
345
|
+
/* The table's strings live in malloc'd arrays: `keep`, a JS array on the stack, holds them
|
|
346
|
+
* for the scan. */
|
|
347
|
+
static JSValue kept(JSContext *ctx, JSValue keep, JSValue v) {
|
|
348
|
+
if (!js_is_exception(v) && js_is_cell(v) && js_array_push(ctx, js_as_object(keep), v) < 0) return JS_EXCEPTION;
|
|
349
|
+
return v;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/* A cell: inspected with depth 0 (-1 for objects of more than two keys), three array items. */
|
|
353
|
+
static JSValue table_cell(JSContext *ctx, JSValue keep, JSValue v) {
|
|
354
|
+
JSInspectOptions o = js_inspect_defaults;
|
|
355
|
+
o.depth = 0;
|
|
356
|
+
if (js_is_object(v) && !js_is_array(v)) {
|
|
357
|
+
JSValue keys = js_own_keys(ctx, js_as_object(v));
|
|
358
|
+
if (js_is_exception(keys)) return keys;
|
|
359
|
+
uint32_t enumerable = 0;
|
|
360
|
+
JSValueArray *list = (JSValueArray *)js_as_cell(keys);
|
|
361
|
+
for (uint32_t i = 0; i < list->cell.aux; i++) {
|
|
362
|
+
JSPropertyDescriptor d;
|
|
363
|
+
if (js_is_symbol(list->values[i])) continue;
|
|
364
|
+
int has = js_get_own_property(ctx, js_as_object(v), list->values[i], &d);
|
|
365
|
+
if (has < 0) return JS_EXCEPTION;
|
|
366
|
+
enumerable += has && (d.attrs & JS_PROP_ENUMERABLE);
|
|
367
|
+
}
|
|
368
|
+
if (enumerable > 2) o.depth = -1;
|
|
369
|
+
}
|
|
370
|
+
o.max_array_length = 3;
|
|
371
|
+
o.break_length = INFINITY;
|
|
372
|
+
return kept(ctx, keep, js_inspect_with(ctx, v, &o));
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
static void put_utf8(char **buf, size_t *len, size_t *cap, const char *s, size_t n) {
|
|
376
|
+
if (*len + n + 1 > *cap) {
|
|
377
|
+
while (*len + n + 1 > *cap) *cap = *cap ? *cap * 2 : 1024;
|
|
378
|
+
char *grown = realloc(*buf, *cap);
|
|
379
|
+
if (!grown) js_fatal("out of memory");
|
|
380
|
+
*buf = grown;
|
|
381
|
+
}
|
|
382
|
+
memcpy(*buf + *len, s, n);
|
|
383
|
+
*len += n;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
#define PUT(s) put_utf8(&out, &len, &cap, (s), strlen(s))
|
|
387
|
+
|
|
388
|
+
static void put_cell(JSContext *ctx, char **out, size_t *len, size_t *cap, JSValue s, uint32_t width) {
|
|
389
|
+
char small[256], *buf;
|
|
390
|
+
size_t n = utf8_of(ctx, s, small, sizeof small, &buf);
|
|
391
|
+
put_utf8(out, len, cap, buf, n);
|
|
392
|
+
if (buf != small) free(buf);
|
|
393
|
+
for (uint32_t i = js_string_length(s); i < width; i++) put_utf8(out, len, cap, " ", 1);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/* head: the column names; columns[c][r]: a cell (undefined: empty). */
|
|
397
|
+
static void render_table(JSContext *ctx, JSValue *head, uint32_t ncols, JSValue **columns, uint32_t *lengths) {
|
|
398
|
+
uint32_t nrows = 0;
|
|
399
|
+
for (uint32_t c = 0; c < ncols; c++) if (lengths[c] > nrows) nrows = lengths[c];
|
|
400
|
+
uint32_t *widths = calloc(ncols ? ncols : 1, sizeof *widths);
|
|
401
|
+
if (!widths) js_fatal("out of memory");
|
|
402
|
+
for (uint32_t c = 0; c < ncols; c++) {
|
|
403
|
+
widths[c] = js_string_length(head[c]);
|
|
404
|
+
for (uint32_t r = 0; r < lengths[c]; r++)
|
|
405
|
+
if (js_is_string(columns[c][r]) && js_string_length(columns[c][r]) > widths[c]) widths[c] = js_string_length(columns[c][r]);
|
|
406
|
+
}
|
|
407
|
+
char *out = NULL;
|
|
408
|
+
size_t len = 0, cap = 0;
|
|
409
|
+
JSValue empty = js_empty_string();
|
|
410
|
+
for (int line = 0; line < 3; line++) { /* top, below the head, bottom */
|
|
411
|
+
static const char *const ends[3][3] = { { "┌", "┬", "┐" }, { "├", "┼", "┤" }, { "└", "┴", "┘" } };
|
|
412
|
+
if (line == 2) {
|
|
413
|
+
for (uint32_t r = 0; r < nrows; r++) {
|
|
414
|
+
PUT("│ ");
|
|
415
|
+
for (uint32_t c = 0; c < ncols; c++) {
|
|
416
|
+
JSValue cell = r < lengths[c] && js_is_string(columns[c][r]) ? columns[c][r] : empty;
|
|
417
|
+
put_cell(ctx, &out, &len, &cap, cell, widths[c]);
|
|
418
|
+
PUT(c + 1 < ncols ? " │ " : " │\n");
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
PUT(ends[line][0]);
|
|
423
|
+
for (uint32_t c = 0; c < ncols; c++) {
|
|
424
|
+
for (uint32_t k = 0; k < widths[c] + 2; k++) PUT("─");
|
|
425
|
+
PUT(c + 1 < ncols ? ends[line][1] : ends[line][2]);
|
|
426
|
+
}
|
|
427
|
+
if (line < 2) PUT("\n");
|
|
428
|
+
if (line == 0) {
|
|
429
|
+
PUT("│ ");
|
|
430
|
+
for (uint32_t c = 0; c < ncols; c++) {
|
|
431
|
+
put_cell(ctx, &out, &len, &cap, head[c], widths[c]);
|
|
432
|
+
PUT(c + 1 < ncols ? " │ " : " │\n");
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
emit(1, out, len);
|
|
437
|
+
free(out);
|
|
438
|
+
free(widths);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
NATIVE(console_table) {
|
|
442
|
+
UNUSED_ARGS;
|
|
443
|
+
JSValue data = ARG(0), properties = ARG(1);
|
|
444
|
+
if (!js_is_object(data)) return print_args(ctx, 1, 1, &data);
|
|
445
|
+
JSValue keep = js_new_array(ctx, 0);
|
|
446
|
+
if (js_is_exception(keep)) return keep;
|
|
447
|
+
JSValue index_keys = js_own_keys(ctx, js_as_object(data));
|
|
448
|
+
if (js_is_exception(index_keys)) return index_keys;
|
|
449
|
+
JSValueArray *ik = (JSValueArray *)js_as_cell(index_keys);
|
|
450
|
+
/* the rows: Object.keys(data) */
|
|
451
|
+
uint32_t nrows = 0;
|
|
452
|
+
JSValue *rows = malloc((ik->cell.aux + 1) * sizeof *rows);
|
|
453
|
+
if (!rows) js_fatal("out of memory");
|
|
454
|
+
for (uint32_t i = 0; i < ik->cell.aux; i++) {
|
|
455
|
+
JSPropertyDescriptor d;
|
|
456
|
+
if (js_is_symbol(ik->values[i])) continue;
|
|
457
|
+
int has = js_get_own_property(ctx, js_as_object(data), ik->values[i], &d);
|
|
458
|
+
if (has < 0) goto fail_rows;
|
|
459
|
+
if (has && (d.attrs & JS_PROP_ENUMERABLE)) rows[nrows++] = ik->values[i];
|
|
460
|
+
}
|
|
461
|
+
{
|
|
462
|
+
/* columns: (index), each property in first-seen order, then Values */
|
|
463
|
+
uint32_t cap = 8, ncols = 1;
|
|
464
|
+
JSValue *head = malloc(cap * sizeof *head);
|
|
465
|
+
JSValue **columns = malloc(cap * sizeof *columns);
|
|
466
|
+
uint32_t *lengths = calloc(cap, sizeof *lengths);
|
|
467
|
+
JSValue *values = calloc(nrows + 1, sizeof *values);
|
|
468
|
+
bool has_values = false;
|
|
469
|
+
JSValue result = JS_UNDEFINED;
|
|
470
|
+
if (!head || !columns || !lengths || !values) js_fatal("out of memory");
|
|
471
|
+
head[0] = kept(ctx, keep, js_new_string_cstr(ctx, "(index)"));
|
|
472
|
+
columns[0] = malloc((nrows + 1) * sizeof **columns);
|
|
473
|
+
if (!columns[0]) js_fatal("out of memory");
|
|
474
|
+
for (uint32_t r = 0; r < nrows; r++) {
|
|
475
|
+
columns[0][r] = js_is_number(rows[r]) ? kept(ctx, keep, js_number_to_string(ctx, rows[r])) : rows[r];
|
|
476
|
+
values[r] = JS_UNDEFINED;
|
|
477
|
+
}
|
|
478
|
+
lengths[0] = nrows;
|
|
479
|
+
for (uint32_t r = 0; r < nrows && !js_is_exception(result); r++) {
|
|
480
|
+
JSValue item = kept(ctx, keep, js_get_value(ctx, data, rows[r]));
|
|
481
|
+
if (js_is_exception(item)) {
|
|
482
|
+
result = item;
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
bool primitive = !js_is_object(item);
|
|
486
|
+
if (js_is_undefined(properties) && primitive) {
|
|
487
|
+
has_values = true;
|
|
488
|
+
values[r] = table_cell(ctx, keep, item);
|
|
489
|
+
if (js_is_exception(values[r])) result = values[r];
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
JSValue keys = js_is_undefined(properties) ? kept(ctx, keep, js_own_keys(ctx, js_as_object(item))) : JS_UNDEFINED;
|
|
493
|
+
if (js_is_exception(keys)) {
|
|
494
|
+
result = keys;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
uint32_t nkeys = js_is_undefined(properties) ? ((JSValueArray *)js_as_cell(keys))->cell.aux
|
|
498
|
+
: (js_is_array(properties) ? js_array_length(js_as_object(properties)) : 0);
|
|
499
|
+
for (uint32_t k = 0; k < nkeys; k++) {
|
|
500
|
+
JSValue key;
|
|
501
|
+
if (js_is_undefined(properties)) {
|
|
502
|
+
key = ((JSValueArray *)js_as_cell(keys))->values[k];
|
|
503
|
+
JSPropertyDescriptor d;
|
|
504
|
+
if (js_is_symbol(key)) continue;
|
|
505
|
+
int has = js_get_own_property(ctx, js_as_object(item), key, &d);
|
|
506
|
+
if (has < 0) { result = JS_EXCEPTION; break; }
|
|
507
|
+
if (!has || !(d.attrs & JS_PROP_ENUMERABLE)) continue;
|
|
508
|
+
} else {
|
|
509
|
+
key = js_get_elem(ctx, properties, js_index_key(k));
|
|
510
|
+
if (!js_is_exception(key)) key = kept(ctx, keep, js_to_property_key(ctx, key));
|
|
511
|
+
if (js_is_exception(key)) { result = key; break; }
|
|
512
|
+
}
|
|
513
|
+
JSValue name = kept(ctx, keep, js_is_number(key) ? js_number_to_string(ctx, key) : js_is_string(key) ? key : js_to_string(ctx, key));
|
|
514
|
+
if (js_is_exception(name)) { result = name; break; }
|
|
515
|
+
uint32_t c = 1;
|
|
516
|
+
while (c < ncols && !js_string_equals(ctx, head[c], name)) c++;
|
|
517
|
+
if (c == ncols) {
|
|
518
|
+
if (ncols == cap) {
|
|
519
|
+
cap *= 2;
|
|
520
|
+
head = realloc(head, cap * sizeof *head);
|
|
521
|
+
columns = realloc(columns, cap * sizeof *columns);
|
|
522
|
+
lengths = realloc(lengths, cap * sizeof *lengths);
|
|
523
|
+
if (!head || !columns || !lengths) js_fatal("out of memory");
|
|
524
|
+
}
|
|
525
|
+
head[ncols] = name;
|
|
526
|
+
columns[ncols] = malloc((nrows + 1) * sizeof **columns);
|
|
527
|
+
if (!columns[ncols]) js_fatal("out of memory");
|
|
528
|
+
for (uint32_t i = 0; i < nrows; i++) columns[ncols][i] = JS_UNDEFINED;
|
|
529
|
+
lengths[ncols] = 0;
|
|
530
|
+
ncols++;
|
|
531
|
+
}
|
|
532
|
+
JSValue cell = js_empty_string();
|
|
533
|
+
JSPropertyDescriptor d;
|
|
534
|
+
int has = primitive ? 0 : js_get_own_property(ctx, js_as_object(item), key, &d);
|
|
535
|
+
if (has < 0) { result = JS_EXCEPTION; break; }
|
|
536
|
+
if (has) {
|
|
537
|
+
JSValue v = kept(ctx, keep, js_get_value(ctx, item, key));
|
|
538
|
+
cell = js_is_exception(v) ? v : table_cell(ctx, keep, v);
|
|
539
|
+
if (js_is_exception(cell)) { result = cell; break; }
|
|
540
|
+
}
|
|
541
|
+
columns[c][r] = cell;
|
|
542
|
+
if (lengths[c] < r + 1) lengths[c] = r + 1;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
if (!js_is_exception(result)) {
|
|
546
|
+
if (has_values) {
|
|
547
|
+
if (ncols == cap) {
|
|
548
|
+
cap++;
|
|
549
|
+
head = realloc(head, cap * sizeof *head);
|
|
550
|
+
columns = realloc(columns, cap * sizeof *columns);
|
|
551
|
+
lengths = realloc(lengths, cap * sizeof *lengths);
|
|
552
|
+
if (!head || !columns || !lengths) js_fatal("out of memory");
|
|
553
|
+
}
|
|
554
|
+
head[ncols] = kept(ctx, keep, js_new_string_cstr(ctx, "Values"));
|
|
555
|
+
columns[ncols] = values;
|
|
556
|
+
lengths[ncols] = nrows;
|
|
557
|
+
values = NULL;
|
|
558
|
+
ncols++;
|
|
559
|
+
}
|
|
560
|
+
render_table(ctx, head, ncols, columns, lengths);
|
|
561
|
+
}
|
|
562
|
+
for (uint32_t c = 0; c < ncols; c++) if (columns[c] != values) free(columns[c]);
|
|
563
|
+
free(values);
|
|
564
|
+
free(head);
|
|
565
|
+
free(columns);
|
|
566
|
+
free(lengths);
|
|
567
|
+
free(rows);
|
|
568
|
+
js_keep_alive(keep);
|
|
569
|
+
return result;
|
|
570
|
+
}
|
|
571
|
+
fail_rows:
|
|
572
|
+
free(rows);
|
|
573
|
+
return JS_EXCEPTION;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/* console.clear: Node clears a terminal and leaves a file or pipe alone; visaljs doesn't
|
|
577
|
+
* clear terminals yet */
|
|
578
|
+
NATIVE(console_clear) {
|
|
579
|
+
UNUSED_ARGS;
|
|
580
|
+
(void)ctx, (void)argc, (void)argv;
|
|
581
|
+
return JS_UNDEFINED;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
JSValue js_new_console(JSContext *ctx) {
|
|
585
|
+
JSValue console = js_new_object(ctx);
|
|
586
|
+
if (js_is_exception(console)) return console;
|
|
587
|
+
JSObject *c = js_as_object(console);
|
|
588
|
+
static const struct { const char *name; JSNativeFn fn; } methods[] = {
|
|
589
|
+
{ "log", console_log }, { "warn", console_error }, { "dir", console_dir }, { "time", console_time },
|
|
590
|
+
{ "timeEnd", console_time_end }, { "timeLog", console_time_log }, { "trace", console_trace },
|
|
591
|
+
{ "assert", console_assert }, { "clear", console_clear }, { "count", console_count },
|
|
592
|
+
{ "countReset", console_count_reset }, { "group", console_group }, { "groupEnd", console_group_end },
|
|
593
|
+
{ "table", console_table }, { "debug", console_log }, { "info", console_log }, { "dirxml", console_log },
|
|
594
|
+
{ "error", console_error }, { "groupCollapsed", console_group },
|
|
595
|
+
};
|
|
596
|
+
/* own enumerable methods, in Node's order */
|
|
597
|
+
for (size_t i = 0; i < sizeof methods / sizeof methods[0]; i++) {
|
|
598
|
+
JSValue name = js_atom_from_cstr(ctx, methods[i].name);
|
|
599
|
+
JSValue f = js_new_native(ctx, methods[i].fn, name, 0, JS_FN_STRICT);
|
|
600
|
+
if (js_is_exception(f)) return f;
|
|
601
|
+
js_define_data(ctx, c, name, f, JS_PROP_DEFAULT);
|
|
602
|
+
}
|
|
603
|
+
return console;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/* ---- The test host's print, and uncaught errors ----------------------------------------- */
|
|
607
|
+
|
|
608
|
+
JSValue js_print(JSContext *ctx, JSValue callee, JSValue this_val,
|
|
609
|
+
uint32_t argc, const JSValue *argv, JSValue new_target) {
|
|
610
|
+
UNUSED_ARGS;
|
|
611
|
+
JSValue s = js_to_string(ctx, ARG(0));
|
|
612
|
+
if (js_is_exception(s)) return JS_EXCEPTION;
|
|
613
|
+
js_write_output(ctx, 1, s);
|
|
614
|
+
fputc('\n', stdout);
|
|
615
|
+
return JS_UNDEFINED;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
void js_report_error(JSContext *ctx, const char *prefix, JSValue e) {
|
|
619
|
+
fflush(stdout);
|
|
620
|
+
/* An error prints as "Name: message" (ADR 0004; no frames: plan/unsupported.md), other
|
|
621
|
+
* objects as their ToString, primitives as console.log prints them. */
|
|
622
|
+
JSValue s = js_is_error(e) ? js_error_to_string(ctx, e) : js_is_object(e) ? js_to_string(ctx, e) : js_format(ctx, 1, &e);
|
|
623
|
+
if (js_is_exception(s)) {
|
|
624
|
+
(void)js_take_exception(ctx);
|
|
625
|
+
fprintf(stderr, "%sexception\n", prefix);
|
|
626
|
+
} else {
|
|
627
|
+
fputs(prefix, stderr);
|
|
628
|
+
js_write_output(ctx, 2, s);
|
|
629
|
+
fputc('\n', stderr);
|
|
630
|
+
}
|
|
631
|
+
fflush(stderr);
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
int js_report_uncaught(JSContext *ctx) {
|
|
635
|
+
js_report_error(ctx, "Uncaught ", js_take_exception(ctx));
|
|
636
|
+
return 1;
|
|
637
|
+
}
|