pub struct Runtime { /* private fields */ }Expand description
A runtime: one heap, one realm, one job queue. Cloning shares it.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub const GC_STRESS_AVAILABLE: bool = false
pub const GC_STRESS_AVAILABLE: bool = false
Whether this build has the stress collector.
Sourcepub const IC_STATS_AVAILABLE: bool = false
pub const IC_STATS_AVAILABLE: bool = false
Whether this build counts inline-cache hits (ic_report returns
Some).
pub fn with_options(options: RuntimeOptions) -> Self
Sourcepub fn with_host(host: impl Host + 'static, options: RuntimeOptions) -> Self
pub fn with_host(host: impl Host + 'static, options: RuntimeOptions) -> Self
A runtime over host (the clock, the time zone, output, files).
Sourcepub fn new_with_host_services(host: impl Host + 'static) -> Self
pub fn new_with_host_services(host: impl Host + 'static) -> Self
Runtime::with_host with the default options (the current API’s
name).
Sourcepub fn new_context(&self) -> Result<Context, RuntimeError>
pub fn new_context(&self) -> Result<Context, RuntimeError>
The runtime’s one realm (the current API’s name: a second call returns the same realm, never a new one).
Sourcepub fn is_same_runtime(&self, other: &Self) -> bool
pub fn is_same_runtime(&self, other: &Self) -> bool
Whether self and other are the same runtime.
Sourcepub fn interrupt_handle(&self) -> InterruptHandle
pub fn interrupt_handle(&self) -> InterruptHandle
The handle another thread interrupts this runtime’s scripts with.
Sourcepub fn set_can_block(&self, can_block: bool) -> Result<(), RuntimeError>
pub fn set_can_block(&self, can_block: bool) -> Result<(), RuntimeError>
Whether Atomics.wait may block.
Sourcepub fn set_debug_info_mode(
&self,
mode: DebugInfoMode,
) -> Result<(), RuntimeError>
pub fn set_debug_info_mode( &self, mode: DebugInfoMode, ) -> Result<(), RuntimeError>
The debug information functions compiled from now on keep.
pub fn debug_info_mode(&self) -> Result<DebugInfoMode, RuntimeError>
Sourcepub fn set_module_loader(
&self,
loader: impl ModuleLoader + 'static,
) -> Result<(), RuntimeError>
pub fn set_module_loader( &self, loader: impl ModuleLoader + 'static, ) -> Result<(), RuntimeError>
Installs the module loader; import and import() go through it.
Sourcepub fn is_job_pending(&self) -> Result<bool, RuntimeError>
pub fn is_job_pending(&self) -> Result<bool, RuntimeError>
Whether a job is pending.
Sourcepub fn run_pending_job(&self) -> Result<PendingJobOutcome, RuntimeError>
pub fn run_pending_job(&self) -> Result<PendingJobOutcome, RuntimeError>
Runs the oldest pending job. A job that throws returns
RuntimeError::Exception with the thrown value; the queue keeps the
jobs after it. Rejected inside an execution turn,
leaving the job queued.
Sourcepub fn execute_pending_job(&self) -> Result<PendingJobOutcome, RuntimeError>
pub fn execute_pending_job(&self) -> Result<PendingJobOutcome, RuntimeError>
Runtime::run_pending_job (the current API’s name).
Sourcepub fn run_jobs(&self) -> Result<(), RuntimeError>
pub fn run_jobs(&self) -> Result<(), RuntimeError>
Runs jobs until the queue is empty or one throws.
Sourcepub fn with_execution_turn<T>(
&self,
body: impl FnOnce() -> Result<T, RuntimeError>,
) -> Result<T, RuntimeError>
pub fn with_execution_turn<T>( &self, body: impl FnOnce() -> Result<T, RuntimeError>, ) -> Result<T, RuntimeError>
Runs body as one synchronous execution sequence: objects a
WeakRef keeps alive stay alive until the turn ends
(ECMASCRIPT-WEAKREF-LIFETIME-001).
Sourcepub fn promise_snapshot(
&self,
promise: &ObjectRef,
) -> Result<Option<PromiseSnapshot>, RuntimeError>
pub fn promise_snapshot( &self, promise: &ObjectRef, ) -> Result<Option<PromiseSnapshot>, RuntimeError>
A promise’s state and result; None when promise is not one.
Sourcepub fn set_track_rejections(&self, track: bool) -> Result<(), RuntimeError>
pub fn set_track_rejections(&self, track: bool) -> Result<(), RuntimeError>
Keeps every rejected promise without a handler until one is attached
(QuickJS’s js_std_promise_rejection_tracker).
Sourcepub fn take_unhandled_rejections(
&self,
) -> Result<Vec<(ObjectRef, Value)>, RuntimeError>
pub fn take_unhandled_rejections( &self, ) -> Result<Vec<(ObjectRef, Value)>, RuntimeError>
The tracked unhandled rejections, promise and reason, in rejection order; the list is emptied.
Sourcepub fn run_gc(&self) -> Result<GcStats, RuntimeError>
pub fn run_gc(&self) -> Result<GcStats, RuntimeError>
Runs a full collection; the collector’s statistics after it.
pub fn gc_stats(&self) -> Result<GcStats, RuntimeError>
Sourcepub fn memory_report(&self) -> Result<MemoryReport, RuntimeError>
pub fn memory_report(&self) -> Result<MemoryReport, RuntimeError>
What every part of the runtime holds, without a collection.
Sourcepub fn set_gc_policy(&self, policy: GcPolicy) -> Result<(), RuntimeError>
pub fn set_gc_policy(&self, policy: GcPolicy) -> Result<(), RuntimeError>
When the collector runs: on heap growth (the default) or only at the
cap and on Runtime::run_gc.
pub fn gc_policy(&self) -> Result<GcPolicy, RuntimeError>
Sourcepub fn set_gc_stress(&self, interval: Option<u32>) -> Result<(), RuntimeError>
pub fn set_gc_stress(&self, interval: Option<u32>) -> Result<(), RuntimeError>
Collects before every interval-th allocating operation (qjs --gc-stress=N), or stops (None); only in a build with the stress
collector (Runtime::GC_STRESS_AVAILABLE).
Sourcepub fn set_record_gc_pauses(&self, record: bool) -> Result<(), RuntimeError>
pub fn set_record_gc_pauses(&self, record: bool) -> Result<(), RuntimeError>
Records every collection’s pause (for Runtime::gc_report).
Sourcepub fn gc_report(&self) -> Result<String, RuntimeError>
pub fn gc_report(&self) -> Result<String, RuntimeError>
--gc-stats’s line: collections, pauses and their percentiles, live
and reserved bytes.
Sourcepub fn ic_report(&self, worst: usize) -> Result<Option<String>, RuntimeError>
pub fn ic_report(&self, worst: usize) -> Result<Option<String>, RuntimeError>
The inline-cache report (--ic-stats), when the build counts.
Sourcepub fn disassemble(
&self,
source: &[u8],
filename: &str,
) -> Result<String, RuntimeError>
pub fn disassemble( &self, source: &[u8], filename: &str, ) -> Result<String, RuntimeError>
The disassembly of every unit source compiles to, root first.
pub fn intern_property_key( &self, text: &str, ) -> Result<PropertyKey, RuntimeError>
pub fn intern_property_key_js_string( &self, text: &JsString, ) -> Result<PropertyKey, RuntimeError>
Sourcepub fn property_key_to_js_string(
&self,
key: &PropertyKey,
) -> Result<JsString, RuntimeError>
pub fn property_key_to_js_string( &self, key: &PropertyKey, ) -> Result<JsString, RuntimeError>
The key as a string; a symbol key’s description (empty when it has none).
pub fn new_symbol( &self, description: Option<JsString>, ) -> Result<SymbolRef, RuntimeError>
pub fn symbol_description( &self, symbol: &SymbolRef, ) -> Result<Option<JsString>, RuntimeError>
pub fn well_known_symbol( &self, symbol: WellKnownSymbol, ) -> Result<SymbolRef, RuntimeError>
pub fn get_prototype_of( &self, object: &ObjectRef, ) -> Result<Option<ObjectRef>, RuntimeError>
pub fn set_prototype_of( &self, object: &ObjectRef, prototype: Option<&ObjectRef>, ) -> Result<bool, RuntimeError>
Sourcepub fn as_callable(
&self,
object: &ObjectRef,
) -> Result<Option<CallableRef>, RuntimeError>
pub fn as_callable( &self, object: &ObjectRef, ) -> Result<Option<CallableRef>, RuntimeError>
The object as a callable reference; None when it is not callable.
pub fn is_constructor(&self, object: &ObjectRef) -> Result<bool, RuntimeError>
Sourcepub fn is_array_object(&self, object: &ObjectRef) -> Result<bool, RuntimeError>
pub fn is_array_object(&self, object: &ObjectRef) -> Result<bool, RuntimeError>
IsArray.
pub fn is_error_object(&self, object: &ObjectRef) -> Result<bool, RuntimeError>
pub fn define_own_property( &self, object: &ObjectRef, key: &PropertyKey, descriptor: &OrdinaryPropertyDescriptor, ) -> Result<bool, RuntimeError>
pub fn get_own_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<Option<CompleteOrdinaryPropertyDescriptor>, RuntimeError>
pub fn delete_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<bool, RuntimeError>
pub fn has_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<bool, RuntimeError>
pub fn has_own_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<bool, RuntimeError>
pub fn own_property_keys( &self, object: &ObjectRef, ) -> Result<Vec<PropertyKey>, RuntimeError>
Sourcepub fn print_value(&self, value: &Value) -> Result<String, RuntimeError>
pub fn print_value(&self, value: &Value) -> Result<String, RuntimeError>
QuickJS’s JS_PrintValue: what print and an uncaught-exception dump
show. Runs no JavaScript (no accessor, trap or coercion).
Sourcepub fn qjs_print_value_bytes(
&self,
value: &Value,
) -> Result<Vec<u8>, RuntimeError>
pub fn qjs_print_value_bytes( &self, value: &Value, ) -> Result<Vec<u8>, RuntimeError>
Runtime::print_value as the bytes QuickJS writes: a lone
surrogate of a raw name, message or stack as its own three bytes
(WTF-8) instead of U+FFFD.