3b6b75bb46
This commit introduces two new buffer wrapper types to `deno_core`. The main benefit of these new wrappers is that they can wrap a number of different underlying buffer types. This allows for a more flexible read and write API on resources that will require less copying of data between different buffer representations. - `BufView` is a read-only view onto a buffer. It can be backed by `ZeroCopyBuf`, `Vec<u8>`, and `bytes::Bytes`. - `BufViewMut` is a read-write view onto a buffer. It can be cheaply converted into a `BufView`. It can be backed by `ZeroCopyBuf` or `Vec<u8>`. Both new buffer views have a cursor. This means that the start point of the view can be constrained to write / read from just a slice of the view. Only the start point of the slice can be adjusted. The end point is fixed. To adjust the end point, the underlying buffer needs to be truncated. Readable resources have been changed to better cater to resources that do not support BYOB reads. The basic `read` method now returns a `BufView` instead of taking a `ZeroCopyBuf` to fill. This allows the operation to return buffers that the resource has already allocated, instead of forcing the caller to allocate the buffer. BYOB reads are still very useful for resources that support them, so a new `read_byob` method has been added that takes a `BufViewMut` to fill. `op_read` attempts to use `read_byob` if the resource supports it, which falls back to `read` and performs an additional copy if it does not. For Rust->JS reads this change should have no impact, but for Rust->Rust reads, this allows the caller to avoid an additional copy in many scenarios. This combined with the support for `BufView` to be backed by `bytes::Bytes` allows us to avoid one data copy when piping from a `fetch` response into an `ext/http` response. Writable resources have been changed to take a `BufView` instead of a `ZeroCopyBuf` as an argument. This allows for less copying of data in certain scenarios, as described above. Additionally a new `Resource::write_all` method has been added that takes a `BufView` and continually attempts to write the resource until the entire buffer has been written. Certain resources like files can override this method to provide a more efficient `write_all` implementation. |
||
---|---|---|
.. | ||
examples | ||
js | ||
ops | ||
build.rs | ||
Cargo.toml | ||
colors.rs | ||
errors.rs | ||
fmt_errors.rs | ||
fs_util.rs | ||
inspector_server.rs | ||
js.rs | ||
lib.rs | ||
permissions.rs | ||
README.md | ||
tokio_util.rs | ||
web_worker.rs | ||
worker.rs | ||
worker_bootstrap.rs |
deno_runtime
crate
This is a slim version of the Deno CLI which removes typescript integration and various tooling (like lint and doc). Basically only JavaScript execution with Deno's operating system bindings (ops).
Stability
This crate is built using battle-tested modules that were originally in deno
crate, however the API of this crate is subject to rapid and breaking changes.
MainWorker
The main API of this crate is MainWorker
. MainWorker
is a structure
encapsulating deno_core::JsRuntime
with a set of ops used to implement Deno
namespace.
When creating a MainWorker
implementors must call MainWorker::bootstrap
to
prepare JS runtime for use.
MainWorker
is highly configurable and allows to customize many of the
runtime's properties:
- module loading implementation
- error formatting
- support for source maps
- support for V8 inspector and Chrome Devtools debugger
- HTTP client user agent, CA certificate
- random number generator seed
Worker
Web API
deno_runtime
comes with support for Worker
Web API. The Worker
API is
implemented using WebWorker
structure.
When creating a new instance of MainWorker
implementors must provide a
callback function that is used when creating a new instance of Worker
.
All WebWorker
instances are descendents of MainWorker
which is responsible
for setting up communication with child worker. Each WebWorker
spawns a new OS
thread that is dedicated solely to that worker.