Skip to main content

Realm

Struct Realm 

Source
pub struct Realm {
    pub global: Gc<JsObject>,
    pub object_proto: Gc<JsObject>,
    pub function_proto: Gc<JsObject>,
    pub array_proto: Gc<JsObject>,
    pub globals: BTreeMap<String, Gc<Cell>>,
    pub declared: Vec<String>,
    pub lexical_consts: BTreeSet<String>,
    pub errors: BTreeMap<&'static str, Gc<JsObject>>,
    pub string_proto: Option<Gc<JsObject>>,
    pub number_proto: Option<Gc<JsObject>>,
    pub boolean_proto: Option<Gc<JsObject>>,
    pub error_proto: Gc<JsObject>,
}
Expand description

Everything one JavaScript realm owns.

A realm is the set of objects a script can reach without naming them: the global object, the prototype chain roots, and the global binding cells.

Fields§

§global: Gc<JsObject>

The global object.

§object_proto: Gc<JsObject>

Object.prototype.

§function_proto: Gc<JsObject>

Function.prototype, which is itself callable.

§array_proto: Gc<JsObject>

Array.prototype.

§globals: BTreeMap<String, Gc<Cell>>

Reference cells for globals declared by the script.

A declared global is read with get_var (by name) but written with put_var_ref (through the cell), so the cell is what makes a function declaration and its uses agree on one binding.

§declared: Vec<String>

Names of the globals that came from a declaration, which are non-configurable properties of the global object.

§lexical_consts: BTreeSet<String>

Names among the lexical globals that are const.

const-ness cannot be read back off the bytecode in every case: a closure that refers to a global const gets a GlobalRef entry whose flags the forwarding path does not carry, so a store through it would look like a plain let. The realm records it once, at declaration, and answers for every reader.

§errors: BTreeMap<&'static str, Gc<JsObject>>

The error constructors by class name, so a runtime error can throw a real TypeError instance rather than a look-alike object.

§string_proto: Option<Gc<JsObject>>

String.prototype, used by ToString on primitives and by the boxing path.

§number_proto: Option<Gc<JsObject>>

Number.prototype.

§boolean_proto: Option<Gc<JsObject>>

Boolean.prototype.

§error_proto: Gc<JsObject>

Error.prototype, the prototype of every error instance.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Realm

§

impl !Send for Realm

§

impl !Sync for Realm

§

impl !UnwindSafe for Realm

§

impl Forget for Realm

§

impl Freeze for Realm

§

impl Move for Realm

§

impl Unpin for Realm

§

impl UnsafeUnpin for Realm

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.