#[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
impl Value
pub fn is_undefined(&self) -> bool
pub fn is_null(&self) -> bool
pub fn is_null_or_undefined(&self) -> bool
pub fn is_boolean(&self) -> bool
pub fn is_int32(&self) -> bool
pub fn is_double(&self) -> bool
pub fn is_number(&self) -> bool
pub fn is_primitive(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_object(&self) -> bool
pub fn is_object_or_null(&self) -> bool
pub fn is_magic(&self) -> bool
pub fn is_symbol(&self) -> bool
pub fn is_bigint(&self) -> bool
pub fn is_gcthing(&self) -> bool
pub fn to_boolean(&self) -> bool
pub fn to_int32(&self) -> i32
pub fn to_double(&self) -> f64
pub fn to_number(&self) -> f64
pub fn to_string(&self) -> *mut JSString
pub fn to_object(&self) -> *mut JSObject
pub fn to_object_or_null(&self) -> *mut JSObject
pub fn to_symbol(&self) -> *mut Symbol
pub fn to_bigint(&self) -> *mut BigInt
pub fn to_private(&self) -> *const c_void
pub fn to_gcthing(&self) -> *mut c_void
pub fn is_markable(&self) -> bool
pub fn trace_kind(&self) -> TraceKind
Trait Implementations§
source§impl FromJSValConvertible for Value
impl FromJSValConvertible for Value
source§unsafe fn from_jsval(
_cx: *mut JSContext,
value: Handle<'_, Value>,
_option: (),
) -> Result<ConversionResult<Value>, ()>
unsafe fn from_jsval( _cx: *mut JSContext, value: Handle<'_, Value>, _option: (), ) -> Result<ConversionResult<Value>, ()>
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 ToJSValConvertible for Value
impl ToJSValConvertible for Value
impl Copy for Value
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> 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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>
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>
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>
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>
source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.