Skip to main content

NativeCx

Struct NativeCx 

Source
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>

Source

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

The same view for a shorter borrow.

Source

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.

Source

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

Source

pub fn heap(&self) -> &Heap

Source

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

Source

pub fn realm(&self) -> &'a Realm

Source

pub fn interrupt_flag(&self) -> Arc<AtomicBool> ⓘ

The flag another thread sets to interrupt the running script.

Source

pub fn is_interrupted(&self) -> bool

Whether an interrupt is unwinding (the last throw was one).

Source

pub fn clear_interrupted(&mut self)

Ends an interrupt’s unwinding, at the outermost entry: the runtime runs scripts again.

Source

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

Source

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

Source

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<'_>

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 run_script(&mut self, script: ObjectId) -> Result<Value, Throw>

Runs a script function with the global object as this.

Source

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

Holds value for the embedder until NativeCx::release.

Source

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

Source

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

Source

pub fn global_object(&self) -> ObjectId

Source

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

Source

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

An ordinary object inheriting from %Object.prototype%.

Source

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.

Source

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.

Source

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.

Source

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

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>

ToPropertyKey(value).

Source

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

Source

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

object.[[Get]](key, receiver).

Source

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

object.[[Set]](key, value, receiver).

Source

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

object.[[GetOwnProperty]](key).

Source

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

object.[[DefineOwnProperty]](key, descriptor).

Source

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

object.[[Delete]](key).

Source

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

HasProperty(object, key).

Source

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

HasOwnProperty(object, key).

Source

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

object.[[OwnPropertyKeys]]().

Source

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

object.[[GetPrototypeOf]]().

Source

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

object.[[SetPrototypeOf]](prototype).

Source

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

object.[[PreventExtensions]]().

Source

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.

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>

IsArray(value): throws for a revoked proxy.

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

Whether value is a promise.

Source

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

Source

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

An ordinary object inheriting from prototype (None for null).

Source

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

CreateArrayFromList(values).

Source

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.

Source

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.

Source

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

NewPromiseCapability(%Promise%): the promise and its resolving functions, unrooted.

Source

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

A pending promise of %Promise.prototype%.

Source

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.

Source

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.

Source

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

Source

pub fn array_buffer_write( &mut self, object: ObjectId, offset: usize, data: &[u8], ) -> Result<(), Throw>

Writes data into the buffer at offset.

Source

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

Source

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.

Source

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

QuickJS’s JS_DetachArrayBuffer: detaches an ArrayBuffer; anything else is ignored.

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>

A string of repr, which the caller made canonical (OneByte whenever every unit fits in a byte).

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

The BigInt of the decimal text decimal (an optional -, then digits); None when it does not parse.

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>

A new symbol with description (Symbol(description)).

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>

ToString(value).

Source

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

ToNumber(value).

Source

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

ToBoolean(value).

Source

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

ToObject(value).

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>

IsLooselyEqual(x, y).

Source

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

SameValue(x, y).

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

typeof value.

Source

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

The kind of a value without running JavaScript.

Source

pub fn run_gc(&mut self)

Runs a full collection. Only between entries: the embedder’s handles and the fixed roots are the roots.

Source§

impl NativeCx<'_>

Source

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

Source

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

Source

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

Source§

impl NativeCx<'_>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for NativeCx<'a>

§

impl<'a> !Send for NativeCx<'a>

§

impl<'a> !Sync for NativeCx<'a>

§

impl<'a> !UnwindSafe for NativeCx<'a>

§

impl<'a> Freeze for NativeCx<'a>

§

impl<'a> Unpin for NativeCx<'a>

§

impl<'a> UnsafeUnpin for NativeCx<'a>

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.