Skip to main content

Runtime

Struct Runtime 

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

Implementations§

Source§

impl Runtime

Source

pub fn set_script_runner(&mut self, runner: ScriptRunner)

Lets $262.agent.start run agents’ scripts through runner.

Source

pub fn join_agents(&mut self)

Waits for every agent this runtime started.

Source§

impl Runtime

Source

pub fn native_cx(&mut self) -> NativeCx<'_>

The embedder’s view of the runtime between entries.

Source§

impl Runtime

Source

pub fn key_from_units( &mut self, units: &[u16], ) -> Result<PropertyKey, HeapError>

Source

pub fn key_from_symbol(&self, symbol: Value) -> Option<PropertyKey>

The key of a symbol value; None for any other value.

Source

pub fn to_property_key(&mut self, value: Value) -> Result<PropertyKey, Throw>

Source

pub fn key_name(&self, key: PropertyKey) -> KeyName

Source

pub fn get( &mut self, object: ObjectId, key: PropertyKey, receiver: Value, ) -> Result<Value, Throw>

Source

pub fn set( &mut self, object: ObjectId, key: PropertyKey, value: Value, receiver: Value, ) -> Result<bool, Throw>

Source

pub fn get_own_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<Option<PropertyDescriptor>, Throw>

Source

pub fn define_own_property( &mut self, object: ObjectId, key: PropertyKey, descriptor: &PropertyDescriptor, ) -> Result<bool, Throw>

Source

pub fn delete_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<bool, Throw>

Source

pub fn has_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<bool, Throw>

Source

pub fn has_own_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<bool, Throw>

Source

pub fn own_property_keys( &mut self, object: ObjectId, ) -> Result<Vec<PropertyKey>, Throw>

Source

pub fn get_prototype_of( &mut self, object: ObjectId, ) -> Result<Option<ObjectId>, Throw>

Source

pub fn set_prototype_of( &mut self, object: ObjectId, prototype: Option<ObjectId>, ) -> Result<bool, Throw>

Source

pub fn prevent_extensions(&mut self, object: ObjectId) -> Result<bool, Throw>

Source

pub fn construct( &mut self, function: Value, args: &[Value], new_target: Value, ) -> Result<Value, Throw>

Source

pub fn is_callable(&self, value: Value) -> bool

IsCallable(value).

Source

pub fn is_constructor(&self, value: Value) -> bool

IsConstructor(value).

Source

pub fn is_array(&mut self, value: Value) -> Result<bool, Throw>

Source

pub fn is_error(&self, value: Value) -> bool

Whether value is an Error instance (has [[ErrorData]]).

Source

pub fn is_promise(&mut self, value: Value) -> bool

Source

pub fn object_kind(&self, object: ObjectId) -> ObjectKind

Source

pub fn new_object_with_prototype( &mut self, prototype: Option<ObjectId>, ) -> Result<ObjectId, HeapError>

Source

pub fn new_array_from(&mut self, values: &[Value]) -> Result<ObjectId, Throw>

Source

pub fn new_error( &mut self, kind: ErrorKind, message: &str, ) -> Result<Value, HeapError>

Source

pub fn new_located_error( &mut self, kind: ErrorKind, message: &str, file: &str, line: u32, column: u32, ) -> Result<Value, HeapError>

Source

pub fn new_promise(&mut self) -> Result<ObjectId, Throw>

Source

pub fn detach_array_buffer(&mut self, value: Value) -> Result<(), Throw>

Source

pub fn new_string(&mut self, text: &str) -> Result<Value, HeapError>

Source

pub fn new_string_units(&mut self, units: &[u16]) -> Result<Value, HeapError>

Source

pub fn new_string_repr(&mut self, repr: StringRepr) -> Result<Value, HeapError>

Source

pub fn string_repr(&self, value: Value) -> Option<&StringRepr>

A string value’s code units, flattened; None for any other value.

Source

pub fn string_lossy(&self, value: Value) -> Option<String>

A string value as Rust text (lone surrogates replaced).

Source

pub fn new_bigint(&mut self, decimal: &str) -> Option<Result<Value, HeapError>>

Source

pub fn bigint_decimal(&self, value: Value) -> Option<String>

A BigInt value in decimal; None for any other value.

Source

pub fn new_symbol( &mut self, description: Option<&[u16]>, ) -> Result<Value, HeapError>

Source

pub fn symbol_description(&self, value: Value) -> Option<Vec<u16>>

A symbol’s [[Description]]; None when it is undefined or value is not a symbol.

Source

pub fn well_known_symbol(&self, name: &str) -> Option<Value>

The well-known symbol Symbol.<name> ("iterator", …).

Source

pub fn well_known_symbol_key(&self, name: &str) -> Option<PropertyKey>

Source

pub fn to_string(&mut self, value: Value) -> Result<Value, Throw>

Source

pub fn to_number(&mut self, value: Value) -> Result<f64, Throw>

Source

pub fn to_boolean(&self, value: Value) -> bool

ToBoolean(value).

Source

pub fn to_object(&mut self, value: Value) -> Result<ObjectId, Throw>

Source

pub fn strict_equals(&self, x: Value, y: Value) -> bool

IsStrictlyEqual(x, y).

Source

pub fn loose_equals(&mut self, x: Value, y: Value) -> Result<bool, Throw>

Source

pub fn same_value(&mut self, x: Value, y: Value) -> bool

Source

pub fn same_value_zero(&self, x: Value, y: Value) -> bool

SameValueZero(x, y).

Source

pub fn type_of(&mut self, value: Value) -> String

Source

pub fn kind_of(&self, value: Value) -> Kind

The kind of a value without running JavaScript.

Source

pub fn run_gc(&mut self)

Source§

impl Runtime

Source

pub fn new(options: impl Into<RuntimeOptions>) -> Result<Runtime, HeapError>

Source

pub fn regexps(&self) -> &RegExpStore

Source

pub fn realm(&self) -> &Realm

Source

pub fn host(&mut self) -> &mut Services

Source

pub fn set_can_block(&mut self, can_block: bool)

Whether Atomics.wait may block (Test262’s CanBlockIsFalse clears it).

Source

pub fn set_host(&mut self, hooks: Box<dyn Host>)

Installs the embedder’s hooks and seeds Math.random from Host::random_seed.

Source

pub fn set_track_rejections(&mut self, track: bool)

Keeps every rejected promise without a handler alive until a handler is attached or Runtime::clear_unhandled_rejections (QuickJS’s js_std_promise_rejection_tracker). Off by default.

Source

pub fn unhandled_rejections(&self) -> &[Value]

The tracked unhandled rejected promises, in rejection order.

Source

pub fn clear_unhandled_rejections(&mut self)

Source

pub fn capture_output(&mut self)

Sends print output to a buffer; Runtime::take_output returns it.

Source

pub fn take_output(&mut self) -> String

The output captured since the last call.

Source

pub fn install_test262_host(&mut self) -> Result<(), HeapError>

Defines the Test262 host object $262 on the global object.

Source

pub fn install_print(&mut self) -> Result<(), HeapError>

Defines qjs’s print and console.log on the global object.

Source

pub fn install_std(&mut self) -> Result<(), HeapError>

Defines qjs’s --std globals, load and read, over the host’s read_file.

Source

pub fn install_qjs_helpers( &mut self, script_args: Option<&[String]>, ) -> Result<(), HeapError>

Defines qjs’s helpers as QuickJS’s js_std_add_helpers does: console, scriptArgs when given, print.

Source

pub fn install_script_args(&mut self, args: &[String]) -> Result<(), HeapError>

Defines qjs’s scriptArgs.

Source

pub fn run_script(&mut self, script: ObjectId) -> Result<Value, Throw>

Runs a script function (from Runtime::instantiate) with the global object as this. The result is unrooted.

Source

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

Runs pending jobs until the queue is empty; the host calls it at its boundary. A job that throws stops the drain.

Source

pub fn run_pending_job(&mut self) -> Result<bool, Throw>

Runs the oldest pending job (then clears the kept objects); false when none was pending. A job that throws reports the throw.

Source

pub fn clear_kept_objects(&mut self)

ClearKeptObjects: the end of a synchronous execution sequence.

Source

pub fn has_pending_jobs(&self) -> bool

Whether jobs are pending.

Source

pub fn call( &mut self, function: Value, this: Value, args: &[Value], ) -> Result<Value, Throw>

Calls function; the result or the thrown value is unrooted. The caller keeps function alive (a handle or a rooted object).

Source

pub fn display(&mut self, value: Value) -> Result<String, Throw>

ToString(value) as Rust text, for hosts printing a result or an uncaught exception. Calls back into JavaScript for objects.

Source

pub fn vm_stack(&self) -> &VmStack

The register file and frame table.

Source

pub fn set_stack_limit(&mut self, registers: u32)

Source

pub fn set_native_stack_budget(&mut self, bytes: usize)

Sets the bytes of host stack nested re-entries into the loop may use (RuntimeOptions::native_stack_budget): a host that knows how much stack the thread has left sets it before an outermost entry.

Source

pub fn heap(&self) -> &Heap

Source

pub fn heap_mut(&mut self) -> &mut Heap

Source

pub fn code(&self) -> &CodeStore

Source

pub fn units(&self) -> Units<'_>

Every published unit: the code store’s and the heap’s.

Source

pub fn heap_and_code(&mut self) -> (&mut Heap, &CodeStore)

The heap and the code store borrowed together, so code can be read while the heap is mutated.

Source

pub fn publish(&mut self, unit: CodeUnit) -> Result<CodeUnitId, ValidateError>

Validates unit and appends it to the code store. Its children must be published first.

Source

pub fn instantiate( &mut self, root: CodeUnitId, constants: &[&[Value]], ) -> Result<ObjectId, HeapError>

A function object for the published unit root, with a bytecode record for it and every unit below it. constants holds one table per unit, in the pre-order of Units::tree; each must have the unit’s constant_count entries. The constants need no rooting.

Source

pub fn compiler(&mut self) -> Compiler<'_>

The heap, the code store and the realm, for a compilation whose units live as long as the runtime (in the code store, where the loop runs them as a plain borrow): the program and its modules.

Source

pub fn transient_compiler(&mut self) -> Compiler<'_>

Runtime::compiler for code the embedder compiles and lets go of (a REPL’s lines): its units go in the heap, as eval’s do, and are freed once no function names them.

Source

pub fn set_compiler(&mut self, compile: CompileFn)

Installs the embedder’s compiler, for eval, the Function constructors and $262.evalScript.

Source

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

The inline-cache report, when the counters exist (the ic-stats feature or a debug build): hits and misses per cache kind, the site states, and the worst sites with the most misses (unit name, instruction index, key).

Source

pub fn disassemble(&self, unit: CodeUnitId) -> String

The disassembly of unit, with atom keys spelled out.

Source

pub fn global_object(&self) -> ObjectId

Source

pub fn intrinsic(&self, intrinsic: Intrinsic) -> ObjectId

Source

pub fn template_object( &mut self, cooked: &[Value], raw: &[Value], ) -> Result<ObjectId, HeapError>

A tagged template’s site object: a frozen array of the cooked strings with a frozen raw array of the raw ones (strings and undefined).

Source

pub fn new_object(&mut self) -> Result<ObjectId, HeapError>

An ordinary object inheriting from %Object.prototype%.

Source

pub fn new_array(&mut self, capacity: u32) -> Result<ObjectId, HeapError>

Source

pub fn new_function( &mut self, scope: Option<ScopeId>, ) -> Result<ObjectId, HeapError>

Source

pub fn new_scope( &mut self, parent: Option<ScopeId>, slots: u32, ) -> Result<ScopeId, HeapError>

Source

pub fn thrown_summary(&mut self, value: Value) -> Option<ThrownSummary>

What a test host reports of a thrown object without running JavaScript: the error name (an own name string, else the prototype’s, else the prototype’s constructor’s own name other than Object), the own message string and the own stack string. Accessors and non-string values count as absent; None for a primitive.

Source

pub fn memory_report(&self) -> MemoryReport

What every part of the runtime holds, read without a collection. Its reserved total equals Heap::bytes.

Source

pub fn hold(&mut self, value: Value) -> Handle

Holds value for the embedder until Runtime::release.

Source

pub fn held(&self, handle: Handle) -> Value

Source

pub fn release(&mut self, handle: Handle)

Source§

impl Runtime

Source

pub fn set_module_host(&mut self, host: ModuleHost)

Installs the embedder’s module loader.

Source

pub fn forget_module(&mut self, name: &str)

Drops the module named name from the name map: a later import of the name loads it again. Modules that imported it keep the record.

Source

pub fn run_module(&mut self, name: &str) -> Result<Value, Throw>

Loads, links and evaluates the module named name (already normalized); returns the promise of its evaluation, unrooted.

Source

pub fn run_module_phased( &mut self, name: &str, ) -> Result<Value, (ModulePhase, Throw)>

Runtime::run_module with the step that threw: loading (compiling the graph), linking or evaluating.

Source

pub fn promise_state(&mut self, promise: Value) -> Option<(i32, Value)>

The state of a promise (0 pending, 1 fulfilled, 2 rejected) and its result.

Source§

impl Runtime

Source

pub fn print_value(&mut self, value: Value) -> String

The value as QuickJS’s JS_PrintValue prints it; a string is quoted and escaped (print writes a top-level string raw instead). A lone surrogate in a raw C string shows as U+FFFD; Self::print_value_bytes keeps it.

Source

pub fn print_value_bytes(&mut self, value: Value) -> Vec<u8> ⓘ

Self::print_value as the bytes QuickJS writes (WTF-8).

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> 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 = !

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.