quickjs-capi 0.14.0

C ABI compatibility layer: the QuickJS C API on top of the pure-Rust engine
Documentation
//! `JS_AddIntrinsic*`: installing the built-in objects a context needs.
//!
//! # The one structural fact
//!
//! This engine installs every intrinsic when a context's interpreter is built
//! (`builtins::install`), so a context that exists at all already has them. The reference
//! splits installation into sixteen calls because it wants a *reduced* context — `JS_NewContextRaw`
//! plus a chosen subset — and because a context it never evaluates in must cost nothing.
//!
//! So these functions are all the same function, and they answer `0` (success). That is not a
//! stub: it is what "the intrinsic is installed" means here, and the alternative — a
//! lazily-filled realm that can be half-installed — would add a state to the engine that no
//! script can observe and that every builtin would have to check.
//!
//! # `JS_AddIntrinsicIntl` and `JS_AddIntrinsicTemporal` answer `-1`
//!
//! Those are the two the engine genuinely does not have: `Intl` needs a locale database and a
//! collator, and `Temporal` is M13 (unstarted). Answering success would let a host believe a
//! script can use `Intl.NumberFormat`, and the script's `TypeError` would then look like a
//! bug in the host rather than a missing feature in the library.

use crate::runtime::JsContext;

/// The answer every installed intrinsic gives: `0`, meaning success.
fn installed(_ctx: *mut JsContext) -> core::ffi::c_int {
    0
}

/// `JS_AddIntrinsicBaseObjects`: `Object`, `Function`, `Array`, `String`, `Number`, …
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicBaseObjects(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicDate`: `Date`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicDate(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicEval`: `eval` and `Function`'s runtime compilation.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicEval(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicStringNormalize`: `String.prototype.normalize`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicStringNormalize(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicRegExp`: `RegExp`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicRegExp(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicRegExpCompiler`: the regexp-to-bytecode compiler.
///
/// Void because the reference has no way to fail it; the engine's regexp engine is a
/// backtracking matcher over the parsed pattern, so there is nothing to compile.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicRegExpCompiler(_ctx: *mut JsContext) {}

/// `JS_AddIntrinsicJSON`: `JSON`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicJSON(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicProxy`: `Proxy` and `Reflect`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicProxy(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicMapSet`: `Map`, `Set`, `WeakMap`, `WeakSet`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicMapSet(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicTypedArrays`: `ArrayBuffer`, the views and `DataView`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicTypedArrays(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicPromise`: `Promise`, and `Symbol.asyncIterator`'s machinery.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicPromise(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicWeakRef`: `WeakRef` and `FinalizationRegistry`.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicWeakRef(ctx: *mut JsContext) -> core::ffi::c_int {
    installed(ctx)
}

/// `JS_AddIntrinsicIntl`: `Intl`, which this engine does not have.
///
/// `-1` is the reference's failure answer, and the context is left untouched.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicIntl(_ctx: *mut JsContext) -> core::ffi::c_int {
    -1
}

/// `JS_AddIntrinsicTemporal`: `Temporal`, which is M13 and unstarted.
#[unsafe(no_mangle)]
pub extern "C" fn JS_AddIntrinsicTemporal(_ctx: *mut JsContext) -> core::ffi::c_int {
    -1
}

/// `JS_SetLocaleCallbacks`: install a locale implementation.
///
/// There is no place to put one — nothing in the engine consults locale callbacks, because
/// there is no `Intl` and `toLocaleString` falls back to `toString` — so the pointer is
/// accepted and dropped. A host that installs one gets the default behaviour, which the README
/// records next to `JS_AddIntrinsicIntl`.
///
/// # Safety
///
/// `callbacks` is ignored.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn JS_SetLocaleCallbacks(
    _ctx: *mut JsContext,
    _callbacks: *const core::ffi::c_void,
) {
}