pub struct GCLock<'ast, 'ctx> { /* private fields */ }Expand description
Implementations§
Source§impl<'ast, 'ctx> GCLock<'ast, 'ctx>
impl<'ast, 'ctx> GCLock<'ast, 'ctx>
Sourcepub fn new(ctx: &'ctx mut Context<'ast>) -> Self
pub fn new(ctx: &'ctx mut Context<'ast>) -> Self
§Panics
Will panic if there is already an active GCLock on this thread.
Sourcepub fn atom_bytes<V: Into<Vec<u8>> + AsRef<[u8]>>(&self, value: V) -> AtomBytes
pub fn atom_bytes<V: Into<Vec<u8>> + AsRef<[u8]>>(&self, value: V) -> AtomBytes
Add a byte-string to the identifier table.
Sourcepub fn bytes(&self, ident: AtomBytes) -> &[u8] ⓘ
pub fn bytes(&self, ident: AtomBytes) -> &[u8] ⓘ
Obtain the contents of an atom from the atom table.
Sourcepub fn bytes_str_lossy(&self, ident: AtomBytes) -> &str
pub fn bytes_str_lossy(&self, ident: AtomBytes) -> &str
Obtain the contents of an atom as a string, substituting U+FFFD for
anything unrepresentable. This is the usual way to print an
identifier’s name: gc.bytes_str_lossy(id.name.get()). See
AtomTable::bytes_str_lossy.
Sourcepub fn try_bytes_str(&self, ident: AtomBytes) -> Option<&str>
pub fn try_bytes_str(&self, ident: AtomBytes) -> Option<&str>
Obtain the contents of an atom as a string, or None if it holds an
unpaired surrogate — a legal JS string value with no UTF-8 form. This
is the right accessor for string-literal values, where substituting
U+FFFD would silently corrupt the program’s data. Note a surrogate
pair, which is how an astral character is stored, comes back as
Some. See AtomTable::try_bytes_str.
Source§impl<'ast, 'ctx> GCLock<'ast, 'ctx>
impl<'ast, 'ctx> GCLock<'ast, 'ctx>
Sourcepub unsafe fn alloc_scope<'s>(&'s self) -> AllocationScope<'s, 'ast, 'ctx>
pub unsafe fn alloc_scope<'s>(&'s self) -> AllocationScope<'s, 'ast, 'ctx>
Open an allocation scope: everything allocated between this call and
the returned guard’s drop is reclaimed at drop (nodes and list
elements). Mirrors the C++ AllocationScope discipline the PreParse
pass uses (JSParserImpl.cpp:516-560).
§Safety
The caller must guarantee that when the guard drops:
- no
&Node,NodeList,&NodeListElement, or interior reference into an allocation made after this call survives — the storage is freed and any such reference dangles; and - no
NodeRcpoints into those allocations (debug-asserted).
If the Context ran gc() before this pass, in-scope allocations
may be served from the free list at pre-watermark positions; those
escape reclamation harmlessly (unreferenced until the next gc()).