visaljs 0.0.0-stage → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (520) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/cli.js +8084 -0
  4. package/node/include/js_node.h +46 -0
  5. package/node/prelude/async_hooks.js +88 -0
  6. package/node/prelude/buffer.js +31 -0
  7. package/node/prelude/crypto.js +114 -0
  8. package/node/prelude/events.js +227 -0
  9. package/node/prelude/fs.js +79 -0
  10. package/node/prelude/http.js +536 -0
  11. package/node/prelude/http2.js +30 -0
  12. package/node/prelude/internal/crypto/asym.js +333 -0
  13. package/node/prelude/internal/crypto/cipher.js +205 -0
  14. package/node/prelude/internal/crypto/hash.js +137 -0
  15. package/node/prelude/internal/crypto/kdf.js +182 -0
  16. package/node/prelude/internal/crypto/keys.js +603 -0
  17. package/node/prelude/internal/crypto/random.js +118 -0
  18. package/node/prelude/internal/crypto/util.js +76 -0
  19. package/node/prelude/internal/errors.js +88 -0
  20. package/node/prelude/internal/querystring.js +105 -0
  21. package/node/prelude/module.js +53 -0
  22. package/node/prelude/net.js +51 -0
  23. package/node/prelude/os.js +129 -0
  24. package/node/prelude/path.js +257 -0
  25. package/node/prelude/process.js +21 -0
  26. package/node/prelude/querystring.js +469 -0
  27. package/node/prelude/stream.js +1327 -0
  28. package/node/prelude/stream_promises.js +7 -0
  29. package/node/prelude/stream_web.js +6 -0
  30. package/node/prelude/string_decoder.js +236 -0
  31. package/node/prelude/tty.js +18 -0
  32. package/node/prelude/url.js +1156 -0
  33. package/node/prelude/util.js +64 -0
  34. package/node/prelude/zlib.js +81 -0
  35. package/node/src/host_fs.c +126 -0
  36. package/node/src/host_http.c +486 -0
  37. package/node/src/host_os.c +505 -0
  38. package/node/src/host_sys.c +78 -0
  39. package/node/third_party/libuv/LICENSE +19 -0
  40. package/node/third_party/libuv/include/uv/aix.h +32 -0
  41. package/node/third_party/libuv/include/uv/bsd.h +34 -0
  42. package/node/third_party/libuv/include/uv/darwin.h +61 -0
  43. package/node/third_party/libuv/include/uv/errno.h +483 -0
  44. package/node/third_party/libuv/include/uv/linux.h +34 -0
  45. package/node/third_party/libuv/include/uv/os390.h +33 -0
  46. package/node/third_party/libuv/include/uv/posix.h +31 -0
  47. package/node/third_party/libuv/include/uv/sunos.h +44 -0
  48. package/node/third_party/libuv/include/uv/threadpool.h +37 -0
  49. package/node/third_party/libuv/include/uv/tree.h +521 -0
  50. package/node/third_party/libuv/include/uv/unix.h +512 -0
  51. package/node/third_party/libuv/include/uv/version.h +43 -0
  52. package/node/third_party/libuv/include/uv/win.h +698 -0
  53. package/node/third_party/libuv/include/uv.h +1990 -0
  54. package/node/third_party/libuv/src/fs-poll.c +290 -0
  55. package/node/third_party/libuv/src/heap-inl.h +245 -0
  56. package/node/third_party/libuv/src/idna.c +560 -0
  57. package/node/third_party/libuv/src/idna.h +31 -0
  58. package/node/third_party/libuv/src/inet.c +298 -0
  59. package/node/third_party/libuv/src/queue.h +90 -0
  60. package/node/third_party/libuv/src/random.c +123 -0
  61. package/node/third_party/libuv/src/strscpy.c +38 -0
  62. package/node/third_party/libuv/src/strscpy.h +39 -0
  63. package/node/third_party/libuv/src/strtok.c +52 -0
  64. package/node/third_party/libuv/src/strtok.h +27 -0
  65. package/node/third_party/libuv/src/thread-common.c +175 -0
  66. package/node/third_party/libuv/src/threadpool.c +419 -0
  67. package/node/third_party/libuv/src/timer.c +200 -0
  68. package/node/third_party/libuv/src/unix/async.c +418 -0
  69. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +164 -0
  70. package/node/third_party/libuv/src/unix/core.c +2104 -0
  71. package/node/third_party/libuv/src/unix/darwin-proctitle.c +176 -0
  72. package/node/third_party/libuv/src/unix/darwin-stub.h +97 -0
  73. package/node/third_party/libuv/src/unix/darwin-syscalls.h +17 -0
  74. package/node/third_party/libuv/src/unix/darwin.c +237 -0
  75. package/node/third_party/libuv/src/unix/dl.c +80 -0
  76. package/node/third_party/libuv/src/unix/fs.c +2303 -0
  77. package/node/third_party/libuv/src/unix/fsevents.c +906 -0
  78. package/node/third_party/libuv/src/unix/getaddrinfo.c +252 -0
  79. package/node/third_party/libuv/src/unix/getnameinfo.c +121 -0
  80. package/node/third_party/libuv/src/unix/internal.h +530 -0
  81. package/node/third_party/libuv/src/unix/kqueue.c +667 -0
  82. package/node/third_party/libuv/src/unix/linux.c +2761 -0
  83. package/node/third_party/libuv/src/unix/loop-watcher.c +68 -0
  84. package/node/third_party/libuv/src/unix/loop.c +240 -0
  85. package/node/third_party/libuv/src/unix/pipe.c +555 -0
  86. package/node/third_party/libuv/src/unix/poll.c +159 -0
  87. package/node/third_party/libuv/src/unix/process.c +1123 -0
  88. package/node/third_party/libuv/src/unix/procfs-exepath.c +45 -0
  89. package/node/third_party/libuv/src/unix/proctitle.c +157 -0
  90. package/node/third_party/libuv/src/unix/random-devurandom.c +93 -0
  91. package/node/third_party/libuv/src/unix/random-getentropy.c +57 -0
  92. package/node/third_party/libuv/src/unix/random-getrandom.c +86 -0
  93. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +99 -0
  94. package/node/third_party/libuv/src/unix/signal.c +581 -0
  95. package/node/third_party/libuv/src/unix/stream.c +1567 -0
  96. package/node/third_party/libuv/src/unix/tcp.c +673 -0
  97. package/node/third_party/libuv/src/unix/thread.c +975 -0
  98. package/node/third_party/libuv/src/unix/tty.c +510 -0
  99. package/node/third_party/libuv/src/unix/udp.c +1434 -0
  100. package/node/third_party/libuv/src/uv-common.c +1051 -0
  101. package/node/third_party/libuv/src/uv-common.h +474 -0
  102. package/node/third_party/libuv/src/uv-data-getter-setters.c +119 -0
  103. package/node/third_party/libuv/src/version.c +45 -0
  104. package/node/third_party/llhttp/LICENSE +22 -0
  105. package/node/third_party/llhttp/api.c +509 -0
  106. package/node/third_party/llhttp/http.c +170 -0
  107. package/node/third_party/llhttp/llhttp.c +10099 -0
  108. package/node/third_party/llhttp/llhttp.h +907 -0
  109. package/package.json +25 -4
  110. package/runtime/include/js_atoms.gen.h +68 -0
  111. package/runtime/include/js_atoms.h +54 -0
  112. package/runtime/include/js_bigint.h +93 -0
  113. package/runtime/include/js_buffer.h +79 -0
  114. package/runtime/include/js_builtins.h +168 -0
  115. package/runtime/include/js_console.h +58 -0
  116. package/runtime/include/js_convert.h +22 -0
  117. package/runtime/include/js_core.def +188 -0
  118. package/runtime/include/js_crypto.h +58 -0
  119. package/runtime/include/js_error.h +37 -0
  120. package/runtime/include/js_exception.h +65 -0
  121. package/runtime/include/js_function.h +167 -0
  122. package/runtime/include/js_gc.h +195 -0
  123. package/runtime/include/js_generator.h +96 -0
  124. package/runtime/include/js_host.h +19 -0
  125. package/runtime/include/js_jobs.h +84 -0
  126. package/runtime/include/js_module.h +16 -0
  127. package/runtime/include/js_object.h +384 -0
  128. package/runtime/include/js_ops.h +111 -0
  129. package/runtime/include/js_promise.h +45 -0
  130. package/runtime/include/js_regexp.h +25 -0
  131. package/runtime/include/js_runtime.h +30 -0
  132. package/runtime/include/js_symbol.h +62 -0
  133. package/runtime/include/js_web.h +110 -0
  134. package/runtime/include/jscell.h +48 -0
  135. package/runtime/include/jscontext.h +240 -0
  136. package/runtime/include/jsnum.h +42 -0
  137. package/runtime/include/jsstring.h +161 -0
  138. package/runtime/include/jsvalue.h +142 -0
  139. package/runtime/src/arguments.c +115 -0
  140. package/runtime/src/array.c +1145 -0
  141. package/runtime/src/arraybuffer.c +608 -0
  142. package/runtime/src/async_iter.c +479 -0
  143. package/runtime/src/atoms.c +157 -0
  144. package/runtime/src/base64.c +107 -0
  145. package/runtime/src/bigint.c +1189 -0
  146. package/runtime/src/blob.c +371 -0
  147. package/runtime/src/buffer.c +1357 -0
  148. package/runtime/src/builtin_table.c +100 -0
  149. package/runtime/src/builtins.c +987 -0
  150. package/runtime/src/builtins_util.h +53 -0
  151. package/runtime/src/collections.c +912 -0
  152. package/runtime/src/components.c +28 -0
  153. package/runtime/src/console.c +637 -0
  154. package/runtime/src/convert.c +82 -0
  155. package/runtime/src/core_all.c +21 -0
  156. package/runtime/src/crypto.c +116 -0
  157. package/runtime/src/crypto_asym.c +644 -0
  158. package/runtime/src/crypto_cipher.c +671 -0
  159. package/runtime/src/crypto_hash.c +260 -0
  160. package/runtime/src/crypto_host.c +414 -0
  161. package/runtime/src/crypto_internal.h +304 -0
  162. package/runtime/src/crypto_kdf.c +143 -0
  163. package/runtime/src/crypto_key.c +171 -0
  164. package/runtime/src/crypto_pkey.c +794 -0
  165. package/runtime/src/crypto_subtle.c +1675 -0
  166. package/runtime/src/date.c +940 -0
  167. package/runtime/src/domexception.c +169 -0
  168. package/runtime/src/elements.c +312 -0
  169. package/runtime/src/elements.h +45 -0
  170. package/runtime/src/encoding.c +485 -0
  171. package/runtime/src/error.c +297 -0
  172. package/runtime/src/events.c +793 -0
  173. package/runtime/src/exception.c +56 -0
  174. package/runtime/src/fetch.c +772 -0
  175. package/runtime/src/function.c +530 -0
  176. package/runtime/src/gc.c +803 -0
  177. package/runtime/src/generator.c +218 -0
  178. package/runtime/src/global.c +119 -0
  179. package/runtime/src/headers.c +557 -0
  180. package/runtime/src/inspect.c +1792 -0
  181. package/runtime/src/internal.h +80 -0
  182. package/runtime/src/iterate.c +94 -0
  183. package/runtime/src/iterator.c +409 -0
  184. package/runtime/src/jobs.c +337 -0
  185. package/runtime/src/jsnum.c +353 -0
  186. package/runtime/src/json.c +1028 -0
  187. package/runtime/src/math.c +243 -0
  188. package/runtime/src/module.c +336 -0
  189. package/runtime/src/number.c +176 -0
  190. package/runtime/src/object.c +1265 -0
  191. package/runtime/src/ops.c +322 -0
  192. package/runtime/src/os.c +196 -0
  193. package/runtime/src/os.h +29 -0
  194. package/runtime/src/process.c +432 -0
  195. package/runtime/src/promise.c +721 -0
  196. package/runtime/src/proxy.c +570 -0
  197. package/runtime/src/reflect.c +194 -0
  198. package/runtime/src/regexp.c +1141 -0
  199. package/runtime/src/regexp_anchor.h +34 -0
  200. package/runtime/src/regexp_message.h +32 -0
  201. package/runtime/src/shape.c +294 -0
  202. package/runtime/src/shape.h +46 -0
  203. package/runtime/src/streams.c +1046 -0
  204. package/runtime/src/streams.h +47 -0
  205. package/runtime/src/string.c +364 -0
  206. package/runtime/src/string_builtins.c +837 -0
  207. package/runtime/src/symbol.c +143 -0
  208. package/runtime/src/test_host.c +59 -0
  209. package/runtime/src/typedarray.c +1330 -0
  210. package/runtime/src/tznames.gen.h +712 -0
  211. package/runtime/src/uri.c +169 -0
  212. package/runtime/src/url.c +2116 -0
  213. package/runtime/src/weak.c +486 -0
  214. package/runtime/src/web.c +214 -0
  215. package/runtime/src/wrapper.c +59 -0
  216. package/runtime/src/writable.c +1486 -0
  217. package/runtime/third_party/ada-idna/LICENSE-MIT +18 -0
  218. package/runtime/third_party/ada-idna/README.md +27 -0
  219. package/runtime/third_party/ada-idna/convert.mjs +83 -0
  220. package/runtime/third_party/ada-idna/idna.c +416 -0
  221. package/runtime/third_party/ada-idna/idna.h +15 -0
  222. package/runtime/third_party/ada-idna/idna_tables.h +2657 -0
  223. package/runtime/third_party/bearssl/LICENSE.txt +21 -0
  224. package/runtime/third_party/bearssl/README.txt +136 -0
  225. package/runtime/third_party/bearssl/VERSION +1 -0
  226. package/runtime/third_party/bearssl/inc/bearssl.h +183 -0
  227. package/runtime/third_party/bearssl/inc/bearssl_aead.h +1059 -0
  228. package/runtime/third_party/bearssl/inc/bearssl_block.h +2618 -0
  229. package/runtime/third_party/bearssl/inc/bearssl_ec.h +967 -0
  230. package/runtime/third_party/bearssl/inc/bearssl_hash.h +1346 -0
  231. package/runtime/third_party/bearssl/inc/bearssl_hmac.h +241 -0
  232. package/runtime/third_party/bearssl/inc/bearssl_kdf.h +284 -0
  233. package/runtime/third_party/bearssl/inc/bearssl_pem.h +294 -0
  234. package/runtime/third_party/bearssl/inc/bearssl_prf.h +150 -0
  235. package/runtime/third_party/bearssl/inc/bearssl_rand.h +397 -0
  236. package/runtime/third_party/bearssl/inc/bearssl_rsa.h +1655 -0
  237. package/runtime/third_party/bearssl/inc/bearssl_ssl.h +4296 -0
  238. package/runtime/third_party/bearssl/inc/bearssl_x509.h +1474 -0
  239. package/runtime/third_party/bearssl/src/aead/ccm.c +346 -0
  240. package/runtime/third_party/bearssl/src/aead/eax.c +525 -0
  241. package/runtime/third_party/bearssl/src/aead/gcm.c +318 -0
  242. package/runtime/third_party/bearssl/src/codec/ccopy.c +44 -0
  243. package/runtime/third_party/bearssl/src/codec/dec16be.c +38 -0
  244. package/runtime/third_party/bearssl/src/codec/dec16le.c +38 -0
  245. package/runtime/third_party/bearssl/src/codec/dec32be.c +38 -0
  246. package/runtime/third_party/bearssl/src/codec/dec32le.c +38 -0
  247. package/runtime/third_party/bearssl/src/codec/dec64be.c +38 -0
  248. package/runtime/third_party/bearssl/src/codec/dec64le.c +38 -0
  249. package/runtime/third_party/bearssl/src/codec/enc16be.c +38 -0
  250. package/runtime/third_party/bearssl/src/codec/enc16le.c +38 -0
  251. package/runtime/third_party/bearssl/src/codec/enc32be.c +38 -0
  252. package/runtime/third_party/bearssl/src/codec/enc32le.c +38 -0
  253. package/runtime/third_party/bearssl/src/codec/enc64be.c +38 -0
  254. package/runtime/third_party/bearssl/src/codec/enc64le.c +38 -0
  255. package/runtime/third_party/bearssl/src/codec/pemdec.c +526 -0
  256. package/runtime/third_party/bearssl/src/codec/pemdec.t0 +314 -0
  257. package/runtime/third_party/bearssl/src/codec/pemenc.c +173 -0
  258. package/runtime/third_party/bearssl/src/config.h +247 -0
  259. package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +121 -0
  260. package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +171 -0
  261. package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +398 -0
  262. package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +390 -0
  263. package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +1478 -0
  264. package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +800 -0
  265. package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +605 -0
  266. package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +831 -0
  267. package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +46 -0
  268. package/runtime/third_party/bearssl/src/ec/ec_default.c +36 -0
  269. package/runtime/third_party/bearssl/src/ec/ec_keygen.c +86 -0
  270. package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +2124 -0
  271. package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +1469 -0
  272. package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +1765 -0
  273. package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +1781 -0
  274. package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +824 -0
  275. package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +826 -0
  276. package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +85 -0
  277. package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +51 -0
  278. package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +57 -0
  279. package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +64 -0
  280. package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +134 -0
  281. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +36 -0
  282. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +36 -0
  283. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +36 -0
  284. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +36 -0
  285. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +47 -0
  286. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +45 -0
  287. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +174 -0
  288. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +48 -0
  289. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +166 -0
  290. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +47 -0
  291. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +45 -0
  292. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +173 -0
  293. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +48 -0
  294. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +165 -0
  295. package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +121 -0
  296. package/runtime/third_party/bearssl/src/hash/dig_oid.c +84 -0
  297. package/runtime/third_party/bearssl/src/hash/dig_size.c +50 -0
  298. package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +345 -0
  299. package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +251 -0
  300. package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +154 -0
  301. package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +389 -0
  302. package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +411 -0
  303. package/runtime/third_party/bearssl/src/hash/md5.c +208 -0
  304. package/runtime/third_party/bearssl/src/hash/md5sha1.c +141 -0
  305. package/runtime/third_party/bearssl/src/hash/mgf1.c +56 -0
  306. package/runtime/third_party/bearssl/src/hash/multihash.c +166 -0
  307. package/runtime/third_party/bearssl/src/hash/sha1.c +191 -0
  308. package/runtime/third_party/bearssl/src/hash/sha2big.c +285 -0
  309. package/runtime/third_party/bearssl/src/hash/sha2small.c +341 -0
  310. package/runtime/third_party/bearssl/src/inner.h +2577 -0
  311. package/runtime/third_party/bearssl/src/int/i15_add.c +46 -0
  312. package/runtime/third_party/bearssl/src/int/i15_bitlen.c +44 -0
  313. package/runtime/third_party/bearssl/src/int/i15_decmod.c +124 -0
  314. package/runtime/third_party/bearssl/src/int/i15_decode.c +56 -0
  315. package/runtime/third_party/bearssl/src/int/i15_decred.c +100 -0
  316. package/runtime/third_party/bearssl/src/int/i15_encode.c +56 -0
  317. package/runtime/third_party/bearssl/src/int/i15_fmont.c +59 -0
  318. package/runtime/third_party/bearssl/src/int/i15_iszero.c +39 -0
  319. package/runtime/third_party/bearssl/src/int/i15_moddiv.c +465 -0
  320. package/runtime/third_party/bearssl/src/int/i15_modpow.c +50 -0
  321. package/runtime/third_party/bearssl/src/int/i15_modpow2.c +160 -0
  322. package/runtime/third_party/bearssl/src/int/i15_montmul.c +184 -0
  323. package/runtime/third_party/bearssl/src/int/i15_mulacc.c +61 -0
  324. package/runtime/third_party/bearssl/src/int/i15_muladd.c +173 -0
  325. package/runtime/third_party/bearssl/src/int/i15_ninv15.c +38 -0
  326. package/runtime/third_party/bearssl/src/int/i15_reduce.c +66 -0
  327. package/runtime/third_party/bearssl/src/int/i15_rshift.c +47 -0
  328. package/runtime/third_party/bearssl/src/int/i15_sub.c +46 -0
  329. package/runtime/third_party/bearssl/src/int/i15_tmont.c +36 -0
  330. package/runtime/third_party/bearssl/src/int/i31_add.c +46 -0
  331. package/runtime/third_party/bearssl/src/int/i31_bitlen.c +44 -0
  332. package/runtime/third_party/bearssl/src/int/i31_decmod.c +124 -0
  333. package/runtime/third_party/bearssl/src/int/i31_decode.c +57 -0
  334. package/runtime/third_party/bearssl/src/int/i31_decred.c +103 -0
  335. package/runtime/third_party/bearssl/src/int/i31_encode.c +79 -0
  336. package/runtime/third_party/bearssl/src/int/i31_fmont.c +60 -0
  337. package/runtime/third_party/bearssl/src/int/i31_iszero.c +39 -0
  338. package/runtime/third_party/bearssl/src/int/i31_moddiv.c +488 -0
  339. package/runtime/third_party/bearssl/src/int/i31_modpow.c +65 -0
  340. package/runtime/third_party/bearssl/src/int/i31_modpow2.c +160 -0
  341. package/runtime/third_party/bearssl/src/int/i31_montmul.c +127 -0
  342. package/runtime/third_party/bearssl/src/int/i31_mulacc.c +74 -0
  343. package/runtime/third_party/bearssl/src/int/i31_muladd.c +157 -0
  344. package/runtime/third_party/bearssl/src/int/i31_ninv31.c +39 -0
  345. package/runtime/third_party/bearssl/src/int/i31_reduce.c +66 -0
  346. package/runtime/third_party/bearssl/src/int/i31_rshift.c +47 -0
  347. package/runtime/third_party/bearssl/src/int/i31_sub.c +46 -0
  348. package/runtime/third_party/bearssl/src/int/i31_tmont.c +36 -0
  349. package/runtime/third_party/bearssl/src/int/i32_add.c +51 -0
  350. package/runtime/third_party/bearssl/src/int/i32_bitlen.c +44 -0
  351. package/runtime/third_party/bearssl/src/int/i32_decmod.c +77 -0
  352. package/runtime/third_party/bearssl/src/int/i32_decode.c +63 -0
  353. package/runtime/third_party/bearssl/src/int/i32_decred.c +107 -0
  354. package/runtime/third_party/bearssl/src/int/i32_div32.c +56 -0
  355. package/runtime/third_party/bearssl/src/int/i32_encode.c +72 -0
  356. package/runtime/third_party/bearssl/src/int/i32_fmont.c +60 -0
  357. package/runtime/third_party/bearssl/src/int/i32_iszero.c +39 -0
  358. package/runtime/third_party/bearssl/src/int/i32_modpow.c +65 -0
  359. package/runtime/third_party/bearssl/src/int/i32_montmul.c +69 -0
  360. package/runtime/third_party/bearssl/src/int/i32_mulacc.c +56 -0
  361. package/runtime/third_party/bearssl/src/int/i32_muladd.c +138 -0
  362. package/runtime/third_party/bearssl/src/int/i32_ninv32.c +39 -0
  363. package/runtime/third_party/bearssl/src/int/i32_reduce.c +66 -0
  364. package/runtime/third_party/bearssl/src/int/i32_sub.c +51 -0
  365. package/runtime/third_party/bearssl/src/int/i32_tmont.c +36 -0
  366. package/runtime/third_party/bearssl/src/int/i62_modpow2.c +493 -0
  367. package/runtime/third_party/bearssl/src/kdf/hkdf.c +107 -0
  368. package/runtime/third_party/bearssl/src/kdf/shake.c +590 -0
  369. package/runtime/third_party/bearssl/src/mac/hmac.c +122 -0
  370. package/runtime/third_party/bearssl/src/mac/hmac_ct.c +193 -0
  371. package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +206 -0
  372. package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +157 -0
  373. package/runtime/third_party/bearssl/src/rand/sysrng.c +252 -0
  374. package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +38 -0
  375. package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +36 -0
  376. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +38 -0
  377. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +38 -0
  378. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +38 -0
  379. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +38 -0
  380. package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +38 -0
  381. package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +36 -0
  382. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +38 -0
  383. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +38 -0
  384. package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +38 -0
  385. package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +36 -0
  386. package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +583 -0
  387. package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +99 -0
  388. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +41 -0
  389. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +44 -0
  390. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +37 -0
  391. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +43 -0
  392. package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +209 -0
  393. package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +320 -0
  394. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +40 -0
  395. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +44 -0
  396. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +113 -0
  397. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +152 -0
  398. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +37 -0
  399. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +608 -0
  400. package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +99 -0
  401. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +41 -0
  402. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +44 -0
  403. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +37 -0
  404. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +43 -0
  405. package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +203 -0
  406. package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +318 -0
  407. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +40 -0
  408. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +44 -0
  409. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +106 -0
  410. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +152 -0
  411. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +41 -0
  412. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +44 -0
  413. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +37 -0
  414. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +43 -0
  415. package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +160 -0
  416. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +40 -0
  417. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +44 -0
  418. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +77 -0
  419. package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +57 -0
  420. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +61 -0
  421. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +64 -0
  422. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +57 -0
  423. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +63 -0
  424. package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +223 -0
  425. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +60 -0
  426. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +64 -0
  427. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +125 -0
  428. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +112 -0
  429. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +145 -0
  430. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
  431. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +121 -0
  432. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +106 -0
  433. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +121 -0
  434. package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +52 -0
  435. package/runtime/third_party/bearssl/src/settings.c +306 -0
  436. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +69 -0
  437. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +67 -0
  438. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +84 -0
  439. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +142 -0
  440. package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +254 -0
  441. package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +157 -0
  442. package/runtime/third_party/bearssl/src/symcipher/aes_common.c +112 -0
  443. package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +328 -0
  444. package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +398 -0
  445. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +104 -0
  446. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +81 -0
  447. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +114 -0
  448. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +433 -0
  449. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +159 -0
  450. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +115 -0
  451. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +111 -0
  452. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +91 -0
  453. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +116 -0
  454. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +422 -0
  455. package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +170 -0
  456. package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +112 -0
  457. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +445 -0
  458. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +670 -0
  459. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +417 -0
  460. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +717 -0
  461. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +946 -0
  462. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +69 -0
  463. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +67 -0
  464. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +84 -0
  465. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +142 -0
  466. package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +176 -0
  467. package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +129 -0
  468. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +240 -0
  469. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +223 -0
  470. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +122 -0
  471. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +211 -0
  472. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +596 -0
  473. package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +106 -0
  474. package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +237 -0
  475. package/runtime/third_party/bearssl/src/symcipher/des_ct.c +411 -0
  476. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +87 -0
  477. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +69 -0
  478. package/runtime/third_party/bearssl/src/symcipher/des_support.c +166 -0
  479. package/runtime/third_party/bearssl/src/symcipher/des_tab.c +310 -0
  480. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +85 -0
  481. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +67 -0
  482. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +260 -0
  483. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +297 -0
  484. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +475 -0
  485. package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +221 -0
  486. package/runtime/third_party/bearssl/src/x509/asn1.t0 +757 -0
  487. package/runtime/third_party/bearssl/src/x509/asn1enc.c +93 -0
  488. package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +110 -0
  489. package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +161 -0
  490. package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +97 -0
  491. package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +96 -0
  492. package/runtime/third_party/bearssl/src/x509/skey_decoder.c +653 -0
  493. package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +376 -0
  494. package/runtime/third_party/bearssl/src/x509/x509_decoder.c +776 -0
  495. package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +324 -0
  496. package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +105 -0
  497. package/runtime/third_party/bearssl/src/x509/x509_minimal.c +1722 -0
  498. package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +1526 -0
  499. package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +59 -0
  500. package/runtime/third_party/quickjs-dtoa/LICENSE +22 -0
  501. package/runtime/third_party/quickjs-dtoa/README.md +23 -0
  502. package/runtime/third_party/quickjs-dtoa/dtoa.c +1640 -0
  503. package/runtime/third_party/quickjs-dtoa/dtoa.h +83 -0
  504. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +89 -0
  505. package/runtime/third_party/quickjs-regexp/LICENSE +22 -0
  506. package/runtime/third_party/quickjs-regexp/README.md +22 -0
  507. package/runtime/third_party/quickjs-regexp/cutils.c +641 -0
  508. package/runtime/third_party/quickjs-regexp/cutils.h +457 -0
  509. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +73 -0
  510. package/runtime/third_party/quickjs-regexp/libregexp.c +3448 -0
  511. package/runtime/third_party/quickjs-regexp/libregexp.h +65 -0
  512. package/runtime/third_party/quickjs-regexp/libunicode-table.h +5206 -0
  513. package/runtime/third_party/quickjs-regexp/libunicode.c +2124 -0
  514. package/runtime/third_party/quickjs-regexp/libunicode.h +196 -0
  515. package/runtime/third_party/v8-ieee754/LICENSE +61 -0
  516. package/runtime/third_party/v8-ieee754/README.md +22 -0
  517. package/runtime/third_party/v8-ieee754/convert.py +84 -0
  518. package/runtime/third_party/v8-ieee754/ieee754.c +3030 -0
  519. package/runtime/third_party/v8-ieee754/ieee754.h +27 -0
  520. package/runtime/tools/regexp_compile.c +90 -0
@@ -0,0 +1,667 @@
1
+ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ * of this software and associated documentation files (the "Software"), to
4
+ * deal in the Software without restriction, including without limitation the
5
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6
+ * sell copies of the Software, and to permit persons to whom the Software is
7
+ * furnished to do so, subject to the following conditions:
8
+ *
9
+ * The above copyright notice and this permission notice shall be included in
10
+ * all copies or substantial portions of the Software.
11
+ *
12
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18
+ * IN THE SOFTWARE.
19
+ */
20
+
21
+ #include "uv.h"
22
+ #include "internal.h"
23
+
24
+ #include <assert.h>
25
+ #include <stdlib.h>
26
+ #include <string.h>
27
+ #include <errno.h>
28
+
29
+ #include <sys/sysctl.h>
30
+ #include <sys/types.h>
31
+ #include <sys/event.h>
32
+ #include <sys/time.h>
33
+ #if defined(__FreeBSD__)
34
+ #include <sys/user.h>
35
+ #endif
36
+ #include <unistd.h>
37
+ #include <fcntl.h>
38
+ #include <time.h>
39
+
40
+ /*
41
+ * Required on
42
+ * - Until at least FreeBSD 11.0
43
+ * - Older versions of Mac OS X
44
+ *
45
+ * http://www.boost.org/doc/libs/1_61_0/boost/asio/detail/kqueue_reactor.hpp
46
+ */
47
+ #ifndef EV_OOBAND
48
+ #define EV_OOBAND EV_FLAG1
49
+ #endif
50
+
51
+ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags);
52
+
53
+
54
+ int uv__kqueue_init(uv_loop_t* loop) {
55
+ loop->backend_fd = kqueue();
56
+ if (loop->backend_fd == -1)
57
+ return UV__ERR(errno);
58
+
59
+ uv__cloexec(loop->backend_fd, 1);
60
+
61
+ return 0;
62
+ }
63
+
64
+
65
+ #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
66
+ static _Atomic int uv__has_forked_with_cfrunloop;
67
+ #endif
68
+
69
+ int uv__io_fork(uv_loop_t* loop) {
70
+ int err;
71
+ loop->backend_fd = -1;
72
+ err = uv__kqueue_init(loop);
73
+ if (err)
74
+ return err;
75
+
76
+ #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
77
+ if (loop->cf_state != NULL) {
78
+ /* We cannot start another CFRunloop and/or thread in the child
79
+ process; CF aborts if you try or if you try to touch the thread
80
+ at all to kill it. So the best we can do is ignore it from now
81
+ on. This means we can't watch directories in the same way
82
+ anymore (like other BSDs). It also means we cannot properly
83
+ clean up the allocated resources; calling
84
+ uv__fsevents_loop_delete from uv_loop_close will crash the
85
+ process. So we sidestep the issue by pretending like we never
86
+ started it in the first place.
87
+ */
88
+ atomic_store_explicit(&uv__has_forked_with_cfrunloop,
89
+ 1,
90
+ memory_order_relaxed);
91
+ uv__free(loop->cf_state);
92
+ loop->cf_state = NULL;
93
+ }
94
+ #endif /* #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */
95
+ return err;
96
+ }
97
+
98
+
99
+ int uv__io_check_fd(uv_loop_t* loop, int fd) {
100
+ struct kevent ev[2];
101
+ struct stat sb;
102
+ #ifdef __APPLE__
103
+ char path[MAXPATHLEN];
104
+ #endif
105
+
106
+ if (uv__fstat(fd, &sb))
107
+ return UV__ERR(errno);
108
+
109
+ /* On FreeBSD, kqueue only supports EVFILT_READ notification for regular files
110
+ * and always reports ready events for writing, resulting in busy-looping.
111
+ *
112
+ * On Darwin, DragonFlyBSD, NetBSD and OpenBSD, kqueue reports ready events for
113
+ * regular files as readable and writable only once, acting like an EV_ONESHOT.
114
+ *
115
+ * Neither of the above cases should be added to the kqueue.
116
+ */
117
+ if (S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode))
118
+ return UV_EINVAL;
119
+
120
+ #ifdef __APPLE__
121
+ /* On Darwin (both macOS and iOS), in addition to regular files, FIFOs also don't
122
+ * work properly with kqueue: the disconnection from the last writer won't trigger
123
+ * an event for kqueue in spite of what the man pages say. Thus, we also disallow
124
+ * the case of S_IFIFO. */
125
+ if (S_ISFIFO(sb.st_mode)) {
126
+ /* File descriptors of FIFO, pipe and kqueue share the same type of file,
127
+ * therefore there is no way to tell them apart via stat.st_mode&S_IFMT.
128
+ * Fortunately, FIFO is the only one that has a persisted file on filesystem,
129
+ * from which we're able to make the distinction for it. */
130
+ if (!fcntl(fd, F_GETPATH, path))
131
+ return UV_EINVAL;
132
+ }
133
+ #endif
134
+
135
+ EV_SET(ev, fd, EVFILT_READ, EV_ADD, 0, 0, 0);
136
+ EV_SET(ev + 1, fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
137
+ if (kevent(loop->backend_fd, ev, 2, NULL, 0, NULL))
138
+ return UV__ERR(errno);
139
+
140
+ return 0;
141
+ }
142
+
143
+
144
+ static void uv__kqueue_delete(int kqfd, const struct kevent *ev) {
145
+ struct kevent change;
146
+
147
+ EV_SET(&change, ev->ident, ev->filter, EV_DELETE, 0, 0, 0);
148
+
149
+ if (0 == kevent(kqfd, &change, 1, NULL, 0, NULL))
150
+ return;
151
+
152
+ if (errno == EBADF || errno == ENOENT)
153
+ return;
154
+
155
+ abort();
156
+ }
157
+
158
+
159
+ void uv__io_poll(uv_loop_t* loop, int timeout) {
160
+ uv__loop_internal_fields_t* lfields;
161
+ struct kevent events[1024];
162
+ struct kevent* ev;
163
+ struct timespec spec;
164
+ unsigned int nevents;
165
+ unsigned int revents;
166
+ struct uv__queue* q;
167
+ uv__io_t* w;
168
+ uv_process_t* process;
169
+ sigset_t* pset;
170
+ sigset_t set;
171
+ uint64_t base;
172
+ uint64_t diff;
173
+ int have_signals;
174
+ int filter;
175
+ int fflags;
176
+ int count;
177
+ int nfds;
178
+ int fd;
179
+ int op;
180
+ int i;
181
+ int user_timeout;
182
+ int reset_timeout;
183
+
184
+ if (loop->nfds == 0) {
185
+ assert(uv__queue_empty(&loop->watcher_queue));
186
+ return;
187
+ }
188
+
189
+ lfields = uv__get_internal_fields(loop);
190
+ nevents = 0;
191
+
192
+ while (!uv__queue_empty(&loop->watcher_queue)) {
193
+ q = uv__queue_head(&loop->watcher_queue);
194
+ uv__queue_remove(q);
195
+ uv__queue_init(q);
196
+
197
+ w = uv__queue_data(q, uv__io_t, watcher_queue);
198
+ assert(w->pevents != 0);
199
+ assert(w->fd >= 0);
200
+ assert(w->fd < (int) loop->nwatchers);
201
+
202
+ if ((w->events & POLLIN) == 0 && (w->pevents & POLLIN) != 0) {
203
+ filter = EVFILT_READ;
204
+ fflags = 0;
205
+ op = EV_ADD;
206
+
207
+ if (w->cb == uv__fs_event) {
208
+ filter = EVFILT_VNODE;
209
+ fflags = NOTE_ATTRIB | NOTE_WRITE | NOTE_RENAME
210
+ | NOTE_DELETE | NOTE_EXTEND | NOTE_REVOKE;
211
+ op = EV_ADD | EV_ONESHOT; /* Stop the event from firing repeatedly. */
212
+ }
213
+
214
+ EV_SET(events + nevents, w->fd, filter, op, fflags, 0, 0);
215
+
216
+ if (++nevents == ARRAY_SIZE(events)) {
217
+ if (kevent(loop->backend_fd, events, nevents, NULL, 0, NULL))
218
+ abort();
219
+ nevents = 0;
220
+ }
221
+ }
222
+
223
+ if ((w->events & POLLOUT) == 0 && (w->pevents & POLLOUT) != 0) {
224
+ EV_SET(events + nevents, w->fd, EVFILT_WRITE, EV_ADD, 0, 0, 0);
225
+
226
+ if (++nevents == ARRAY_SIZE(events)) {
227
+ if (kevent(loop->backend_fd, events, nevents, NULL, 0, NULL))
228
+ abort();
229
+ nevents = 0;
230
+ }
231
+ }
232
+
233
+ if ((w->events & UV__POLLPRI) == 0 && (w->pevents & UV__POLLPRI) != 0) {
234
+ EV_SET(events + nevents, w->fd, EV_OOBAND, EV_ADD, 0, 0, 0);
235
+
236
+ if (++nevents == ARRAY_SIZE(events)) {
237
+ if (kevent(loop->backend_fd, events, nevents, NULL, 0, NULL))
238
+ abort();
239
+ nevents = 0;
240
+ }
241
+ }
242
+
243
+ w->events = w->pevents;
244
+ }
245
+
246
+ pset = NULL;
247
+ if (loop->flags & UV_LOOP_BLOCK_SIGPROF) {
248
+ pset = &set;
249
+ sigemptyset(pset);
250
+ sigaddset(pset, SIGPROF);
251
+ }
252
+
253
+ assert(timeout >= -1);
254
+ base = loop->time;
255
+ count = 48; /* Benchmarks suggest this gives the best throughput. */
256
+
257
+ if (lfields->flags & UV_METRICS_IDLE_TIME) {
258
+ reset_timeout = 1;
259
+ user_timeout = timeout;
260
+ timeout = 0;
261
+ } else {
262
+ reset_timeout = 0;
263
+ }
264
+
265
+ for (;; nevents = 0) {
266
+ /* Only need to set the provider_entry_time if timeout != 0. The function
267
+ * will return early if the loop isn't configured with UV_METRICS_IDLE_TIME.
268
+ */
269
+ if (timeout != 0)
270
+ uv__metrics_set_provider_entry_time(loop);
271
+
272
+ if (timeout != -1) {
273
+ spec.tv_sec = timeout / 1000;
274
+ spec.tv_nsec = (timeout % 1000) * 1000000;
275
+ }
276
+
277
+ if (pset != NULL)
278
+ pthread_sigmask(SIG_BLOCK, pset, NULL);
279
+
280
+ /* Store the current timeout in a location that's globally accessible so
281
+ * other locations like uv__work_done() can determine whether the queue
282
+ * of events in the callback were waiting when poll was called.
283
+ */
284
+ lfields->current_timeout = timeout;
285
+
286
+ nfds = kevent(loop->backend_fd,
287
+ events,
288
+ nevents,
289
+ events,
290
+ ARRAY_SIZE(events),
291
+ timeout == -1 ? NULL : &spec);
292
+
293
+ if (nfds == -1)
294
+ assert(errno == EINTR);
295
+ else if (nfds == 0)
296
+ /* Unlimited timeout should only return with events or signal. */
297
+ assert(timeout != -1);
298
+
299
+ if (pset != NULL)
300
+ pthread_sigmask(SIG_UNBLOCK, pset, NULL);
301
+
302
+ /* Update loop->time unconditionally. It's tempting to skip the update when
303
+ * timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
304
+ * operating system didn't reschedule our process while in the syscall.
305
+ */
306
+ uv__update_time(loop);
307
+
308
+ if (nfds == 0 || nfds == -1) {
309
+ /* If kqueue is empty or interrupted, we might still have children ready
310
+ * to reap immediately. */
311
+ if (loop->flags & UV_LOOP_REAP_CHILDREN) {
312
+ loop->flags &= ~UV_LOOP_REAP_CHILDREN;
313
+ uv__wait_children(loop);
314
+ assert((reset_timeout == 0 ? timeout : user_timeout) == 0);
315
+ return; /* Equivalent to fall-through behavior. */
316
+ }
317
+
318
+ if (reset_timeout != 0) {
319
+ timeout = user_timeout;
320
+ reset_timeout = 0;
321
+ } else if (nfds == 0) {
322
+ return;
323
+ }
324
+
325
+ /* Interrupted by a signal. Update timeout and poll again. */
326
+ goto update_timeout;
327
+ }
328
+
329
+ have_signals = 0;
330
+ nevents = 0;
331
+
332
+ assert(loop->watchers != NULL);
333
+ loop->watchers[loop->nwatchers] = (void*) events;
334
+ loop->watchers[loop->nwatchers + 1] = (void*) (uintptr_t) nfds;
335
+ for (i = 0; i < nfds; i++) {
336
+ ev = events + i;
337
+ fd = ev->ident;
338
+
339
+ /* Handle kevent NOTE_EXIT results */
340
+ if (ev->filter == EVFILT_PROC) {
341
+ uv__queue_foreach(q, &loop->process_handles) {
342
+ process = uv__queue_data(q, uv_process_t, queue);
343
+ if (process->pid == fd) {
344
+ process->flags |= UV_HANDLE_REAP;
345
+ loop->flags |= UV_LOOP_REAP_CHILDREN;
346
+ break;
347
+ }
348
+ }
349
+ nevents++;
350
+ continue;
351
+ }
352
+
353
+ /* Skip invalidated events, see uv__platform_invalidate_fd */
354
+ if (fd == -1)
355
+ continue;
356
+ w = loop->watchers[fd];
357
+
358
+ if (w == NULL) {
359
+ /* File descriptor that we've stopped watching, disarm it. */
360
+ uv__kqueue_delete(loop->backend_fd, ev);
361
+ continue;
362
+ }
363
+
364
+ #if UV__KQUEUE_EVFILT_USER
365
+ if (ev->filter == EVFILT_USER) {
366
+ w = &loop->async_io_watcher;
367
+ assert(fd == w->fd);
368
+ uv__metrics_update_idle_time(loop);
369
+ w->cb(loop, w, w->events);
370
+ nevents++;
371
+ continue;
372
+ }
373
+ #endif
374
+
375
+ if (ev->filter == EVFILT_VNODE) {
376
+ assert(w->events == POLLIN);
377
+ assert(w->pevents == POLLIN);
378
+ uv__metrics_update_idle_time(loop);
379
+ w->cb(loop, w, ev->fflags); /* XXX always uv__fs_event() */
380
+ nevents++;
381
+ continue;
382
+ }
383
+
384
+ revents = 0;
385
+
386
+ if (ev->filter == EVFILT_READ) {
387
+ if (w->pevents & POLLIN)
388
+ revents |= POLLIN;
389
+ else
390
+ uv__kqueue_delete(loop->backend_fd, ev);
391
+
392
+ if ((ev->flags & EV_EOF) && (w->pevents & UV__POLLRDHUP))
393
+ revents |= UV__POLLRDHUP;
394
+ }
395
+
396
+ if (ev->filter == EV_OOBAND) {
397
+ if (w->pevents & UV__POLLPRI)
398
+ revents |= UV__POLLPRI;
399
+ else
400
+ uv__kqueue_delete(loop->backend_fd, ev);
401
+ }
402
+
403
+ if (ev->filter == EVFILT_WRITE) {
404
+ if (w->pevents & POLLOUT)
405
+ revents |= POLLOUT;
406
+ else
407
+ uv__kqueue_delete(loop->backend_fd, ev);
408
+ }
409
+
410
+ if (ev->flags & EV_ERROR)
411
+ revents |= POLLERR;
412
+
413
+ if (revents == 0)
414
+ continue;
415
+
416
+ /* Run signal watchers last. This also affects child process watchers
417
+ * because those are implemented in terms of signal watchers.
418
+ */
419
+ if (w == &loop->signal_io_watcher) {
420
+ have_signals = 1;
421
+ } else {
422
+ uv__metrics_update_idle_time(loop);
423
+ w->cb(loop, w, revents);
424
+ }
425
+
426
+ nevents++;
427
+ }
428
+
429
+ if (loop->flags & UV_LOOP_REAP_CHILDREN) {
430
+ loop->flags &= ~UV_LOOP_REAP_CHILDREN;
431
+ uv__wait_children(loop);
432
+ }
433
+
434
+ uv__metrics_inc_events(loop, nevents);
435
+ if (reset_timeout != 0) {
436
+ timeout = user_timeout;
437
+ reset_timeout = 0;
438
+ uv__metrics_inc_events_waiting(loop, nevents);
439
+ }
440
+
441
+ if (have_signals != 0) {
442
+ uv__metrics_update_idle_time(loop);
443
+ loop->signal_io_watcher.cb(loop, &loop->signal_io_watcher, POLLIN);
444
+ }
445
+
446
+ loop->watchers[loop->nwatchers] = NULL;
447
+ loop->watchers[loop->nwatchers + 1] = NULL;
448
+
449
+ if (have_signals != 0)
450
+ return; /* Event loop should cycle now so don't poll again. */
451
+
452
+ if (nevents != 0) {
453
+ if (nfds == ARRAY_SIZE(events) && --count != 0) {
454
+ /* Poll for more events but don't block this time. */
455
+ timeout = 0;
456
+ continue;
457
+ }
458
+ return;
459
+ }
460
+
461
+ update_timeout:
462
+ if (timeout == 0)
463
+ return;
464
+
465
+ if (timeout == -1)
466
+ continue;
467
+
468
+ assert(timeout > 0);
469
+
470
+ diff = loop->time - base;
471
+ if (diff >= (uint64_t) timeout)
472
+ return;
473
+
474
+ timeout -= diff;
475
+ }
476
+ }
477
+
478
+
479
+ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
480
+ struct kevent* events;
481
+ uintptr_t i;
482
+ uintptr_t nfds;
483
+
484
+ assert(loop->watchers != NULL);
485
+ assert(fd >= 0);
486
+
487
+ events = (struct kevent*) loop->watchers[loop->nwatchers];
488
+ nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1];
489
+ if (events == NULL)
490
+ return;
491
+
492
+ /* Invalidate events with same file descriptor */
493
+ for (i = 0; i < nfds; i++)
494
+ if ((int) events[i].ident == fd && events[i].filter != EVFILT_PROC)
495
+ events[i].ident = -1;
496
+ }
497
+
498
+
499
+ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags) {
500
+ uv_fs_event_t* handle;
501
+ struct kevent ev;
502
+ int events;
503
+ const char* path;
504
+ #if defined(F_GETPATH)
505
+ /* MAXPATHLEN == PATH_MAX but the former is what XNU calls it internally. */
506
+ char pathbuf[MAXPATHLEN];
507
+ #endif
508
+
509
+ handle = container_of(w, uv_fs_event_t, event_watcher);
510
+
511
+ if (fflags & (NOTE_ATTRIB | NOTE_EXTEND))
512
+ events = UV_CHANGE;
513
+ else
514
+ events = UV_RENAME;
515
+
516
+ path = NULL;
517
+ #if defined(F_GETPATH)
518
+ /* Also works when the file has been unlinked from the file system. Passing
519
+ * in the path when the file has been deleted is arguably a little strange
520
+ * but it's consistent with what the inotify backend does.
521
+ */
522
+ if (fcntl(handle->event_watcher.fd, F_GETPATH, pathbuf) == 0)
523
+ path = uv__basename_r(pathbuf);
524
+ #elif defined(F_KINFO)
525
+ /* We try to get the file info reference from the file descriptor.
526
+ * the struct's kf_structsize must be initialised beforehand
527
+ * whether with the KINFO_FILE_SIZE constant or this way.
528
+ */
529
+ struct stat statbuf;
530
+ struct kinfo_file kf;
531
+
532
+ if (handle->event_watcher.fd != -1 &&
533
+ (!uv__fstat(handle->event_watcher.fd, &statbuf) && !(statbuf.st_mode & S_IFDIR))) {
534
+ /* we are purposely not using KINFO_FILE_SIZE here
535
+ * as it is not available on non intl archs
536
+ * and here it gives 1392 too on intel.
537
+ * anyway, the man page also mentions we can proceed
538
+ * this way.
539
+ */
540
+ kf.kf_structsize = sizeof(kf);
541
+ if (fcntl(handle->event_watcher.fd, F_KINFO, &kf) == 0)
542
+ path = uv__basename_r(kf.kf_path);
543
+ }
544
+ #endif
545
+ handle->cb(handle, path, events, 0);
546
+
547
+ if (handle->event_watcher.fd == -1)
548
+ return;
549
+
550
+ /* Watcher operates in one-shot mode, re-arm it. */
551
+ fflags = NOTE_ATTRIB | NOTE_WRITE | NOTE_RENAME
552
+ | NOTE_DELETE | NOTE_EXTEND | NOTE_REVOKE;
553
+
554
+ EV_SET(&ev, w->fd, EVFILT_VNODE, EV_ADD | EV_ONESHOT, fflags, 0, 0);
555
+
556
+ if (kevent(loop->backend_fd, &ev, 1, NULL, 0, NULL))
557
+ abort();
558
+ }
559
+
560
+
561
+ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
562
+ uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
563
+ return 0;
564
+ }
565
+
566
+
567
+ int uv_fs_event_start(uv_fs_event_t* handle,
568
+ uv_fs_event_cb cb,
569
+ const char* path,
570
+ unsigned int flags) {
571
+ int fd;
572
+ int r;
573
+ #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
574
+ struct stat statbuf;
575
+ #endif
576
+
577
+ if (uv__is_active(handle))
578
+ return UV_EINVAL;
579
+
580
+ handle->cb = cb;
581
+ handle->path = uv__strdup(path);
582
+ if (handle->path == NULL)
583
+ return UV_ENOMEM;
584
+
585
+ /* TODO open asynchronously - but how do we report back errors? */
586
+ fd = open(handle->path, O_RDONLY);
587
+ if (fd == -1) {
588
+ uv__free(handle->path);
589
+ handle->path = NULL;
590
+ return UV__ERR(errno);
591
+ }
592
+
593
+ #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
594
+ /* Nullify field to perform checks later */
595
+ handle->cf_cb = NULL;
596
+ handle->realpath = NULL;
597
+ handle->realpath_len = 0;
598
+ handle->cf_flags = flags;
599
+
600
+ if (uv__fstat(fd, &statbuf))
601
+ goto fallback;
602
+ /* FSEvents works only with directories */
603
+ if (!(statbuf.st_mode & S_IFDIR))
604
+ goto fallback;
605
+
606
+ if (0 == atomic_load_explicit(&uv__has_forked_with_cfrunloop,
607
+ memory_order_relaxed)) {
608
+ /* The fallback fd is no longer needed */
609
+ uv__close_nocheckstdio(fd);
610
+ handle->event_watcher.fd = -1;
611
+ r = uv__fsevents_init(handle);
612
+ if (r == 0) {
613
+ uv__handle_start(handle);
614
+ } else {
615
+ uv__free(handle->path);
616
+ handle->path = NULL;
617
+ }
618
+ return r;
619
+ }
620
+ fallback:
621
+ #endif /* #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 */
622
+
623
+ r = uv__io_init_start(handle->loop,
624
+ &handle->event_watcher,
625
+ uv__fs_event,
626
+ fd,
627
+ POLLIN);
628
+
629
+ if (!r)
630
+ uv__handle_start(handle);
631
+
632
+ return r;
633
+ }
634
+
635
+
636
+ int uv_fs_event_stop(uv_fs_event_t* handle) {
637
+ int r;
638
+ r = 0;
639
+
640
+ if (!uv__is_active(handle))
641
+ return 0;
642
+
643
+ uv__handle_stop(handle);
644
+
645
+ #if defined(__APPLE__) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
646
+ if (0 == atomic_load_explicit(&uv__has_forked_with_cfrunloop,
647
+ memory_order_relaxed))
648
+ if (handle->cf_cb != NULL)
649
+ r = uv__fsevents_close(handle);
650
+ #endif
651
+
652
+ if (handle->event_watcher.fd != -1) {
653
+ uv__io_close(handle->loop, &handle->event_watcher);
654
+ uv__close(handle->event_watcher.fd);
655
+ handle->event_watcher.fd = -1;
656
+ }
657
+
658
+ uv__free(handle->path);
659
+ handle->path = NULL;
660
+
661
+ return r;
662
+ }
663
+
664
+
665
+ void uv__fs_event_close(uv_fs_event_t* handle) {
666
+ uv_fs_event_stop(handle);
667
+ }