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,837 @@
|
|
|
1
|
+
/* String and String.prototype (§22.1): core built-ins (ADR 0014). Case conversion and
|
|
2
|
+
* normalization use QuickJS's libunicode (ADR 0015's vendored copy); the regex-based methods
|
|
3
|
+
* dispatch to @@match/@@replace/@@search/@@split on their argument as the spec makes them, and
|
|
4
|
+
* create a RegExp (the RegExp component, ADR 0015) only where the spec does. */
|
|
5
|
+
#include "builtins_util.h"
|
|
6
|
+
|
|
7
|
+
#include <math.h>
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
#include <string.h>
|
|
10
|
+
|
|
11
|
+
#include "internal.h"
|
|
12
|
+
#include "js_atoms.h"
|
|
13
|
+
#include "js_convert.h"
|
|
14
|
+
#include "js_error.h"
|
|
15
|
+
#include "js_exception.h"
|
|
16
|
+
#include "js_ops.h"
|
|
17
|
+
#include "jsstring.h"
|
|
18
|
+
#include "cutils.h" /* QuickJS's helpers, which libunicode.h expects */
|
|
19
|
+
#include "libunicode.h"
|
|
20
|
+
|
|
21
|
+
/* ---- A growable UTF-16 buffer ------------------------------------------------------------- */
|
|
22
|
+
|
|
23
|
+
typedef struct {
|
|
24
|
+
uint16_t *units;
|
|
25
|
+
size_t length, cap;
|
|
26
|
+
} Builder;
|
|
27
|
+
|
|
28
|
+
static void reserve(Builder *b, size_t more) {
|
|
29
|
+
if (b->length + more <= b->cap) return;
|
|
30
|
+
size_t cap = b->cap ? b->cap * 2 : 64;
|
|
31
|
+
while (cap < b->length + more) cap *= 2;
|
|
32
|
+
uint16_t *u = realloc(b->units, cap * sizeof *u);
|
|
33
|
+
if (!u) js_fatal("out of memory building a string");
|
|
34
|
+
b->units = u;
|
|
35
|
+
b->cap = cap;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static void put_unit(Builder *b, uint32_t u) {
|
|
39
|
+
reserve(b, 1);
|
|
40
|
+
b->units[b->length++] = (uint16_t)u;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static void put_code_point(Builder *b, uint32_t c) {
|
|
44
|
+
if (c < 0x10000) {
|
|
45
|
+
put_unit(b, c);
|
|
46
|
+
} else {
|
|
47
|
+
put_unit(b, 0xD800 + ((c - 0x10000) >> 10));
|
|
48
|
+
put_unit(b, 0xDC00 + ((c - 0x10000) & 0x3FF));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static void put_view(Builder *b, JSStrView v, uint32_t start, uint32_t end) {
|
|
53
|
+
reserve(b, end - start);
|
|
54
|
+
for (uint32_t i = start; i < end; i++) b->units[b->length++] = (uint16_t)js_view_at(v, i);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static void put_ascii(Builder *b, const char *s) {
|
|
58
|
+
while (*s) put_unit(b, (uint8_t)*s++);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static JSValue finish(JSContext *ctx, Builder *b) {
|
|
62
|
+
if (b->length > JS_STRING_MAX_LENGTH) {
|
|
63
|
+
free(b->units);
|
|
64
|
+
return js_throw_range_error(ctx, "Invalid string length");
|
|
65
|
+
}
|
|
66
|
+
JSValue s = js_new_string_utf16(ctx, b->units, (uint32_t)b->length);
|
|
67
|
+
free(b->units);
|
|
68
|
+
return s;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/* The code point at i (a lone surrogate is itself); *next is where the next one starts. */
|
|
72
|
+
static uint32_t code_point_at(JSStrView v, uint32_t i, uint32_t *next) {
|
|
73
|
+
uint32_t c = js_view_at(v, i);
|
|
74
|
+
if (c >= 0xD800 && c <= 0xDBFF && i + 1 < v.length) {
|
|
75
|
+
uint32_t d = js_view_at(v, i + 1);
|
|
76
|
+
if (d >= 0xDC00 && d <= 0xDFFF) {
|
|
77
|
+
*next = i + 2;
|
|
78
|
+
return 0x10000 + ((c - 0xD800) << 10) + (d - 0xDC00);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
*next = i + 1;
|
|
82
|
+
return c;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ---- Helpers ---------------------------------------------------------------------------- */
|
|
86
|
+
|
|
87
|
+
/* RequireObjectCoercible(this), then ToString. */
|
|
88
|
+
static JSValue this_string(JSContext *ctx, JSValue v, const char *method) {
|
|
89
|
+
if (!js_require_this(ctx, v, method)) return JS_EXCEPTION;
|
|
90
|
+
return js_to_string(ctx, v);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* StringIndexOf (§6.1.4.1): the first match at or after `from`, or -1. */
|
|
94
|
+
static int64_t index_of(JSStrView h, JSStrView n, uint32_t from) {
|
|
95
|
+
if (n.length > h.length) return -1;
|
|
96
|
+
for (uint32_t i = from; i + n.length <= h.length; i++) {
|
|
97
|
+
uint32_t j = 0;
|
|
98
|
+
while (j < n.length && js_view_at(h, i + j) == js_view_at(n, j)) j++;
|
|
99
|
+
if (j == n.length) return i;
|
|
100
|
+
}
|
|
101
|
+
return -1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static bool is_white_space(uint32_t c) {
|
|
105
|
+
switch (c) {
|
|
106
|
+
case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x20: case 0xA0: case 0x1680:
|
|
107
|
+
case 0x2028: case 0x2029: case 0x202F: case 0x205F: case 0x3000: case 0xFEFF:
|
|
108
|
+
return true;
|
|
109
|
+
default:
|
|
110
|
+
return c >= 0x2000 && c <= 0x200A;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/* IsRegExp (§7.2.8): an object whose @@match is truthy (or, with none, a RegExp). */
|
|
115
|
+
static int is_regexp(JSContext *ctx, JSValue v) {
|
|
116
|
+
if (!js_is_object(v)) return 0;
|
|
117
|
+
JSValue matcher = js_get_value(ctx, v, JS_SYMBOL(match));
|
|
118
|
+
if (js_is_exception(matcher)) return -1;
|
|
119
|
+
if (!js_is_undefined(matcher)) return js_truthy(matcher);
|
|
120
|
+
return strcmp(js_as_object(v)->shape->cls->name, "RegExp") == 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* GetMethod (§7.3.10): undefined for null or undefined, a TypeError if not callable. */
|
|
124
|
+
static JSValue get_method(JSContext *ctx, JSValue v, JSValue key) {
|
|
125
|
+
JSValue f = js_get_value(ctx, v, key);
|
|
126
|
+
if (js_is_exception(f) || js_is_nullish(f)) return js_is_exception(f) ? f : JS_UNDEFINED;
|
|
127
|
+
if (!js_is_callable(f)) return js_throw_type_error(ctx, "%s is not a function", "Symbol method");
|
|
128
|
+
return f;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* RegExpCreate (§22.2.3.1), through the RegExp component (ADR 0015). */
|
|
132
|
+
static JSValue regexp_create(JSContext *ctx, JSValue pattern, const char *flags, const char *method) {
|
|
133
|
+
JSValue ctor = ctx->intrinsics[JS_INTRINSIC_REGEXP];
|
|
134
|
+
if (!js_is_function(ctor)) return js_throw_type_error(ctx, "%s needs RegExp (not supported yet)", method);
|
|
135
|
+
JSValue args[2] = { js_is_undefined(pattern) ? js_empty_string() : pattern, flags ? js_new_string_cstr(ctx, flags) : JS_UNDEFINED };
|
|
136
|
+
return js_construct(ctx, ctor, 2, args, ctor, NULL);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* ---- String (§22.1.1, §22.1.2) ---------------------------------------------------------- */
|
|
140
|
+
|
|
141
|
+
static JSValue string_ctor(JSContext *ctx, JSValue callee, JSValue this_val, uint32_t argc, const JSValue *argv, JSValue new_target) {
|
|
142
|
+
UNUSED_ARGS;
|
|
143
|
+
JSValue s;
|
|
144
|
+
if (!argc) s = js_empty_string();
|
|
145
|
+
else if (js_is_undefined(new_target) && js_is_symbol(argv[0])) return js_symbol_descriptive_string(ctx, argv[0]); /* String(sym) */
|
|
146
|
+
else s = js_to_string(ctx, argv[0]);
|
|
147
|
+
if (js_is_exception(s) || js_is_undefined(new_target)) return s;
|
|
148
|
+
JSValue proto = js_get_prototype_from_constructor(ctx, new_target, JS_INTRINSIC_STRING_PROTOTYPE);
|
|
149
|
+
return js_is_exception(proto) ? proto : js_new_wrapper(ctx, s, proto);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
CORE(string_from_char_code) {
|
|
153
|
+
UNUSED_ARGS;
|
|
154
|
+
Builder b = { 0 };
|
|
155
|
+
for (uint32_t i = 0; i < argc; i++) {
|
|
156
|
+
double d;
|
|
157
|
+
if (js_to_number(ctx, &d, argv[i]) < 0) {
|
|
158
|
+
free(b.units);
|
|
159
|
+
return JS_EXCEPTION;
|
|
160
|
+
}
|
|
161
|
+
put_unit(&b, (uint16_t)js_double_to_int32(d));
|
|
162
|
+
}
|
|
163
|
+
return finish(ctx, &b);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
CORE(string_from_code_point) {
|
|
167
|
+
UNUSED_ARGS;
|
|
168
|
+
Builder b = { 0 };
|
|
169
|
+
for (uint32_t i = 0; i < argc; i++) {
|
|
170
|
+
double d;
|
|
171
|
+
if (js_to_number(ctx, &d, argv[i]) < 0) {
|
|
172
|
+
free(b.units);
|
|
173
|
+
return JS_EXCEPTION;
|
|
174
|
+
}
|
|
175
|
+
if (d != floor(d) || d < 0 || d > 0x10FFFF) {
|
|
176
|
+
free(b.units);
|
|
177
|
+
JSValue shown = js_to_string(ctx, argv[i]);
|
|
178
|
+
if (js_is_exception(shown)) return shown;
|
|
179
|
+
JSValue prefix = js_new_string_cstr(ctx, "Invalid code point ");
|
|
180
|
+
JSValue m = js_concat(ctx, prefix, shown);
|
|
181
|
+
return js_is_exception(m) ? m : js_throw(ctx, js_new_error(ctx, JS_RANGE_ERROR, m));
|
|
182
|
+
}
|
|
183
|
+
put_code_point(&b, (uint32_t)d);
|
|
184
|
+
}
|
|
185
|
+
return finish(ctx, &b);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/* String.raw(template, ...substitutions) (§22.1.2.4) */
|
|
189
|
+
CORE(string_raw) {
|
|
190
|
+
UNUSED_ARGS;
|
|
191
|
+
if (js_is_nullish(ARG(0))) return js_throw_type_error(ctx, "Cannot convert undefined or null to object");
|
|
192
|
+
JSValue raw = js_get_value(ctx, ARG(0), js_atom_from_cstr(ctx, "raw"));
|
|
193
|
+
if (js_is_exception(raw)) return raw;
|
|
194
|
+
if (js_is_nullish(raw)) return js_throw_type_error(ctx, "Cannot convert undefined or null to object");
|
|
195
|
+
double len;
|
|
196
|
+
if (js_length_of_array_like(ctx, raw, &len) < 0) return JS_EXCEPTION;
|
|
197
|
+
JSValue r = js_empty_string();
|
|
198
|
+
for (double i = 0; i < len; i++) {
|
|
199
|
+
JSValue seg = js_get_value(ctx, raw, js_index_key_of(ctx, i));
|
|
200
|
+
if (!js_is_exception(seg)) seg = js_to_string(ctx, seg);
|
|
201
|
+
if (js_is_exception(seg) || js_is_exception(r = js_concat(ctx, r, seg))) return JS_EXCEPTION;
|
|
202
|
+
if (i + 1 < len && i + 1 < argc) {
|
|
203
|
+
JSValue sub = js_to_string(ctx, argv[(uint32_t)i + 1]);
|
|
204
|
+
if (js_is_exception(sub) || js_is_exception(r = js_concat(ctx, r, sub))) return JS_EXCEPTION;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return r;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* ---- String.prototype (§22.1.3) ------------------------------------------------------------ */
|
|
211
|
+
|
|
212
|
+
CORE(string_proto_at) {
|
|
213
|
+
UNUSED_ARGS;
|
|
214
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.at");
|
|
215
|
+
double rel;
|
|
216
|
+
if (js_is_exception(s) || js_to_integer_or_infinity(ctx, &rel, ARG(0)) < 0) return JS_EXCEPTION;
|
|
217
|
+
double len = js_string_length(s), k = rel >= 0 ? rel : len + rel;
|
|
218
|
+
if (k < 0 || k >= len) return JS_UNDEFINED;
|
|
219
|
+
return js_substring(ctx, s, (uint32_t)k, (uint32_t)k + 1);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
CORE(string_proto_char_at) {
|
|
223
|
+
UNUSED_ARGS;
|
|
224
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.charAt");
|
|
225
|
+
double pos;
|
|
226
|
+
if (js_is_exception(s) || js_to_integer_or_infinity(ctx, &pos, ARG(0)) < 0) return JS_EXCEPTION;
|
|
227
|
+
if (pos < 0 || pos >= js_string_length(s)) return js_empty_string();
|
|
228
|
+
return js_substring(ctx, s, (uint32_t)pos, (uint32_t)pos + 1);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
CORE(string_proto_char_code_at) {
|
|
232
|
+
UNUSED_ARGS;
|
|
233
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.charCodeAt");
|
|
234
|
+
double pos;
|
|
235
|
+
if (js_is_exception(s) || js_to_integer_or_infinity(ctx, &pos, ARG(0)) < 0) return JS_EXCEPTION;
|
|
236
|
+
JSStrView v = js_string_view(ctx, s);
|
|
237
|
+
if (pos < 0 || pos >= v.length) return js_double(NAN);
|
|
238
|
+
return js_int32((int32_t)js_view_at(v, (uint32_t)pos));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
CORE(string_proto_code_point_at) {
|
|
242
|
+
UNUSED_ARGS;
|
|
243
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.codePointAt");
|
|
244
|
+
double pos;
|
|
245
|
+
if (js_is_exception(s) || js_to_integer_or_infinity(ctx, &pos, ARG(0)) < 0) return JS_EXCEPTION;
|
|
246
|
+
JSStrView v = js_string_view(ctx, s);
|
|
247
|
+
if (pos < 0 || pos >= v.length) return JS_UNDEFINED;
|
|
248
|
+
uint32_t next;
|
|
249
|
+
return js_int32((int32_t)code_point_at(v, (uint32_t)pos, &next));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
CORE(string_proto_concat) {
|
|
253
|
+
UNUSED_ARGS;
|
|
254
|
+
JSValue r = this_string(ctx, this_val, "String.prototype.concat");
|
|
255
|
+
for (uint32_t i = 0; i < argc && !js_is_exception(r); i++) {
|
|
256
|
+
JSValue s = js_to_string(ctx, argv[i]);
|
|
257
|
+
r = js_is_exception(s) ? s : js_concat(ctx, r, s);
|
|
258
|
+
}
|
|
259
|
+
return r;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* startsWith / endsWith / includes: the search string may not be a RegExp. */
|
|
263
|
+
static JSValue search_string(JSContext *ctx, JSValue v, const char *method) {
|
|
264
|
+
int re = is_regexp(ctx, v);
|
|
265
|
+
if (re < 0) return JS_EXCEPTION;
|
|
266
|
+
if (re) return js_throw_type_error(ctx, "First argument to %s must not be a regular expression", method);
|
|
267
|
+
return js_to_string(ctx, v);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
CORE(string_proto_ends_with) {
|
|
271
|
+
UNUSED_ARGS;
|
|
272
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.endsWith");
|
|
273
|
+
JSValue search = js_is_exception(s) ? s : search_string(ctx, ARG(0), "String.prototype.endsWith");
|
|
274
|
+
if (js_is_exception(search)) return search;
|
|
275
|
+
double len = js_string_length(s), end = len;
|
|
276
|
+
if (!js_is_undefined(ARG(1))) {
|
|
277
|
+
if (js_to_integer_or_infinity(ctx, &end, ARG(1)) < 0) return JS_EXCEPTION;
|
|
278
|
+
end = fmin(fmax(end, 0), len);
|
|
279
|
+
}
|
|
280
|
+
double n = js_string_length(search), start = end - n;
|
|
281
|
+
if (start < 0) return JS_FALSE;
|
|
282
|
+
JSStrView h = js_string_view(ctx, s), sv = js_string_view(ctx, search);
|
|
283
|
+
for (uint32_t i = 0; i < n; i++)
|
|
284
|
+
if (js_view_at(h, (uint32_t)start + i) != js_view_at(sv, i)) return JS_FALSE;
|
|
285
|
+
return JS_TRUE;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
CORE(string_proto_starts_with) {
|
|
289
|
+
UNUSED_ARGS;
|
|
290
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.startsWith");
|
|
291
|
+
JSValue search = js_is_exception(s) ? s : search_string(ctx, ARG(0), "String.prototype.startsWith");
|
|
292
|
+
if (js_is_exception(search)) return search;
|
|
293
|
+
double len = js_string_length(s), start;
|
|
294
|
+
if (js_to_integer_or_infinity(ctx, &start, ARG(1)) < 0) return JS_EXCEPTION;
|
|
295
|
+
start = fmin(fmax(start, 0), len);
|
|
296
|
+
double n = js_string_length(search);
|
|
297
|
+
if (start + n > len) return JS_FALSE;
|
|
298
|
+
JSStrView h = js_string_view(ctx, s), sv = js_string_view(ctx, search);
|
|
299
|
+
for (uint32_t i = 0; i < n; i++)
|
|
300
|
+
if (js_view_at(h, (uint32_t)start + i) != js_view_at(sv, i)) return JS_FALSE;
|
|
301
|
+
return JS_TRUE;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
CORE(string_proto_includes) {
|
|
305
|
+
UNUSED_ARGS;
|
|
306
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.includes");
|
|
307
|
+
JSValue search = js_is_exception(s) ? s : search_string(ctx, ARG(0), "String.prototype.includes");
|
|
308
|
+
if (js_is_exception(search)) return search;
|
|
309
|
+
double pos;
|
|
310
|
+
if (js_to_integer_or_infinity(ctx, &pos, ARG(1)) < 0) return JS_EXCEPTION;
|
|
311
|
+
double len = js_string_length(s);
|
|
312
|
+
pos = fmin(fmax(pos, 0), len);
|
|
313
|
+
return js_bool(index_of(js_string_view(ctx, s), js_string_view(ctx, search), (uint32_t)pos) >= 0);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
CORE(string_proto_index_of) {
|
|
317
|
+
UNUSED_ARGS;
|
|
318
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.indexOf");
|
|
319
|
+
JSValue search = js_is_exception(s) ? s : js_to_string(ctx, ARG(0));
|
|
320
|
+
double pos;
|
|
321
|
+
if (js_is_exception(search) || js_to_integer_or_infinity(ctx, &pos, ARG(1)) < 0) return JS_EXCEPTION;
|
|
322
|
+
double len = js_string_length(s);
|
|
323
|
+
pos = fmin(fmax(pos, 0), len);
|
|
324
|
+
return js_number((double)index_of(js_string_view(ctx, s), js_string_view(ctx, search), (uint32_t)pos));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
CORE(string_proto_last_index_of) {
|
|
328
|
+
UNUSED_ARGS;
|
|
329
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.lastIndexOf");
|
|
330
|
+
JSValue search = js_is_exception(s) ? s : js_to_string(ctx, ARG(0));
|
|
331
|
+
double num;
|
|
332
|
+
if (js_is_exception(search) || js_to_number(ctx, &num, ARG(1)) < 0) return JS_EXCEPTION;
|
|
333
|
+
double len = js_string_length(s), n = js_string_length(search);
|
|
334
|
+
double pos = num != num ? INFINITY : num == INFINITY || num == -INFINITY ? num : trunc(num);
|
|
335
|
+
double start = fmin(fmax(pos, 0), len);
|
|
336
|
+
if (n > len) return js_int32(-1);
|
|
337
|
+
JSStrView h = js_string_view(ctx, s), sv = js_string_view(ctx, search);
|
|
338
|
+
for (double i = fmin(start, len - n); i >= 0; i--) {
|
|
339
|
+
uint32_t j = 0;
|
|
340
|
+
while (j < n && js_view_at(h, (uint32_t)i + j) == js_view_at(sv, j)) j++;
|
|
341
|
+
if (j == n) return js_number(i);
|
|
342
|
+
}
|
|
343
|
+
return js_int32(-1);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
CORE(string_proto_is_well_formed) {
|
|
347
|
+
UNUSED_ARGS;
|
|
348
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.isWellFormed");
|
|
349
|
+
if (js_is_exception(s)) return s;
|
|
350
|
+
JSStrView v = js_string_view(ctx, s);
|
|
351
|
+
for (uint32_t i = 0, next; i < v.length; i = next) {
|
|
352
|
+
uint32_t c = code_point_at(v, i, &next);
|
|
353
|
+
if (c >= 0xD800 && c <= 0xDFFF) return JS_FALSE;
|
|
354
|
+
}
|
|
355
|
+
return JS_TRUE;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
CORE(string_proto_to_well_formed) {
|
|
359
|
+
UNUSED_ARGS;
|
|
360
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.toWellFormed");
|
|
361
|
+
if (js_is_exception(s)) return s;
|
|
362
|
+
JSStrView v = js_string_view(ctx, s);
|
|
363
|
+
Builder b = { 0 };
|
|
364
|
+
for (uint32_t i = 0, next; i < v.length; i = next) {
|
|
365
|
+
uint32_t c = code_point_at(v, i, &next);
|
|
366
|
+
put_code_point(&b, c >= 0xD800 && c <= 0xDFFF ? 0xFFFD : c);
|
|
367
|
+
}
|
|
368
|
+
return finish(ctx, &b);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/* localeCompare without Intl (later, M7): by code units. Node compares by ICU collation,
|
|
372
|
+
* which differs for mixed case and accents (plan/unsupported.md). */
|
|
373
|
+
CORE(string_proto_locale_compare) {
|
|
374
|
+
UNUSED_ARGS;
|
|
375
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.localeCompare");
|
|
376
|
+
JSValue that = js_is_exception(s) ? s : js_to_string(ctx, ARG(0));
|
|
377
|
+
if (js_is_exception(that)) return that;
|
|
378
|
+
int c = js_string_compare(ctx, s, that);
|
|
379
|
+
return js_int32(c < 0 ? -1 : c > 0 ? 1 : 0);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
CORE(string_proto_normalize) {
|
|
383
|
+
UNUSED_ARGS;
|
|
384
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.normalize");
|
|
385
|
+
if (js_is_exception(s)) return s;
|
|
386
|
+
UnicodeNormalizationEnum form = UNICODE_NFC;
|
|
387
|
+
if (!js_is_undefined(ARG(0))) {
|
|
388
|
+
JSValue f = js_to_string(ctx, ARG(0));
|
|
389
|
+
if (js_is_exception(f)) return f;
|
|
390
|
+
char name[8] = { 0 };
|
|
391
|
+
JSStrView fv = js_string_view(ctx, f);
|
|
392
|
+
for (uint32_t i = 0; i < fv.length && i < 7; i++) name[i] = (char)js_view_at(fv, i);
|
|
393
|
+
if (fv.length > 4 || !strcmp(name, "")) form = (UnicodeNormalizationEnum)-1;
|
|
394
|
+
else if (!strcmp(name, "NFC")) form = UNICODE_NFC;
|
|
395
|
+
else if (!strcmp(name, "NFD")) form = UNICODE_NFD;
|
|
396
|
+
else if (!strcmp(name, "NFKC")) form = UNICODE_NFKC;
|
|
397
|
+
else if (!strcmp(name, "NFKD")) form = UNICODE_NFKD;
|
|
398
|
+
else form = (UnicodeNormalizationEnum)-1;
|
|
399
|
+
if ((int)form < 0) return js_throw_range_error(ctx, "The normalization form should be one of NFC, NFD, NFKC, NFKD.");
|
|
400
|
+
}
|
|
401
|
+
JSStrView v = js_string_view(ctx, s);
|
|
402
|
+
uint32_t *cps = malloc((v.length ? v.length : 1) * sizeof *cps);
|
|
403
|
+
if (!cps) js_fatal("out of memory");
|
|
404
|
+
int n = 0;
|
|
405
|
+
for (uint32_t i = 0, next; i < v.length; i = next) cps[n++] = code_point_at(v, i, &next);
|
|
406
|
+
uint32_t *out = NULL;
|
|
407
|
+
int len = unicode_normalize(&out, cps, n, form, NULL, NULL);
|
|
408
|
+
free(cps);
|
|
409
|
+
if (len < 0) js_fatal("out of memory normalizing");
|
|
410
|
+
Builder b = { 0 };
|
|
411
|
+
for (int i = 0; i < len; i++) put_code_point(&b, out[i]);
|
|
412
|
+
free(out);
|
|
413
|
+
return finish(ctx, &b);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/* padStart / padEnd (§22.1.3.17.1 StringPaddingBuiltinsImpl) */
|
|
417
|
+
static JSValue pad(JSContext *ctx, JSValue this_val, uint32_t argc, const JSValue *argv, bool start, const char *method) {
|
|
418
|
+
JSValue s = this_string(ctx, this_val, method);
|
|
419
|
+
double max_len;
|
|
420
|
+
if (js_is_exception(s) || js_to_integer_or_infinity(ctx, &max_len, ARG(0)) < 0) return JS_EXCEPTION;
|
|
421
|
+
double len = js_string_length(s);
|
|
422
|
+
if (max_len <= len) return s;
|
|
423
|
+
JSValue fill = js_is_undefined(ARG(1)) ? js_char_string(' ') : js_to_string(ctx, ARG(1));
|
|
424
|
+
if (js_is_exception(fill)) return fill;
|
|
425
|
+
if (js_string_length(fill) == 0) return s;
|
|
426
|
+
if (max_len > JS_STRING_MAX_LENGTH) return js_throw_range_error(ctx, "Invalid string length");
|
|
427
|
+
JSStrView f = js_string_view(ctx, fill), sv = js_string_view(ctx, s);
|
|
428
|
+
Builder b = { 0 };
|
|
429
|
+
if (!start) put_view(&b, sv, 0, sv.length);
|
|
430
|
+
for (double i = 0; i < max_len - len; i++) put_unit(&b, js_view_at(f, (uint32_t)fmod(i, f.length)));
|
|
431
|
+
if (start) put_view(&b, sv, 0, sv.length);
|
|
432
|
+
return finish(ctx, &b);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
CORE(string_proto_pad_end) {
|
|
436
|
+
UNUSED_ARGS;
|
|
437
|
+
return pad(ctx, this_val, argc, argv, false, "String.prototype.padEnd");
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
CORE(string_proto_pad_start) {
|
|
441
|
+
UNUSED_ARGS;
|
|
442
|
+
return pad(ctx, this_val, argc, argv, true, "String.prototype.padStart");
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
CORE(string_proto_repeat) {
|
|
446
|
+
UNUSED_ARGS;
|
|
447
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.repeat");
|
|
448
|
+
double n;
|
|
449
|
+
if (js_is_exception(s) || js_to_integer_or_infinity(ctx, &n, ARG(0)) < 0) return JS_EXCEPTION;
|
|
450
|
+
if (n < 0 || n == INFINITY) {
|
|
451
|
+
JSValue shown = js_to_string(ctx, js_number(n));
|
|
452
|
+
JSValue m = js_is_exception(shown) ? shown : js_concat(ctx, js_new_string_cstr(ctx, "Invalid count value: "), shown);
|
|
453
|
+
return js_is_exception(m) ? m : js_throw(ctx, js_new_error(ctx, JS_RANGE_ERROR, m));
|
|
454
|
+
}
|
|
455
|
+
double len = js_string_length(s);
|
|
456
|
+
if (n == 0 || len == 0) return js_empty_string();
|
|
457
|
+
if (len * n > JS_STRING_MAX_LENGTH) return js_throw_range_error(ctx, "Invalid string length");
|
|
458
|
+
JSStrView v = js_string_view(ctx, s);
|
|
459
|
+
Builder b = { 0 };
|
|
460
|
+
for (double i = 0; i < n; i++) put_view(&b, v, 0, v.length);
|
|
461
|
+
return finish(ctx, &b);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/* GetSubstitution (§22.1.3.19.1) for a string search: $$, $&, $`, $' (no captures). */
|
|
465
|
+
static void put_substitution(Builder *b, JSStrView str, uint32_t position, uint32_t matched_len, JSStrView replacement) {
|
|
466
|
+
for (uint32_t i = 0; i < replacement.length; i++) {
|
|
467
|
+
uint32_t c = js_view_at(replacement, i);
|
|
468
|
+
if (c == '$' && i + 1 < replacement.length) {
|
|
469
|
+
uint32_t d = js_view_at(replacement, i + 1);
|
|
470
|
+
if (d == '$') { put_unit(b, '$'); i++; continue; }
|
|
471
|
+
if (d == '&') { put_view(b, str, position, position + matched_len); i++; continue; }
|
|
472
|
+
if (d == '`') { put_view(b, str, 0, position); i++; continue; }
|
|
473
|
+
if (d == '\'') { put_view(b, str, position + matched_len < str.length ? position + matched_len : str.length, str.length); i++; continue; }
|
|
474
|
+
}
|
|
475
|
+
put_unit(b, c);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/* replace / replaceAll with a string pattern (§22.1.3.19, §22.1.3.20) */
|
|
480
|
+
static JSValue replace(JSContext *ctx, JSValue this_val, uint32_t argc, const JSValue *argv, bool all, const char *method) {
|
|
481
|
+
if (!js_require_this(ctx, this_val, method)) return JS_EXCEPTION;
|
|
482
|
+
JSValue search_value = ARG(0), replace_value = ARG(1);
|
|
483
|
+
if (js_is_object(search_value)) { /* primitives' Symbol methods aren't consulted */
|
|
484
|
+
if (all) {
|
|
485
|
+
int re = is_regexp(ctx, search_value);
|
|
486
|
+
if (re < 0) return JS_EXCEPTION;
|
|
487
|
+
if (re) {
|
|
488
|
+
JSValue flags = js_get_value(ctx, search_value, js_atom_from_cstr(ctx, "flags"));
|
|
489
|
+
if (js_is_exception(flags)) return flags;
|
|
490
|
+
if (js_is_nullish(flags)) return js_throw_type_error(ctx, "String.prototype.replaceAll called with a non-global RegExp argument");
|
|
491
|
+
JSValue fs = js_to_string(ctx, flags);
|
|
492
|
+
if (js_is_exception(fs)) return fs;
|
|
493
|
+
if (index_of(js_string_view(ctx, fs), js_view_latin1("g", 1), 0) < 0)
|
|
494
|
+
return js_throw_type_error(ctx, "String.prototype.replaceAll called with a non-global RegExp argument");
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
JSValue replacer = get_method(ctx, search_value, JS_SYMBOL(replace));
|
|
498
|
+
if (js_is_exception(replacer)) return replacer;
|
|
499
|
+
if (!js_is_undefined(replacer)) {
|
|
500
|
+
JSValue args[2] = { this_val, replace_value };
|
|
501
|
+
return js_call(ctx, replacer, search_value, 2, args);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
JSValue s = js_to_string(ctx, this_val);
|
|
505
|
+
JSValue search = js_is_exception(s) ? s : js_to_string(ctx, search_value);
|
|
506
|
+
if (js_is_exception(search)) return search;
|
|
507
|
+
bool functional = js_is_callable(replace_value);
|
|
508
|
+
if (!functional) {
|
|
509
|
+
replace_value = js_to_string(ctx, replace_value);
|
|
510
|
+
if (js_is_exception(replace_value)) return replace_value;
|
|
511
|
+
}
|
|
512
|
+
JSStrView str = js_string_view(ctx, s), sv = js_string_view(ctx, search);
|
|
513
|
+
uint32_t advance = sv.length ? sv.length : 1;
|
|
514
|
+
Builder b = { 0 };
|
|
515
|
+
uint32_t end_of_last = 0;
|
|
516
|
+
bool found = false;
|
|
517
|
+
for (int64_t pos = index_of(str, sv, 0); pos >= 0; pos = all && (uint32_t)pos + advance <= str.length ? index_of(str, sv, (uint32_t)pos + advance) : -1) {
|
|
518
|
+
found = true;
|
|
519
|
+
put_view(&b, str, end_of_last, (uint32_t)pos);
|
|
520
|
+
if (functional) {
|
|
521
|
+
JSValue args[3] = { search, js_number((double)pos), s };
|
|
522
|
+
JSValue r = js_call(ctx, replace_value, JS_UNDEFINED, 3, args);
|
|
523
|
+
JSValue rs = js_is_exception(r) ? r : js_to_string(ctx, r);
|
|
524
|
+
if (js_is_exception(rs)) {
|
|
525
|
+
free(b.units);
|
|
526
|
+
return rs;
|
|
527
|
+
}
|
|
528
|
+
JSStrView rv = js_string_view(ctx, rs);
|
|
529
|
+
put_view(&b, rv, 0, rv.length);
|
|
530
|
+
str = js_string_view(ctx, s); /* user code ran: views may have moved (flattening) */
|
|
531
|
+
sv = js_string_view(ctx, search);
|
|
532
|
+
} else {
|
|
533
|
+
put_substitution(&b, str, (uint32_t)pos, sv.length, js_string_view(ctx, replace_value));
|
|
534
|
+
}
|
|
535
|
+
end_of_last = (uint32_t)pos + sv.length;
|
|
536
|
+
if (!all) break;
|
|
537
|
+
}
|
|
538
|
+
if (!found) {
|
|
539
|
+
free(b.units);
|
|
540
|
+
return s;
|
|
541
|
+
}
|
|
542
|
+
put_view(&b, str, end_of_last < str.length ? end_of_last : str.length, str.length);
|
|
543
|
+
return finish(ctx, &b);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
CORE(string_proto_replace) {
|
|
547
|
+
UNUSED_ARGS;
|
|
548
|
+
return replace(ctx, this_val, argc, argv, false, "String.prototype.replace");
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
CORE(string_proto_replace_all) {
|
|
552
|
+
UNUSED_ARGS;
|
|
553
|
+
return replace(ctx, this_val, argc, argv, true, "String.prototype.replaceAll");
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/* match / matchAll / search (§22.1.3.13, .14, .23): the argument's @@match/@@matchAll/@@search,
|
|
557
|
+
* or a new RegExp's. */
|
|
558
|
+
static JSValue regexp_method(JSContext *ctx, JSValue this_val, JSValue regexp, JSValue symbol, const char *flags, bool all, const char *method) {
|
|
559
|
+
if (!js_require_this(ctx, this_val, method)) return JS_EXCEPTION;
|
|
560
|
+
if (js_is_object(regexp)) { /* primitives' Symbol methods aren't consulted */
|
|
561
|
+
if (all) {
|
|
562
|
+
int re = is_regexp(ctx, regexp);
|
|
563
|
+
if (re < 0) return JS_EXCEPTION;
|
|
564
|
+
if (re) {
|
|
565
|
+
JSValue f = js_get_value(ctx, regexp, js_atom_from_cstr(ctx, "flags"));
|
|
566
|
+
if (js_is_exception(f)) return f;
|
|
567
|
+
if (js_is_nullish(f)) return js_throw_type_error(ctx, "String.prototype.matchAll called with a non-global RegExp argument");
|
|
568
|
+
JSValue fs = js_to_string(ctx, f);
|
|
569
|
+
if (js_is_exception(fs)) return fs;
|
|
570
|
+
if (index_of(js_string_view(ctx, fs), js_view_latin1("g", 1), 0) < 0)
|
|
571
|
+
return js_throw_type_error(ctx, "String.prototype.matchAll called with a non-global RegExp argument");
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
JSValue m = get_method(ctx, regexp, symbol);
|
|
575
|
+
if (js_is_exception(m)) return m;
|
|
576
|
+
if (!js_is_undefined(m)) return js_call(ctx, m, regexp, 1, &this_val);
|
|
577
|
+
}
|
|
578
|
+
JSValue s = js_to_string(ctx, this_val);
|
|
579
|
+
if (js_is_exception(s)) return s;
|
|
580
|
+
JSValue rx = regexp_create(ctx, regexp, flags, method);
|
|
581
|
+
if (js_is_exception(rx)) return rx;
|
|
582
|
+
JSValue m = js_get_value(ctx, rx, symbol);
|
|
583
|
+
if (js_is_exception(m)) return m;
|
|
584
|
+
return js_call(ctx, m, rx, 1, &s);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
CORE(string_proto_match) {
|
|
588
|
+
UNUSED_ARGS;
|
|
589
|
+
return regexp_method(ctx, this_val, ARG(0), JS_SYMBOL(match), NULL, false, "String.prototype.match");
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
CORE(string_proto_match_all) {
|
|
593
|
+
UNUSED_ARGS;
|
|
594
|
+
return regexp_method(ctx, this_val, ARG(0), JS_SYMBOL(matchAll), "g", true, "String.prototype.matchAll");
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
CORE(string_proto_search) {
|
|
598
|
+
UNUSED_ARGS;
|
|
599
|
+
return regexp_method(ctx, this_val, ARG(0), JS_SYMBOL(search), NULL, false, "String.prototype.search");
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/* split (§22.1.3.23) */
|
|
603
|
+
CORE(string_proto_split) {
|
|
604
|
+
UNUSED_ARGS;
|
|
605
|
+
if (!js_require_this(ctx, this_val, "String.prototype.split")) return JS_EXCEPTION;
|
|
606
|
+
JSValue separator = ARG(0), limit = ARG(1);
|
|
607
|
+
if (js_is_object(separator)) { /* primitives' Symbol methods aren't consulted */
|
|
608
|
+
JSValue splitter = get_method(ctx, separator, JS_SYMBOL(split));
|
|
609
|
+
if (js_is_exception(splitter)) return splitter;
|
|
610
|
+
if (!js_is_undefined(splitter)) {
|
|
611
|
+
JSValue args[2] = { this_val, limit };
|
|
612
|
+
return js_call(ctx, splitter, separator, 2, args);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
JSValue s = js_to_string(ctx, this_val);
|
|
616
|
+
if (js_is_exception(s)) return s;
|
|
617
|
+
double lim = 4294967295.0;
|
|
618
|
+
if (!js_is_undefined(limit)) {
|
|
619
|
+
double d;
|
|
620
|
+
if (js_to_number(ctx, &d, limit) < 0) return JS_EXCEPTION;
|
|
621
|
+
lim = (uint32_t)js_double_to_int32(d);
|
|
622
|
+
}
|
|
623
|
+
JSValue r = js_to_string(ctx, separator);
|
|
624
|
+
if (js_is_exception(r)) return r;
|
|
625
|
+
JSValue a = js_new_array(ctx, 0);
|
|
626
|
+
if (js_is_exception(a) || lim == 0) return a;
|
|
627
|
+
if (js_is_undefined(separator)) return js_array_push(ctx, js_as_object(a), s) < 0 ? JS_EXCEPTION : a;
|
|
628
|
+
JSStrView str = js_string_view(ctx, s), sep = js_string_view(ctx, r);
|
|
629
|
+
if (str.length == 0) {
|
|
630
|
+
if (sep.length != 0 && js_array_push(ctx, js_as_object(a), s) < 0) return JS_EXCEPTION;
|
|
631
|
+
return a;
|
|
632
|
+
}
|
|
633
|
+
if (sep.length == 0) {
|
|
634
|
+
for (uint32_t i = 0; i < str.length && i < lim; i++)
|
|
635
|
+
if (js_array_push(ctx, js_as_object(a), js_substring(ctx, s, i, i + 1)) < 0) return JS_EXCEPTION;
|
|
636
|
+
return a;
|
|
637
|
+
}
|
|
638
|
+
uint32_t p = 0;
|
|
639
|
+
for (int64_t q = index_of(str, sep, 0); q >= 0; q = index_of(js_string_view(ctx, s), js_string_view(ctx, r), p)) {
|
|
640
|
+
if (js_array_push(ctx, js_as_object(a), js_substring(ctx, s, p, (uint32_t)q)) < 0) return JS_EXCEPTION;
|
|
641
|
+
if (js_array_length(js_as_object(a)) >= lim) return a;
|
|
642
|
+
p = (uint32_t)q + sep.length;
|
|
643
|
+
}
|
|
644
|
+
if (js_array_push(ctx, js_as_object(a), js_substring(ctx, s, p, js_string_length(s))) < 0) return JS_EXCEPTION;
|
|
645
|
+
return a;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
CORE(string_proto_slice) {
|
|
649
|
+
UNUSED_ARGS;
|
|
650
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.slice");
|
|
651
|
+
if (js_is_exception(s)) return s;
|
|
652
|
+
double len = js_string_length(s), start, end;
|
|
653
|
+
if (js_relative_index(ctx, ARG(0), len, 0, &start) < 0 || js_relative_index(ctx, ARG(1), len, len, &end) < 0) return JS_EXCEPTION;
|
|
654
|
+
if (start >= end) return js_empty_string();
|
|
655
|
+
return js_substring(ctx, s, (uint32_t)start, (uint32_t)end);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
CORE(string_proto_substring) {
|
|
659
|
+
UNUSED_ARGS;
|
|
660
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.substring");
|
|
661
|
+
if (js_is_exception(s)) return s;
|
|
662
|
+
double len = js_string_length(s), a, b = len;
|
|
663
|
+
if (js_to_integer_or_infinity(ctx, &a, ARG(0)) < 0) return JS_EXCEPTION;
|
|
664
|
+
if (!js_is_undefined(ARG(1)) && js_to_integer_or_infinity(ctx, &b, ARG(1)) < 0) return JS_EXCEPTION;
|
|
665
|
+
a = fmin(fmax(a, 0), len);
|
|
666
|
+
b = fmin(fmax(b, 0), len);
|
|
667
|
+
return js_substring(ctx, s, (uint32_t)fmin(a, b), (uint32_t)fmax(a, b));
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/* substr (Annex B §B.2.2.1) */
|
|
671
|
+
CORE(string_proto_substr) {
|
|
672
|
+
UNUSED_ARGS;
|
|
673
|
+
JSValue s = this_string(ctx, this_val, "String.prototype.substr");
|
|
674
|
+
if (js_is_exception(s)) return s;
|
|
675
|
+
double size = js_string_length(s), start, length = size;
|
|
676
|
+
if (js_to_integer_or_infinity(ctx, &start, ARG(0)) < 0) return JS_EXCEPTION;
|
|
677
|
+
if (start == -INFINITY) start = 0;
|
|
678
|
+
else if (start < 0) start = fmax(size + start, 0);
|
|
679
|
+
else start = fmin(start, size);
|
|
680
|
+
if (!js_is_undefined(ARG(1)) && js_to_integer_or_infinity(ctx, &length, ARG(1)) < 0) return JS_EXCEPTION;
|
|
681
|
+
double end = fmin(start + length, size);
|
|
682
|
+
if (start >= end) return js_empty_string();
|
|
683
|
+
return js_substring(ctx, s, (uint32_t)start, (uint32_t)end);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
static JSValue case_convert(JSContext *ctx, JSValue this_val, bool lower, const char *method) {
|
|
687
|
+
JSValue s = this_string(ctx, this_val, method);
|
|
688
|
+
if (js_is_exception(s)) return s;
|
|
689
|
+
JSStrView v = js_string_view(ctx, s);
|
|
690
|
+
Builder b = { 0 };
|
|
691
|
+
for (uint32_t i = 0, next; i < v.length; i = next) {
|
|
692
|
+
uint32_t c = code_point_at(v, i, &next);
|
|
693
|
+
uint32_t res[LRE_CC_RES_LEN_MAX];
|
|
694
|
+
int n;
|
|
695
|
+
if (c == 0x3A3 && lower) { /* capital sigma: final (ς) or not (σ), §22.1.3.28 */
|
|
696
|
+
bool final = false;
|
|
697
|
+
uint32_t k = i, c1 = 0;
|
|
698
|
+
while (k > 0) { /* before: a cased letter, past case-ignorable ones */
|
|
699
|
+
c1 = js_view_at(v, --k);
|
|
700
|
+
if (!lre_is_case_ignorable(c1)) break;
|
|
701
|
+
}
|
|
702
|
+
if (i > 0 && lre_is_cased(c1)) {
|
|
703
|
+
final = true;
|
|
704
|
+
for (uint32_t j = next, after; j < v.length; j = after) { /* after: no cased letter */
|
|
705
|
+
uint32_t c2 = code_point_at(v, j, &after);
|
|
706
|
+
if (lre_is_case_ignorable(c2)) continue;
|
|
707
|
+
final = !lre_is_cased(c2);
|
|
708
|
+
break;
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
res[0] = final ? 0x3C2 : 0x3C3;
|
|
712
|
+
n = 1;
|
|
713
|
+
} else {
|
|
714
|
+
n = lre_case_conv(res, c, lower ? 1 : 0);
|
|
715
|
+
}
|
|
716
|
+
for (int j = 0; j < n; j++) put_code_point(&b, res[j]);
|
|
717
|
+
}
|
|
718
|
+
return finish(ctx, &b);
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
CORE(string_proto_to_lower_case) {
|
|
722
|
+
UNUSED_ARGS;
|
|
723
|
+
return case_convert(ctx, this_val, true, "String.prototype.toLowerCase");
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
CORE(string_proto_to_upper_case) {
|
|
727
|
+
UNUSED_ARGS;
|
|
728
|
+
return case_convert(ctx, this_val, false, "String.prototype.toUpperCase");
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/* The locale variants without Intl (later, M7): the root locale's mapping. */
|
|
732
|
+
CORE(string_proto_to_locale_lower_case) {
|
|
733
|
+
UNUSED_ARGS;
|
|
734
|
+
return case_convert(ctx, this_val, true, "String.prototype.toLocaleLowerCase");
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
CORE(string_proto_to_locale_upper_case) {
|
|
738
|
+
UNUSED_ARGS;
|
|
739
|
+
return case_convert(ctx, this_val, false, "String.prototype.toLocaleUpperCase");
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
static JSValue trim(JSContext *ctx, JSValue this_val, bool start, bool end, const char *method) {
|
|
743
|
+
JSValue s = this_string(ctx, this_val, method);
|
|
744
|
+
if (js_is_exception(s)) return s;
|
|
745
|
+
JSStrView v = js_string_view(ctx, s);
|
|
746
|
+
uint32_t a = 0, b = v.length;
|
|
747
|
+
if (start) while (a < b && is_white_space(js_view_at(v, a))) a++;
|
|
748
|
+
if (end) while (b > a && is_white_space(js_view_at(v, b - 1))) b--;
|
|
749
|
+
return a == 0 && b == v.length ? s : js_substring(ctx, s, a, b);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
CORE(string_proto_trim) {
|
|
753
|
+
UNUSED_ARGS;
|
|
754
|
+
return trim(ctx, this_val, true, true, "String.prototype.trim");
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
CORE(string_proto_trim_start) {
|
|
758
|
+
UNUSED_ARGS;
|
|
759
|
+
return trim(ctx, this_val, true, false, "String.prototype.trimStart");
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
CORE(string_proto_trim_end) {
|
|
763
|
+
UNUSED_ARGS;
|
|
764
|
+
return trim(ctx, this_val, false, true, "String.prototype.trimEnd");
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
CORE(string_proto_to_string) {
|
|
768
|
+
UNUSED_ARGS;
|
|
769
|
+
JSValue s = js_this_primitive(this_val, js_is_string);
|
|
770
|
+
if (js_is_empty(s)) return js_throw_type_error(ctx, "String.prototype.toString requires that 'this' be a String");
|
|
771
|
+
return s;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
CORE(string_proto_value_of) {
|
|
775
|
+
UNUSED_ARGS;
|
|
776
|
+
JSValue s = js_this_primitive(this_val, js_is_string);
|
|
777
|
+
if (js_is_empty(s)) return js_throw_type_error(ctx, "String.prototype.valueOf requires that 'this' be a String");
|
|
778
|
+
return s;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/* The HTML methods (Annex B §B.2.2.2 CreateHTML): `<tag attr="value">string</tag>`, quotes
|
|
782
|
+
* in the value as ". */
|
|
783
|
+
static JSValue create_html(JSContext *ctx, JSValue this_val, const char *tag, const char *attr, JSValue value, const char *method) {
|
|
784
|
+
JSValue s = this_string(ctx, this_val, method);
|
|
785
|
+
if (js_is_exception(s)) return s;
|
|
786
|
+
JSValue v = attr ? js_to_string(ctx, value) : JS_UNDEFINED;
|
|
787
|
+
if (js_is_exception(v)) return v;
|
|
788
|
+
Builder b = { 0 };
|
|
789
|
+
put_unit(&b, '<');
|
|
790
|
+
put_ascii(&b, tag);
|
|
791
|
+
if (attr) {
|
|
792
|
+
put_unit(&b, ' ');
|
|
793
|
+
put_ascii(&b, attr);
|
|
794
|
+
put_ascii(&b, "=\"");
|
|
795
|
+
JSStrView vv = js_string_view(ctx, v);
|
|
796
|
+
for (uint32_t i = 0; i < vv.length; i++) {
|
|
797
|
+
uint32_t c = js_view_at(vv, i);
|
|
798
|
+
if (c == '"') put_ascii(&b, """);
|
|
799
|
+
else put_unit(&b, c);
|
|
800
|
+
}
|
|
801
|
+
put_unit(&b, '"');
|
|
802
|
+
}
|
|
803
|
+
put_unit(&b, '>');
|
|
804
|
+
JSStrView sv = js_string_view(ctx, s);
|
|
805
|
+
put_view(&b, sv, 0, sv.length);
|
|
806
|
+
put_ascii(&b, "</");
|
|
807
|
+
put_ascii(&b, tag);
|
|
808
|
+
put_unit(&b, '>');
|
|
809
|
+
return finish(ctx, &b);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
#define HTML_METHOD(fn, tag, attr) \
|
|
813
|
+
CORE(string_html_##fn) { \
|
|
814
|
+
UNUSED_ARGS; \
|
|
815
|
+
return create_html(ctx, this_val, tag, attr, ARG(0), "String.prototype." #fn); \
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
HTML_METHOD(anchor, "a", "name")
|
|
819
|
+
HTML_METHOD(big, "big", NULL)
|
|
820
|
+
HTML_METHOD(blink, "blink", NULL)
|
|
821
|
+
HTML_METHOD(bold, "b", NULL)
|
|
822
|
+
HTML_METHOD(fixed, "tt", NULL)
|
|
823
|
+
HTML_METHOD(fontcolor, "font", "color")
|
|
824
|
+
HTML_METHOD(fontsize, "font", "size")
|
|
825
|
+
HTML_METHOD(italics, "i", NULL)
|
|
826
|
+
HTML_METHOD(link, "a", "href")
|
|
827
|
+
HTML_METHOD(small, "small", NULL)
|
|
828
|
+
HTML_METHOD(strike, "strike", NULL)
|
|
829
|
+
HTML_METHOD(sub, "sub", NULL)
|
|
830
|
+
HTML_METHOD(sup, "sup", NULL)
|
|
831
|
+
|
|
832
|
+
/* ---- The objects ----------------------------------------------------------------------------- */
|
|
833
|
+
|
|
834
|
+
JSValue js_string_realm_init(JSContext *ctx, JSObject *global,
|
|
835
|
+
JSValue (*define_constructor)(JSContext *, JSObject *, const char *, JSNativeFn, uint32_t, JSValue)) {
|
|
836
|
+
return define_constructor(ctx, global, "String", string_ctor, 1, ctx->intrinsics[JS_INTRINSIC_STRING_PROTOTYPE]);
|
|
837
|
+
}
|