glendix/js/object
Builds plain, prototype-safe JavaScript data objects from typed entries.
This module owns data-only object construction. It converts typed Gleam
scalars into opaque JavaScript values and assembles them into plain objects
whose keys are always ordinary own data properties. Dynamic interop such as
property reads and writes, method calls, and constructor invocation lives in
the separate glendix/js/reflect module, so this data boundary never
depends on arbitrary reflection.
Construction keeps a small bespoke FFI (Object.fromEntries) on purpose: no
ecosystem package builds a live, prototype-pollution-safe plain object.
The public gleam/javascript API only covers arrays, promises, and symbols,
while Plinth has no general plain-object builder. A gleam/json round-trip
would be indirect and lossy for live handles. The retained FFI guarantees
that even a __proto__ entry is stored as ordinary own data instead of
invoking the legacy prototype setter.
Types
Represents a JavaScript boolean value.
pub type JsBoolean {
TrueValue
FalseValue
}
Constructors
-
TrueValueJavaScript
true. -
FalseValueJavaScript
false.
Values
pub fn bool(value value: JsBoolean) -> JsValue
Converts a typed JavaScript boolean into a JavaScript value.
pub fn from_entries(
entries entries: List(#(String, JsValue)),
) -> JsObject
Creates an object from ordered key-value entries.
The typed input prevents malformed entry shapes. JavaScript property
enumeration rules preserve the order of ordinary string keys, duplicate
keys keep their last value, and special keys such as __proto__ are stored
as own data properties.