pub struct Runtime { /* private fields */ }Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn set_script_runner(&mut self, runner: ScriptRunner)
pub fn set_script_runner(&mut self, runner: ScriptRunner)
Lets $262.agent.start run agents’ scripts through runner.
Sourcepub fn join_agents(&mut self)
pub fn join_agents(&mut self)
Waits for every agent this runtime started.
Source§impl Runtime
impl Runtime
Sourcepub fn key_from_units(
&mut self,
units: &[u16],
) -> Result<PropertyKey, HeapError>
pub fn key_from_units( &mut self, units: &[u16], ) -> Result<PropertyKey, HeapError>
Sourcepub fn key_from_symbol(&self, symbol: Value) -> Option<PropertyKey>
pub fn key_from_symbol(&self, symbol: Value) -> Option<PropertyKey>
The key of a symbol value; None for any other value.
Sourcepub fn to_property_key(&mut self, value: Value) -> Result<PropertyKey, Throw>
pub fn to_property_key(&mut self, value: Value) -> Result<PropertyKey, Throw>
pub fn key_name(&self, key: PropertyKey) -> KeyName
Sourcepub fn get(
&mut self,
object: ObjectId,
key: PropertyKey,
receiver: Value,
) -> Result<Value, Throw>
pub fn get( &mut self, object: ObjectId, key: PropertyKey, receiver: Value, ) -> Result<Value, Throw>
Sourcepub fn set(
&mut self,
object: ObjectId,
key: PropertyKey,
value: Value,
receiver: Value,
) -> Result<bool, Throw>
pub fn set( &mut self, object: ObjectId, key: PropertyKey, value: Value, receiver: Value, ) -> Result<bool, Throw>
Sourcepub fn get_own_property(
&mut self,
object: ObjectId,
key: PropertyKey,
) -> Result<Option<PropertyDescriptor>, Throw>
pub fn get_own_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<Option<PropertyDescriptor>, Throw>
Sourcepub fn define_own_property(
&mut self,
object: ObjectId,
key: PropertyKey,
descriptor: &PropertyDescriptor,
) -> Result<bool, Throw>
pub fn define_own_property( &mut self, object: ObjectId, key: PropertyKey, descriptor: &PropertyDescriptor, ) -> Result<bool, Throw>
Sourcepub fn delete_property(
&mut self,
object: ObjectId,
key: PropertyKey,
) -> Result<bool, Throw>
pub fn delete_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<bool, Throw>
Sourcepub fn has_property(
&mut self,
object: ObjectId,
key: PropertyKey,
) -> Result<bool, Throw>
pub fn has_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<bool, Throw>
Sourcepub fn has_own_property(
&mut self,
object: ObjectId,
key: PropertyKey,
) -> Result<bool, Throw>
pub fn has_own_property( &mut self, object: ObjectId, key: PropertyKey, ) -> Result<bool, Throw>
Sourcepub fn own_property_keys(
&mut self,
object: ObjectId,
) -> Result<Vec<PropertyKey>, Throw>
pub fn own_property_keys( &mut self, object: ObjectId, ) -> Result<Vec<PropertyKey>, Throw>
Sourcepub fn set_prototype_of(
&mut self,
object: ObjectId,
prototype: Option<ObjectId>,
) -> Result<bool, Throw>
pub fn set_prototype_of( &mut self, object: ObjectId, prototype: Option<ObjectId>, ) -> Result<bool, Throw>
Sourcepub fn construct(
&mut self,
function: Value,
args: &[Value],
new_target: Value,
) -> Result<Value, Throw>
pub fn construct( &mut self, function: Value, args: &[Value], new_target: Value, ) -> Result<Value, Throw>
Sourcepub fn is_callable(&self, value: Value) -> bool
pub fn is_callable(&self, value: Value) -> bool
IsCallable(value).
Sourcepub fn is_constructor(&self, value: Value) -> bool
pub fn is_constructor(&self, value: Value) -> bool
IsConstructor(value).
Sourcepub fn is_error(&self, value: Value) -> bool
pub fn is_error(&self, value: Value) -> bool
Whether value is an Error instance (has [[ErrorData]]).
Sourcepub fn is_promise(&mut self, value: Value) -> bool
pub fn is_promise(&mut self, value: Value) -> bool
pub fn object_kind(&self, object: ObjectId) -> ObjectKind
Sourcepub fn new_object_with_prototype(
&mut self,
prototype: Option<ObjectId>,
) -> Result<ObjectId, HeapError>
pub fn new_object_with_prototype( &mut self, prototype: Option<ObjectId>, ) -> Result<ObjectId, HeapError>
Sourcepub fn new_located_error(
&mut self,
kind: ErrorKind,
message: &str,
file: &str,
line: u32,
column: u32,
) -> Result<Value, HeapError>
pub fn new_located_error( &mut self, kind: ErrorKind, message: &str, file: &str, line: u32, column: u32, ) -> Result<Value, HeapError>
Sourcepub fn new_promise(&mut self) -> Result<ObjectId, Throw>
pub fn new_promise(&mut self) -> Result<ObjectId, Throw>
Sourcepub fn new_string_repr(&mut self, repr: StringRepr) -> Result<Value, HeapError>
pub fn new_string_repr(&mut self, repr: StringRepr) -> Result<Value, HeapError>
Sourcepub fn string_repr(&self, value: Value) -> Option<&StringRepr>
pub fn string_repr(&self, value: Value) -> Option<&StringRepr>
A string value’s code units, flattened; None for any other value.
Sourcepub fn string_lossy(&self, value: Value) -> Option<String>
pub fn string_lossy(&self, value: Value) -> Option<String>
A string value as Rust text (lone surrogates replaced).
Sourcepub fn bigint_decimal(&self, value: Value) -> Option<String>
pub fn bigint_decimal(&self, value: Value) -> Option<String>
A BigInt value in decimal; None for any other value.
Sourcepub fn symbol_description(&self, value: Value) -> Option<Vec<u16>>
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.
Sourcepub fn well_known_symbol(&self, name: &str) -> Option<Value>
pub fn well_known_symbol(&self, name: &str) -> Option<Value>
The well-known symbol Symbol.<name> ("iterator", …).
pub fn well_known_symbol_key(&self, name: &str) -> Option<PropertyKey>
Sourcepub fn to_boolean(&self, value: Value) -> bool
pub fn to_boolean(&self, value: Value) -> bool
ToBoolean(value).
Sourcepub fn strict_equals(&self, x: Value, y: Value) -> bool
pub fn strict_equals(&self, x: Value, y: Value) -> bool
IsStrictlyEqual(x, y).
Sourcepub fn same_value(&mut self, x: Value, y: Value) -> bool
pub fn same_value(&mut self, x: Value, y: Value) -> bool
Sourcepub fn same_value_zero(&self, x: Value, y: Value) -> bool
pub fn same_value_zero(&self, x: Value, y: Value) -> bool
SameValueZero(x, y).
Source§impl Runtime
impl Runtime
pub fn new(options: impl Into<RuntimeOptions>) -> Result<Runtime, HeapError>
pub fn regexps(&self) -> &RegExpStore
pub fn realm(&self) -> &Realm
pub fn host(&mut self) -> &mut Services
Sourcepub fn set_can_block(&mut self, can_block: bool)
pub fn set_can_block(&mut self, can_block: bool)
Whether Atomics.wait may block (Test262’s CanBlockIsFalse
clears it).
Sourcepub fn set_host(&mut self, hooks: Box<dyn Host>)
pub fn set_host(&mut self, hooks: Box<dyn Host>)
Installs the embedder’s hooks and seeds Math.random from
Host::random_seed.
Sourcepub fn set_track_rejections(&mut self, track: bool)
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.
Sourcepub fn unhandled_rejections(&self) -> &[Value]
pub fn unhandled_rejections(&self) -> &[Value]
The tracked unhandled rejected promises, in rejection order.
pub fn clear_unhandled_rejections(&mut self)
Sourcepub fn capture_output(&mut self)
pub fn capture_output(&mut self)
Sends print output to a buffer; Runtime::take_output returns it.
Sourcepub fn take_output(&mut self) -> String
pub fn take_output(&mut self) -> String
The output captured since the last call.
Sourcepub fn install_test262_host(&mut self) -> Result<(), HeapError>
pub fn install_test262_host(&mut self) -> Result<(), HeapError>
Defines the Test262 host object $262 on the global object.
Sourcepub fn install_print(&mut self) -> Result<(), HeapError>
pub fn install_print(&mut self) -> Result<(), HeapError>
Defines qjs’s print and console.log on the global object.
Sourcepub fn install_std(&mut self) -> Result<(), HeapError>
pub fn install_std(&mut self) -> Result<(), HeapError>
Defines qjs’s --std globals, load and read, over the host’s
read_file.
Sourcepub fn install_qjs_helpers(
&mut self,
script_args: Option<&[String]>,
) -> Result<(), HeapError>
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.
Sourcepub fn install_script_args(&mut self, args: &[String]) -> Result<(), HeapError>
pub fn install_script_args(&mut self, args: &[String]) -> Result<(), HeapError>
Defines qjs’s scriptArgs.
Sourcepub fn run_script(&mut self, script: ObjectId) -> Result<Value, Throw>
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.
Sourcepub fn run_jobs(&mut self) -> Result<(), Throw>
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.
Sourcepub fn run_pending_job(&mut self) -> Result<bool, Throw>
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.
Sourcepub fn clear_kept_objects(&mut self)
pub fn clear_kept_objects(&mut self)
ClearKeptObjects: the end of a synchronous execution sequence.
Sourcepub fn has_pending_jobs(&self) -> bool
pub fn has_pending_jobs(&self) -> bool
Whether jobs are pending.
Sourcepub fn call(
&mut self,
function: Value,
this: Value,
args: &[Value],
) -> Result<Value, Throw>
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).
Sourcepub fn display(&mut self, value: Value) -> Result<String, Throw>
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.
pub fn set_stack_limit(&mut self, registers: u32)
Sourcepub fn set_native_stack_budget(&mut self, bytes: usize)
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.
pub fn heap(&self) -> &Heap
pub fn heap_mut(&mut self) -> &mut Heap
pub fn code(&self) -> &CodeStore
Sourcepub fn heap_and_code(&mut self) -> (&mut Heap, &CodeStore)
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.
Sourcepub fn publish(&mut self, unit: CodeUnit) -> Result<CodeUnitId, ValidateError>
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.
Sourcepub fn instantiate(
&mut self,
root: CodeUnitId,
constants: &[&[Value]],
) -> Result<ObjectId, HeapError>
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.
Sourcepub fn compiler(&mut self) -> Compiler<'_>
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.
Sourcepub fn transient_compiler(&mut self) -> Compiler<'_>
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.
Sourcepub fn set_compiler(&mut self, compile: CompileFn)
pub fn set_compiler(&mut self, compile: CompileFn)
Installs the embedder’s compiler, for eval, the Function
constructors and $262.evalScript.
Sourcepub fn ic_report(&self, worst: usize) -> Option<String>
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).
Sourcepub fn disassemble(&self, unit: CodeUnitId) -> String
pub fn disassemble(&self, unit: CodeUnitId) -> String
The disassembly of unit, with atom keys spelled out.
pub fn global_object(&self) -> ObjectId
pub fn intrinsic(&self, intrinsic: Intrinsic) -> ObjectId
Sourcepub fn template_object(
&mut self,
cooked: &[Value],
raw: &[Value],
) -> Result<ObjectId, HeapError>
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).
Sourcepub fn new_object(&mut self) -> Result<ObjectId, HeapError>
pub fn new_object(&mut self) -> Result<ObjectId, HeapError>
An ordinary object inheriting from %Object.prototype%.
pub fn new_array(&mut self, capacity: u32) -> Result<ObjectId, HeapError>
pub fn new_function( &mut self, scope: Option<ScopeId>, ) -> Result<ObjectId, HeapError>
pub fn new_scope( &mut self, parent: Option<ScopeId>, slots: u32, ) -> Result<ScopeId, HeapError>
Sourcepub fn thrown_summary(&mut self, value: Value) -> Option<ThrownSummary>
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.
Sourcepub fn memory_report(&self) -> MemoryReport
pub fn memory_report(&self) -> MemoryReport
What every part of the runtime holds, read without a collection. Its
reserved total equals Heap::bytes.
Sourcepub fn hold(&mut self, value: Value) -> Handle
pub fn hold(&mut self, value: Value) -> Handle
Holds value for the embedder until Runtime::release.
pub fn held(&self, handle: Handle) -> Value
pub fn release(&mut self, handle: Handle)
Source§impl Runtime
impl Runtime
Sourcepub fn set_module_host(&mut self, host: ModuleHost)
pub fn set_module_host(&mut self, host: ModuleHost)
Installs the embedder’s module loader.
Sourcepub fn forget_module(&mut self, name: &str)
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.
Sourcepub fn run_module(&mut self, name: &str) -> Result<Value, Throw>
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.
Sourcepub fn run_module_phased(
&mut self,
name: &str,
) -> Result<Value, (ModulePhase, Throw)>
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§impl Runtime
impl Runtime
Sourcepub fn print_value(&mut self, value: Value) -> String
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.
Sourcepub fn print_value_bytes(&mut self, value: Value) -> Vec<u8> ⓘ
pub fn print_value_bytes(&mut self, value: Value) -> Vec<u8> ⓘ
Self::print_value as the bytes QuickJS writes (WTF-8).