Struct mozjs_sys::jsapi::JS::Value

source ·
#[repr(C)]
pub struct Value { pub asBits_: u64, }
Expand description

[SMDOC] JS::Value type

JS::Value is the interface for a single JavaScript Engine value. A few general notes on JS::Value:

  • JS::Value has setX() and isX() members for X in

    { Int32, Double, String, Symbol, BigInt, Boolean, Undefined, Null, Object, Magic }

    JS::Value also contains toX() for each of the non-singleton types.

  • Magic is a singleton type whose payload contains either a JSWhyMagic “reason” for the magic value or a uint32_t value. By providing JSWhyMagic values when creating and checking for magic values, it is possible to assert, at runtime, that only magic values with the expected reason flow through a particular value. For example, if cx->exception has a magic value, the reason must be JS_GENERATOR_CLOSING.

  • The JS::Value operations are preferred. The JSVAL_* operations remain for compatibility; they may be removed at some point. These operations mostly provide similar functionality. But there are a few key differences. One is that JS::Value gives null a separate type. Also, to help prevent mistakenly boxing a nullable JSObject* as an object, Value::setObject takes a JSObject&. (Conversely, Value::toObject returns a JSObject&.) A convenience member Value::setObjectOrNull is provided.

  • Note that JS::Value is 8 bytes on 32 and 64-bit architectures. Thus, on 32-bit user code should avoid copying jsval/JS::Value as much as possible, preferring to pass by const Value&.

§Spectre mitigations

To mitigate Spectre attacks, we do the following:

  • On 64-bit platforms, when unboxing a Value, we XOR the bits with the expected type tag (instead of masking the payload bits). This guarantees that toString, toObject, toSymbol will return an invalid pointer (because some high bits will be set) when called on a Value with a different type tag.

  • On 32-bit platforms,when unboxing an object/string/symbol Value, we use a conditional move (not speculated) to zero the payload register if the type doesn’t match.

Fields§

§asBits_: u64

Implementations§

source§

impl Value

source

fn asBits(&self) -> u64

source

pub fn is_undefined(&self) -> bool

source

pub fn is_null(&self) -> bool

source

pub fn is_null_or_undefined(&self) -> bool

source

pub fn is_boolean(&self) -> bool

source

pub fn is_int32(&self) -> bool

source

pub fn is_double(&self) -> bool

source

pub fn is_number(&self) -> bool

source

pub fn is_primitive(&self) -> bool

source

pub fn is_string(&self) -> bool

source

pub fn is_object(&self) -> bool

source

pub fn is_object_or_null(&self) -> bool

source

pub fn is_magic(&self) -> bool

source

pub fn is_symbol(&self) -> bool

source

pub fn is_bigint(&self) -> bool

source

pub fn is_gcthing(&self) -> bool

source

pub fn to_boolean(&self) -> bool

source

pub fn to_int32(&self) -> i32

source

pub fn to_double(&self) -> f64

source

pub fn to_number(&self) -> f64

source

pub fn to_string(&self) -> *mut JSString

source

pub fn to_object(&self) -> *mut JSObject

source

pub fn to_object_or_null(&self) -> *mut JSObject

source

pub fn to_symbol(&self) -> *mut Symbol

source

pub fn to_bigint(&self) -> *mut BigInt

source

pub fn to_private(&self) -> *const c_void

source

pub fn to_gcthing(&self) -> *mut c_void

source

pub fn is_markable(&self) -> bool

source

pub fn trace_kind(&self) -> TraceKind

Trait Implementations§

source§

impl Clone for Value

source§

fn clone(&self) -> Value

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Value

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl GCMethods for Value

source§

unsafe fn initial() -> Value

Create a default value
source§

unsafe fn post_barrier(v: *mut Value, prev: Value, next: Value)

Place a post-write barrier
source§

impl PartialEq for Value

source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl RootKind for Value

source§

type Vtable = ()

source§

const VTABLE: Self::Vtable = ()

source§

const KIND: RootKind = JS::RootKind::Value

source§

impl Copy for Value

source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> Filterable for T

source§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T