pub struct NativeCx<'a> { /* private fields */ }Expand description
The embedder’s view of a running engine: the heap, the realm, the
services and the code store, owned (Runtime::native_cx) or borrowed
(inside a host function).
Implementations§
Source§impl<'a> NativeCx<'a>
impl<'a> NativeCx<'a>
Sourcepub fn compiler(&mut self, transient: bool) -> Compiler<'_>
pub fn compiler(&mut self, transient: bool) -> Compiler<'_>
The heap, the code store and the realm for a compilation. Its units
go in the code store when the store is owned and transient is
false, else in the heap: inside a host function the running loop
borrows the store, so code compiled there is transient whatever
transient says.
Sourcepub fn owns_code(&self) -> bool
pub fn owns_code(&self) -> bool
Whether the code store is the runtime’s own (between entries), not the running loop’s (inside a host function).
pub fn heap(&self) -> &Heap
pub fn heap_mut(&mut self) -> &mut Heap
pub fn realm(&self) -> &'a Realm
Sourcepub fn interrupt_flag(&self) -> Arc<AtomicBool> ⓘ
pub fn interrupt_flag(&self) -> Arc<AtomicBool> ⓘ
The flag another thread sets to interrupt the running script.
Sourcepub fn is_interrupted(&self) -> bool
pub fn is_interrupted(&self) -> bool
Whether an interrupt is unwinding (the last throw was one).
Sourcepub fn clear_interrupted(&mut self)
pub fn clear_interrupted(&mut self)
Ends an interrupt’s unwinding, at the outermost entry: the runtime runs scripts again.
Sourcepub fn install_std(&mut self) -> Result<(), HeapError>
pub fn install_std(&mut self) -> Result<(), HeapError>
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>
Sourcepub fn set_native_stack_budget(&mut self, bytes: usize)
pub fn set_native_stack_budget(&mut self, bytes: usize)
The bytes of host stack nested re-entries into the loop may use.
Source§impl NativeCx<'_>
impl NativeCx<'_>
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 run_script(&mut self, script: ObjectId) -> Result<Value, Throw>
pub fn run_script(&mut self, script: ObjectId) -> Result<Value, Throw>
Runs a script function with the global object as this.
Sourcepub fn hold(&mut self, value: Value) -> Handle
pub fn hold(&mut self, value: Value) -> Handle
Holds value for the embedder until NativeCx::release.
pub fn held(&self, handle: Handle) -> Value
pub fn release(&mut self, handle: Handle)
pub fn global_object(&self) -> ObjectId
pub fn intrinsic(&self, intrinsic: Intrinsic) -> ObjectId
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%.
Sourcepub fn new_host_function(
&mut self,
name: &str,
length: u32,
constructor: bool,
data: &[Value],
body: Rc<HostFn>,
) -> Result<ObjectId, HeapError>
pub fn new_host_function( &mut self, name: &str, length: u32, constructor: bool, data: &[Value], body: Rc<HostFn>, ) -> Result<ObjectId, HeapError>
A host function named name with length, whose body is body
and whose captured values are data (read through
NativeCall::data). A
constructor may be called by new; it gets no prototype
property (the embedder defines one). data must be rooted by the
caller.
Sourcepub fn new_host_object(
&mut self,
prototype: Option<ObjectId>,
data: Rc<dyn Any>,
) -> Result<ObjectId, HeapError>
pub fn new_host_object( &mut self, prototype: Option<ObjectId>, data: Rc<dyn Any>, ) -> Result<ObjectId, HeapError>
An object inheriting from prototype (None for null) that holds
the embedder’s data, read back by NativeCx::host_data. The datum
drops when the object is collected.
Sourcepub fn host_data(&self, object: ObjectId) -> Option<Rc<dyn Any>>
pub fn host_data(&self, object: ObjectId) -> Option<Rc<dyn Any>>
The datum of a host object, whatever its type; None for any other
object.
Sourcepub fn key_from_units(
&mut self,
units: &[u16],
) -> Result<PropertyKey, HeapError>
pub fn key_from_units( &mut self, units: &[u16], ) -> Result<PropertyKey, HeapError>
The property key of the string units (an array index when it is
one’s canonical form).
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>
ToPropertyKey(value).
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>
object.[[Get]](key, receiver).
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>
object.[[Set]](key, value, receiver).
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>
object.[[GetOwnProperty]](key).
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>
object.[[DefineOwnProperty]](key, descriptor).
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>
object.[[Delete]](key).
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>
HasProperty(object, key).
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>
HasOwnProperty(object, key).
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>
object.[[OwnPropertyKeys]]().
Sourcepub fn get_prototype_of(
&mut self,
object: ObjectId,
) -> Result<Option<ObjectId>, Throw>
pub fn get_prototype_of( &mut self, object: ObjectId, ) -> Result<Option<ObjectId>, Throw>
object.[[GetPrototypeOf]]().
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>
object.[[SetPrototypeOf]](prototype).
Sourcepub fn prevent_extensions(&mut self, object: ObjectId) -> Result<bool, Throw>
pub fn prevent_extensions(&mut self, object: ObjectId) -> Result<bool, Throw>
object.[[PreventExtensions]]().
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>
Construct(function, args, new_target); new_target is function
itself for a plain new.
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_array(&mut self, value: Value) -> Result<bool, Throw>
pub fn is_array(&mut self, value: Value) -> Result<bool, Throw>
IsArray(value): throws for a revoked proxy.
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
Whether value is a promise.
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>
An ordinary object inheriting from prototype (None for null).
Sourcepub fn new_array_from(&mut self, values: &[Value]) -> Result<ObjectId, Throw>
pub fn new_array_from(&mut self, values: &[Value]) -> Result<ObjectId, Throw>
CreateArrayFromList(values).
Sourcepub fn new_error(
&mut self,
kind: ErrorKind,
message: &str,
) -> Result<Value, HeapError>
pub fn new_error( &mut self, kind: ErrorKind, message: &str, ) -> Result<Value, HeapError>
A new error object of kind with message, a stack from the
running frames.
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>
A new error object located at file:line:column (a compile error):
fileName, lineNumber and columnNumber, and a stack that
starts there, the running frames after it.
Sourcepub fn new_promise_capability(
&mut self,
) -> Result<(ObjectId, ObjectId, ObjectId), Throw>
pub fn new_promise_capability( &mut self, ) -> Result<(ObjectId, ObjectId, ObjectId), Throw>
NewPromiseCapability(%Promise%): the promise and its resolving
functions, unrooted.
Sourcepub fn new_promise(&mut self) -> Result<ObjectId, Throw>
pub fn new_promise(&mut self) -> Result<ObjectId, Throw>
A pending promise of %Promise.prototype%.
Sourcepub fn new_array_buffer(&mut self, len: usize) -> Result<ObjectId, Throw>
pub fn new_array_buffer(&mut self, len: usize) -> Result<ObjectId, Throw>
A new ArrayBuffer of len zero bytes; a RangeError past
MAX_BUFFER_LENGTH.
Sourcepub fn array_buffer_len(&self, object: ObjectId) -> Option<usize>
pub fn array_buffer_len(&self, object: ObjectId) -> Option<usize>
A buffer’s length in bytes; None when object is not a buffer or
is detached.
Sourcepub fn array_buffer_read(
&mut self,
object: ObjectId,
offset: usize,
out: &mut [u8],
) -> Result<(), Throw>
pub fn array_buffer_read( &mut self, object: ObjectId, offset: usize, out: &mut [u8], ) -> Result<(), Throw>
Copies out.len() bytes of the buffer from offset (a shared
buffer’s byte by byte through its atomics).
Sourcepub fn array_buffer_write(
&mut self,
object: ObjectId,
offset: usize,
data: &[u8],
) -> Result<(), Throw>
pub fn array_buffer_write( &mut self, object: ObjectId, offset: usize, data: &[u8], ) -> Result<(), Throw>
Writes data into the buffer at offset.
Sourcepub fn array_buffer_bytes(&self, object: ObjectId) -> Option<&[u8]>
pub fn array_buffer_bytes(&self, object: ObjectId) -> Option<&[u8]>
The bytes of an attached ArrayBuffer; None for anything else,
a SharedArrayBuffer included (its bytes are atomics).
Sourcepub fn typed_array_view(
&self,
object: ObjectId,
) -> Option<(ElementKind, ObjectId, usize, Option<usize>)>
pub fn typed_array_view( &self, object: ObjectId, ) -> Option<(ElementKind, ObjectId, usize, Option<usize>)>
A typed array’s element kind, buffer, byte offset and current
length (None when it is out of bounds of its buffer or the buffer
is detached); None for anything but a typed array.
Sourcepub fn detach_array_buffer(&mut self, value: Value) -> Result<(), Throw>
pub fn detach_array_buffer(&mut self, value: Value) -> Result<(), Throw>
QuickJS’s JS_DetachArrayBuffer: detaches an ArrayBuffer; anything
else is ignored.
pub fn new_string(&mut self, text: &str) -> Result<Value, HeapError>
pub fn new_string_units(&mut self, units: &[u16]) -> Result<Value, HeapError>
Sourcepub fn new_string_repr(&mut self, repr: StringRepr) -> Result<Value, HeapError>
pub fn new_string_repr(&mut self, repr: StringRepr) -> Result<Value, HeapError>
A string of repr, which the caller made canonical (OneByte
whenever every unit fits in a byte).
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 new_bigint(&mut self, decimal: &str) -> Option<Result<Value, HeapError>>
pub fn new_bigint(&mut self, decimal: &str) -> Option<Result<Value, HeapError>>
The BigInt of the decimal text decimal (an optional -, then
digits); None when it does not parse.
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 new_symbol(
&mut self,
description: Option<&[u16]>,
) -> Result<Value, HeapError>
pub fn new_symbol( &mut self, description: Option<&[u16]>, ) -> Result<Value, HeapError>
A new symbol with description (Symbol(description)).
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 loose_equals(&mut self, x: Value, y: Value) -> Result<bool, Throw>
pub fn loose_equals(&mut self, x: Value, y: Value) -> Result<bool, Throw>
IsLooselyEqual(x, y).
Sourcepub fn same_value(&mut self, x: Value, y: Value) -> bool
pub fn same_value(&mut self, x: Value, y: Value) -> bool
SameValue(x, y).
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).