pub struct JsValue(/* private fields */);Expand description
A JSValue: the eight bytes the C API passes by value.
Implementations§
Source§impl JsValue
impl JsValue
Sourcepub const fn new(bits: u64) -> JsValue
pub const fn new(bits: u64) -> JsValue
Wrap raw bits. The only way to build one without going through a constructor, and
what JS_VALUE_GET_* is on the other side of.
Sourcepub const fn tag(self) -> i32
pub const fn tag(self) -> i32
The tag, as JS_VALUE_GET_TAG computes it: an arithmetic shift of the whole word.
A negative answer is a reference-counted payload, and only -1 (OBJECT) can
reach the engine: the reference’s other negative tags name its own containers
(strings, symbols, bytecode, modules) which live inside objects here instead.
Sourcepub const fn norm_tag(self) -> i32
pub const fn norm_tag(self) -> i32
JS_VALUE_GET_NORM_TAG: the tag with every float spelling collapsed to
JS_TAG_FLOAT64.
Sourcepub const fn tag_is_float(tag: i32) -> bool
pub const fn tag_is_float(tag: i32) -> bool
JS_TAG_IS_FLOAT64(tag): whether a tag outside the named range means “double”.
Sourcepub const fn is_float(self) -> bool
pub const fn is_float(self) -> bool
Whether this value is a double (JS_TAG_IS_FLOAT64(JS_VALUE_GET_NORM_TAG(v))).
Sourcepub const fn has_ref_count(self) -> bool
pub const fn has_ref_count(self) -> bool
JS_VALUE_HAS_REF_COUNT: every negative tag.
Sourcepub const fn payload(self) -> u64
pub const fn payload(self) -> u64
JS_VALUE_GET_PTR: the low 47 bits as a pointer.
Matching the reference means not checking the range here — the mask is what C
does — and rejecting an out-of-range pointer at the point it is built instead
(JsValue::mkptr).
Sourcepub const fn mkval(tag: i32, val: u32) -> JsValue
pub const fn mkval(tag: i32, val: u32) -> JsValue
JS_MKVAL(tag, val): a tag with a 32-bit payload.
Sourcepub fn mkptr(tag: i32, ptr: *mut ()) -> JsValue
pub fn mkptr(tag: i32, ptr: *mut ()) -> JsValue
JS_MKPTR(tag, ptr): a tag with a pointer payload.
§Panics
When ptr does not fit in 47 bits. That is a broken invariant rather than a
recoverable error: the reference would truncate the pointer and hand C a value
that reads and writes the wrong memory. Every allocator this crate controls keeps
its blocks in the low half of the address space; a host that supplies its own
allocator has to keep the same promise (see docs/m15-plan.md §3, D1).
Sourcepub const fn is_exception(self) -> bool
pub const fn is_exception(self) -> bool
JS_IsException.
Sourcepub const fn is_undefined(self) -> bool
pub const fn is_undefined(self) -> bool
JS_IsUndefined.
Sourcepub const fn to_float(self) -> f64
pub const fn to_float(self) -> f64
The double, as JS_VALUE_GET_FLOAT64.
No tag check: the reference’s macro does not have one either, and its callers
always know the tag. JsValue::as_float is the checked spelling.