pub enum PropertyKey {
String(Wtf8),
Symbol(Gc<JsSymbol>),
}Expand description
The mutable half of an object. What a property is keyed by.
A string and a symbol are separate key spaces even when they look alike: o["a"]
and o[Symbol("a")] are two properties, and o[Symbol("a")] is not reachable by
any string. Symbols are also invisible to for/Object.keys/JSON.stringify,
which is the whole point of them, so the distinction has to survive into the
property table rather than being flattened into a name.
Variants§
String(Wtf8)
An ordinary string key, held as WTF-8 so a key containing an unpaired surrogate
addresses one property rather than colliding with its U+FFFD replacement.
Symbol(Gc<JsSymbol>)
A symbol key.
Implementations§
Source§impl PropertyKey
impl PropertyKey
Sourcepub fn hash_code(&self) -> usize
pub fn hash_code(&self) -> usize
A cheap hash of this key, for an inline cache’s slot choice.
Not a hash of the whole string: a long property name would make the cache slower than
the lookup it is caching. Mixing the length with the first and last byte is enough to
separate the names that appear on one object (x/y, value/add), and a
collision only costs a miss.
Source§impl PropertyKey
impl PropertyKey
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
The key as a string, for the operations that only accept one.
A symbol has no string form that would address it, so this answers None —
which is what makes get_field on a symbol key fall through to the general
path instead of silently reading a same-named string property.