pub struct Context<'ast> {
pub atom_table: AtomTable,
pub warn_undefined: bool,
/* private fields */
}Expand description
The storage for AST nodes.
Can be used to allocate and free nodes.
Nodes allocated in one Context must not be referenced by another Context’s AST.
Fields§
§atom_table: AtomTableAll identifiers are kept here.
warn_undefined: boolWhether to warn about undefined variables in strict mode functions.
Implementations§
Source§impl<'ast> Context<'ast>
impl<'ast> Context<'ast>
Sourcepub fn lock<'ctx>(&'ctx mut self) -> GCLock<'ast, 'ctx>
pub fn lock<'ctx>(&'ctx mut self) -> GCLock<'ast, 'ctx>
Acquire a GCLock on this Context.
This is just a more ergonomic way to call GCLock::new.
Sourcepub fn atom_table(&self) -> &AtomTable
pub fn atom_table(&self) -> &AtomTable
Return the atom table.
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. 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, which has no UTF-8 form. See
AtomTable::try_bytes_str.
Sourcepub fn strict_mode(&self) -> bool
pub fn strict_mode(&self) -> bool
Return true if strict mode has been forced globally.
Sourcepub fn enable_strict_mode(&mut self)
pub fn enable_strict_mode(&mut self)
Enable strict mode. Note that it cannot be unset.
Sourcepub fn enable_eval(&self) -> bool
pub fn enable_eval(&self) -> bool
Return true if eval() is enabled. Mirrors C++
Context::getEnableEval() (Context.h:407-409).
Sourcepub fn set_enable_eval(&mut self, v: bool)
pub fn set_enable_eval(&mut self, v: bool)
Enable or disable eval(). Mirrors C++
Context::setEnableEval() (Context.h:410-412).
Sourcepub fn parse_flow(&self) -> bool
pub fn parse_flow(&self) -> bool
Return true if Flow type parsing is enabled.
Mirrors C++ Context::getParseFlow().
Sourcepub fn set_parse_flow(&mut self, v: bool)
pub fn set_parse_flow(&mut self, v: bool)
Enable or disable Flow type parsing.
Mirrors C++ Context::setParseFlow().
Sourcepub fn parse_flow_ambiguous(&self) -> bool
pub fn parse_flow_ambiguous(&self) -> bool
Return true if the Flow ambiguous-expression grammar is enabled.
Mirrors C++ Context::getParseFlowAmbiguous().
Sourcepub fn set_parse_flow_ambiguous(&mut self, v: bool)
pub fn set_parse_flow_ambiguous(&mut self, v: bool)
Enable or disable the Flow ambiguous-expression grammar.
Sourcepub fn parse_flow_component_syntax(&self) -> bool
pub fn parse_flow_component_syntax(&self) -> bool
Return true if Flow component/hook syntax is enabled.
Mirrors C++ Context::getParseFlowComponentSyntax().
Sourcepub fn set_parse_flow_component_syntax(&mut self, v: bool)
pub fn set_parse_flow_component_syntax(&mut self, v: bool)
Enable or disable Flow component/hook syntax.
Sourcepub fn parse_flow_records(&self) -> bool
pub fn parse_flow_records(&self) -> bool
Return true if Flow record declarations/expressions are enabled.
Mirrors C++ Context::getParseFlowRecords().
Sourcepub fn set_parse_flow_records(&mut self, v: bool)
pub fn set_parse_flow_records(&mut self, v: bool)
Enable or disable Flow record declarations/expressions.
Sourcepub fn parse_flow_match(&self) -> bool
pub fn parse_flow_match(&self) -> bool
Return true if Flow match expressions/statements are enabled.
Mirrors C++ Context::getParseFlowMatch().
Sourcepub fn set_parse_flow_match(&mut self, v: bool)
pub fn set_parse_flow_match(&mut self, v: bool)
Enable or disable Flow match expressions/statements.
Sourcepub fn parse_ts(&self) -> bool
pub fn parse_ts(&self) -> bool
Return true if TypeScript type parsing is enabled.
Mirrors C++ Context::getParseTS().
Sourcepub fn set_parse_ts(&mut self, v: bool)
pub fn set_parse_ts(&mut self, v: bool)
Enable or disable TypeScript type parsing.
Mirrors C++ Context::setParseTS().
Sourcepub fn parse_jsx(&self) -> bool
pub fn parse_jsx(&self) -> bool
Return true if JSX parsing is enabled. Mirrors C++
Context::getParseJSX().
Sourcepub fn set_parse_jsx(&mut self, v: bool)
pub fn set_parse_jsx(&mut self, v: bool)
Enable or disable JSX parsing. Mirrors C++ Context::setParseJSX().
Currently only read by the TS <Type> cast gate; the setter is wired
when the JSX phase lands.
Sourcepub fn preemptive_function_compilation_threshold(&self) -> u32
pub fn preemptive_function_compilation_threshold(&self) -> u32
Return the preemptive-function-compilation threshold (bytes). Port of
Context::getPreemptiveFunctionCompilationThreshold() (Context.h:516-518).
Sourcepub fn set_preemptive_function_compilation_threshold(&mut self, byte_count: u32)
pub fn set_preemptive_function_compilation_threshold(&mut self, byte_count: u32)
Set the preemptive-function-compilation threshold (bytes). Port of
Context::setPreemptiveFunctionCompilationThreshold() (Context.h:520-522).
Sourcepub fn take_freed_node_ids(&mut self) -> Vec<NodeId>
pub fn take_freed_node_ids(&mut self) -> Vec<NodeId>
Drain and return the ids of every node freed (by gc() or by an
AllocationScope truncation) since the last call. Consumers use this
to prune dead entries out of side tables keyed by NodeId.
Sourcepub fn num_nodes(&self) -> usize
pub fn num_nodes(&self) -> usize
Returns the number of node slots which have been allocated. Includes nodes currently in use as well as nodes in the free list.
Sourcepub fn num_list_elements(&self) -> usize
pub fn num_list_elements(&self) -> usize
Returns the number of list-element slots which have been allocated. Includes elements currently in use as well as elements in the free list.
Sourcepub fn num_free_nodes(&self) -> usize
pub fn num_free_nodes(&self) -> usize
Returns the number of node slots currently in the free list (i.e. allocated but unused, reclaimed by GC).
Sourcepub fn storage_size(&self) -> usize
pub fn storage_size(&self) -> usize
Returns the approximate size of just the AST storages in bytes. Includes the allocated nodes, lists, as well as free lists for both.
Trait Implementations§
Source§impl Drop for Context<'_>
impl Drop for Context<'_>
Source§fn drop(&mut self)
fn drop(&mut self)
Ensure that there are no outstanding NodeRcs into this Context which will be
invalidated once it is dropped.
§Panics
Will panic if there are any NodeRcs stored when this Context is dropped.
The panic is the only effect: before panicking, the node storage and
the NodeRc counter are leaked (Context::leak_noderc_targets), so
the outstanding handles — which are dropped during the ensuing
unwind, or later still if the panic is caught — decrement refcounts in
memory that is still valid. Leaking the arena is the price of keeping a
caller’s bug a panic instead of a use-after-free.