pub enum Atom {
Str(String),
Index(u32),
Null,
}Expand description
One entry of a function’s atom table.
The reference keeps two kinds of atom in one namespace, and the distinction is
visible in the bytecode: an array-index atom is not a string at all but a
tagged uint32, which is why { 2: x } disassembles as define_field 2 while
{ "1.5": x } prints define_field "1.5". Collapsing the two would make the
disassembly wrong and lose information on the way back in, so the kind is
carried here.
Variants§
Str(String)
An interned string.
Index(u32)
A canonical array index, held as a number rather than a string.
Null
The reference’s JS_ATOM_NULL: no name at all.
Only a handful of opcodes take one — throw_error with the generic message, and
delete super.x — and the dump prints it as <null> rather than as an empty string,
which is why it is a variant instead of Str(String::new()).
Implementations§
Source§impl Atom
impl Atom
Sourcepub fn from_text(text: &str) -> Atom
pub fn from_text(text: &str) -> Atom
The atom the reference’s JS_NewAtomStr would make of text.
A canonical array index no greater than 2^31 - 1 is never interned as a
string: the reference returns a tagged integer instead. Anything else —
"007", "1e2", "-0", or an index past the tag range — stays a string.