quickjs-capi 0.14.1

C ABI compatibility layer: the QuickJS C API on top of the pure-Rust engine
Documentation
//! The two directions of the bridge, as free functions.
//!
//! [`crate::convert`] owns the actual conversions; this module exists so that the exported
//! API files can write `jsvalue_of(value)` and `value_of(js)` without each of them importing
//! the same pair of names. The names read the way the C API does — a `JSValue` is what goes
//! over the boundary, a `Value` is what the engine holds.

use engine::Value;

use crate::convert;
use crate::jsvalue::JsValue;

/// Box an engine value as a `JSValue` the caller owns.
pub fn jsvalue_of(value: Value) -> JsValue {
    convert::encode(&value)
}

/// The engine value behind a `JSValue`, when it is one this layer can decode.
///
/// # Safety
///
/// `value` must be a `JSValue` from this crate (or a primitive), and a reference-counted one
/// must be alive.
pub unsafe fn value_of(value: JsValue) -> Option<Value> {
    // SAFETY: the caller's contract.
    unsafe { convert::decode(value) }
}