#[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

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 CustomTrace for Value

source§

impl Debug for Value

source§

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

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

impl Default for Value

source§

fn default() -> Value

Returns the “default value” for a type. Read more
source§

impl FromJSValConvertible for Value

§

type Config = ()

Optional configurable behaviour switch; use () for no configuration.
source§

unsafe fn from_jsval( _cx: *mut JSContext, value: Handle<'_, Value>, _option: () ) -> Result<ConversionResult<Value>, ()>

Convert val to type Self. Optional configuration of type T can be passed as the option argument. If it returns Err(()), a JSAPI exception is pending. If it returns Ok(Failure(reason)), there is no pending JSAPI exception.
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<Value> for Value

source§

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

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

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

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

impl RootKind for Value

source§

fn rootKind() -> RootKind

Returns the rooting kind for Self.
source§

impl ToJSValConvertible for Value

source§

unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandle<'_, Value>)

Convert self to a JSVal. JSAPI failure causes a panic.
source§

impl Copy for Value

source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> MaybeBoxed<Box<T, Global>> for T

source§

fn maybe_boxed(self) -> Box<T, Global>

Convert
source§

impl<T> MaybeBoxed<T> for T

source§

fn maybe_boxed(self) -> T

Convert
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for Pwhere R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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<V, T> VZip<V> for Twhere V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Erased for T

source§

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

source§

impl<T> MaybeSendSync for T

source§

impl<T> WasmNotSend for Twhere T: Send,

source§

impl<T> WasmNotSync for Twhere T: Sync,