pub enum JsValue {
Undefined,
Null,
Bool(bool),
Number(f64),
String(String),
Object(*mut JSObject),
}Variants§
Undefined
Null
Bool(bool)
Number(f64)
String(String)
Object(*mut JSObject)
GC-unsafe: the *mut JSObject pointer is NOT rooted. This variant must
only be used as a transient conversion value within a single no-GC window
(i.e., created from jsval_to_jsvalue and consumed by to_jsval before
any JS code runs that could trigger GC). Storing JsValue::Object in a
struct field, local variable across an await point, or collection that
outlives the current SM API call will cause use-after-free if GC moves
or collects the object.
For persistent storage, use GcStore (see bao_runtime::gc_store):
gc_store_insert(cx, key, obj)— store with simple key (__gc_cache_{key})gc_store_insert_ns(cx, namespace, key, obj)— store with namespaced key (__gc_{namespace}_{key})gc_store_get(cx, key)/gc_store_get_ns(cx, namespace, key)— retrievegc_store_remove(cx, key)/gc_store_remove_ns(cx, namespace, key)— remove
GcStore stores objects as properties on the JS global, so SpiderMonkey’s GC manages them naturally — no raw pointer that could dangle after GC.
Implementations§
Source§impl JsValue
impl JsValue
pub fn is_undefined(&self) -> bool
pub fn is_null(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_object(&self) -> bool
pub fn as_bool(&self) -> Option<bool>
pub fn as_number(&self) -> Option<f64>
pub fn as_string(&self) -> Option<&str>
pub fn as_object(&self) -> Option<*mut JSObject>
pub fn to_display_string(&self) -> String
Trait Implementations§
Auto Trait Implementations§
impl !Send for JsValue
impl !Sync for JsValue
impl Freeze for JsValue
impl RefUnwindSafe for JsValue
impl Unpin for JsValue
impl UnsafeUnpin for JsValue
impl UnwindSafe for JsValue
Blanket Implementations§
Source§impl<T> AsCtxPtr for Twhere
T: ?Sized,
impl<T> AsCtxPtr for Twhere
T: ?Sized,
Source§fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
fn as_ctx_ptr(&self) -> *mut Selfwhere
Self: Sized,
self’s address as *mut Self for deferred-task / scopeguard /
ref_guard ctx slots. The closures/trampolines deref it as shared
(&*p) — every method they reach is &self post-R-2, so no write
provenance is required; the *mut spelling is purely to match the
existing DerefOnDrop / HasAutoFlush / RefCount ABI.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Filterable for T
impl<T> Filterable for T
Source§fn filterable(
self,
filter_name: &'static str,
) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(DataRequest<'_>) -> bool>
Creates a filterable data provider with the given name for debugging. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> MaybeBoxed<Box<T>> for T
impl<T> MaybeBoxed<Box<T>> for T
Source§fn maybe_boxed(self) -> Box<T>
fn maybe_boxed(self) -> Box<T>
Convert
Source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
Source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
Convert