mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
### What does this PR do? <!-- **Please explain what your changes do** --> This PR should fix #14219 and implement `WebAssembly.instantiateStreaming()` and `WebAssembly.compileStreaming()`. This is a mixture of WebKit's implementation (using a helper, `handleResponseOnStreamingAction`, also containing a fast-path for blobs) and some of Node.js's validation (error messages) and its builtin-based strategy to consume chunks from streams. `src/bun.js/bindings/GlobalObject.zig` has a helper function (`getBodyStreamOrBytesForWasmStreaming`), called by C++, to validate the response (like [Node.js](214e4db60e/lib/internal/wasm_web_api.js) does) and to extract the data from the response, either as a slice/span (if we can get the data synchronously), or as a `ReadableStream` body (if the data is still pending or if it is a file/S3 `Blob`). In C++, `handleResponseOnStreamingAction` is called by `compileStreaming` and `instantiateStreaming` on the `JSC::GlobalObjectMethodTable`, just like in [WebKit](97ee3c598a/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (L517)). It calls the aforementioned Zig helper for validation and getting the response data. The data is then fed into `JSC::Wasm::StreamingCompiler`. If the data is received as a `ReadableStream`, then we call a JS builtin in `WasmStreaming.ts` to iterate over each chunk of the stream, like [Node.js](214e4db60e/lib/internal/wasm_web_api.js (L50-L52)) does. The `JSC::Wasm::StreamingCompiler` is passed into JS through a new wrapper object, `WebCore::WasmStreamingCompiler`, like [Node.js](214e4db60e/src/node_wasm_web_api.h) does. It has `addBytes`, `finalize`, `error`, and (unused) `cancel` methods to mirror the underlying JSC class. (If there's a simpler way to do this, please let me know...that would be very much appreciated) - [x] Code changes ### How did you verify your code works? <!-- **For code changes, please include automated tests**. Feel free to uncomment the line below --> I wrote automated tests (`test/js/web/fetch/wasm-streaming.test`). <!-- If JavaScript/TypeScript modules or builtins changed: --> - [x] I included a test for the new code, or existing tests cover it - [x] I ran my tests locally and they pass (`bun-debug test test/js/web/fetch/wasm-streaming.test`) <!-- If Zig files changed: --> - [x] I checked the lifetime of memory allocated to verify it's (1) freed and (2) only freed when it should be (NOTE: consumed `AnyBlob` bodies are freed, and all other allocations are in C++ and either GCed or ref-counted) - [x] I included a test for the new code, or an existing test covers it (NOTE: via JS/TS unit test) - [x] JSValue used outside of the stack is either wrapped in a JSC.Strong or is JSValueProtect'ed (NOTE: N/A, JSValue never used outside the stack) - [x] I wrote TypeScript/JavaScript tests and they pass locally (`bun-debug test test/js/web/fetch/wasm-streaming.test`) --------- Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
166 lines
4.9 KiB
Plaintext
166 lines
4.9 KiB
Plaintext
src/js/builtins.d.ts
|
|
src/js/builtins/Bake.ts
|
|
src/js/builtins/BundlerPlugin.ts
|
|
src/js/builtins/ByteLengthQueuingStrategy.ts
|
|
src/js/builtins/CommonJS.ts
|
|
src/js/builtins/ConsoleObject.ts
|
|
src/js/builtins/CountQueuingStrategy.ts
|
|
src/js/builtins/Glob.ts
|
|
src/js/builtins/ImportMetaObject.ts
|
|
src/js/builtins/Ipc.ts
|
|
src/js/builtins/JSBufferConstructor.ts
|
|
src/js/builtins/JSBufferPrototype.ts
|
|
src/js/builtins/NodeModuleObject.ts
|
|
src/js/builtins/Peek.ts
|
|
src/js/builtins/ProcessObjectInternals.ts
|
|
src/js/builtins/ReadableByteStreamController.ts
|
|
src/js/builtins/ReadableByteStreamInternals.ts
|
|
src/js/builtins/ReadableStream.ts
|
|
src/js/builtins/ReadableStreamBYOBReader.ts
|
|
src/js/builtins/ReadableStreamBYOBRequest.ts
|
|
src/js/builtins/ReadableStreamDefaultController.ts
|
|
src/js/builtins/ReadableStreamDefaultReader.ts
|
|
src/js/builtins/ReadableStreamInternals.ts
|
|
src/js/builtins/shell.ts
|
|
src/js/builtins/StreamInternals.ts
|
|
src/js/builtins/TextDecoderStream.ts
|
|
src/js/builtins/TextEncoderStream.ts
|
|
src/js/builtins/TransformStream.ts
|
|
src/js/builtins/TransformStreamDefaultController.ts
|
|
src/js/builtins/TransformStreamInternals.ts
|
|
src/js/builtins/UtilInspect.ts
|
|
src/js/builtins/WasmStreaming.ts
|
|
src/js/builtins/WritableStreamDefaultController.ts
|
|
src/js/builtins/WritableStreamDefaultWriter.ts
|
|
src/js/builtins/WritableStreamInternals.ts
|
|
src/js/bun/ffi.ts
|
|
src/js/bun/sql.ts
|
|
src/js/bun/sqlite.ts
|
|
src/js/internal-for-testing.ts
|
|
src/js/internal/abort_listener.ts
|
|
src/js/internal/assert/assertion_error.ts
|
|
src/js/internal/assert/calltracker.ts
|
|
src/js/internal/assert/myers_diff.ts
|
|
src/js/internal/assert/utils.ts
|
|
src/js/internal/buffer.ts
|
|
src/js/internal/cluster/child.ts
|
|
src/js/internal/cluster/isPrimary.ts
|
|
src/js/internal/cluster/primary.ts
|
|
src/js/internal/cluster/RoundRobinHandle.ts
|
|
src/js/internal/cluster/Worker.ts
|
|
src/js/internal/crypto/x509.ts
|
|
src/js/internal/debugger.ts
|
|
src/js/internal/errors.ts
|
|
src/js/internal/fifo.ts
|
|
src/js/internal/fixed_queue.ts
|
|
src/js/internal/freelist.ts
|
|
src/js/internal/fs/cp-sync.ts
|
|
src/js/internal/fs/cp.ts
|
|
src/js/internal/fs/glob.ts
|
|
src/js/internal/fs/streams.ts
|
|
src/js/internal/html.ts
|
|
src/js/internal/http.ts
|
|
src/js/internal/http/FakeSocket.ts
|
|
src/js/internal/linkedlist.ts
|
|
src/js/internal/primordials.js
|
|
src/js/internal/promisify.ts
|
|
src/js/internal/shared.ts
|
|
src/js/internal/stream.promises.ts
|
|
src/js/internal/stream.ts
|
|
src/js/internal/streams/add-abort-signal.ts
|
|
src/js/internal/streams/compose.ts
|
|
src/js/internal/streams/destroy.ts
|
|
src/js/internal/streams/duplex.ts
|
|
src/js/internal/streams/duplexify.ts
|
|
src/js/internal/streams/duplexpair.ts
|
|
src/js/internal/streams/end-of-stream.ts
|
|
src/js/internal/streams/from.ts
|
|
src/js/internal/streams/lazy_transform.ts
|
|
src/js/internal/streams/legacy.ts
|
|
src/js/internal/streams/native-readable.ts
|
|
src/js/internal/streams/operators.ts
|
|
src/js/internal/streams/passthrough.ts
|
|
src/js/internal/streams/pipeline.ts
|
|
src/js/internal/streams/readable.ts
|
|
src/js/internal/streams/state.ts
|
|
src/js/internal/streams/transform.ts
|
|
src/js/internal/streams/utils.ts
|
|
src/js/internal/streams/writable.ts
|
|
src/js/internal/timers.ts
|
|
src/js/internal/tls.ts
|
|
src/js/internal/tty.ts
|
|
src/js/internal/url.ts
|
|
src/js/internal/util/colors.ts
|
|
src/js/internal/util/inspect.d.ts
|
|
src/js/internal/util/inspect.js
|
|
src/js/internal/util/mime.ts
|
|
src/js/internal/validators.ts
|
|
src/js/internal/webstreams_adapters.ts
|
|
src/js/node/_http_agent.ts
|
|
src/js/node/_http_client.ts
|
|
src/js/node/_http_common.ts
|
|
src/js/node/_http_incoming.ts
|
|
src/js/node/_http_outgoing.ts
|
|
src/js/node/_http_server.ts
|
|
src/js/node/_stream_duplex.ts
|
|
src/js/node/_stream_passthrough.ts
|
|
src/js/node/_stream_readable.ts
|
|
src/js/node/_stream_transform.ts
|
|
src/js/node/_stream_wrap.ts
|
|
src/js/node/_stream_writable.ts
|
|
src/js/node/_tls_common.ts
|
|
src/js/node/assert.strict.ts
|
|
src/js/node/assert.ts
|
|
src/js/node/async_hooks.ts
|
|
src/js/node/child_process.ts
|
|
src/js/node/cluster.ts
|
|
src/js/node/console.ts
|
|
src/js/node/crypto.ts
|
|
src/js/node/dgram.ts
|
|
src/js/node/diagnostics_channel.ts
|
|
src/js/node/dns.promises.ts
|
|
src/js/node/dns.ts
|
|
src/js/node/domain.ts
|
|
src/js/node/events.ts
|
|
src/js/node/fs.promises.ts
|
|
src/js/node/fs.ts
|
|
src/js/node/http.ts
|
|
src/js/node/http2.ts
|
|
src/js/node/https.ts
|
|
src/js/node/inspector.ts
|
|
src/js/node/net.ts
|
|
src/js/node/os.ts
|
|
src/js/node/path.posix.ts
|
|
src/js/node/path.ts
|
|
src/js/node/path.win32.ts
|
|
src/js/node/perf_hooks.ts
|
|
src/js/node/punycode.ts
|
|
src/js/node/querystring.ts
|
|
src/js/node/readline.promises.ts
|
|
src/js/node/readline.ts
|
|
src/js/node/repl.ts
|
|
src/js/node/stream.consumers.ts
|
|
src/js/node/stream.promises.ts
|
|
src/js/node/stream.ts
|
|
src/js/node/stream.web.ts
|
|
src/js/node/test.ts
|
|
src/js/node/timers.promises.ts
|
|
src/js/node/timers.ts
|
|
src/js/node/tls.ts
|
|
src/js/node/trace_events.ts
|
|
src/js/node/tty.ts
|
|
src/js/node/url.ts
|
|
src/js/node/util.ts
|
|
src/js/node/v8.ts
|
|
src/js/node/vm.ts
|
|
src/js/node/wasi.ts
|
|
src/js/node/worker_threads.ts
|
|
src/js/node/zlib.ts
|
|
src/js/private.d.ts
|
|
src/js/thirdparty/isomorphic-fetch.ts
|
|
src/js/thirdparty/node-fetch.ts
|
|
src/js/thirdparty/undici.js
|
|
src/js/thirdparty/vercel_fetch.js
|
|
src/js/thirdparty/ws.js
|
|
src/js/wasi-runner.js
|