Skip to main content

GCLock

Struct GCLock 

Source
pub struct GCLock<'ast, 'ctx> { /* private fields */ }
Expand description

A way to view the Context.

Provides the user the ability to create new nodes and dereference NodeRc.

At most one is allowed to be active in any thread at any time. This is to ensure no &Node can be shared between Contexts.

Implementations§

Source§

impl<'ast, 'ctx> GCLock<'ast, 'ctx>

Source

pub fn new(ctx: &'ctx mut Context<'ast>) -> Self

§Panics

Will panic if there is already an active GCLock on this thread.

Source

pub fn alloc<'s>(&'s self, n: Node<'s>) -> &'s Node<'s>

Allocate a node in the ctx.

Source

pub fn ctx(&self) -> &Context<'ast>

Return a reference to the owning Context.

Source

pub fn atom_bytes<V: Into<Vec<u8>> + AsRef<[u8]>>(&self, value: V) -> AtomBytes

Add a byte-string to the identifier table.

Source

pub fn bytes(&self, ident: AtomBytes) -> &[u8]

Obtain the contents of an atom from the atom table.

Source

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.

Source

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>

Source

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 NodeRc points 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()).

Trait Implementations§

Source§

impl Drop for GCLock<'_, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'ast, 'ctx> !RefUnwindSafe for GCLock<'ast, 'ctx>

§

impl<'ast, 'ctx> !Send for GCLock<'ast, 'ctx>

§

impl<'ast, 'ctx> !Sync for GCLock<'ast, 'ctx>

§

impl<'ast, 'ctx> !UnwindSafe for GCLock<'ast, 'ctx>

§

impl<'ast, 'ctx> Freeze for GCLock<'ast, 'ctx>

§

impl<'ast, 'ctx> Unpin for GCLock<'ast, 'ctx>

§

impl<'ast, 'ctx> UnsafeUnpin for GCLock<'ast, 'ctx>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.