comlink-sys 0.0.1

Raw bindings to the Comlink JavaScript library
Documentation
//! Raw bindings to the [Comlink](https://github.com/GoogleChromeLabs/comlink)
//! JavaScript library, covering its whole public surface and nothing more. The
//! ergonomic layer lives in the [`comlink`](https://docs.rs/comlink) crate.
//!
//! Every item here is imported from the bare `comlink` module specifier, so the
//! npm package of that name has to be resolvable by whatever bundler or module
//! loader serves the generated JavaScript.
//!
//! Comlink gives several parameters JavaScript default values, which
//! `wasm_bindgen` cannot express. Each of those is bound once per arity, named
//! after the parameters it passes, following the `web-sys` convention.

use wasm_bindgen::prelude::*;

#[wasm_bindgen(module = "comlink")]
extern "C" {
    /// Serves calls on the global scope, dispatching them onto `obj`.
    pub fn expose(obj: &JsValue);

    /// Serves calls on `endpoint`, dispatching them onto `obj`.
    #[wasm_bindgen(js_name = expose)]
    pub fn expose_with_endpoint(obj: &JsValue, endpoint: &JsValue);

    /// Serves calls on `endpoint`, ignoring messages whose origin matches none
    /// of `allowed_origins` (an array of strings and regular expressions).
    #[wasm_bindgen(js_name = expose)]
    pub fn expose_with_endpoint_and_allowed_origins(
        obj: &JsValue,
        endpoint: &JsValue,
        allowed_origins: &js_sys::Array,
    );

    /// Returns the object exposed on `endpoint` as a JavaScript `Proxy`.
    pub fn wrap(endpoint: &JsValue) -> JsValue;

    /// Returns a proxy for `endpoint` whose calls are applied to `target`.
    #[wasm_bindgen(js_name = wrap)]
    pub fn wrap_with_target(endpoint: &JsValue, target: &JsValue) -> JsValue;

    /// Marks `transfers` as the transferables of the next post of `value`, and
    /// returns `value` unchanged.
    pub fn transfer(value: &JsValue, transfers: &js_sys::Array) -> JsValue;

    /// Marks `obj` to cross as a `MessagePort`-backed proxy rather than being
    /// structurally cloned.
    pub fn proxy(obj: &JsValue) -> JsValue;

    /// Wraps a window-like object into an endpoint that posts to it and listens
    /// on the global scope.
    #[wasm_bindgen(js_name = windowEndpoint)]
    pub fn window_endpoint(window: &JsValue) -> JsValue;

    /// Wraps a window-like object into an endpoint listening on `context`.
    #[wasm_bindgen(js_name = windowEndpoint)]
    pub fn window_endpoint_with_context(window: &JsValue, context: &JsValue) -> JsValue;

    /// Wraps a window-like object into an endpoint listening on `context` and
    /// posting with `target_origin`.
    #[wasm_bindgen(js_name = windowEndpoint)]
    pub fn window_endpoint_with_context_and_target_origin(
        window: &JsValue,
        context: &JsValue,
        target_origin: &str,
    ) -> JsValue;

    /// The property marking an object as proxied rather than cloned, which is
    /// what [`proxy`] sets.
    #[wasm_bindgen(thread_local_v2, js_name = proxyMarker)]
    pub static PROXY_MARKER: js_sys::Symbol;

    /// The method on a proxy returning a new endpoint for the same object.
    #[wasm_bindgen(thread_local_v2, js_name = createEndpoint)]
    pub static CREATE_ENDPOINT: js_sys::Symbol;

    /// The method on a proxy releasing the remote object.
    #[wasm_bindgen(thread_local_v2, js_name = releaseProxy)]
    pub static RELEASE_PROXY: js_sys::Symbol;

    /// The property on an exposed object naming the method to call once the
    /// last proxy for it is released.
    #[wasm_bindgen(thread_local_v2, js_name = finalizer)]
    pub static FINALIZER: js_sys::Symbol;

    /// The name-keyed map of handlers serializing values comlink cannot clone.
    #[wasm_bindgen(thread_local_v2, js_name = transferHandlers)]
    pub static TRANSFER_HANDLERS: js_sys::Map;
}