@capsule-run/sdk 0.8.4 → 0.8.6
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/dist/polyfills/fs.d.ts.map +1 -1
- package/dist/polyfills/fs.js +4 -3
- package/dist/polyfills/fs.js.map +1 -1
- package/dist/polyfills/process.d.ts.map +1 -1
- package/dist/polyfills/process.js +10 -8
- package/dist/polyfills/process.js.map +1 -1
- package/dist/polyfills/unenv-runtime/_internal/types.d.mts +5 -0
- package/dist/polyfills/unenv-runtime/_internal/types.mjs +1 -0
- package/dist/polyfills/unenv-runtime/_internal/utils.d.mts +14 -0
- package/dist/polyfills/unenv-runtime/_internal/utils.mjs +49 -0
- package/dist/polyfills/unenv-runtime/mock/empty.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/mock/empty.mjs +1 -0
- package/dist/polyfills/unenv-runtime/mock/noop.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/mock/noop.mjs +1 -0
- package/dist/polyfills/unenv-runtime/mock/proxy.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/mock/proxy.mjs +43 -0
- package/dist/polyfills/unenv-runtime/node/assert/strict.d.mts +4 -0
- package/dist/polyfills/unenv-runtime/node/assert/strict.mjs +25 -0
- package/dist/polyfills/unenv-runtime/node/assert.d.mts +165 -0
- package/dist/polyfills/unenv-runtime/node/assert.mjs +737 -0
- package/dist/polyfills/unenv-runtime/node/async_hooks.d.mts +5 -0
- package/dist/polyfills/unenv-runtime/node/async_hooks.mjs +15 -0
- package/dist/polyfills/unenv-runtime/node/buffer.d.mts +19 -0
- package/dist/polyfills/unenv-runtime/node/buffer.mjs +35 -0
- package/dist/polyfills/unenv-runtime/node/child_process.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/node/child_process.mjs +21 -0
- package/dist/polyfills/unenv-runtime/node/cluster.d.mts +33 -0
- package/dist/polyfills/unenv-runtime/node/cluster.mjs +71 -0
- package/dist/polyfills/unenv-runtime/node/console.d.mts +38 -0
- package/dist/polyfills/unenv-runtime/node/console.mjs +74 -0
- package/dist/polyfills/unenv-runtime/node/constants.d.mts +13 -0
- package/dist/polyfills/unenv-runtime/node/constants.mjs +254 -0
- package/dist/polyfills/unenv-runtime/node/crypto.d.mts +6 -0
- package/dist/polyfills/unenv-runtime/node/crypto.mjs +138 -0
- package/dist/polyfills/unenv-runtime/node/dgram.d.mts +6 -0
- package/dist/polyfills/unenv-runtime/node/dgram.mjs +12 -0
- package/dist/polyfills/unenv-runtime/node/diagnostics_channel.d.mts +11 -0
- package/dist/polyfills/unenv-runtime/node/diagnostics_channel.mjs +34 -0
- package/dist/polyfills/unenv-runtime/node/dns/promises.d.mts +27 -0
- package/dist/polyfills/unenv-runtime/node/dns/promises.mjs +75 -0
- package/dist/polyfills/unenv-runtime/node/dns.d.mts +29 -0
- package/dist/polyfills/unenv-runtime/node/dns.mjs +81 -0
- package/dist/polyfills/unenv-runtime/node/domain.d.mts +8 -0
- package/dist/polyfills/unenv-runtime/node/domain.mjs +16 -0
- package/dist/polyfills/unenv-runtime/node/events.d.mts +13 -0
- package/dist/polyfills/unenv-runtime/node/events.mjs +12 -0
- package/dist/polyfills/unenv-runtime/node/fs/promises.d.mts +7 -0
- package/dist/polyfills/unenv-runtime/node/fs/promises.mjs +38 -0
- package/dist/polyfills/unenv-runtime/node/fs.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/fs.mjs +117 -0
- package/dist/polyfills/unenv-runtime/node/http.d.mts +23 -0
- package/dist/polyfills/unenv-runtime/node/http.mjs +45 -0
- package/dist/polyfills/unenv-runtime/node/http2.d.mts +15 -0
- package/dist/polyfills/unenv-runtime/node/http2.mjs +284 -0
- package/dist/polyfills/unenv-runtime/node/https.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/https.mjs +16 -0
- package/dist/polyfills/unenv-runtime/node/inspector/promises.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/inspector/promises.mjs +40 -0
- package/dist/polyfills/unenv-runtime/node/inspector.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/node/inspector.mjs +53 -0
- package/dist/polyfills/unenv-runtime/node/internal/async_hooks/async-hook.d.mts +7 -0
- package/dist/polyfills/unenv-runtime/node/internal/async_hooks/async-hook.mjs +115 -0
- package/dist/polyfills/unenv-runtime/node/internal/async_hooks/async-local-storage.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/async_hooks/async-local-storage.mjs +36 -0
- package/dist/polyfills/unenv-runtime/node/internal/async_hooks/async-resource.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/async_hooks/async-resource.mjs +37 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/base64.d.mts +4 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/base64.mjs +97 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/buffer.d.mts +13 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/buffer.mjs +1846 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/file.d.mts +14 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/file.mjs +26 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/ieee754.d.mts +4 -0
- package/dist/polyfills/unenv-runtime/node/internal/buffer/ieee754.mjs +89 -0
- package/dist/polyfills/unenv-runtime/node/internal/crypto/constants.d.mts +58 -0
- package/dist/polyfills/unenv-runtime/node/internal/crypto/constants.mjs +58 -0
- package/dist/polyfills/unenv-runtime/node/internal/crypto/node.d.mts +78 -0
- package/dist/polyfills/unenv-runtime/node/internal/crypto/node.mjs +110 -0
- package/dist/polyfills/unenv-runtime/node/internal/crypto/web.d.mts +5 -0
- package/dist/polyfills/unenv-runtime/node/internal/crypto/web.mjs +9 -0
- package/dist/polyfills/unenv-runtime/node/internal/dgram/socket.d.mts +31 -0
- package/dist/polyfills/unenv-runtime/node/internal/dgram/socket.mjs +61 -0
- package/dist/polyfills/unenv-runtime/node/internal/diagnostics_channel/channel.d.mts +18 -0
- package/dist/polyfills/unenv-runtime/node/internal/diagnostics_channel/channel.mjs +40 -0
- package/dist/polyfills/unenv-runtime/node/internal/diagnostics_channel/tracing-channel.d.mts +19 -0
- package/dist/polyfills/unenv-runtime/node/internal/diagnostics_channel/tracing-channel.mjs +48 -0
- package/dist/polyfills/unenv-runtime/node/internal/dns/constants.d.mts +28 -0
- package/dist/polyfills/unenv-runtime/node/internal/dns/constants.mjs +28 -0
- package/dist/polyfills/unenv-runtime/node/internal/domain/domain.d.mts +13 -0
- package/dist/polyfills/unenv-runtime/node/internal/domain/domain.mjs +19 -0
- package/dist/polyfills/unenv-runtime/node/internal/events/events.d.mts +207 -0
- package/dist/polyfills/unenv-runtime/node/internal/events/events.mjs +1097 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/classes.d.mts +8 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/classes.mjs +8 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/constants.d.mts +59 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/constants.mjs +59 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/fs.d.mts +96 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/fs.mjs +106 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/promises.d.mts +32 -0
- package/dist/polyfills/unenv-runtime/node/internal/fs/promises.mjs +32 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/agent.d.mts +14 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/agent.mjs +16 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/constants.d.mts +67 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/constants.mjs +103 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/request.d.mts +31 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/request.mjs +53 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/response.d.mts +42 -0
- package/dist/polyfills/unenv-runtime/node/internal/http/response.mjs +101 -0
- package/dist/polyfills/unenv-runtime/node/internal/http2/constants.d.mts +241 -0
- package/dist/polyfills/unenv-runtime/node/internal/http2/constants.mjs +241 -0
- package/dist/polyfills/unenv-runtime/node/internal/net/server.d.mts +17 -0
- package/dist/polyfills/unenv-runtime/node/internal/net/server.mjs +33 -0
- package/dist/polyfills/unenv-runtime/node/internal/net/socket.d.mts +45 -0
- package/dist/polyfills/unenv-runtime/node/internal/net/socket.mjs +83 -0
- package/dist/polyfills/unenv-runtime/node/internal/os/constants.d.mts +133 -0
- package/dist/polyfills/unenv-runtime/node/internal/os/constants.mjs +133 -0
- package/dist/polyfills/unenv-runtime/node/internal/perf_hooks/constants.d.mts +25 -0
- package/dist/polyfills/unenv-runtime/node/internal/perf_hooks/constants.mjs +25 -0
- package/dist/polyfills/unenv-runtime/node/internal/perf_hooks/histogram.d.mts +28 -0
- package/dist/polyfills/unenv-runtime/node/internal/perf_hooks/histogram.mjs +43 -0
- package/dist/polyfills/unenv-runtime/node/internal/perf_hooks/performance.d.mts +103 -0
- package/dist/polyfills/unenv-runtime/node/internal/perf_hooks/performance.mjs +232 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/env.d.mts +1 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/env.mjs +40 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/hrtime.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/hrtime.mjs +21 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/nexttick.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/nexttick.mjs +55 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/node-version.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/node-version.mjs +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/process.d.mts +113 -0
- package/dist/polyfills/unenv-runtime/node/internal/process/process.mjs +238 -0
- package/dist/polyfills/unenv-runtime/node/internal/punycode/punycode.d.mts +59 -0
- package/dist/polyfills/unenv-runtime/node/internal/punycode/punycode.mjs +410 -0
- package/dist/polyfills/unenv-runtime/node/internal/querystring/querystring.d.mts +11 -0
- package/dist/polyfills/unenv-runtime/node/internal/querystring/querystring.mjs +320 -0
- package/dist/polyfills/unenv-runtime/node/internal/readline/interface.d.mts +20 -0
- package/dist/polyfills/unenv-runtime/node/internal/readline/interface.mjs +31 -0
- package/dist/polyfills/unenv-runtime/node/internal/readline/promises/interface.d.mts +7 -0
- package/dist/polyfills/unenv-runtime/node/internal/readline/promises/interface.mjs +6 -0
- package/dist/polyfills/unenv-runtime/node/internal/readline/promises/readline.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/internal/readline/promises/readline.mjs +20 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/duplex.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/duplex.mjs +19 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/readable.d.mts +67 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/readable.mjs +112 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/transform.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/transform.mjs +9 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/writable.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/stream/writable.mjs +87 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/immediate.d.mts +9 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/immediate.mjs +28 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/scheduler.d.mts +6 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/scheduler.mjs +10 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/set-immediate.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/set-immediate.mjs +13 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/set-interval.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/set-interval.mjs +8 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/set-timeout.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/set-timeout.mjs +11 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/timeout.d.mts +11 -0
- package/dist/polyfills/unenv-runtime/node/internal/timers/timeout.mjs +30 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/constants.d.mts +7 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/constants.mjs +7 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/secure-context.d.mts +4 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/secure-context.mjs +3 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/server.d.mts +9 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/server.mjs +15 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/tls-socket.d.mts +31 -0
- package/dist/polyfills/unenv-runtime/node/internal/tls/tls-socket.mjs +48 -0
- package/dist/polyfills/unenv-runtime/node/internal/trace_events/tracing.d.mts +7 -0
- package/dist/polyfills/unenv-runtime/node/internal/trace_events/tracing.mjs +10 -0
- package/dist/polyfills/unenv-runtime/node/internal/tty/read-stream.d.mts +8 -0
- package/dist/polyfills/unenv-runtime/node/internal/tty/read-stream.mjs +12 -0
- package/dist/polyfills/unenv-runtime/node/internal/tty/write-stream.d.mts +20 -0
- package/dist/polyfills/unenv-runtime/node/internal/tty/write-stream.mjs +44 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/constants.d.mts +44 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/constants.mjs +44 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/errors.d.mts +26 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/errors.mjs +54 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/url.d.mts +22 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/url.mjs +181 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/util.d.mts +4 -0
- package/dist/polyfills/unenv-runtime/node/internal/url/util.mjs +7 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/inherits.d.mts +1 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/inherits.mjs +12 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/legacy-types.d.mts +19 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/legacy-types.mjs +25 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/log.d.mts +8 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/log.mjs +55 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/mime.d.mts +19 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/mime.mjs +35 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/promisify.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/promisify.mjs +23 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/types.d.mts +45 -0
- package/dist/polyfills/unenv-runtime/node/internal/util/types.mjs +45 -0
- package/dist/polyfills/unenv-runtime/node/internal/v8/deserializer.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/node/internal/v8/deserializer.mjs +23 -0
- package/dist/polyfills/unenv-runtime/node/internal/v8/profiler.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/internal/v8/profiler.mjs +11 -0
- package/dist/polyfills/unenv-runtime/node/internal/v8/serializer.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/node/internal/v8/serializer.mjs +15 -0
- package/dist/polyfills/unenv-runtime/node/internal/vm/constants.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/vm/constants.mjs +2 -0
- package/dist/polyfills/unenv-runtime/node/internal/vm/script.d.mts +7 -0
- package/dist/polyfills/unenv-runtime/node/internal/vm/script.mjs +15 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/broadcast-channel.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/broadcast-channel.mjs +13 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/message-channel.d.mts +5 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/message-channel.mjs +5 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/message-port.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/message-port.mjs +17 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/worker.d.mts +21 -0
- package/dist/polyfills/unenv-runtime/node/internal/worker_threads/worker.mjs +25 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/codes.d.mts +21 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/codes.mjs +21 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/constants.d.mts +108 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/constants.mjs +108 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/_shared.d.mts +22 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/_shared.mjs +40 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/brotli.d.mts +16 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/brotli.mjs +16 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/deflate.d.mts +29 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/deflate.mjs +36 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/gzip.d.mts +16 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/gzip.mjs +16 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/zip.d.mts +9 -0
- package/dist/polyfills/unenv-runtime/node/internal/zlib/formats/zip.mjs +9 -0
- package/dist/polyfills/unenv-runtime/node/module.d.mts +54 -0
- package/dist/polyfills/unenv-runtime/node/module.mjs +191 -0
- package/dist/polyfills/unenv-runtime/node/net.d.mts +22 -0
- package/dist/polyfills/unenv-runtime/node/net.mjs +52 -0
- package/dist/polyfills/unenv-runtime/node/os.d.mts +26 -0
- package/dist/polyfills/unenv-runtime/node/os.mjs +118 -0
- package/dist/polyfills/unenv-runtime/node/path/posix.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/path/posix.mjs +2 -0
- package/dist/polyfills/unenv-runtime/node/path/win32.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/path/win32.mjs +2 -0
- package/dist/polyfills/unenv-runtime/node/path.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/node/path.mjs +31 -0
- package/dist/polyfills/unenv-runtime/node/perf_hooks.d.mts +8 -0
- package/dist/polyfills/unenv-runtime/node/perf_hooks.mjs +51 -0
- package/dist/polyfills/unenv-runtime/node/process.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/process.mjs +12 -0
- package/dist/polyfills/unenv-runtime/node/punycode.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/punycode.mjs +3 -0
- package/dist/polyfills/unenv-runtime/node/querystring.d.mts +49 -0
- package/dist/polyfills/unenv-runtime/node/querystring.mjs +766 -0
- package/dist/polyfills/unenv-runtime/node/readline/promises.d.mts +6 -0
- package/dist/polyfills/unenv-runtime/node/readline/promises.mjs +10 -0
- package/dist/polyfills/unenv-runtime/node/readline.d.mts +13 -0
- package/dist/polyfills/unenv-runtime/node/readline.mjs +21 -0
- package/dist/polyfills/unenv-runtime/node/repl.d.mts +10 -0
- package/dist/polyfills/unenv-runtime/node/repl.mjs +20 -0
- package/dist/polyfills/unenv-runtime/node/sqlite.d.mts +6 -0
- package/dist/polyfills/unenv-runtime/node/sqlite.mjs +9 -0
- package/dist/polyfills/unenv-runtime/node/stream/consumers.d.mts +7 -0
- package/dist/polyfills/unenv-runtime/node/stream/consumers.mjs +13 -0
- package/dist/polyfills/unenv-runtime/node/stream/promises.d.mts +4 -0
- package/dist/polyfills/unenv-runtime/node/stream/promises.mjs +7 -0
- package/dist/polyfills/unenv-runtime/node/stream/web.d.mts +24 -0
- package/dist/polyfills/unenv-runtime/node/stream/web.mjs +41 -0
- package/dist/polyfills/unenv-runtime/node/stream.d.mts +42 -0
- package/dist/polyfills/unenv-runtime/node/stream.mjs +54 -0
- package/dist/polyfills/unenv-runtime/node/string_decoder.d.mts +5 -0
- package/dist/polyfills/unenv-runtime/node/string_decoder.mjs +3 -0
- package/dist/polyfills/unenv-runtime/node/sys.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/node/sys.mjs +2 -0
- package/dist/polyfills/unenv-runtime/node/timers/promises.d.mts +6 -0
- package/dist/polyfills/unenv-runtime/node/timers/promises.mjs +14 -0
- package/dist/polyfills/unenv-runtime/node/timers.d.mts +15 -0
- package/dist/polyfills/unenv-runtime/node/timers.mjs +32 -0
- package/dist/polyfills/unenv-runtime/node/tls.d.mts +15 -0
- package/dist/polyfills/unenv-runtime/node/tls.mjs +41 -0
- package/dist/polyfills/unenv-runtime/node/trace_events.d.mts +5 -0
- package/dist/polyfills/unenv-runtime/node/trace_events.mjs +9 -0
- package/dist/polyfills/unenv-runtime/node/tty.d.mts +9 -0
- package/dist/polyfills/unenv-runtime/node/tty.mjs +12 -0
- package/dist/polyfills/unenv-runtime/node/url.d.mts +61 -0
- package/dist/polyfills/unenv-runtime/node/url.mjs +1044 -0
- package/dist/polyfills/unenv-runtime/node/util/types.d.mts +3 -0
- package/dist/polyfills/unenv-runtime/node/util/types.mjs +3 -0
- package/dist/polyfills/unenv-runtime/node/util.d.mts +32 -0
- package/dist/polyfills/unenv-runtime/node/util.mjs +84 -0
- package/dist/polyfills/unenv-runtime/node/v8.d.mts +29 -0
- package/dist/polyfills/unenv-runtime/node/v8.mjs +108 -0
- package/dist/polyfills/unenv-runtime/node/vm.d.mts +15 -0
- package/dist/polyfills/unenv-runtime/node/vm.mjs +41 -0
- package/dist/polyfills/unenv-runtime/node/wasi.d.mts +4 -0
- package/dist/polyfills/unenv-runtime/node/wasi.mjs +3 -0
- package/dist/polyfills/unenv-runtime/node/worker_threads.d.mts +23 -0
- package/dist/polyfills/unenv-runtime/node/worker_threads.mjs +55 -0
- package/dist/polyfills/unenv-runtime/node/zlib.d.mts +16 -0
- package/dist/polyfills/unenv-runtime/node/zlib.mjs +212 -0
- package/dist/polyfills/unenv-runtime/npm/cross-fetch.d.mts +6 -0
- package/dist/polyfills/unenv-runtime/npm/cross-fetch.mjs +6 -0
- package/dist/polyfills/unenv-runtime/npm/debug.d.mts +15 -0
- package/dist/polyfills/unenv-runtime/npm/debug.mjs +43 -0
- package/dist/polyfills/unenv-runtime/npm/fsevents.d.mts +16 -0
- package/dist/polyfills/unenv-runtime/npm/fsevents.mjs +20 -0
- package/dist/polyfills/unenv-runtime/npm/inherits.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/npm/inherits.mjs +2 -0
- package/dist/polyfills/unenv-runtime/npm/node-fetch.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/npm/node-fetch.mjs +23 -0
- package/dist/polyfills/unenv-runtime/npm/whatwg-url/index.d.mts +13 -0
- package/dist/polyfills/unenv-runtime/npm/whatwg-url/index.mjs +15 -0
- package/dist/polyfills/unenv-runtime/npm/whatwg-url/webidl2js-wrapper.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/npm/whatwg-url/webidl2js-wrapper.mjs +2 -0
- package/dist/polyfills/unenv-runtime/polyfill/buffer.d.mts +1 -0
- package/dist/polyfills/unenv-runtime/polyfill/buffer.mjs +4 -0
- package/dist/polyfills/unenv-runtime/polyfill/globalthis-global.d.mts +1 -0
- package/dist/polyfills/unenv-runtime/polyfill/globalthis-global.mjs +5 -0
- package/dist/polyfills/unenv-runtime/polyfill/globalthis.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/polyfill/globalthis.mjs +2 -0
- package/dist/polyfills/unenv-runtime/polyfill/package.json +3 -0
- package/dist/polyfills/unenv-runtime/polyfill/performance.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/polyfill/performance.mjs +10 -0
- package/dist/polyfills/unenv-runtime/polyfill/process.d.mts +2 -0
- package/dist/polyfills/unenv-runtime/polyfill/process.mjs +10 -0
- package/dist/polyfills/unenv-runtime/polyfill/source-maps.mjs +15 -0
- package/dist/polyfills/unenv-runtime/polyfill/timers.d.mts +1 -0
- package/dist/polyfills/unenv-runtime/polyfill/timers.mjs +7 -0
- package/dist/polyfills/unenv-runtime/web/performance/_polyfills.d.mts +100 -0
- package/dist/polyfills/unenv-runtime/web/performance/_polyfills.mjs +184 -0
- package/dist/polyfills/unenv-runtime/web/performance/index.d.mts +12 -0
- package/dist/polyfills/unenv-runtime/web/performance/index.mjs +14 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +39 -10
- package/dist/run.js.map +1 -1
- package/package.json +2 -2
- package/src/polyfills/fs.ts +5 -3
- package/src/polyfills/process.ts +10 -8
- package/src/run.ts +41 -11
|
@@ -0,0 +1,1097 @@
|
|
|
1
|
+
import { AsyncResource } from "node:async_hooks";
|
|
2
|
+
// By default EventEmitters will print a warning if more than 10 listeners are
|
|
3
|
+
// added to it. This is a useful default which helps finding memory leaks.
|
|
4
|
+
let defaultMaxListeners = 10;
|
|
5
|
+
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
|
|
6
|
+
// Inspect (mocked)
|
|
7
|
+
const inspect = (value, _opts) => value;
|
|
8
|
+
// Errors
|
|
9
|
+
const ERR_INVALID_THIS = Error;
|
|
10
|
+
const ERR_UNHANDLED_ERROR = Error;
|
|
11
|
+
const ERR_INVALID_ARG_TYPE = Error;
|
|
12
|
+
const AbortError = Error;
|
|
13
|
+
const genericNodeError = Error;
|
|
14
|
+
// Symbols
|
|
15
|
+
const kRejection = /* @__PURE__ */ Symbol.for("nodejs.rejection");
|
|
16
|
+
const kCapture = /* @__PURE__ */ Symbol.for("kCapture");
|
|
17
|
+
const kErrorMonitor = /* @__PURE__ */ Symbol.for("events.errorMonitor");
|
|
18
|
+
const kShapeMode = /* @__PURE__ */ Symbol.for("shapeMode");
|
|
19
|
+
const kMaxEventTargetListeners = /* @__PURE__ */ Symbol.for("events.maxEventTargetListeners");
|
|
20
|
+
const kEnhanceStackBeforeInspector = /* @__PURE__ */ Symbol.for("kEnhanceStackBeforeInspector");
|
|
21
|
+
const kWatermarkData = /* @__PURE__ */ Symbol.for("nodejs.watermarkData");
|
|
22
|
+
const kEventEmitter = /* @__PURE__ */ Symbol.for("kEventEmitter");
|
|
23
|
+
const kAsyncResource = /* @__PURE__ */ Symbol.for("kAsyncResource");
|
|
24
|
+
const kFirstEventParam = /* @__PURE__ */ Symbol.for("kFirstEventParam");
|
|
25
|
+
const kResistStopPropagation = /* @__PURE__ */ Symbol.for("kResistStopPropagation");
|
|
26
|
+
const kMaxEventTargetListenersWarned = /* @__PURE__ */ Symbol.for("events.maxEventTargetListenersWarned");
|
|
27
|
+
// ----------------------------------------------------------------------------
|
|
28
|
+
// EventEmitter
|
|
29
|
+
// ----------------------------------------------------------------------------
|
|
30
|
+
export class _EventEmitter {
|
|
31
|
+
// Internal state
|
|
32
|
+
_events = undefined;
|
|
33
|
+
_eventsCount = 0;
|
|
34
|
+
_maxListeners = defaultMaxListeners;
|
|
35
|
+
[kCapture] = false;
|
|
36
|
+
[kShapeMode] = false;
|
|
37
|
+
// Symbols
|
|
38
|
+
static captureRejectionSymbol = kRejection;
|
|
39
|
+
static errorMonitor = kErrorMonitor;
|
|
40
|
+
static kMaxEventTargetListeners = kMaxEventTargetListeners;
|
|
41
|
+
static kMaxEventTargetListenersWarned = kMaxEventTargetListenersWarned;
|
|
42
|
+
// Static utils
|
|
43
|
+
static usingDomains = false;
|
|
44
|
+
static get on() {
|
|
45
|
+
return on;
|
|
46
|
+
}
|
|
47
|
+
static get once() {
|
|
48
|
+
return once;
|
|
49
|
+
}
|
|
50
|
+
static get getEventListeners() {
|
|
51
|
+
return getEventListeners;
|
|
52
|
+
}
|
|
53
|
+
static get getMaxListeners() {
|
|
54
|
+
return getMaxListeners;
|
|
55
|
+
}
|
|
56
|
+
static get addAbortListener() {
|
|
57
|
+
return addAbortListener;
|
|
58
|
+
}
|
|
59
|
+
static get EventEmitterAsyncResource() {
|
|
60
|
+
return EventEmitterAsyncResource;
|
|
61
|
+
}
|
|
62
|
+
static get EventEmitter() {
|
|
63
|
+
return _EventEmitter;
|
|
64
|
+
}
|
|
65
|
+
static setMaxListeners(n = defaultMaxListeners, ...eventTargets) {
|
|
66
|
+
// validateNumber(n, "setMaxListeners", 0);
|
|
67
|
+
if (eventTargets.length === 0) {
|
|
68
|
+
defaultMaxListeners = n;
|
|
69
|
+
} else {
|
|
70
|
+
for (const target of eventTargets) {
|
|
71
|
+
if (isEventTarget(target)) {
|
|
72
|
+
// @ts-expect-error
|
|
73
|
+
target[kMaxEventTargetListeners] = n;
|
|
74
|
+
// @ts-expect-error
|
|
75
|
+
target[kMaxEventTargetListenersWarned] = false;
|
|
76
|
+
} else if (typeof target.setMaxListeners === "function") {
|
|
77
|
+
target.setMaxListeners(n);
|
|
78
|
+
} else {
|
|
79
|
+
throw new ERR_INVALID_ARG_TYPE(
|
|
80
|
+
"eventTargets",
|
|
81
|
+
["EventEmitter", "EventTarget"],
|
|
82
|
+
// @ts-expect-error
|
|
83
|
+
target
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
static listenerCount(emitter, type) {
|
|
90
|
+
if (typeof emitter.listenerCount === "function") {
|
|
91
|
+
return emitter.listenerCount(type);
|
|
92
|
+
}
|
|
93
|
+
_EventEmitter.prototype.listenerCount.call(emitter, type);
|
|
94
|
+
}
|
|
95
|
+
static init() {
|
|
96
|
+
throw new Error("EventEmitter.init() is not implemented.");
|
|
97
|
+
}
|
|
98
|
+
static get captureRejections() {
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
return this[kCapture];
|
|
101
|
+
}
|
|
102
|
+
static set captureRejections(value) {
|
|
103
|
+
// validateBoolean(value, "captureRejections");
|
|
104
|
+
// @ts-expect-error
|
|
105
|
+
this[kCapture] = value;
|
|
106
|
+
}
|
|
107
|
+
static get defaultMaxListeners() {
|
|
108
|
+
return defaultMaxListeners;
|
|
109
|
+
}
|
|
110
|
+
static set defaultMaxListeners(arg) {
|
|
111
|
+
// validateNumber(arg, "defaultMaxListeners", 0);
|
|
112
|
+
defaultMaxListeners = arg;
|
|
113
|
+
}
|
|
114
|
+
// Constructor
|
|
115
|
+
constructor(opts) {
|
|
116
|
+
if (this._events === undefined || this._events === Object.getPrototypeOf(this)._events) {
|
|
117
|
+
this._events = { __proto__: null };
|
|
118
|
+
this._eventsCount = 0;
|
|
119
|
+
this[kShapeMode] = false;
|
|
120
|
+
} else {
|
|
121
|
+
this[kShapeMode] = true;
|
|
122
|
+
}
|
|
123
|
+
this._maxListeners = this._maxListeners || undefined;
|
|
124
|
+
if (opts?.captureRejections) {
|
|
125
|
+
// validateBoolean(opts.captureRejections, "options.captureRejections");
|
|
126
|
+
this[kCapture] = Boolean(opts.captureRejections);
|
|
127
|
+
} else {
|
|
128
|
+
// Assigning the kCapture property directly saves an expensive
|
|
129
|
+
// prototype lookup in a very sensitive hot path.
|
|
130
|
+
this[kCapture] = _EventEmitter.prototype[kCapture];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Increases the max listeners of the event emitter.
|
|
135
|
+
* @param {number} n
|
|
136
|
+
* @returns {EventEmitter}
|
|
137
|
+
*/
|
|
138
|
+
setMaxListeners(n) {
|
|
139
|
+
// validateNumber(n, "setMaxListeners", 0);
|
|
140
|
+
this._maxListeners = n;
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns the current max listener value for the event emitter.
|
|
145
|
+
* @returns {number}
|
|
146
|
+
*/
|
|
147
|
+
getMaxListeners() {
|
|
148
|
+
return _getMaxListeners(this);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Synchronously calls each of the listeners registered
|
|
152
|
+
* for the event.
|
|
153
|
+
* @param {...any} [args]
|
|
154
|
+
* @returns {boolean}
|
|
155
|
+
*/
|
|
156
|
+
emit(type, ...args) {
|
|
157
|
+
let doError = type === "error";
|
|
158
|
+
const events = this._events;
|
|
159
|
+
if (events !== undefined) {
|
|
160
|
+
if (doError && events[kErrorMonitor] !== undefined) this.emit(kErrorMonitor, ...args);
|
|
161
|
+
doError = doError && events.error === undefined;
|
|
162
|
+
} else if (!doError) return false;
|
|
163
|
+
// If there is no 'error' event listener then throw.
|
|
164
|
+
if (doError) {
|
|
165
|
+
let er;
|
|
166
|
+
if (args.length > 0) er = args[0];
|
|
167
|
+
if (er instanceof Error) {
|
|
168
|
+
try {
|
|
169
|
+
const capture = {};
|
|
170
|
+
Error.captureStackTrace?.(capture, _EventEmitter.prototype.emit);
|
|
171
|
+
Object.defineProperty(er, kEnhanceStackBeforeInspector, {
|
|
172
|
+
__proto__: null,
|
|
173
|
+
value: Function.prototype.bind(enhanceStackTrace, this, er, capture),
|
|
174
|
+
configurable: true
|
|
175
|
+
});
|
|
176
|
+
} catch {}
|
|
177
|
+
// Note: The comments on the `throw` lines are intentional, they show
|
|
178
|
+
// up in Node's output if this results in an unhandled exception.
|
|
179
|
+
throw er;
|
|
180
|
+
}
|
|
181
|
+
let stringifiedEr;
|
|
182
|
+
try {
|
|
183
|
+
stringifiedEr = inspect(er);
|
|
184
|
+
} catch {
|
|
185
|
+
stringifiedEr = er;
|
|
186
|
+
}
|
|
187
|
+
// At least give some kind of context to the user
|
|
188
|
+
const err = new ERR_UNHANDLED_ERROR(stringifiedEr);
|
|
189
|
+
// @ts-expect-error
|
|
190
|
+
err.context = er;
|
|
191
|
+
throw err;
|
|
192
|
+
}
|
|
193
|
+
const handler = events[type];
|
|
194
|
+
if (handler === undefined) return false;
|
|
195
|
+
if (typeof handler === "function") {
|
|
196
|
+
const result = handler.apply(this, args);
|
|
197
|
+
// We check if result is undefined first because that
|
|
198
|
+
// is the most common case so we do not pay any perf
|
|
199
|
+
// penalty
|
|
200
|
+
if (result !== undefined && result !== null) {
|
|
201
|
+
addCatch(this, result, type, args);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
const len = handler.length;
|
|
205
|
+
const listeners = arrayClone(handler);
|
|
206
|
+
for (let i = 0; i < len; ++i) {
|
|
207
|
+
const result = listeners[i].apply(this, args);
|
|
208
|
+
// We check if result is undefined first because that
|
|
209
|
+
// is the most common case so we do not pay any perf
|
|
210
|
+
// penalty.
|
|
211
|
+
// This code is duplicated because extracting it away
|
|
212
|
+
// would make it non-inlineable.
|
|
213
|
+
if (result !== undefined && result !== null) {
|
|
214
|
+
addCatch(this, result, type, args);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Adds a listener to the event emitter.
|
|
222
|
+
* @returns {EventEmitter}
|
|
223
|
+
*/
|
|
224
|
+
addListener(type, listener) {
|
|
225
|
+
_addListener(this, type, listener, false);
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
on(type, listener) {
|
|
229
|
+
return this.addListener(type, listener);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Adds the `listener` function to the beginning of
|
|
233
|
+
* the listeners array.
|
|
234
|
+
*/
|
|
235
|
+
prependListener(type, listener) {
|
|
236
|
+
_addListener(this, type, listener, true);
|
|
237
|
+
return this;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Adds a one-time `listener` function to the event emitter.
|
|
241
|
+
*/
|
|
242
|
+
once(type, listener) {
|
|
243
|
+
checkListener(listener);
|
|
244
|
+
this.on(type, _onceWrap(this, type, listener));
|
|
245
|
+
return this;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Adds a one-time `listener` function to the beginning of
|
|
249
|
+
* the listeners array.
|
|
250
|
+
*/
|
|
251
|
+
prependOnceListener(type, listener) {
|
|
252
|
+
checkListener(listener);
|
|
253
|
+
this.prependListener(type, _onceWrap(this, type, listener));
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Removes the specified `listener` from the listeners array.
|
|
258
|
+
* @param {string | symbol} type
|
|
259
|
+
* @param {Function} listener
|
|
260
|
+
* @returns {EventEmitter}
|
|
261
|
+
*/
|
|
262
|
+
removeListener(type, listener) {
|
|
263
|
+
checkListener(listener);
|
|
264
|
+
const events = this._events;
|
|
265
|
+
if (events === undefined) return this;
|
|
266
|
+
const list = events[type];
|
|
267
|
+
if (list === undefined) return this;
|
|
268
|
+
if (list === listener || list.listener === listener) {
|
|
269
|
+
this._eventsCount -= 1;
|
|
270
|
+
if (this[kShapeMode]) {
|
|
271
|
+
events[type] = undefined;
|
|
272
|
+
} else if (this._eventsCount === 0) {
|
|
273
|
+
this._events = { __proto__: null };
|
|
274
|
+
} else {
|
|
275
|
+
delete events[type];
|
|
276
|
+
if (events.removeListener) this.emit("removeListener", type, list.listener || listener);
|
|
277
|
+
}
|
|
278
|
+
} else if (typeof list !== "function") {
|
|
279
|
+
let position = -1;
|
|
280
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
281
|
+
if (list[i] === listener || list[i].listener === listener) {
|
|
282
|
+
position = i;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (position < 0) return this;
|
|
287
|
+
if (position === 0) list.shift();
|
|
288
|
+
else {
|
|
289
|
+
spliceOne(list, position);
|
|
290
|
+
}
|
|
291
|
+
if (list.length === 1) events[type] = list[0];
|
|
292
|
+
if (events.removeListener !== undefined) this.emit("removeListener", type, listener);
|
|
293
|
+
}
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
off(type, listener) {
|
|
297
|
+
return this.removeListener(type, listener);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Removes all listeners from the event emitter. (Only
|
|
301
|
+
* removes listeners for a specific event name if specified
|
|
302
|
+
* as `type`).
|
|
303
|
+
*/
|
|
304
|
+
removeAllListeners(type) {
|
|
305
|
+
const events = this._events;
|
|
306
|
+
if (events === undefined) return this;
|
|
307
|
+
// Not listening for removeListener, no need to emit
|
|
308
|
+
if (events.removeListener === undefined) {
|
|
309
|
+
if (arguments.length === 0) {
|
|
310
|
+
this._events = { __proto__: null };
|
|
311
|
+
this._eventsCount = 0;
|
|
312
|
+
} else if (events[type] !== undefined) {
|
|
313
|
+
if (--this._eventsCount === 0) this._events = { __proto__: null };
|
|
314
|
+
else delete events[type];
|
|
315
|
+
}
|
|
316
|
+
this[kShapeMode] = false;
|
|
317
|
+
return this;
|
|
318
|
+
}
|
|
319
|
+
// Emit removeListener for all listeners on all events
|
|
320
|
+
if (arguments.length === 0) {
|
|
321
|
+
for (const key of Reflect.ownKeys(events)) {
|
|
322
|
+
if (key === "removeListener") continue;
|
|
323
|
+
this.removeAllListeners(key);
|
|
324
|
+
}
|
|
325
|
+
this.removeAllListeners("removeListener");
|
|
326
|
+
this._events = { __proto__: null };
|
|
327
|
+
this._eventsCount = 0;
|
|
328
|
+
this[kShapeMode] = false;
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
const listeners = events[type];
|
|
332
|
+
if (typeof listeners === "function") {
|
|
333
|
+
this.removeListener(type, listeners);
|
|
334
|
+
} else if (listeners !== undefined) {
|
|
335
|
+
// LIFO order
|
|
336
|
+
for (let i = listeners.length - 1; i >= 0; i--) {
|
|
337
|
+
this.removeListener(type, listeners[i]);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return this;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Returns a copy of the array of listeners for the event name
|
|
344
|
+
* specified as `type`.
|
|
345
|
+
* @param {string | symbol} type
|
|
346
|
+
* @returns {Function[]}
|
|
347
|
+
*/
|
|
348
|
+
listeners(type) {
|
|
349
|
+
return _listeners(this, type, true);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Returns a copy of the array of listeners and wrappers for
|
|
353
|
+
* the event name specified as `type`.
|
|
354
|
+
* @returns {Function[]}
|
|
355
|
+
*/
|
|
356
|
+
rawListeners(type) {
|
|
357
|
+
return _listeners(this, type, false);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Returns an array listing the events for which
|
|
361
|
+
* the emitter has registered listeners.
|
|
362
|
+
* @returns {any[]}
|
|
363
|
+
*/
|
|
364
|
+
eventNames() {
|
|
365
|
+
return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Returns the number of listeners listening to event name
|
|
369
|
+
*/
|
|
370
|
+
listenerCount(eventName, listener) {
|
|
371
|
+
const events = this._events;
|
|
372
|
+
if (events !== undefined) {
|
|
373
|
+
const evlistener = events[eventName];
|
|
374
|
+
if (typeof evlistener === "function") {
|
|
375
|
+
if (listener != null) {
|
|
376
|
+
return listener === evlistener || listener === evlistener.listener ? 1 : 0;
|
|
377
|
+
}
|
|
378
|
+
return 1;
|
|
379
|
+
} else if (evlistener !== undefined) {
|
|
380
|
+
if (listener != null) {
|
|
381
|
+
let matching = 0;
|
|
382
|
+
for (let i = 0, l = evlistener.length; i < l; i++) {
|
|
383
|
+
if (evlistener[i] === listener || evlistener[i].listener === listener) {
|
|
384
|
+
matching++;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return matching;
|
|
388
|
+
}
|
|
389
|
+
return evlistener.length;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return 0;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
// ----------------------------------------------------------------------------
|
|
396
|
+
// EventEmitterAsyncResource
|
|
397
|
+
// ----------------------------------------------------------------------------
|
|
398
|
+
export class EventEmitterAsyncResource extends _EventEmitter {
|
|
399
|
+
/**
|
|
400
|
+
* @param {{
|
|
401
|
+
* name?: string,
|
|
402
|
+
* triggerAsyncId?: number,
|
|
403
|
+
* requireManualDestroy?: boolean,
|
|
404
|
+
* }} [options]
|
|
405
|
+
*/
|
|
406
|
+
constructor(options) {
|
|
407
|
+
let name;
|
|
408
|
+
if (typeof options === "string") {
|
|
409
|
+
name = options;
|
|
410
|
+
options = undefined;
|
|
411
|
+
} else {
|
|
412
|
+
// if (new.target === EventEmitterAsyncResource) {
|
|
413
|
+
// validateString(options?.name, "options.name");
|
|
414
|
+
// }
|
|
415
|
+
name = options?.name || new.target.name;
|
|
416
|
+
}
|
|
417
|
+
super(options);
|
|
418
|
+
// @ts-expect-error
|
|
419
|
+
this[kAsyncResource] = new EventEmitterReferencingAsyncResource(this, name, options);
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* @param {symbol,string} event
|
|
423
|
+
* @param {...any} args
|
|
424
|
+
* @returns {boolean}
|
|
425
|
+
*/
|
|
426
|
+
emit(event, ...args) {
|
|
427
|
+
// @ts-expect-error
|
|
428
|
+
if (this[kAsyncResource] === undefined) throw new ERR_INVALID_THIS("EventEmitterAsyncResource");
|
|
429
|
+
const { asyncResource } = this;
|
|
430
|
+
Array.prototype.unshift(args, super.emit, this, event);
|
|
431
|
+
return Reflect.apply(asyncResource.runInAsyncScope, asyncResource, args);
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* @returns {void}
|
|
435
|
+
*/
|
|
436
|
+
emitDestroy() {
|
|
437
|
+
// @ts-expect-error
|
|
438
|
+
if (this[kAsyncResource] === undefined) throw new ERR_INVALID_THIS("EventEmitterAsyncResource");
|
|
439
|
+
this.asyncResource.emitDestroy();
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* @type {number}
|
|
443
|
+
*/
|
|
444
|
+
get asyncId() {
|
|
445
|
+
// @ts-expect-error
|
|
446
|
+
if (this[kAsyncResource] === undefined) throw new ERR_INVALID_THIS("EventEmitterAsyncResource");
|
|
447
|
+
return this.asyncResource.asyncId();
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* @type {number}
|
|
451
|
+
*/
|
|
452
|
+
get triggerAsyncId() {
|
|
453
|
+
// @ts-expect-error
|
|
454
|
+
if (this[kAsyncResource] === undefined) throw new ERR_INVALID_THIS("EventEmitterAsyncResource");
|
|
455
|
+
return this.asyncResource.triggerAsyncId();
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* @type {EventEmitterReferencingAsyncResource}
|
|
459
|
+
*/
|
|
460
|
+
get asyncResource() {
|
|
461
|
+
// @ts-expect-error
|
|
462
|
+
if (this[kAsyncResource] === undefined) throw new ERR_INVALID_THIS("EventEmitterAsyncResource");
|
|
463
|
+
// @ts-expect-error
|
|
464
|
+
return this[kAsyncResource];
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
// This implementation was adapted straight from addaleax's
|
|
468
|
+
// eventemitter-asyncresource MIT-licensed userland module.
|
|
469
|
+
// https://github.com/addaleax/eventemitter-asyncresource
|
|
470
|
+
class EventEmitterReferencingAsyncResource extends AsyncResource {
|
|
471
|
+
/**
|
|
472
|
+
* @param {EventEmitter} ee
|
|
473
|
+
* @param {string} [type]
|
|
474
|
+
* @param {{
|
|
475
|
+
* triggerAsyncId?: number,
|
|
476
|
+
* requireManualDestroy?: boolean,
|
|
477
|
+
* }} [options]
|
|
478
|
+
*/
|
|
479
|
+
constructor(ee, type, options) {
|
|
480
|
+
super(type, options);
|
|
481
|
+
// @ts-expect-error
|
|
482
|
+
this[kEventEmitter] = ee;
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* @type {EventEmitter}
|
|
486
|
+
*/
|
|
487
|
+
get eventEmitter() {
|
|
488
|
+
// @ts-expect-error
|
|
489
|
+
if (this[kEventEmitter] === undefined) throw new ERR_INVALID_THIS("EventEmitterReferencingAsyncResource");
|
|
490
|
+
// @ts-expect-error
|
|
491
|
+
return this[kEventEmitter];
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
// ----------------------------------------------------------------------------
|
|
495
|
+
// Exported utils
|
|
496
|
+
// ----------------------------------------------------------------------------
|
|
497
|
+
/**
|
|
498
|
+
* Returns an `AsyncIterator` that iterates `event` events.
|
|
499
|
+
* @param {EventEmitter} emitter
|
|
500
|
+
* @param {string | symbol} event
|
|
501
|
+
* @param {{
|
|
502
|
+
* signal: AbortSignal;
|
|
503
|
+
* close?: string[];
|
|
504
|
+
* highWaterMark?: number,
|
|
505
|
+
* lowWaterMark?: number
|
|
506
|
+
* }} [options]
|
|
507
|
+
* @returns {AsyncIterator}
|
|
508
|
+
*/
|
|
509
|
+
export const on = function on(emitter, event, options = {}) {
|
|
510
|
+
// Parameters validation
|
|
511
|
+
// validateObject(options, "options");
|
|
512
|
+
const signal = options.signal;
|
|
513
|
+
// validateAbortSignal(signal, "options.signal");
|
|
514
|
+
if (signal?.aborted) {
|
|
515
|
+
throw new AbortError(undefined, { cause: signal?.reason });
|
|
516
|
+
}
|
|
517
|
+
// Support both highWaterMark and highWatermark for backward compatibility
|
|
518
|
+
const highWatermark = options.highWaterMark ?? options.highWatermark ?? Number.MAX_SAFE_INTEGER;
|
|
519
|
+
// validateInteger(highWatermark, "options.highWaterMark", 1);
|
|
520
|
+
// Support both lowWaterMark and lowWatermark for backward compatibility
|
|
521
|
+
const lowWatermark = options.lowWaterMark ?? options.lowWatermark ?? 1;
|
|
522
|
+
// validateInteger(lowWatermark, "options.lowWaterMark", 1);
|
|
523
|
+
// Preparing controlling queues and variables
|
|
524
|
+
const unconsumedEvents = new FixedQueue();
|
|
525
|
+
const unconsumedPromises = new FixedQueue();
|
|
526
|
+
let paused = false;
|
|
527
|
+
let error = null;
|
|
528
|
+
let finished = false;
|
|
529
|
+
let size = 0;
|
|
530
|
+
const iterator = Object.setPrototypeOf({
|
|
531
|
+
next() {
|
|
532
|
+
// First, we consume all unread events
|
|
533
|
+
if (size) {
|
|
534
|
+
const value = unconsumedEvents.shift();
|
|
535
|
+
size--;
|
|
536
|
+
if (paused && size < lowWatermark) {
|
|
537
|
+
// @ts-expect-error
|
|
538
|
+
emitter.resume?.();
|
|
539
|
+
paused = false;
|
|
540
|
+
}
|
|
541
|
+
return Promise.resolve(createIterResult(value, false));
|
|
542
|
+
}
|
|
543
|
+
// Then we error, if an error happened
|
|
544
|
+
// This happens one time if at all, because after 'error'
|
|
545
|
+
// we stop listening
|
|
546
|
+
if (error) {
|
|
547
|
+
const p = Promise.reject(error);
|
|
548
|
+
// Only the first element errors
|
|
549
|
+
error = null;
|
|
550
|
+
return p;
|
|
551
|
+
}
|
|
552
|
+
// If the iterator is finished, resolve to done
|
|
553
|
+
if (finished) return closeHandler();
|
|
554
|
+
// Wait until an event happens
|
|
555
|
+
return new Promise(function(resolve, reject) {
|
|
556
|
+
unconsumedPromises.push({
|
|
557
|
+
resolve,
|
|
558
|
+
reject
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
},
|
|
562
|
+
return() {
|
|
563
|
+
return closeHandler();
|
|
564
|
+
},
|
|
565
|
+
throw(err) {
|
|
566
|
+
if (!err || !(err instanceof Error)) {
|
|
567
|
+
throw new ERR_INVALID_ARG_TYPE(
|
|
568
|
+
"EventEmitter.AsyncIterator",
|
|
569
|
+
"Error",
|
|
570
|
+
// @ts-expect-error
|
|
571
|
+
err
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
errorHandler(err);
|
|
575
|
+
},
|
|
576
|
+
[Symbol.asyncIterator]() {
|
|
577
|
+
return this;
|
|
578
|
+
},
|
|
579
|
+
[kWatermarkData]: {
|
|
580
|
+
get size() {
|
|
581
|
+
return size;
|
|
582
|
+
},
|
|
583
|
+
get low() {
|
|
584
|
+
return lowWatermark;
|
|
585
|
+
},
|
|
586
|
+
get high() {
|
|
587
|
+
return highWatermark;
|
|
588
|
+
},
|
|
589
|
+
get isPaused() {
|
|
590
|
+
return paused;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}, AsyncIteratorPrototype);
|
|
594
|
+
// Adding event handlers
|
|
595
|
+
const { addEventListener, removeAll } = listenersController();
|
|
596
|
+
addEventListener(emitter, event, options[kFirstEventParam] ? eventHandler : function(...args) {
|
|
597
|
+
return eventHandler(args);
|
|
598
|
+
});
|
|
599
|
+
if (event !== "error" && typeof emitter.on === "function") {
|
|
600
|
+
addEventListener(emitter, "error", errorHandler);
|
|
601
|
+
}
|
|
602
|
+
const closeEvents = options?.close;
|
|
603
|
+
if (closeEvents?.length) {
|
|
604
|
+
for (const closeEvent of closeEvents) {
|
|
605
|
+
addEventListener(emitter, closeEvent, closeHandler);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
const abortListenerDisposable = signal ? addAbortListener(signal, abortListener) : null;
|
|
609
|
+
return iterator;
|
|
610
|
+
function abortListener() {
|
|
611
|
+
errorHandler(new AbortError(undefined, { cause: signal?.reason }));
|
|
612
|
+
}
|
|
613
|
+
function eventHandler(value) {
|
|
614
|
+
if (unconsumedPromises.isEmpty()) {
|
|
615
|
+
size++;
|
|
616
|
+
if (!paused && size > highWatermark) {
|
|
617
|
+
paused = true;
|
|
618
|
+
// @ts-expect-error
|
|
619
|
+
emitter.pause?.();
|
|
620
|
+
}
|
|
621
|
+
unconsumedEvents.push(value);
|
|
622
|
+
} else unconsumedPromises.shift().resolve(createIterResult(value, false));
|
|
623
|
+
}
|
|
624
|
+
function errorHandler(err) {
|
|
625
|
+
if (unconsumedPromises.isEmpty()) error = err;
|
|
626
|
+
else unconsumedPromises.shift().reject(err);
|
|
627
|
+
closeHandler();
|
|
628
|
+
}
|
|
629
|
+
function closeHandler() {
|
|
630
|
+
abortListenerDisposable?.[Symbol.dispose]();
|
|
631
|
+
removeAll();
|
|
632
|
+
finished = true;
|
|
633
|
+
const doneResult = createIterResult(undefined, true);
|
|
634
|
+
while (!unconsumedPromises.isEmpty()) {
|
|
635
|
+
unconsumedPromises.shift().resolve(doneResult);
|
|
636
|
+
}
|
|
637
|
+
return Promise.resolve(doneResult);
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
/**
|
|
641
|
+
* Creates a `Promise` that is fulfilled when the emitter
|
|
642
|
+
* emits the given event.
|
|
643
|
+
* @param {EventEmitter} emitter
|
|
644
|
+
* @param {string} name
|
|
645
|
+
* @param {{ signal: AbortSignal; }} [options]
|
|
646
|
+
* @returns {Promise}
|
|
647
|
+
*/
|
|
648
|
+
export const once = async function once(emitter, name, options = {}) {
|
|
649
|
+
// validateObject(options, "options");
|
|
650
|
+
const signal = options?.signal;
|
|
651
|
+
// validateAbortSignal(signal, "options.signal");
|
|
652
|
+
if (signal?.aborted) {
|
|
653
|
+
throw new AbortError(undefined, { cause: signal?.reason });
|
|
654
|
+
}
|
|
655
|
+
return new Promise((resolve, reject) => {
|
|
656
|
+
const errorListener = (err) => {
|
|
657
|
+
if (typeof emitter.removeListener === "function") {
|
|
658
|
+
emitter.removeListener(name, resolver);
|
|
659
|
+
}
|
|
660
|
+
if (signal != null) {
|
|
661
|
+
eventTargetAgnosticRemoveListener(signal, "abort", abortListener);
|
|
662
|
+
}
|
|
663
|
+
reject(err);
|
|
664
|
+
};
|
|
665
|
+
const resolver = (...args) => {
|
|
666
|
+
if (typeof emitter.removeListener === "function") {
|
|
667
|
+
emitter.removeListener("error", errorListener);
|
|
668
|
+
}
|
|
669
|
+
if (signal != null) {
|
|
670
|
+
eventTargetAgnosticRemoveListener(signal, "abort", abortListener);
|
|
671
|
+
}
|
|
672
|
+
resolve(args);
|
|
673
|
+
};
|
|
674
|
+
const opts = {
|
|
675
|
+
__proto__: null,
|
|
676
|
+
once: true,
|
|
677
|
+
[kResistStopPropagation]: true
|
|
678
|
+
};
|
|
679
|
+
eventTargetAgnosticAddListener(emitter, name, resolver, opts);
|
|
680
|
+
if (name !== "error" && typeof emitter.once === "function") {
|
|
681
|
+
// EventTarget does not have `error` event semantics like Node
|
|
682
|
+
// EventEmitters, we listen to `error` events only on EventEmitters.
|
|
683
|
+
emitter.once("error", errorListener);
|
|
684
|
+
}
|
|
685
|
+
function abortListener() {
|
|
686
|
+
eventTargetAgnosticRemoveListener(emitter, name, resolver);
|
|
687
|
+
eventTargetAgnosticRemoveListener(emitter, "error", errorListener);
|
|
688
|
+
reject(new AbortError(undefined, { cause: signal?.reason }));
|
|
689
|
+
}
|
|
690
|
+
if (signal != null) {
|
|
691
|
+
eventTargetAgnosticAddListener(signal, "abort", abortListener, {
|
|
692
|
+
__proto__: null,
|
|
693
|
+
once: true,
|
|
694
|
+
[kResistStopPropagation]: true
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
};
|
|
699
|
+
export const addAbortListener = function addAbortListener(signal, listener) {
|
|
700
|
+
if (signal === undefined) {
|
|
701
|
+
// @ts-expect-error
|
|
702
|
+
throw new ERR_INVALID_ARG_TYPE("signal", "AbortSignal", signal);
|
|
703
|
+
}
|
|
704
|
+
// validateAbortSignal(signal, 'signal');
|
|
705
|
+
// validateFunction(listener, 'listener');
|
|
706
|
+
let removeEventListener;
|
|
707
|
+
if (signal.aborted) {
|
|
708
|
+
// @ts-expect-error
|
|
709
|
+
queueMicrotask(() => listener());
|
|
710
|
+
} else {
|
|
711
|
+
// TODO(atlowChemi) add { subscription: true } and return directly
|
|
712
|
+
signal.addEventListener("abort", listener, {
|
|
713
|
+
__proto__: null,
|
|
714
|
+
once: true,
|
|
715
|
+
[kResistStopPropagation]: true
|
|
716
|
+
});
|
|
717
|
+
removeEventListener = () => {
|
|
718
|
+
signal.removeEventListener("abort", listener);
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
__proto__: null,
|
|
723
|
+
[Symbol.dispose]() {
|
|
724
|
+
removeEventListener?.();
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
};
|
|
728
|
+
/**
|
|
729
|
+
* Returns a copy of the array of listeners for the event name
|
|
730
|
+
* specified as `type`.
|
|
731
|
+
* @returns {Function[]}
|
|
732
|
+
*/
|
|
733
|
+
export const getEventListeners = function getEventListeners(emitterOrTarget, type) {
|
|
734
|
+
// First check if EventEmitter
|
|
735
|
+
if (typeof emitterOrTarget.listeners === "function") {
|
|
736
|
+
return emitterOrTarget.listeners(type);
|
|
737
|
+
}
|
|
738
|
+
// Require event target lazily to avoid always loading it
|
|
739
|
+
if (isEventTarget(emitterOrTarget)) {
|
|
740
|
+
// @ts-expect-error
|
|
741
|
+
const root = emitterOrTarget[kEvents].get(type);
|
|
742
|
+
const listeners = [];
|
|
743
|
+
let handler = root?.next;
|
|
744
|
+
while (handler?.listener !== undefined) {
|
|
745
|
+
const listener = handler.listener?.deref ? handler.listener.deref() : handler.listener;
|
|
746
|
+
listeners.push(listener);
|
|
747
|
+
handler = handler.next;
|
|
748
|
+
}
|
|
749
|
+
return listeners;
|
|
750
|
+
}
|
|
751
|
+
throw new ERR_INVALID_ARG_TYPE(
|
|
752
|
+
"emitter",
|
|
753
|
+
["EventEmitter", "EventTarget"],
|
|
754
|
+
// @ts-expect-error
|
|
755
|
+
emitterOrTarget
|
|
756
|
+
);
|
|
757
|
+
};
|
|
758
|
+
/**
|
|
759
|
+
* Returns the max listeners set.
|
|
760
|
+
* @param {EventEmitter | EventTarget} emitterOrTarget
|
|
761
|
+
* @returns {number}
|
|
762
|
+
*/
|
|
763
|
+
export const getMaxListeners = function getMaxListeners(emitterOrTarget) {
|
|
764
|
+
if (typeof emitterOrTarget?.getMaxListeners === "function") {
|
|
765
|
+
return _getMaxListeners(emitterOrTarget);
|
|
766
|
+
} else if (emitterOrTarget?.[kMaxEventTargetListeners]) {
|
|
767
|
+
// @ts-expect-error
|
|
768
|
+
return emitterOrTarget[kMaxEventTargetListeners];
|
|
769
|
+
}
|
|
770
|
+
throw new ERR_INVALID_ARG_TYPE(
|
|
771
|
+
"emitter",
|
|
772
|
+
["EventEmitter", "EventTarget"],
|
|
773
|
+
// @ts-expect-error
|
|
774
|
+
emitterOrTarget
|
|
775
|
+
);
|
|
776
|
+
};
|
|
777
|
+
// ----------------------------------------------------------------------------
|
|
778
|
+
// FixedQueue (internal)
|
|
779
|
+
// ----------------------------------------------------------------------------
|
|
780
|
+
// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
|
|
781
|
+
const kSize = 2048;
|
|
782
|
+
const kMask = kSize - 1;
|
|
783
|
+
class FixedCircularBuffer {
|
|
784
|
+
bottom;
|
|
785
|
+
top;
|
|
786
|
+
list;
|
|
787
|
+
next;
|
|
788
|
+
constructor() {
|
|
789
|
+
this.bottom = 0;
|
|
790
|
+
this.top = 0;
|
|
791
|
+
this.list = new Array(kSize);
|
|
792
|
+
this.next = null;
|
|
793
|
+
}
|
|
794
|
+
isEmpty() {
|
|
795
|
+
return this.top === this.bottom;
|
|
796
|
+
}
|
|
797
|
+
isFull() {
|
|
798
|
+
return (this.top + 1 & kMask) === this.bottom;
|
|
799
|
+
}
|
|
800
|
+
push(data) {
|
|
801
|
+
this.list[this.top] = data;
|
|
802
|
+
this.top = this.top + 1 & kMask;
|
|
803
|
+
}
|
|
804
|
+
shift() {
|
|
805
|
+
const nextItem = this.list[this.bottom];
|
|
806
|
+
if (nextItem === undefined) return null;
|
|
807
|
+
this.list[this.bottom] = undefined;
|
|
808
|
+
this.bottom = this.bottom + 1 & kMask;
|
|
809
|
+
return nextItem;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
class FixedQueue {
|
|
813
|
+
head;
|
|
814
|
+
tail;
|
|
815
|
+
constructor() {
|
|
816
|
+
this.head = this.tail = new FixedCircularBuffer();
|
|
817
|
+
}
|
|
818
|
+
isEmpty() {
|
|
819
|
+
return this.head.isEmpty();
|
|
820
|
+
}
|
|
821
|
+
push(data) {
|
|
822
|
+
if (this.head.isFull()) {
|
|
823
|
+
// Head is full: Creates a new queue, sets the old queue's `.next` to it,
|
|
824
|
+
// and sets it as the new main queue.
|
|
825
|
+
this.head = this.head.next = new FixedCircularBuffer();
|
|
826
|
+
}
|
|
827
|
+
this.head.push(data);
|
|
828
|
+
}
|
|
829
|
+
shift() {
|
|
830
|
+
const tail = this.tail;
|
|
831
|
+
const next = tail.shift();
|
|
832
|
+
if (tail.isEmpty() && tail.next !== null) {
|
|
833
|
+
// If there is another queue, it forms the new tail.
|
|
834
|
+
this.tail = tail.next;
|
|
835
|
+
tail.next = null;
|
|
836
|
+
}
|
|
837
|
+
return next;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
// ----------------------------------------------------------------------------
|
|
841
|
+
// Internal utils
|
|
842
|
+
// ----------------------------------------------------------------------------
|
|
843
|
+
function isEventTarget(emitter) {
|
|
844
|
+
return typeof emitter?.addEventListener === "function";
|
|
845
|
+
}
|
|
846
|
+
function checkListener(listener) {
|
|
847
|
+
// validateFunction(listener, "listener");
|
|
848
|
+
}
|
|
849
|
+
function addCatch(that, promise, type, args) {
|
|
850
|
+
if (!that[kCapture]) {
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
// Handle Promises/A+ spec, then could be a getter
|
|
854
|
+
// that throws on second use.
|
|
855
|
+
try {
|
|
856
|
+
const then = promise.then;
|
|
857
|
+
if (typeof then === "function") {
|
|
858
|
+
then.call(promise, undefined, function(err) {
|
|
859
|
+
// The callback is called with nextTick to avoid a follow-up
|
|
860
|
+
// rejection from this promise.
|
|
861
|
+
// Avoid using process. from events to avoid circular dependency
|
|
862
|
+
// process.nextTick(emitUnhandledRejectionOrErr, that, err, type, args);
|
|
863
|
+
setTimeout(emitUnhandledRejectionOrErr, 0, that, err, type, args);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
} catch (error_) {
|
|
867
|
+
that.emit("error", error_);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
function emitUnhandledRejectionOrErr(ee, err, type, args) {
|
|
871
|
+
// @ts-expect-error
|
|
872
|
+
if (typeof ee[kRejection] === "function") {
|
|
873
|
+
// @ts-expect-error
|
|
874
|
+
ee[kRejection](err, type, ...args);
|
|
875
|
+
} else {
|
|
876
|
+
// We have to disable the capture rejections mechanism, otherwise
|
|
877
|
+
// we might end up in an infinite loop.
|
|
878
|
+
const prev = ee[kCapture];
|
|
879
|
+
// If the error handler throws, it is not catchable and it
|
|
880
|
+
// will end up in 'uncaughtException'. We restore the previous
|
|
881
|
+
// value of kCapture in case the uncaughtException is present
|
|
882
|
+
// and the exception is handled.
|
|
883
|
+
try {
|
|
884
|
+
ee[kCapture] = false;
|
|
885
|
+
ee.emit("error", err);
|
|
886
|
+
} finally {
|
|
887
|
+
ee[kCapture] = prev;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
function _getMaxListeners(that) {
|
|
892
|
+
if (that._maxListeners === undefined) return defaultMaxListeners;
|
|
893
|
+
return that._maxListeners;
|
|
894
|
+
}
|
|
895
|
+
function enhanceStackTrace(err, own) {
|
|
896
|
+
let ctorInfo = "";
|
|
897
|
+
try {
|
|
898
|
+
// @ts-expect-error
|
|
899
|
+
const { name } = this.constructor;
|
|
900
|
+
if (name !== "EventEmitter") ctorInfo = ` on ${name} instance`;
|
|
901
|
+
} catch {}
|
|
902
|
+
const sep = `\nEmitted 'error' event${ctorInfo} at:\n`;
|
|
903
|
+
// const errStack = (err.stack || "").split("\n").slice(1);
|
|
904
|
+
const ownStack = (own.stack || "").split("\n").slice(1);
|
|
905
|
+
// const { len, offset } = identicalSequenceRange(ownStack, errStack);
|
|
906
|
+
// if (len > 0) {
|
|
907
|
+
// Array.prototype.splice(
|
|
908
|
+
// ownStack,
|
|
909
|
+
// offset + 1,
|
|
910
|
+
// len - 2,
|
|
911
|
+
// " [... lines matching original stack trace ...]",
|
|
912
|
+
// );
|
|
913
|
+
// }
|
|
914
|
+
return err.stack + sep + ownStack.join("\n");
|
|
915
|
+
}
|
|
916
|
+
function _addListener(target, type, listener, prepend) {
|
|
917
|
+
let m;
|
|
918
|
+
let events;
|
|
919
|
+
let existing;
|
|
920
|
+
checkListener(listener);
|
|
921
|
+
events = target._events;
|
|
922
|
+
if (events === undefined) {
|
|
923
|
+
events = target._events = { __proto__: null };
|
|
924
|
+
target._eventsCount = 0;
|
|
925
|
+
} else {
|
|
926
|
+
// To avoid recursion in the case that type === "newListener"! Before
|
|
927
|
+
// adding it to the listeners, first emit "newListener".
|
|
928
|
+
if (events.newListener !== undefined) {
|
|
929
|
+
// @ts-expect-error
|
|
930
|
+
target.emit("newListener", type, listener.listener ?? listener);
|
|
931
|
+
// Re-assign `events` because a newListener handler could have caused the
|
|
932
|
+
// this._events to be assigned to a new object
|
|
933
|
+
events = target._events;
|
|
934
|
+
}
|
|
935
|
+
existing = events[type];
|
|
936
|
+
}
|
|
937
|
+
if (existing === undefined) {
|
|
938
|
+
// Optimize the case of one listener. Don't need the extra array object.
|
|
939
|
+
events[type] = listener;
|
|
940
|
+
++target._eventsCount;
|
|
941
|
+
} else {
|
|
942
|
+
if (typeof existing === "function") {
|
|
943
|
+
// Adding the second element, need to change to array.
|
|
944
|
+
existing = events[type] = prepend ? [listener, existing] : [existing, listener];
|
|
945
|
+
} else if (prepend) {
|
|
946
|
+
existing.unshift(listener);
|
|
947
|
+
} else {
|
|
948
|
+
existing.push(listener);
|
|
949
|
+
}
|
|
950
|
+
// Check for listener leak
|
|
951
|
+
m = _getMaxListeners(target);
|
|
952
|
+
if (m > 0 && existing.length > m && !existing.warned) {
|
|
953
|
+
existing.warned = true;
|
|
954
|
+
// No error code for this since it is a Warning
|
|
955
|
+
const w = new genericNodeError(`Possible EventEmitter memory leak detected. ${existing.length} ${String(type)} listeners ` + `added to ${inspect(target, { depth: -1 })}. MaxListeners is ${m}. Use emitter.setMaxListeners() to increase limit`, {
|
|
956
|
+
name: "MaxListenersExceededWarning",
|
|
957
|
+
emitter: target,
|
|
958
|
+
type,
|
|
959
|
+
count: existing.length
|
|
960
|
+
});
|
|
961
|
+
// Avoid using process from events to avoid circular dependency
|
|
962
|
+
console.warn(w);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
return target;
|
|
966
|
+
}
|
|
967
|
+
function onceWrapper() {
|
|
968
|
+
// @ts-expect-error
|
|
969
|
+
if (!this.fired) {
|
|
970
|
+
// @ts-expect-error
|
|
971
|
+
this.target.removeListener(this.type, this.wrapFn);
|
|
972
|
+
// @ts-expect-error
|
|
973
|
+
this.fired = true;
|
|
974
|
+
// @ts-expect-error
|
|
975
|
+
if (arguments.length === 0) return this.listener.call(this.target);
|
|
976
|
+
// @ts-expect-error
|
|
977
|
+
return this.listener.apply(this.target, arguments);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
function _onceWrap(target, type, listener) {
|
|
981
|
+
const state = {
|
|
982
|
+
fired: false,
|
|
983
|
+
wrapFn: undefined,
|
|
984
|
+
target,
|
|
985
|
+
type,
|
|
986
|
+
listener
|
|
987
|
+
};
|
|
988
|
+
const wrapped = onceWrapper.bind(state);
|
|
989
|
+
wrapped.listener = listener;
|
|
990
|
+
state.wrapFn = wrapped;
|
|
991
|
+
return wrapped;
|
|
992
|
+
}
|
|
993
|
+
function _listeners(target, type, unwrap) {
|
|
994
|
+
const events = target._events;
|
|
995
|
+
if (events === undefined) return [];
|
|
996
|
+
const evlistener = events[type];
|
|
997
|
+
if (evlistener === undefined) return [];
|
|
998
|
+
if (typeof evlistener === "function") return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
|
999
|
+
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener);
|
|
1000
|
+
}
|
|
1001
|
+
function arrayClone(arr) {
|
|
1002
|
+
// At least since V8 8.3, this implementation is faster than the previous
|
|
1003
|
+
// which always used a simple for-loop
|
|
1004
|
+
switch (arr.length) {
|
|
1005
|
+
case 2: return [arr[0], arr[1]];
|
|
1006
|
+
case 3: return [
|
|
1007
|
+
arr[0],
|
|
1008
|
+
arr[1],
|
|
1009
|
+
arr[2]
|
|
1010
|
+
];
|
|
1011
|
+
case 4: return [
|
|
1012
|
+
arr[0],
|
|
1013
|
+
arr[1],
|
|
1014
|
+
arr[2],
|
|
1015
|
+
arr[3]
|
|
1016
|
+
];
|
|
1017
|
+
case 5: return [
|
|
1018
|
+
arr[0],
|
|
1019
|
+
arr[1],
|
|
1020
|
+
arr[2],
|
|
1021
|
+
arr[3],
|
|
1022
|
+
arr[4]
|
|
1023
|
+
];
|
|
1024
|
+
case 6: return [
|
|
1025
|
+
arr[0],
|
|
1026
|
+
arr[1],
|
|
1027
|
+
arr[2],
|
|
1028
|
+
arr[3],
|
|
1029
|
+
arr[4],
|
|
1030
|
+
arr[5]
|
|
1031
|
+
];
|
|
1032
|
+
}
|
|
1033
|
+
return Array.prototype.slice.call(arr);
|
|
1034
|
+
}
|
|
1035
|
+
function unwrapListeners(arr) {
|
|
1036
|
+
const ret = arrayClone(arr);
|
|
1037
|
+
for (let i = 0; i < ret.length; ++i) {
|
|
1038
|
+
const orig = ret[i].listener;
|
|
1039
|
+
if (typeof orig === "function") ret[i] = orig;
|
|
1040
|
+
}
|
|
1041
|
+
return ret;
|
|
1042
|
+
}
|
|
1043
|
+
function createIterResult(value, done) {
|
|
1044
|
+
return {
|
|
1045
|
+
value,
|
|
1046
|
+
done
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
function eventTargetAgnosticRemoveListener(emitter, name, listener, flags) {
|
|
1050
|
+
if (typeof emitter.removeListener === "function") {
|
|
1051
|
+
emitter.removeListener(name, listener);
|
|
1052
|
+
} else if (typeof emitter.removeEventListener === "function") {
|
|
1053
|
+
emitter.removeEventListener(name, listener, flags);
|
|
1054
|
+
} else {
|
|
1055
|
+
// @ts-expect-error
|
|
1056
|
+
throw new ERR_INVALID_ARG_TYPE("emitter", "EventEmitter", emitter);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
|
|
1060
|
+
if (typeof emitter.on === "function") {
|
|
1061
|
+
if (flags?.once) {
|
|
1062
|
+
emitter.once(name, listener);
|
|
1063
|
+
} else {
|
|
1064
|
+
emitter.on(name, listener);
|
|
1065
|
+
}
|
|
1066
|
+
} else if (typeof emitter.addEventListener === "function") {
|
|
1067
|
+
emitter.addEventListener(name, listener, flags);
|
|
1068
|
+
} else {
|
|
1069
|
+
// @ts-expect-error
|
|
1070
|
+
throw new ERR_INVALID_ARG_TYPE("emitter", "EventEmitter", emitter);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
function listenersController() {
|
|
1074
|
+
const listeners = [];
|
|
1075
|
+
return {
|
|
1076
|
+
addEventListener(emitter, event, handler, flags) {
|
|
1077
|
+
eventTargetAgnosticAddListener(emitter, event, handler, flags);
|
|
1078
|
+
Array.prototype.push(listeners, [
|
|
1079
|
+
emitter,
|
|
1080
|
+
event,
|
|
1081
|
+
handler,
|
|
1082
|
+
flags
|
|
1083
|
+
]);
|
|
1084
|
+
},
|
|
1085
|
+
removeAll() {
|
|
1086
|
+
while (listeners.length > 0) {
|
|
1087
|
+
Reflect.apply(eventTargetAgnosticRemoveListener, undefined, listeners.pop());
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
// As of V8 6.6, depending on the size of the array, this is anywhere
|
|
1093
|
+
// between 1.5-10x faster than the two-arg version of Array#splice()
|
|
1094
|
+
function spliceOne(list, index) {
|
|
1095
|
+
for (; index + 1 < list.length; index++) list[index] = list[index + 1];
|
|
1096
|
+
list.pop();
|
|
1097
|
+
}
|