@scriptc/runtime 0.0.0 → 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 +202 -0
- package/package.json +16 -6
- package/src/scr_array.c +488 -0
- package/src/scr_assert.c +1393 -0
- package/src/scr_async.c +2593 -0
- package/src/scr_async_dyn.c +607 -0
- package/src/scr_bytes.c +1425 -0
- package/src/scr_bytes_io.c +161 -0
- package/src/scr_child.c +3587 -0
- package/src/scr_closure.c +214 -0
- package/src/scr_console.c +143 -0
- package/src/scr_cycle.c +218 -0
- package/src/scr_dc.c +805 -0
- package/src/scr_dgram.c +1007 -0
- package/src/scr_dyn_handle.c +154 -0
- package/src/scr_dyn_invoke.c +644 -0
- package/src/scr_error.c +332 -0
- package/src/scr_events.c +714 -0
- package/src/scr_events_emitter.c +699 -0
- package/src/scr_exception.c +242 -0
- package/src/scr_fetch.c +1130 -0
- package/src/scr_fetch_curl.c +654 -0
- package/src/scr_http.c +3482 -0
- package/src/scr_http2.c +3030 -0
- package/src/scr_inspect.c +803 -0
- package/src/scr_inspect_island.c +51 -0
- package/src/scr_island.c +9363 -0
- package/src/scr_json.c +2151 -0
- package/src/scr_lib.c +3612 -0
- package/src/scr_loop_epoll.c +241 -0
- package/src/scr_loop_kqueue.c +121 -0
- package/src/scr_loop_wsapoll.c +208 -0
- package/src/scr_map.c +591 -0
- package/src/scr_net.c +3017 -0
- package/src/scr_net_island.c +458 -0
- package/src/scr_number.c +115 -0
- package/src/scr_object.c +25 -0
- package/src/scr_path.c +1266 -0
- package/src/scr_platform.h +119 -0
- package/src/scr_readline.c +287 -0
- package/src/scr_regex.c +1080 -0
- package/src/scr_runtime.h +5046 -0
- package/src/scr_stream.c +2877 -0
- package/src/scr_string.c +1264 -0
- package/src/scr_symbol.c +132 -0
- package/src/scr_test.c +662 -0
- package/src/scr_tls.c +1520 -0
- package/src/scr_union.c +105 -0
- package/src/scr_url.c +911 -0
- package/src/scr_url_internal.h +29 -0
- package/src/scr_url_params.c +561 -0
- package/src/scr_watch.c +568 -0
- package/src/scr_web.c +1778 -0
- package/src/scr_win.c +76 -0
- package/src/scr_zlib.c +197 -0
- package/src/scr_zlib_island.c +15 -0
- package/vendor/README.md +52 -0
- package/vendor/curl/COPYRIGHT +534 -0
- package/vendor/curl/include/curl/curl.h +3214 -0
- package/vendor/curl/include/curl/curlver.h +79 -0
- package/vendor/curl/include/curl/easy.h +125 -0
- package/vendor/curl/include/curl/header.h +74 -0
- package/vendor/curl/include/curl/mprintf.h +52 -0
- package/vendor/curl/include/curl/multi.h +460 -0
- package/vendor/curl/include/curl/options.h +70 -0
- package/vendor/curl/include/curl/stdcheaders.h +35 -0
- package/vendor/curl/include/curl/system.h +508 -0
- package/vendor/curl/include/curl/typecheck-gcc.h +716 -0
- package/vendor/curl/include/curl/urlapi.h +149 -0
- package/vendor/curl/include/curl/websockets.h +84 -0
- package/vendor/mbedtls/LICENSE +553 -0
- package/vendor/mbedtls/include/CMakeLists.txt +22 -0
- package/vendor/mbedtls/include/mbedtls/aes.h +631 -0
- package/vendor/mbedtls/include/mbedtls/aria.h +343 -0
- package/vendor/mbedtls/include/mbedtls/asn1.h +642 -0
- package/vendor/mbedtls/include/mbedtls/asn1write.h +390 -0
- package/vendor/mbedtls/include/mbedtls/base64.h +82 -0
- package/vendor/mbedtls/include/mbedtls/bignum.h +1088 -0
- package/vendor/mbedtls/include/mbedtls/block_cipher.h +76 -0
- package/vendor/mbedtls/include/mbedtls/build_info.h +194 -0
- package/vendor/mbedtls/include/mbedtls/camellia.h +305 -0
- package/vendor/mbedtls/include/mbedtls/ccm.h +526 -0
- package/vendor/mbedtls/include/mbedtls/chacha20.h +209 -0
- package/vendor/mbedtls/include/mbedtls/chachapoly.h +351 -0
- package/vendor/mbedtls/include/mbedtls/check_config.h +1149 -0
- package/vendor/mbedtls/include/mbedtls/cipher.h +1250 -0
- package/vendor/mbedtls/include/mbedtls/cmac.h +246 -0
- package/vendor/mbedtls/include/mbedtls/compat-2.x.h +46 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_crypto.h +578 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_from_psa.h +873 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_psa_from_legacy.h +359 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_psa_superset_legacy.h +145 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_ssl.h +91 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_x509.h +35 -0
- package/vendor/mbedtls/include/mbedtls/config_psa.h +61 -0
- package/vendor/mbedtls/include/mbedtls/constant_time.h +36 -0
- package/vendor/mbedtls/include/mbedtls/ctr_drbg.h +596 -0
- package/vendor/mbedtls/include/mbedtls/debug.h +156 -0
- package/vendor/mbedtls/include/mbedtls/des.h +385 -0
- package/vendor/mbedtls/include/mbedtls/dhm.h +972 -0
- package/vendor/mbedtls/include/mbedtls/ecdh.h +455 -0
- package/vendor/mbedtls/include/mbedtls/ecdsa.h +674 -0
- package/vendor/mbedtls/include/mbedtls/ecjpake.h +298 -0
- package/vendor/mbedtls/include/mbedtls/ecp.h +1517 -0
- package/vendor/mbedtls/include/mbedtls/entropy.h +274 -0
- package/vendor/mbedtls/include/mbedtls/error.h +201 -0
- package/vendor/mbedtls/include/mbedtls/gcm.h +387 -0
- package/vendor/mbedtls/include/mbedtls/hkdf.h +124 -0
- package/vendor/mbedtls/include/mbedtls/hmac_drbg.h +434 -0
- package/vendor/mbedtls/include/mbedtls/lms.h +440 -0
- package/vendor/mbedtls/include/mbedtls/mbedtls_config.h +4446 -0
- package/vendor/mbedtls/include/mbedtls/md.h +526 -0
- package/vendor/mbedtls/include/mbedtls/md5.h +190 -0
- package/vendor/mbedtls/include/mbedtls/memory_buffer_alloc.h +142 -0
- package/vendor/mbedtls/include/mbedtls/net_sockets.h +299 -0
- package/vendor/mbedtls/include/mbedtls/nist_kw.h +166 -0
- package/vendor/mbedtls/include/mbedtls/oid.h +727 -0
- package/vendor/mbedtls/include/mbedtls/pem.h +160 -0
- package/vendor/mbedtls/include/mbedtls/pk.h +1303 -0
- package/vendor/mbedtls/include/mbedtls/pkcs12.h +186 -0
- package/vendor/mbedtls/include/mbedtls/pkcs5.h +198 -0
- package/vendor/mbedtls/include/mbedtls/pkcs7.h +252 -0
- package/vendor/mbedtls/include/mbedtls/platform.h +516 -0
- package/vendor/mbedtls/include/mbedtls/platform_time.h +79 -0
- package/vendor/mbedtls/include/mbedtls/platform_util.h +247 -0
- package/vendor/mbedtls/include/mbedtls/poly1305.h +168 -0
- package/vendor/mbedtls/include/mbedtls/private_access.h +20 -0
- package/vendor/mbedtls/include/mbedtls/psa_util.h +207 -0
- package/vendor/mbedtls/include/mbedtls/ripemd160.h +136 -0
- package/vendor/mbedtls/include/mbedtls/rsa.h +1170 -0
- package/vendor/mbedtls/include/mbedtls/sha1.h +219 -0
- package/vendor/mbedtls/include/mbedtls/sha256.h +200 -0
- package/vendor/mbedtls/include/mbedtls/sha3.h +172 -0
- package/vendor/mbedtls/include/mbedtls/sha512.h +208 -0
- package/vendor/mbedtls/include/mbedtls/ssl.h +5887 -0
- package/vendor/mbedtls/include/mbedtls/ssl_cache.h +187 -0
- package/vendor/mbedtls/include/mbedtls/ssl_ciphersuites.h +482 -0
- package/vendor/mbedtls/include/mbedtls/ssl_cookie.h +106 -0
- package/vendor/mbedtls/include/mbedtls/ssl_ticket.h +199 -0
- package/vendor/mbedtls/include/mbedtls/threading.h +167 -0
- package/vendor/mbedtls/include/mbedtls/timing.h +94 -0
- package/vendor/mbedtls/include/mbedtls/version.h +78 -0
- package/vendor/mbedtls/include/mbedtls/x509.h +500 -0
- package/vendor/mbedtls/include/mbedtls/x509_crl.h +184 -0
- package/vendor/mbedtls/include/mbedtls/x509_crt.h +1208 -0
- package/vendor/mbedtls/include/mbedtls/x509_csr.h +382 -0
- package/vendor/mbedtls/include/psa/build_info.h +20 -0
- package/vendor/mbedtls/include/psa/crypto.h +4998 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_auto_enabled.h +31 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_config_dependencies.h +51 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_config_key_pair_types.h +101 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_config_synonyms.h +49 -0
- package/vendor/mbedtls/include/psa/crypto_builtin_composites.h +214 -0
- package/vendor/mbedtls/include/psa/crypto_builtin_key_derivation.h +118 -0
- package/vendor/mbedtls/include/psa/crypto_builtin_primitives.h +114 -0
- package/vendor/mbedtls/include/psa/crypto_compat.h +230 -0
- package/vendor/mbedtls/include/psa/crypto_config.h +145 -0
- package/vendor/mbedtls/include/psa/crypto_driver_common.h +44 -0
- package/vendor/mbedtls/include/psa/crypto_driver_contexts_composites.h +151 -0
- package/vendor/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h +52 -0
- package/vendor/mbedtls/include/psa/crypto_driver_contexts_primitives.h +105 -0
- package/vendor/mbedtls/include/psa/crypto_extra.h +2145 -0
- package/vendor/mbedtls/include/psa/crypto_legacy.h +88 -0
- package/vendor/mbedtls/include/psa/crypto_platform.h +102 -0
- package/vendor/mbedtls/include/psa/crypto_se_driver.h +1383 -0
- package/vendor/mbedtls/include/psa/crypto_sizes.h +1319 -0
- package/vendor/mbedtls/include/psa/crypto_struct.h +527 -0
- package/vendor/mbedtls/include/psa/crypto_types.h +508 -0
- package/vendor/mbedtls/include/psa/crypto_values.h +2782 -0
- package/vendor/mbedtls/library/aes.c +2294 -0
- package/vendor/mbedtls/library/aesce.c +624 -0
- package/vendor/mbedtls/library/aesce.h +136 -0
- package/vendor/mbedtls/library/aesni.c +846 -0
- package/vendor/mbedtls/library/aesni.h +162 -0
- package/vendor/mbedtls/library/alignment.h +704 -0
- package/vendor/mbedtls/library/aria.c +969 -0
- package/vendor/mbedtls/library/asn1parse.c +468 -0
- package/vendor/mbedtls/library/asn1write.c +440 -0
- package/vendor/mbedtls/library/base64.c +322 -0
- package/vendor/mbedtls/library/base64_internal.h +45 -0
- package/vendor/mbedtls/library/bignum.c +2583 -0
- package/vendor/mbedtls/library/bignum_core.c +1240 -0
- package/vendor/mbedtls/library/bignum_core.h +872 -0
- package/vendor/mbedtls/library/bignum_core_invasive.h +38 -0
- package/vendor/mbedtls/library/bignum_internal.h +122 -0
- package/vendor/mbedtls/library/bignum_mod.c +394 -0
- package/vendor/mbedtls/library/bignum_mod.h +452 -0
- package/vendor/mbedtls/library/bignum_mod_raw.c +276 -0
- package/vendor/mbedtls/library/bignum_mod_raw.h +416 -0
- package/vendor/mbedtls/library/bignum_mod_raw_invasive.h +34 -0
- package/vendor/mbedtls/library/block_cipher.c +207 -0
- package/vendor/mbedtls/library/block_cipher_internal.h +99 -0
- package/vendor/mbedtls/library/bn_mul.h +1094 -0
- package/vendor/mbedtls/library/camellia.c +1058 -0
- package/vendor/mbedtls/library/ccm.c +777 -0
- package/vendor/mbedtls/library/chacha20.c +563 -0
- package/vendor/mbedtls/library/chacha20_internal.h +23 -0
- package/vendor/mbedtls/library/chachapoly.c +487 -0
- package/vendor/mbedtls/library/check_crypto_config.h +136 -0
- package/vendor/mbedtls/library/cipher.c +1712 -0
- package/vendor/mbedtls/library/cipher_invasive.h +28 -0
- package/vendor/mbedtls/library/cipher_wrap.c +2482 -0
- package/vendor/mbedtls/library/cipher_wrap.h +178 -0
- package/vendor/mbedtls/library/cmac.c +1067 -0
- package/vendor/mbedtls/library/common.h +487 -0
- package/vendor/mbedtls/library/constant_time.c +247 -0
- package/vendor/mbedtls/library/constant_time_impl.h +541 -0
- package/vendor/mbedtls/library/constant_time_internal.h +579 -0
- package/vendor/mbedtls/library/ctr.h +35 -0
- package/vendor/mbedtls/library/ctr_drbg.c +1016 -0
- package/vendor/mbedtls/library/debug.c +475 -0
- package/vendor/mbedtls/library/debug_internal.h +185 -0
- package/vendor/mbedtls/library/des.c +1042 -0
- package/vendor/mbedtls/library/dhm.c +700 -0
- package/vendor/mbedtls/library/ecdh.c +696 -0
- package/vendor/mbedtls/library/ecdsa.c +858 -0
- package/vendor/mbedtls/library/ecjpake.c +1216 -0
- package/vendor/mbedtls/library/ecp.c +3674 -0
- package/vendor/mbedtls/library/ecp_curves.c +6125 -0
- package/vendor/mbedtls/library/ecp_curves_new.c +9 -0
- package/vendor/mbedtls/library/ecp_internal_alt.h +287 -0
- package/vendor/mbedtls/library/ecp_invasive.h +305 -0
- package/vendor/mbedtls/library/entropy.c +680 -0
- package/vendor/mbedtls/library/entropy_poll.c +233 -0
- package/vendor/mbedtls/library/entropy_poll.h +64 -0
- package/vendor/mbedtls/library/error.c +878 -0
- package/vendor/mbedtls/library/gcm.c +1330 -0
- package/vendor/mbedtls/library/hkdf.c +161 -0
- package/vendor/mbedtls/library/hmac_drbg.c +633 -0
- package/vendor/mbedtls/library/lmots.c +789 -0
- package/vendor/mbedtls/library/lmots.h +288 -0
- package/vendor/mbedtls/library/lms.c +778 -0
- package/vendor/mbedtls/library/md.c +1108 -0
- package/vendor/mbedtls/library/md5.c +426 -0
- package/vendor/mbedtls/library/md_psa.h +26 -0
- package/vendor/mbedtls/library/md_wrap.h +46 -0
- package/vendor/mbedtls/library/memory_buffer_alloc.c +751 -0
- package/vendor/mbedtls/library/mps_common.h +181 -0
- package/vendor/mbedtls/library/mps_error.h +89 -0
- package/vendor/mbedtls/library/mps_reader.c +538 -0
- package/vendor/mbedtls/library/mps_reader.h +366 -0
- package/vendor/mbedtls/library/mps_trace.c +112 -0
- package/vendor/mbedtls/library/mps_trace.h +154 -0
- package/vendor/mbedtls/library/net_sockets.c +694 -0
- package/vendor/mbedtls/library/nist_kw.c +729 -0
- package/vendor/mbedtls/library/oid.c +1166 -0
- package/vendor/mbedtls/library/padlock.c +157 -0
- package/vendor/mbedtls/library/padlock.h +111 -0
- package/vendor/mbedtls/library/pem.c +554 -0
- package/vendor/mbedtls/library/pk.c +1602 -0
- package/vendor/mbedtls/library/pk_ecc.c +261 -0
- package/vendor/mbedtls/library/pk_internal.h +241 -0
- package/vendor/mbedtls/library/pk_wrap.c +1618 -0
- package/vendor/mbedtls/library/pk_wrap.h +138 -0
- package/vendor/mbedtls/library/pkcs12.c +437 -0
- package/vendor/mbedtls/library/pkcs5.c +500 -0
- package/vendor/mbedtls/library/pkcs7.c +787 -0
- package/vendor/mbedtls/library/pkparse.c +1392 -0
- package/vendor/mbedtls/library/pkwrite.c +631 -0
- package/vendor/mbedtls/library/pkwrite.h +121 -0
- package/vendor/mbedtls/library/platform.c +402 -0
- package/vendor/mbedtls/library/platform_util.c +258 -0
- package/vendor/mbedtls/library/poly1305.c +492 -0
- package/vendor/mbedtls/library/psa_crypto.c +9532 -0
- package/vendor/mbedtls/library/psa_crypto_aead.c +646 -0
- package/vendor/mbedtls/library/psa_crypto_aead.h +499 -0
- package/vendor/mbedtls/library/psa_crypto_cipher.c +747 -0
- package/vendor/mbedtls/library/psa_crypto_cipher.h +316 -0
- package/vendor/mbedtls/library/psa_crypto_client.c +22 -0
- package/vendor/mbedtls/library/psa_crypto_core.h +983 -0
- package/vendor/mbedtls/library/psa_crypto_core_common.h +52 -0
- package/vendor/mbedtls/library/psa_crypto_driver_wrappers.h +2896 -0
- package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.c +256 -0
- package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.h +31 -0
- package/vendor/mbedtls/library/psa_crypto_ecp.c +594 -0
- package/vendor/mbedtls/library/psa_crypto_ecp.h +267 -0
- package/vendor/mbedtls/library/psa_crypto_ffdh.c +361 -0
- package/vendor/mbedtls/library/psa_crypto_ffdh.h +131 -0
- package/vendor/mbedtls/library/psa_crypto_hash.c +470 -0
- package/vendor/mbedtls/library/psa_crypto_hash.h +211 -0
- package/vendor/mbedtls/library/psa_crypto_invasive.h +92 -0
- package/vendor/mbedtls/library/psa_crypto_its.h +131 -0
- package/vendor/mbedtls/library/psa_crypto_mac.c +505 -0
- package/vendor/mbedtls/library/psa_crypto_mac.h +264 -0
- package/vendor/mbedtls/library/psa_crypto_pake.c +571 -0
- package/vendor/mbedtls/library/psa_crypto_pake.h +159 -0
- package/vendor/mbedtls/library/psa_crypto_random.c +181 -0
- package/vendor/mbedtls/library/psa_crypto_random.h +72 -0
- package/vendor/mbedtls/library/psa_crypto_random_impl.h +200 -0
- package/vendor/mbedtls/library/psa_crypto_rsa.c +714 -0
- package/vendor/mbedtls/library/psa_crypto_rsa.h +321 -0
- package/vendor/mbedtls/library/psa_crypto_se.c +373 -0
- package/vendor/mbedtls/library/psa_crypto_se.h +192 -0
- package/vendor/mbedtls/library/psa_crypto_slot_management.c +1137 -0
- package/vendor/mbedtls/library/psa_crypto_slot_management.h +344 -0
- package/vendor/mbedtls/library/psa_crypto_storage.c +481 -0
- package/vendor/mbedtls/library/psa_crypto_storage.h +392 -0
- package/vendor/mbedtls/library/psa_its_file.c +254 -0
- package/vendor/mbedtls/library/psa_util.c +614 -0
- package/vendor/mbedtls/library/psa_util_internal.h +100 -0
- package/vendor/mbedtls/library/ripemd160.c +490 -0
- package/vendor/mbedtls/library/rsa.c +3121 -0
- package/vendor/mbedtls/library/rsa_alt_helpers.c +455 -0
- package/vendor/mbedtls/library/rsa_alt_helpers.h +209 -0
- package/vendor/mbedtls/library/rsa_internal.h +188 -0
- package/vendor/mbedtls/library/sha1.c +480 -0
- package/vendor/mbedtls/library/sha256.c +983 -0
- package/vendor/mbedtls/library/sha3.c +721 -0
- package/vendor/mbedtls/library/sha512.c +1115 -0
- package/vendor/mbedtls/library/ssl_cache.c +410 -0
- package/vendor/mbedtls/library/ssl_ciphersuites.c +2050 -0
- package/vendor/mbedtls/library/ssl_ciphersuites_internal.h +154 -0
- package/vendor/mbedtls/library/ssl_client.c +1023 -0
- package/vendor/mbedtls/library/ssl_client.h +22 -0
- package/vendor/mbedtls/library/ssl_cookie.c +384 -0
- package/vendor/mbedtls/library/ssl_debug_helpers.h +85 -0
- package/vendor/mbedtls/library/ssl_debug_helpers_generated.c +251 -0
- package/vendor/mbedtls/library/ssl_misc.h +3198 -0
- package/vendor/mbedtls/library/ssl_msg.c +6619 -0
- package/vendor/mbedtls/library/ssl_ticket.c +556 -0
- package/vendor/mbedtls/library/ssl_tls.c +10234 -0
- package/vendor/mbedtls/library/ssl_tls12_client.c +3688 -0
- package/vendor/mbedtls/library/ssl_tls12_server.c +4311 -0
- package/vendor/mbedtls/library/ssl_tls13_client.c +3208 -0
- package/vendor/mbedtls/library/ssl_tls13_generic.c +1793 -0
- package/vendor/mbedtls/library/ssl_tls13_invasive.h +23 -0
- package/vendor/mbedtls/library/ssl_tls13_keys.c +1918 -0
- package/vendor/mbedtls/library/ssl_tls13_keys.h +668 -0
- package/vendor/mbedtls/library/ssl_tls13_server.c +3624 -0
- package/vendor/mbedtls/library/threading.c +193 -0
- package/vendor/mbedtls/library/threading_internal.h +28 -0
- package/vendor/mbedtls/library/timing.c +152 -0
- package/vendor/mbedtls/library/version.c +32 -0
- package/vendor/mbedtls/library/version_features.c +856 -0
- package/vendor/mbedtls/library/x509.c +1776 -0
- package/vendor/mbedtls/library/x509_create.c +570 -0
- package/vendor/mbedtls/library/x509_crl.c +708 -0
- package/vendor/mbedtls/library/x509_crt.c +3311 -0
- package/vendor/mbedtls/library/x509_csr.c +648 -0
- package/vendor/mbedtls/library/x509_internal.h +101 -0
- package/vendor/mbedtls/library/x509write.c +174 -0
- package/vendor/mbedtls/library/x509write_crt.c +688 -0
- package/vendor/mbedtls/library/x509write_csr.c +336 -0
- package/vendor/quickjs-ng/CMakeLists.txt +566 -0
- package/vendor/quickjs-ng/LICENSE +24 -0
- package/vendor/quickjs-ng/README.md +24 -0
- package/vendor/quickjs-ng/api-test.c +1195 -0
- package/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
- package/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
- package/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
- package/vendor/quickjs-ng/cutils.h +1998 -0
- package/vendor/quickjs-ng/dtoa.c +1619 -0
- package/vendor/quickjs-ng/dtoa.h +87 -0
- package/vendor/quickjs-ng/gen/function_source.c +81 -0
- package/vendor/quickjs-ng/gen/hello.c +53 -0
- package/vendor/quickjs-ng/gen/hello_module.c +106 -0
- package/vendor/quickjs-ng/gen/repl.c +3036 -0
- package/vendor/quickjs-ng/gen/standalone.c +323 -0
- package/vendor/quickjs-ng/gen/test_fib.c +81 -0
- package/vendor/quickjs-ng/libregexp-opcode.h +73 -0
- package/vendor/quickjs-ng/libregexp.c +3474 -0
- package/vendor/quickjs-ng/libregexp.h +101 -0
- package/vendor/quickjs-ng/libunicode-table.h +5173 -0
- package/vendor/quickjs-ng/libunicode.c +2069 -0
- package/vendor/quickjs-ng/libunicode.h +172 -0
- package/vendor/quickjs-ng/list.h +107 -0
- package/vendor/quickjs-ng/lre-test.c +52 -0
- package/vendor/quickjs-ng/qjs.c +762 -0
- package/vendor/quickjs-ng/qjsc.c +673 -0
- package/vendor/quickjs-ng/quickjs-atom.h +280 -0
- package/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
- package/vendor/quickjs-ng/quickjs-libc.c +5037 -0
- package/vendor/quickjs-ng/quickjs-libc.h +87 -0
- package/vendor/quickjs-ng/quickjs-opcode.h +377 -0
- package/vendor/quickjs-ng/quickjs.c +64041 -0
- package/vendor/quickjs-ng/quickjs.h +1447 -0
- package/vendor/quickjs-ng/run-test262.c +2374 -0
- package/vendor/quickjs-ng/unicode_gen.c +3121 -0
- package/vendor/quickjs-ng/unicode_gen_def.h +310 -0
- package/vendor/ryu/LICENSE-Boost +23 -0
- package/vendor/ryu/common.h +114 -0
- package/vendor/ryu/d2s.c +509 -0
- package/vendor/ryu/d2s_full_table.h +367 -0
- package/vendor/ryu/d2s_intrinsics.h +357 -0
- package/vendor/ryu/d2s_small_table.h +186 -0
- package/vendor/ryu/digit_table.h +35 -0
- package/vendor/ryu/ryu.h +46 -0
- package/vendor/zlib/LICENSE +22 -0
- package/vendor/zlib/adler32.c +164 -0
- package/vendor/zlib/compress.c +75 -0
- package/vendor/zlib/crc32.c +1049 -0
- package/vendor/zlib/crc32.h +9446 -0
- package/vendor/zlib/deflate.c +2139 -0
- package/vendor/zlib/deflate.h +377 -0
- package/vendor/zlib/gzclose.c +23 -0
- package/vendor/zlib/gzguts.h +214 -0
- package/vendor/zlib/gzlib.c +582 -0
- package/vendor/zlib/gzread.c +602 -0
- package/vendor/zlib/gzwrite.c +631 -0
- package/vendor/zlib/infback.c +628 -0
- package/vendor/zlib/inffast.c +320 -0
- package/vendor/zlib/inffast.h +11 -0
- package/vendor/zlib/inffixed.h +94 -0
- package/vendor/zlib/inflate.c +1526 -0
- package/vendor/zlib/inflate.h +126 -0
- package/vendor/zlib/inftrees.c +299 -0
- package/vendor/zlib/inftrees.h +62 -0
- package/vendor/zlib/trees.c +1117 -0
- package/vendor/zlib/trees.h +128 -0
- package/vendor/zlib/uncompr.c +85 -0
- package/vendor/zlib/zconf.h +543 -0
- package/vendor/zlib/zlib.h +1938 -0
- package/vendor/zlib/zutil.c +299 -0
- package/vendor/zlib/zutil.h +254 -0
- package/README.md +0 -3
- package/index.js +0 -2
package/src/scr_watch.c
ADDED
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
/* fs.watch — the OPTIONAL file-watching half of the event loop: FSWatcher
|
|
2
|
+
* handles over the unit's own kqueue (EVFILT_VNODE on an O_EVTONLY fd).
|
|
3
|
+
* This translation unit links ONLY into binaries whose IR uses fs.watch
|
|
4
|
+
* (moduleUsesFsWatch — the scr_events/scr_net gating precedent), and the
|
|
5
|
+
* emitted main calls scr_watch_install() before %main, which points the
|
|
6
|
+
* loop's nullable watch hooks (scr_async.c) here. Watch-free programs pay
|
|
7
|
+
* zero bytes and keep their exact link line.
|
|
8
|
+
*
|
|
9
|
+
* Semantics, matched against Node on macOS and pinned by corpus:
|
|
10
|
+
* - fs.watch(path, cb) THROWS Node's fs error synchronously when the path
|
|
11
|
+
* cannot be opened ("ENOENT: no such file or directory, watch 'x'" —
|
|
12
|
+
* the portless polling-fallback catch shape).
|
|
13
|
+
* - The callback fires with "change" (NOTE_WRITE/EXTEND/ATTRIB) or
|
|
14
|
+
* "rename" (NOTE_RENAME/DELETE/REVOKE — rename wins when a drain
|
|
15
|
+
* coalesces both, libuv's precedence).
|
|
16
|
+
* - An open watcher KEEPS THE LOOP ALIVE until close() (Node's persistent
|
|
17
|
+
* default; unref has no lowering — nothing exercises it).
|
|
18
|
+
* - close() is idempotent: the fd closes (dropping its kqueue filter),
|
|
19
|
+
* listeners release, nothing fires again.
|
|
20
|
+
*
|
|
21
|
+
* Platform honesty: kqueue watches the INODE behind the opened fd, not
|
|
22
|
+
* the name — the same stance as libuv's kqueue backend. A
|
|
23
|
+
* rewrite-in-place (writeFileSync truncate, append) delivers "change"
|
|
24
|
+
* reliably. A replace-by-rename delivers ONE "rename" for the old inode,
|
|
25
|
+
* after which this unit REOPENS the path best-effort: when a new file
|
|
26
|
+
* took the name (the atomic-rewrite idiom), watching continues on the
|
|
27
|
+
* new inode; when the name is gone, the watcher stays registered but
|
|
28
|
+
* silent (Node's kqueue backend goes silent the same way — its FSEvents
|
|
29
|
+
* backend on macOS would keep reporting, a documented divergence).
|
|
30
|
+
*
|
|
31
|
+
* The Linux arm is inotify, matched against Linux Node (the differential
|
|
32
|
+
* container's oracle — probed, not assumed): one inotify fd for the
|
|
33
|
+
* unit, one wd per watcher, libuv's exact event mapping — a mask with
|
|
34
|
+
* IN_ATTRIB or IN_MODIFY fires "change", ANY other delivered mask fires
|
|
35
|
+
* "rename", including IN_DELETE_SELF and the trailing IN_IGNORED (Linux
|
|
36
|
+
* Node really does fire two 'rename's for an unlink, and a leading
|
|
37
|
+
* 'change' for the link-count IN_ATTRIB). After IN_IGNORED the wd is
|
|
38
|
+
* dead and the watcher goes silent but stays open (holds the loop) until
|
|
39
|
+
* close() — Node does NOT reopen on Linux, so neither does this arm; the
|
|
40
|
+
* kqueue reopen dance is macOS-only, exactly like libuv. The wd → watcher
|
|
41
|
+
* route trusts the kernel's cyclic wd allocation (idr_alloc_cyclic): a
|
|
42
|
+
* close()-queued IN_IGNORED can never collide with a freshly issued wd.
|
|
43
|
+
*
|
|
44
|
+
* The Windows arm is ReadDirectoryChangesW (see the SCR_HAVE_RDCW block
|
|
45
|
+
* below): directory-handle watching by NAME, so replace-by-rename keeps
|
|
46
|
+
* delivering without any reopen dance — Node-on-Windows's own stance.
|
|
47
|
+
*
|
|
48
|
+
* Event COALESCING is delivery-granular everywhere: one drain pass may
|
|
49
|
+
* merge what Node reports as two events — corpus programs observe "fired
|
|
50
|
+
* at least once", never exact counts. */
|
|
51
|
+
#define _XOPEN_SOURCE 700
|
|
52
|
+
#define _DARWIN_C_SOURCE 1
|
|
53
|
+
#include "scr_runtime.h"
|
|
54
|
+
|
|
55
|
+
#include <errno.h>
|
|
56
|
+
#include <fcntl.h>
|
|
57
|
+
#include <stdio.h>
|
|
58
|
+
#include <stdlib.h>
|
|
59
|
+
#include <string.h>
|
|
60
|
+
#include <unistd.h>
|
|
61
|
+
|
|
62
|
+
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
|
|
63
|
+
defined(__OpenBSD__) || defined(__DragonFly__)
|
|
64
|
+
#define SCR_HAVE_KQUEUE 1
|
|
65
|
+
#include <sys/event.h>
|
|
66
|
+
#elif defined(__linux__)
|
|
67
|
+
#define SCR_HAVE_INOTIFY 1
|
|
68
|
+
#include <sys/inotify.h>
|
|
69
|
+
#elif defined(_WIN32)
|
|
70
|
+
/* The Windows arm is ReadDirectoryChangesW, libuv's exact shape: a FILE
|
|
71
|
+
* watch opens its PARENT directory and filters deliveries by basename, a
|
|
72
|
+
* DIRECTORY watch opens the path itself (non-recursive, fs.watch's
|
|
73
|
+
* default); one overlapped read per watcher is outstanding at a time,
|
|
74
|
+
* its manual-reset event polled at dispatch (the loop's win32 idle sleep
|
|
75
|
+
* caps while watchers pend — scr_async.c). Action mapping matches libuv:
|
|
76
|
+
* FILE_ACTION_MODIFIED fires "change", every other action (added/
|
|
77
|
+
* removed/renamed either direction) fires "rename". Directory-handle
|
|
78
|
+
* watching survives replace-by-rename without the kqueue reopen dance —
|
|
79
|
+
* the NAME is watched, not the inode, which is Node-on-Windows's own
|
|
80
|
+
* stance. */
|
|
81
|
+
#define SCR_HAVE_RDCW 1
|
|
82
|
+
#include <stdalign.h>
|
|
83
|
+
#include <windows.h>
|
|
84
|
+
#endif
|
|
85
|
+
|
|
86
|
+
#ifndef O_EVTONLY
|
|
87
|
+
#define O_EVTONLY O_RDONLY /* non-macOS: a plain read fd watches fine */
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
static void scr_watch_oom(void) {
|
|
91
|
+
fputs("scriptc: out of memory\n", stderr);
|
|
92
|
+
abort();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
typedef struct {
|
|
96
|
+
ScrClosure *cb; /* owned */
|
|
97
|
+
ScrWatchFn fn; /* adapter: event name borrowed */
|
|
98
|
+
} ScrWatchL;
|
|
99
|
+
|
|
100
|
+
struct ScrWatcher {
|
|
101
|
+
size_t rc;
|
|
102
|
+
int fd; /* -1 once closed, or after a failed reopen (silent) */
|
|
103
|
+
#ifdef SCR_HAVE_INOTIFY
|
|
104
|
+
int wd; /* the inotify watch descriptor; -1 once dead (IN_IGNORED
|
|
105
|
+
* arrived or close() removed it) */
|
|
106
|
+
#endif
|
|
107
|
+
#ifdef SCR_HAVE_RDCW
|
|
108
|
+
HANDLE dh; /* the watched directory handle; INVALID once closed or
|
|
109
|
+
* silent (a failed reissue) */
|
|
110
|
+
OVERLAPPED ovl; /* the one outstanding ReadDirectoryChangesW; hEvent is
|
|
111
|
+
* a manual-reset event polled at dispatch */
|
|
112
|
+
wchar_t *filter; /* file watches: the watched basename (UTF-16, ordinal
|
|
113
|
+
* case-insensitive compare); NULL for directory watches */
|
|
114
|
+
bool inflight; /* a read is outstanding (ovl/buf are the kernel's) */
|
|
115
|
+
alignas(DWORD) char buf[4096]; /* FILE_NOTIFY_INFORMATION entries */
|
|
116
|
+
#endif
|
|
117
|
+
bool closed; /* close() called: off the liveness count, listeners gone */
|
|
118
|
+
ScrStr *path; /* the watched path — the reopen-after-rename target */
|
|
119
|
+
ScrWatchL *ls;
|
|
120
|
+
size_t n, cap;
|
|
121
|
+
struct ScrWatcher *next; /* the open-watcher registry (+1 each) */
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
static ScrWatcher *scr_watchers = NULL;
|
|
125
|
+
static size_t scr_watchers_open = 0; /* liveness: open (unclosed) watchers */
|
|
126
|
+
|
|
127
|
+
#ifdef SCR_HAVE_KQUEUE
|
|
128
|
+
static int scr_watch_kq = -1; /* created with the first watch; lives forever */
|
|
129
|
+
|
|
130
|
+
/* Arms the vnode filter for a watcher's current fd. EV_CLEAR: state resets
|
|
131
|
+
* at delivery, so an unserviced event never busy-spins the idle poll (the
|
|
132
|
+
* dispatch drain is the single consumer). */
|
|
133
|
+
static bool scr_watch_arm(ScrWatcher *w) {
|
|
134
|
+
if (scr_watch_kq < 0) {
|
|
135
|
+
scr_watch_kq = kqueue();
|
|
136
|
+
if (scr_watch_kq < 0) return false;
|
|
137
|
+
}
|
|
138
|
+
struct kevent ev;
|
|
139
|
+
EV_SET(&ev, (uintptr_t)w->fd, EVFILT_VNODE, EV_ADD | EV_CLEAR,
|
|
140
|
+
NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB | NOTE_RENAME | NOTE_DELETE | NOTE_REVOKE,
|
|
141
|
+
0, w);
|
|
142
|
+
struct timespec zero = {0, 0};
|
|
143
|
+
return kevent(scr_watch_kq, &ev, 1, NULL, 0, &zero) == 0;
|
|
144
|
+
}
|
|
145
|
+
#endif
|
|
146
|
+
|
|
147
|
+
#ifdef SCR_HAVE_INOTIFY
|
|
148
|
+
static int scr_watch_ino = -1; /* created with the first watch; lives forever */
|
|
149
|
+
|
|
150
|
+
/* libuv's subscription mask: name-level events for directory watches,
|
|
151
|
+
* self events for the file case, IN_IGNORED arriving for free. */
|
|
152
|
+
#define SCR_WATCH_IN_MASK \
|
|
153
|
+
(IN_ATTRIB | IN_CREATE | IN_MODIFY | IN_DELETE | IN_DELETE_SELF | \
|
|
154
|
+
IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVED_TO)
|
|
155
|
+
|
|
156
|
+
static ScrWatcher *scr_watch_by_wd(int wd) {
|
|
157
|
+
if (wd < 0) return NULL;
|
|
158
|
+
for (ScrWatcher *w = scr_watchers; w != NULL; w = w->next) {
|
|
159
|
+
if (!w->closed && w->wd == wd) return w;
|
|
160
|
+
}
|
|
161
|
+
return NULL;
|
|
162
|
+
}
|
|
163
|
+
#endif
|
|
164
|
+
|
|
165
|
+
#ifdef SCR_HAVE_RDCW
|
|
166
|
+
static wchar_t *scr_watch_widen(const char *s) {
|
|
167
|
+
int n = MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0);
|
|
168
|
+
if (n <= 0) return NULL;
|
|
169
|
+
wchar_t *w = malloc((size_t)n * sizeof *w);
|
|
170
|
+
if (!w) scr_watch_oom();
|
|
171
|
+
MultiByteToWideChar(CP_UTF8, 0, s, -1, w, n);
|
|
172
|
+
return w;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* Issues the next overlapped read. False leaves the watcher SILENT (the
|
|
176
|
+
* kqueue arm's exhaustion stance): open, holding the loop, never firing. */
|
|
177
|
+
static bool scr_watch_issue(ScrWatcher *w) {
|
|
178
|
+
ResetEvent(w->ovl.hEvent);
|
|
179
|
+
if (!ReadDirectoryChangesW(w->dh, w->buf, (DWORD)sizeof w->buf, FALSE,
|
|
180
|
+
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME |
|
|
181
|
+
FILE_NOTIFY_CHANGE_ATTRIBUTES | FILE_NOTIFY_CHANGE_SIZE |
|
|
182
|
+
FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_CREATION |
|
|
183
|
+
FILE_NOTIFY_CHANGE_SECURITY,
|
|
184
|
+
NULL, &w->ovl, NULL)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
w->inflight = true;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/* Tears down the win32 backend state — close(), the leak path in
|
|
192
|
+
* release(), and the atexit cleanup all funnel here; idempotent. */
|
|
193
|
+
static void scr_watch_backend_drop(ScrWatcher *w) {
|
|
194
|
+
if (w->dh != INVALID_HANDLE_VALUE) {
|
|
195
|
+
CancelIo(w->dh); /* the queued completion dies with the handle */
|
|
196
|
+
CloseHandle(w->dh);
|
|
197
|
+
w->dh = INVALID_HANDLE_VALUE;
|
|
198
|
+
}
|
|
199
|
+
if (w->ovl.hEvent != NULL) {
|
|
200
|
+
CloseHandle(w->ovl.hEvent);
|
|
201
|
+
w->ovl.hEvent = NULL;
|
|
202
|
+
}
|
|
203
|
+
w->inflight = false;
|
|
204
|
+
free(w->filter);
|
|
205
|
+
w->filter = NULL;
|
|
206
|
+
}
|
|
207
|
+
#endif
|
|
208
|
+
|
|
209
|
+
ScrWatcher *scr_watcher_retain(ScrWatcher *w) {
|
|
210
|
+
if (w->rc != SIZE_MAX) w->rc++;
|
|
211
|
+
return w;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static void scr_watcher_drop_listeners(ScrWatcher *w) {
|
|
215
|
+
for (size_t i = 0; i < w->n; i++) scr_closure_release(w->ls[i].cb);
|
|
216
|
+
free(w->ls);
|
|
217
|
+
w->ls = NULL;
|
|
218
|
+
w->n = w->cap = 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
void scr_watcher_release(ScrWatcher *w) {
|
|
222
|
+
if (!w || w->rc == SIZE_MAX) return;
|
|
223
|
+
if (--w->rc == 0) {
|
|
224
|
+
scr_watcher_drop_listeners(w); /* only reachable pre-close via leaks */
|
|
225
|
+
if (w->fd >= 0) close(w->fd);
|
|
226
|
+
#ifdef SCR_HAVE_RDCW
|
|
227
|
+
scr_watch_backend_drop(w);
|
|
228
|
+
#endif
|
|
229
|
+
scr_str_release(w->path);
|
|
230
|
+
free(w);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
void *scr_watcher_retain_v(void *p) { return scr_watcher_retain((ScrWatcher *)p); }
|
|
235
|
+
void scr_watcher_release_v(void *p) { scr_watcher_release((ScrWatcher *)p); }
|
|
236
|
+
|
|
237
|
+
/* fs.watch(path, cb?) — opens the path NOW (throwing Node's fs error on
|
|
238
|
+
* failure), registers the watcher with the loop, and arms the vnode
|
|
239
|
+
* filter. cb (nullable) moves in as the first listener. Result +1. */
|
|
240
|
+
ScrWatcher *scr_fs_watch(ScrStr *path, ScrClosure *cb /*moves, nullable*/, ScrWatchFn fn) {
|
|
241
|
+
#ifdef SCR_HAVE_INOTIFY
|
|
242
|
+
/* The wd IS the validation: Node's Linux throw comes straight from
|
|
243
|
+
* inotify_add_watch's errno, the same message shape as the open below. */
|
|
244
|
+
if (scr_watch_ino < 0) scr_watch_ino = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
|
245
|
+
int wd = scr_watch_ino >= 0 ? inotify_add_watch(scr_watch_ino, path->data, SCR_WATCH_IN_MASK)
|
|
246
|
+
: -1;
|
|
247
|
+
if (wd < 0) {
|
|
248
|
+
if (cb != NULL) scr_closure_release(cb);
|
|
249
|
+
scr_fs_throw(errno, "watch", path);
|
|
250
|
+
return NULL; /* exception pending */
|
|
251
|
+
}
|
|
252
|
+
#elif defined(SCR_HAVE_RDCW)
|
|
253
|
+
/* Existence is the validation (Node's win32 throw): a missing path is
|
|
254
|
+
* the synchronous ENOENT. A file watch then opens the PARENT directory
|
|
255
|
+
* and remembers the basename to filter deliveries by. */
|
|
256
|
+
wchar_t *wpath = scr_watch_widen(path->data);
|
|
257
|
+
DWORD attrs = wpath != NULL ? GetFileAttributesW(wpath) : INVALID_FILE_ATTRIBUTES;
|
|
258
|
+
if (attrs == INVALID_FILE_ATTRIBUTES) {
|
|
259
|
+
free(wpath);
|
|
260
|
+
if (cb != NULL) scr_closure_release(cb);
|
|
261
|
+
scr_fs_throw(ENOENT, "watch", path);
|
|
262
|
+
return NULL; /* exception pending */
|
|
263
|
+
}
|
|
264
|
+
wchar_t *wfilter = NULL;
|
|
265
|
+
if ((attrs & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
|
266
|
+
wchar_t *base = NULL;
|
|
267
|
+
for (wchar_t *p = wpath; *p != L'\0'; p++)
|
|
268
|
+
if (*p == L'\\' || *p == L'/') base = p;
|
|
269
|
+
if (base != NULL) {
|
|
270
|
+
wfilter = _wcsdup(base + 1);
|
|
271
|
+
if (wfilter == NULL) scr_watch_oom();
|
|
272
|
+
*base = L'\0'; /* wpath is now the parent directory */
|
|
273
|
+
} else {
|
|
274
|
+
wfilter = wpath; /* bare name: watch the cwd, filter by it */
|
|
275
|
+
wpath = _wcsdup(L".");
|
|
276
|
+
if (wpath == NULL) scr_watch_oom();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
HANDLE dh = CreateFileW(wpath, FILE_LIST_DIRECTORY,
|
|
280
|
+
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
|
|
281
|
+
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
|
|
282
|
+
NULL);
|
|
283
|
+
free(wpath);
|
|
284
|
+
if (dh == INVALID_HANDLE_VALUE) {
|
|
285
|
+
free(wfilter);
|
|
286
|
+
if (cb != NULL) scr_closure_release(cb);
|
|
287
|
+
scr_fs_throw(ENOENT, "watch", path);
|
|
288
|
+
return NULL; /* exception pending */
|
|
289
|
+
}
|
|
290
|
+
#else
|
|
291
|
+
int fd = open(path->data, O_EVTONLY | O_NONBLOCK | O_CLOEXEC);
|
|
292
|
+
if (fd < 0) {
|
|
293
|
+
if (cb != NULL) scr_closure_release(cb);
|
|
294
|
+
scr_fs_throw(errno, "watch", path);
|
|
295
|
+
return NULL; /* exception pending */
|
|
296
|
+
}
|
|
297
|
+
#endif
|
|
298
|
+
ScrWatcher *w = calloc(1, sizeof *w);
|
|
299
|
+
if (!w) scr_watch_oom();
|
|
300
|
+
w->rc = 1;
|
|
301
|
+
w->path = scr_str_retain(path);
|
|
302
|
+
if (cb != NULL) {
|
|
303
|
+
w->ls = malloc(sizeof *w->ls);
|
|
304
|
+
if (!w->ls) scr_watch_oom();
|
|
305
|
+
w->ls[0].cb = cb;
|
|
306
|
+
w->ls[0].fn = fn;
|
|
307
|
+
w->n = w->cap = 1;
|
|
308
|
+
}
|
|
309
|
+
#ifdef SCR_HAVE_INOTIFY
|
|
310
|
+
w->fd = -1; /* inotify holds the watch; there is no per-watcher fd */
|
|
311
|
+
w->wd = wd;
|
|
312
|
+
#elif defined(SCR_HAVE_KQUEUE)
|
|
313
|
+
w->fd = fd;
|
|
314
|
+
if (!scr_watch_arm(w)) {
|
|
315
|
+
/* Filter refused (kqueue exhaustion): the watcher exists but never
|
|
316
|
+
* fires — Node's kqueue backend surfaces this as a throw; the honest
|
|
317
|
+
* cheap stance here is silence plus liveness, and nothing real hits
|
|
318
|
+
* it. */
|
|
319
|
+
close(w->fd);
|
|
320
|
+
w->fd = -1;
|
|
321
|
+
}
|
|
322
|
+
#elif defined(SCR_HAVE_RDCW)
|
|
323
|
+
w->fd = -1;
|
|
324
|
+
w->dh = dh;
|
|
325
|
+
w->filter = wfilter;
|
|
326
|
+
w->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
327
|
+
if (w->ovl.hEvent == NULL || !scr_watch_issue(w)) {
|
|
328
|
+
/* the kqueue exhaustion stance: open, holding the loop, silent */
|
|
329
|
+
scr_watch_backend_drop(w);
|
|
330
|
+
}
|
|
331
|
+
#else
|
|
332
|
+
close(fd); /* no backend: open validated the path; no events exist */
|
|
333
|
+
w->fd = -1;
|
|
334
|
+
#endif
|
|
335
|
+
w->next = scr_watchers;
|
|
336
|
+
scr_watchers = scr_watcher_retain(w);
|
|
337
|
+
scr_watchers_open++;
|
|
338
|
+
return w;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* watcher.close() — idempotent: drops the filter (closing the fd deletes
|
|
342
|
+
* its knote AND its queued events), the listeners, and the liveness
|
|
343
|
+
* count. The registry's reference is NOT released here: a listener may
|
|
344
|
+
* close its own watcher while the dispatch drain still holds the pointer
|
|
345
|
+
* in its current event batch — the sweep between batches (and the atexit
|
|
346
|
+
* cleanup) unlinks closed watchers at safe points instead. */
|
|
347
|
+
void scr_watcher_close(ScrWatcher *w) {
|
|
348
|
+
if (w->closed) return;
|
|
349
|
+
w->closed = true;
|
|
350
|
+
#ifdef SCR_HAVE_INOTIFY
|
|
351
|
+
if (w->wd >= 0) {
|
|
352
|
+
/* The queued IN_IGNORED this rm produces finds no open watcher and is
|
|
353
|
+
* skipped; wd numbers are issued cyclically, so it cannot collide
|
|
354
|
+
* with a watch created afterwards. */
|
|
355
|
+
if (scr_watch_ino >= 0) (void)inotify_rm_watch(scr_watch_ino, w->wd);
|
|
356
|
+
w->wd = -1;
|
|
357
|
+
}
|
|
358
|
+
#endif
|
|
359
|
+
#ifdef SCR_HAVE_RDCW
|
|
360
|
+
scr_watch_backend_drop(w);
|
|
361
|
+
#endif
|
|
362
|
+
if (w->fd >= 0) {
|
|
363
|
+
close(w->fd);
|
|
364
|
+
w->fd = -1;
|
|
365
|
+
}
|
|
366
|
+
scr_watcher_drop_listeners(w);
|
|
367
|
+
scr_watchers_open--;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/* Unlinks and releases closed watchers — called only where no fetched
|
|
371
|
+
* event batch can still point at them. */
|
|
372
|
+
static void scr_watch_sweep(void) {
|
|
373
|
+
ScrWatcher **link = &scr_watchers;
|
|
374
|
+
while (*link) {
|
|
375
|
+
ScrWatcher *w = *link;
|
|
376
|
+
if (w->closed) {
|
|
377
|
+
*link = w->next;
|
|
378
|
+
w->next = NULL;
|
|
379
|
+
scr_watcher_release(w); /* the registry's reference */
|
|
380
|
+
} else {
|
|
381
|
+
link = &w->next;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/* The runtime-provided listener adapters. */
|
|
387
|
+
void scr_watch_thunk0(ScrClosure *cb, const char *event) {
|
|
388
|
+
(void)event;
|
|
389
|
+
((void (*)(ScrClosure *))cb->fn)(cb);
|
|
390
|
+
}
|
|
391
|
+
void scr_watch_thunk_event(ScrClosure *cb, const char *event) {
|
|
392
|
+
/* The listener owns its +1 param per the universal convention. */
|
|
393
|
+
ScrStr *e = scr_str_new(event, strlen(event));
|
|
394
|
+
((void (*)(ScrClosure *, ScrStr *))cb->fn)(cb, e);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/* Fires one watcher's listeners with the event name (snapshot — a
|
|
398
|
+
* listener closing the watcher mid-emit still finishes this delivery,
|
|
399
|
+
* and close() drops only the LIVE list). */
|
|
400
|
+
static void scr_watch_fire(ScrWatcher *w, const char *event) {
|
|
401
|
+
size_t n = w->n;
|
|
402
|
+
if (n == 0) return;
|
|
403
|
+
ScrWatchL *snap = malloc(n * sizeof *snap);
|
|
404
|
+
if (!snap) scr_watch_oom();
|
|
405
|
+
for (size_t i = 0; i < n; i++) {
|
|
406
|
+
snap[i] = w->ls[i];
|
|
407
|
+
scr_closure_retain(snap[i].cb);
|
|
408
|
+
}
|
|
409
|
+
for (size_t i = 0; i < n; i++) {
|
|
410
|
+
if (!scr_exc_pending()) snap[i].fn(snap[i].cb, event);
|
|
411
|
+
scr_closure_release(snap[i].cb);
|
|
412
|
+
}
|
|
413
|
+
free(snap);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/* ── the loop hooks (scr_async.c) ────────────────────────────────────── */
|
|
417
|
+
|
|
418
|
+
/* Liveness: every un-closed watcher holds the loop (Node's persistent
|
|
419
|
+
* default) — a silent (fd < 0) watcher included, exactly like Node's. */
|
|
420
|
+
static bool scr_watch_pending(void) { return scr_watchers_open > 0; }
|
|
421
|
+
|
|
422
|
+
static int scr_watch_pollfd(void) {
|
|
423
|
+
#ifdef SCR_HAVE_KQUEUE
|
|
424
|
+
return scr_watch_kq;
|
|
425
|
+
#elif defined(SCR_HAVE_INOTIFY)
|
|
426
|
+
return scr_watch_ino; /* readable while events pend, like a kqueue fd */
|
|
427
|
+
#else
|
|
428
|
+
return -1; /* win32: nothing pollable — the loop's capped sleep serves */
|
|
429
|
+
#endif
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
static void scr_watch_dispatch(void) {
|
|
433
|
+
#ifdef SCR_HAVE_KQUEUE
|
|
434
|
+
if (scr_watch_kq < 0) {
|
|
435
|
+
scr_watch_sweep();
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
for (;;) {
|
|
439
|
+
scr_watch_sweep();
|
|
440
|
+
struct kevent evs[64];
|
|
441
|
+
struct timespec zero = {0, 0};
|
|
442
|
+
int n = kevent(scr_watch_kq, NULL, 0, evs, 64, &zero);
|
|
443
|
+
if (n <= 0) return;
|
|
444
|
+
for (int i = 0; i < n; i++) {
|
|
445
|
+
ScrWatcher *w = (ScrWatcher *)evs[i].udata;
|
|
446
|
+
if (w == NULL || w->closed || w->fd < 0) continue;
|
|
447
|
+
uint32_t ff = evs[i].fflags;
|
|
448
|
+
bool rename = (ff & (NOTE_RENAME | NOTE_DELETE | NOTE_REVOKE)) != 0;
|
|
449
|
+
if (rename) {
|
|
450
|
+
/* The inode left the name: reopen best-effort so the atomic
|
|
451
|
+
* replace-by-rename idiom keeps delivering on the new file. The
|
|
452
|
+
* OLD fd closes first (its filter dies with it) — a coalesced
|
|
453
|
+
* change on the old inode is superseded by the rename. */
|
|
454
|
+
close(w->fd);
|
|
455
|
+
w->fd = open(w->path->data, O_EVTONLY | O_NONBLOCK | O_CLOEXEC);
|
|
456
|
+
if (w->fd >= 0 && !scr_watch_arm(w)) {
|
|
457
|
+
close(w->fd);
|
|
458
|
+
w->fd = -1;
|
|
459
|
+
}
|
|
460
|
+
scr_watch_fire(w, "rename");
|
|
461
|
+
} else if (ff & (NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB)) {
|
|
462
|
+
scr_watch_fire(w, "change");
|
|
463
|
+
}
|
|
464
|
+
if (scr_exc_pending()) return; /* the loop surfaces it */
|
|
465
|
+
}
|
|
466
|
+
if (scr_loop_has_ready()) return; /* microtasks interleave first */
|
|
467
|
+
}
|
|
468
|
+
#elif defined(SCR_HAVE_INOTIFY)
|
|
469
|
+
if (scr_watch_ino < 0) {
|
|
470
|
+
scr_watch_sweep();
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
for (;;) {
|
|
474
|
+
scr_watch_sweep();
|
|
475
|
+
char buf[4096] __attribute__((aligned(__alignof__(struct inotify_event))));
|
|
476
|
+
ssize_t n = read(scr_watch_ino, buf, sizeof buf);
|
|
477
|
+
if (n <= 0) return; /* EAGAIN/EINTR: the next turn retries */
|
|
478
|
+
for (char *p = buf; p < buf + n;) {
|
|
479
|
+
const struct inotify_event *e = (const struct inotify_event *)p;
|
|
480
|
+
p += sizeof *e + e->len;
|
|
481
|
+
ScrWatcher *w = scr_watch_by_wd(e->wd);
|
|
482
|
+
if (w == NULL) continue; /* closed, or a stale post-close IN_IGNORED */
|
|
483
|
+
/* libuv's mapping, probed against Linux Node: IN_ATTRIB/IN_MODIFY
|
|
484
|
+
* fire "change"; every other delivered mask — IN_DELETE_SELF,
|
|
485
|
+
* IN_MOVE_SELF, the name-level events, and IN_IGNORED itself —
|
|
486
|
+
* fires "rename". */
|
|
487
|
+
bool change = (e->mask & (IN_ATTRIB | IN_MODIFY)) != 0;
|
|
488
|
+
if (e->mask & IN_IGNORED) w->wd = -1; /* the kernel dropped the watch:
|
|
489
|
+
* silent (no reopen), like Node */
|
|
490
|
+
scr_watch_fire(w, change ? "change" : "rename");
|
|
491
|
+
if (scr_exc_pending()) return; /* the loop surfaces it */
|
|
492
|
+
}
|
|
493
|
+
if (scr_loop_has_ready()) return; /* microtasks interleave first */
|
|
494
|
+
}
|
|
495
|
+
#elif defined(SCR_HAVE_RDCW)
|
|
496
|
+
scr_watch_sweep();
|
|
497
|
+
for (ScrWatcher *w = scr_watchers; w != NULL; w = w->next) {
|
|
498
|
+
if (w->closed || w->dh == INVALID_HANDLE_VALUE || !w->inflight) continue;
|
|
499
|
+
if (WaitForSingleObject(w->ovl.hEvent, 0) != WAIT_OBJECT_0) continue;
|
|
500
|
+
DWORD bytes = 0;
|
|
501
|
+
BOOL ok = GetOverlappedResult(w->dh, &w->ovl, &bytes, FALSE);
|
|
502
|
+
w->inflight = false;
|
|
503
|
+
/* Deliver from THIS buffer before reissuing (the reissue hands buf
|
|
504
|
+
* back to the kernel). libuv's action mapping: MODIFIED is "change",
|
|
505
|
+
* everything else — added, removed, renamed either direction — is
|
|
506
|
+
* "rename". File watches filter by basename (ordinal,
|
|
507
|
+
* case-insensitive — NTFS name matching); zero bytes is the
|
|
508
|
+
* overflow notification, delivered as a filterless "rename" burst
|
|
509
|
+
* signal the same way libuv degrades. */
|
|
510
|
+
if (ok && bytes == 0) {
|
|
511
|
+
scr_watch_fire(w, "rename");
|
|
512
|
+
if (scr_exc_pending()) return;
|
|
513
|
+
} else if (ok) {
|
|
514
|
+
char *p = w->buf;
|
|
515
|
+
for (;;) {
|
|
516
|
+
FILE_NOTIFY_INFORMATION *e = (FILE_NOTIFY_INFORMATION *)p;
|
|
517
|
+
bool match =
|
|
518
|
+
w->filter == NULL ||
|
|
519
|
+
CompareStringOrdinal(e->FileName, (int)(e->FileNameLength / sizeof(WCHAR)),
|
|
520
|
+
w->filter, -1, TRUE) == CSTR_EQUAL;
|
|
521
|
+
if (match) {
|
|
522
|
+
scr_watch_fire(w, e->Action == FILE_ACTION_MODIFIED ? "change" : "rename");
|
|
523
|
+
if (scr_exc_pending()) return;
|
|
524
|
+
if (w->closed) break; /* a listener closed its own watcher */
|
|
525
|
+
}
|
|
526
|
+
if (e->NextEntryOffset == 0) break;
|
|
527
|
+
p += e->NextEntryOffset;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (!w->closed && w->dh != INVALID_HANDLE_VALUE && !scr_watch_issue(w)) {
|
|
531
|
+
scr_watch_backend_drop(w); /* reissue refused: silent, like kqueue exhaustion */
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
scr_watch_sweep();
|
|
535
|
+
#endif
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/* Exit-time registry cleanup (the events/net-unit precedent): watchers a
|
|
539
|
+
* program legitimately leaves open at exit release their listeners and
|
|
540
|
+
* registry references so the RC audit sees a clean heap. */
|
|
541
|
+
static void scr_watch_cleanup_atexit(void) {
|
|
542
|
+
while (scr_watchers) {
|
|
543
|
+
ScrWatcher *w = scr_watchers;
|
|
544
|
+
scr_watchers = w->next;
|
|
545
|
+
w->next = NULL;
|
|
546
|
+
if (!w->closed) {
|
|
547
|
+
w->closed = true;
|
|
548
|
+
scr_watchers_open--;
|
|
549
|
+
}
|
|
550
|
+
#ifdef SCR_HAVE_RDCW
|
|
551
|
+
scr_watch_backend_drop(w);
|
|
552
|
+
#endif
|
|
553
|
+
if (w->fd >= 0) {
|
|
554
|
+
close(w->fd);
|
|
555
|
+
w->fd = -1;
|
|
556
|
+
}
|
|
557
|
+
scr_watcher_drop_listeners(w);
|
|
558
|
+
scr_watcher_release(w);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
void scr_watch_install(void) {
|
|
563
|
+
static bool installed = false;
|
|
564
|
+
if (installed) return;
|
|
565
|
+
installed = true;
|
|
566
|
+
atexit(scr_watch_cleanup_atexit);
|
|
567
|
+
scr_loop_set_watch(&scr_watch_pending, &scr_watch_dispatch, &scr_watch_pollfd);
|
|
568
|
+
}
|