pub struct JsSymbol { /* private fields */ }Expand description
A JavaScript symbol, stored on the GC heap.
A symbol is a unique property key that is not a string. Its identity is the
allocation, not the description: Symbol("a") !== Symbol("a"), and two symbols with
the same description still key two different properties. Only Symbol.for produces
the same symbol twice, and it does so by looking the key up in the realm’s registry
rather than by comparing descriptions.
Implementations§
Source§impl JsSymbol
impl JsSymbol
Sourcepub fn new_private(name: &str) -> JsSymbol
pub fn new_private(name: &str) -> JsSymbol
A private symbol: the key of a class’s #name property.
JS_NewSymbolFromAtom(ctx, atom, JS_ATOM_TYPE_PRIVATE), where the atom is the
property name including its # — JS_ATOM_hash_constructor is the string
"#constructor", which is how the reference rejects that name. The description is
therefore #x, and every message that prints this symbol gets the # for free.
Sourcepub fn is_private(&self) -> bool
pub fn is_private(&self) -> bool
Whether this symbol is a class-private name.
Sourcepub fn registered(key: String) -> JsSymbol
pub fn registered(key: String) -> JsSymbol
The registry entry for key, as Symbol.for returns it.
Sourcepub fn description(&self) -> Option<&str>
pub fn description(&self) -> Option<&str>
The description, if there is one.
Sourcepub fn registry_key(&self) -> Option<&str>
pub fn registry_key(&self) -> Option<&str>
The registry key, if this symbol came from Symbol.for.
Sourcepub fn to_display_string(&self) -> String
pub fn to_display_string(&self) -> String
Symbol.prototype.toString: Symbol(description).
A description is inserted verbatim, so Symbol("a)b").toString() is
Symbol(a)b) — the spec does not escape it.