Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime { /* private fields */ }
Expand description

A runtime: one heap, one realm, one job queue. Cloning shares it.

Implementations§

Source§

impl Runtime

Source

pub const GC_STRESS_AVAILABLE: bool = false

Whether this build has the stress collector.

Source

pub const IC_STATS_AVAILABLE: bool = false

Whether this build counts inline-cache hits (ic_report returns Some).

Source

pub fn new() -> Self

A runtime with the default host and options.

Source

pub fn with_options(options: RuntimeOptions) -> Self

Source

pub fn with_host(host: impl Host + 'static, options: RuntimeOptions) -> Self

A runtime over host (the clock, the time zone, output, files).

Source

pub fn new_with_host_services(host: impl Host + 'static) -> Self

Runtime::with_host with the default options (the current API’s name).

Source

pub fn context(&self) -> Context

The runtime’s one realm.

Source

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).

Source

pub fn is_same_runtime(&self, other: &Self) -> bool

Whether self and other are the same runtime.

Source

pub fn interrupt_handle(&self) -> InterruptHandle

The handle another thread interrupts this runtime’s scripts with.

Source

pub fn set_can_block(&self, can_block: bool) -> Result<(), RuntimeError>

Whether Atomics.wait may block.

Source

pub fn set_debug_info_mode( &self, mode: DebugInfoMode, ) -> Result<(), RuntimeError>

The debug information functions compiled from now on keep.

Source

pub fn debug_info_mode(&self) -> Result<DebugInfoMode, RuntimeError>

Source

pub fn set_module_loader( &self, loader: impl ModuleLoader + 'static, ) -> Result<(), RuntimeError>

Installs the module loader; import and import() go through it.

Source

pub fn is_job_pending(&self) -> Result<bool, RuntimeError>

Whether a job is pending.

Source

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.

Source

pub fn execute_pending_job(&self) -> Result<PendingJobOutcome, RuntimeError>

Runtime::run_pending_job (the current API’s name).

Source

pub fn run_jobs(&self) -> Result<(), RuntimeError>

Runs jobs until the queue is empty or one throws.

Source

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).

Source

pub fn promise_snapshot( &self, promise: &ObjectRef, ) -> Result<Option<PromiseSnapshot>, RuntimeError>

A promise’s state and result; None when promise is not one.

Source

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).

Source

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.

Source

pub fn run_gc(&self) -> Result<GcStats, RuntimeError>

Runs a full collection; the collector’s statistics after it.

Source

pub fn gc_stats(&self) -> Result<GcStats, RuntimeError>

Source

pub fn memory_report(&self) -> Result<MemoryReport, RuntimeError>

What every part of the runtime holds, without a collection.

Source

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.

Source

pub fn gc_policy(&self) -> Result<GcPolicy, RuntimeError>

Source

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).

Source

pub fn set_record_gc_pauses(&self, record: bool) -> Result<(), RuntimeError>

Records every collection’s pause (for Runtime::gc_report).

Source

pub fn gc_report(&self) -> Result<String, RuntimeError>

--gc-stats’s line: collections, pauses and their percentiles, live and reserved bytes.

Source

pub fn ic_report(&self, worst: usize) -> Result<Option<String>, RuntimeError>

The inline-cache report (--ic-stats), when the build counts.

Source

pub fn disassemble( &self, source: &[u8], filename: &str, ) -> Result<String, RuntimeError>

The disassembly of every unit source compiles to, root first.

Source

pub fn intern_property_key( &self, text: &str, ) -> Result<PropertyKey, RuntimeError>

Source

pub fn intern_property_key_js_string( &self, text: &JsString, ) -> Result<PropertyKey, RuntimeError>

Source

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).

Source

pub fn new_symbol( &self, description: Option<JsString>, ) -> Result<SymbolRef, RuntimeError>

Source

pub fn symbol_description( &self, symbol: &SymbolRef, ) -> Result<Option<JsString>, RuntimeError>

Source

pub fn well_known_symbol( &self, symbol: WellKnownSymbol, ) -> Result<SymbolRef, RuntimeError>

Source

pub fn get_prototype_of( &self, object: &ObjectRef, ) -> Result<Option<ObjectRef>, RuntimeError>

Source

pub fn set_prototype_of( &self, object: &ObjectRef, prototype: Option<&ObjectRef>, ) -> Result<bool, RuntimeError>

Source

pub fn as_callable( &self, object: &ObjectRef, ) -> Result<Option<CallableRef>, RuntimeError>

The object as a callable reference; None when it is not callable.

Source

pub fn is_constructor(&self, object: &ObjectRef) -> Result<bool, RuntimeError>

Source

pub fn is_array_object(&self, object: &ObjectRef) -> Result<bool, RuntimeError>

IsArray.

Source

pub fn is_error_object(&self, object: &ObjectRef) -> Result<bool, RuntimeError>

Source

pub fn define_own_property( &self, object: &ObjectRef, key: &PropertyKey, descriptor: &OrdinaryPropertyDescriptor, ) -> Result<bool, RuntimeError>

Source

pub fn get_own_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<Option<CompleteOrdinaryPropertyDescriptor>, RuntimeError>

Source

pub fn delete_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<bool, RuntimeError>

Source

pub fn has_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<bool, RuntimeError>

Source

pub fn has_own_property( &self, object: &ObjectRef, key: &PropertyKey, ) -> Result<bool, RuntimeError>

Source

pub fn own_property_keys( &self, object: &ObjectRef, ) -> Result<Vec<PropertyKey>, RuntimeError>

Source

pub fn type_of(&self, value: &Value) -> Result<String, RuntimeError>

typeof value.

Source

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).

Source

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.

Trait Implementations§

Source§

impl Clone for Runtime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Runtime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.