pub struct Realm {Show 38 fields
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 bigint_proto: Option<Gc<JsObject>>,
pub error_proto: Gc<JsObject>,
pub date_proto: Gc<JsObject>,
pub generator_proto: Gc<JsObject>,
pub promise_proto: Option<Gc<JsObject>>,
pub async_generator_proto: Option<Gc<JsObject>>,
pub symbol_proto: Option<Gc<JsObject>>,
pub internal_slots: BTreeMap<&'static str, Value>,
pub symbol_registry: BTreeMap<String, Value>,
pub regexp_proto: Option<Gc<JsObject>>,
pub regexp_ctor: Option<Gc<JsObject>>,
pub suppressed_error_proto: Option<Gc<JsObject>>,
pub disposable_stack_proto: Option<Gc<JsObject>>,
pub map_proto: Option<Gc<JsObject>>,
pub set_proto: Option<Gc<JsObject>>,
pub array_buffer_proto: Option<Gc<JsObject>>,
pub typed_array_proto: Option<Gc<JsObject>>,
pub typed_array_protos: Vec<Gc<JsObject>>,
pub data_view_proto: Option<Gc<JsObject>>,
pub async_disposable_stack_proto: Option<Gc<JsObject>>,
pub iterator_proto: Option<Gc<JsObject>>,
pub iterator_helper_proto: Option<Gc<JsObject>>,
pub iterator_wrap_proto: Option<Gc<JsObject>>,
pub generator_function_proto: Option<Gc<JsObject>>,
pub async_function_proto: Option<Gc<JsObject>>,
pub async_generator_function_proto: Option<Gc<JsObject>>,
pub iterator_protos: BTreeMap<String, Gc<JsObject>>,
/* private fields */
}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.
bigint_proto: Option<Gc<JsObject>>BigInt.prototype.
error_proto: Gc<JsObject>Error.prototype, the prototype of every error instance.
date_proto: Gc<JsObject>Date.prototype, so the constructor can build an instance in the
function-call form (Date() returns a string) without going through new.
generator_proto: Gc<JsObject>%GeneratorPrototype%, the prototype of every generator object.
promise_proto: Option<Gc<JsObject>>Promise.prototype, the prototype of every promise.
async_generator_proto: Option<Gc<JsObject>>%AsyncGeneratorPrototype%, the prototype of every async function* result.
symbol_proto: Option<Gc<JsObject>>Symbol.prototype.
internal_slots: BTreeMap<&'static str, Value>The symbols behind the engine’s own hidden slots: _value, _class,
_date_value.
These are symbol keys on purpose. A "_value" property is visible to
Object.getOwnPropertyNames, so new Number(1) reported an own property the
language does not have and new Error() listed _class beside message and
stack — and a caller that copies every own property (which
Object.create(null, props) effectively does) tried to write an internal name and
threw. A symbol key is invisible to getOwnPropertyNames, Object.keys, for…in
and JSON.stringify, while remaining an ordinary traced property.
symbol_registry: BTreeMap<String, Value>The Symbol.for registry: key -> symbol.
Scoped to the realm, which is what makes Symbol.for("k") answer the same
symbol every time within one script while a fresh realm starts empty.
regexp_proto: Option<Gc<JsObject>>RegExp.prototype, filled in by the RegExp builtin.
regexp_ctor: Option<Gc<JsObject>>The RegExp constructor.
suppressed_error_proto: Option<Gc<JsObject>>SuppressedError.prototype, which using builds its aggregates from.
The prototype rather than the constructor on purpose: a script that replaces
SuppressedError.prototype.constructor must not be able to divert the engine’s own
error wrapping, which the using test suite checks explicitly.
disposable_stack_proto: Option<Gc<JsObject>>The DisposableStack prototype, for move’s intrinsic construction.
map_proto: Option<Gc<JsObject>>Map.prototype.
set_proto: Option<Gc<JsObject>>Set.prototype.
array_buffer_proto: Option<Gc<JsObject>>ArrayBuffer.prototype.
typed_array_proto: Option<Gc<JsObject>>%TypedArray%.prototype, the prototype every view type inherits from.
typed_array_protos: Vec<Gc<JsObject>>One prototype per view type, in [builtins::typedarray::ELEMENT_TYPES] order.
A typed array answers map/filter/slice with a new view of the same type, and
the result has to carry the per-type prototype — otherwise r.constructor.name is
"Object" and r instanceof Int32Array is false.
data_view_proto: Option<Gc<JsObject>>DataView.prototype.
async_disposable_stack_proto: Option<Gc<JsObject>>The AsyncDisposableStack prototype.
iterator_proto: Option<Gc<JsObject>>Iterator.prototype.
iterator_helper_proto: Option<Gc<JsObject>>%IteratorHelperPrototype%, the prototype every lazy helper object gets.
It sits between the helper and Iterator.prototype, which is how a helper is both
an Iterator and recognisable as a helper (Object.prototype.toString says
[object Iterator Helper]).
iterator_wrap_proto: Option<Gc<JsObject>>%WrapForValidIteratorPrototype%, the prototype Iterator.from gives an iterable
that was not already an Iterator.
Distinct from the helper prototype on purpose: it forwards next and return
untouched and does not override @@toStringTag, so
Object.prototype.toString.call(Iterator.from(xs)) says [object Iterator].
generator_function_proto: Option<Gc<JsObject>>%GeneratorFunction.prototype% — what a generator function inherits from.
async_function_proto: Option<Gc<JsObject>>%AsyncFunction.prototype%.
async_generator_function_proto: Option<Gc<JsObject>>%AsyncGeneratorFunction.prototype%.
iterator_protos: BTreeMap<String, Gc<JsObject>>One %…IteratorPrototype% per kind, keyed by its @@toStringTag.
Cached because the identity is observable: Object.getPrototypeOf([].values())
has to equal Object.getPrototypeOf([][Symbol.iterator]()), and building a fresh
prototype per iterator made every array iterator’s prototype distinct.
Implementations§
Source§impl Realm
impl Realm
Sourcepub fn set_well_known_symbols(&mut self, symbols: Vec<Value>)
pub fn set_well_known_symbols(&mut self, symbols: Vec<Value>)
Record the well-known symbols, in the order Symbol’s installer made them.
Sourcepub fn well_known(&self, which: WellKnown) -> Value
pub fn well_known(&self, which: WellKnown) -> Value
A well-known symbol.
Sourcepub fn well_known_key(&self, which: WellKnown) -> PropertyKey
pub fn well_known_key(&self, which: WellKnown) -> PropertyKey
The well-known symbol as a property key.