pub trait Js: Sealed {
Show 81 methods
// Required methods
fn eval(&mut self, source: &str) -> JsResult<Value>;
fn eval_bytes(&mut self, source: &[u8]) -> JsResult<Value>;
fn eval_with_filename(
&mut self,
source: &str,
filename: &str,
) -> JsResult<Value>;
fn eval_with_options(
&mut self,
source: &str,
options: &EvalOptions,
) -> JsResult<Value>;
fn eval_bytes_with_options(
&mut self,
source: &[u8],
options: &EvalOptions,
) -> JsResult<Value>;
fn eval_bytes_with_filename(
&mut self,
source: &[u8],
filename: &str,
) -> JsResult<Value>;
fn compile(&mut self, source: &str) -> JsResult<FunctionBytecodeRef>;
fn compile_bytes(&mut self, source: &[u8]) -> JsResult<FunctionBytecodeRef>;
fn compile_with_filename(
&mut self,
source: &str,
filename: &str,
) -> JsResult<FunctionBytecodeRef>;
fn compile_with_options(
&mut self,
source: &str,
options: &CompileOptions,
) -> JsResult<FunctionBytecodeRef>;
fn compile_bytes_with_options(
&mut self,
source: &[u8],
options: &CompileOptions,
) -> JsResult<FunctionBytecodeRef>;
fn compile_bytes_with_filename(
&mut self,
source: &[u8],
filename: &str,
) -> JsResult<FunctionBytecodeRef>;
fn execute(&mut self, script: &FunctionBytecodeRef) -> JsResult<Value>;
fn compile_module(&mut self, source: &str) -> JsResult<ModuleBytecodeRef>;
fn compile_module_bytes(
&mut self,
source: &[u8],
) -> JsResult<ModuleBytecodeRef>;
fn compile_module_with_filename(
&mut self,
source: &str,
filename: &str,
) -> JsResult<ModuleBytecodeRef>;
fn compile_module_bytes_with_options(
&mut self,
source: &[u8],
options: &CompileOptions,
) -> JsResult<ModuleBytecodeRef>;
fn compile_module_bytes_with_filename(
&mut self,
source: &[u8],
filename: &str,
) -> JsResult<ModuleBytecodeRef>;
fn compile_module_bytes_with_import_meta(
&mut self,
source: &[u8],
filename: &str,
import_meta: Vec<(String, Value)>,
) -> JsResult<ModuleBytecodeRef>;
fn execute_module(&mut self, module: &ModuleBytecodeRef) -> JsResult<Value>;
fn call(
&mut self,
callable: &CallableRef,
this_value: Value,
arguments: &[Value],
) -> JsResult<Value>;
fn construct(
&mut self,
constructor: &CallableRef,
arguments: &[Value],
) -> JsResult<Value>;
fn construct_with_new_target(
&mut self,
constructor: &CallableRef,
new_target: &CallableRef,
arguments: &[Value],
) -> JsResult<Value>;
fn new_object(&mut self) -> JsResult<ObjectRef>;
fn new_object_with_prototype(
&mut self,
prototype: Option<&ObjectRef>,
) -> JsResult<ObjectRef>;
fn new_array(&mut self) -> JsResult<ObjectRef>;
fn new_array_from_values(
&mut self,
values: Vec<Value>,
) -> JsResult<ObjectRef>;
fn get_own_property(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
) -> JsResult<Option<CompleteOrdinaryPropertyDescriptor>>;
fn define_own_property(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
descriptor: &OrdinaryPropertyDescriptor,
) -> JsResult<bool>;
fn get_property(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
) -> JsResult<Value>;
fn get_property_with_receiver(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
receiver: Value,
) -> JsResult<Value>;
fn set_property(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
value: Value,
) -> JsResult<bool>;
fn set_property_with_receiver(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
value: Value,
receiver: Value,
) -> JsResult<bool>;
fn delete_property(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
) -> JsResult<bool>;
fn has_property(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
) -> JsResult<bool>;
fn has_own_property(
&mut self,
object: &ObjectRef,
key: &PropertyKey,
) -> JsResult<bool>;
fn own_property_keys(
&mut self,
object: &ObjectRef,
) -> JsResult<Vec<PropertyKey>>;
fn get_prototype_of(
&mut self,
object: &ObjectRef,
) -> JsResult<Option<ObjectRef>>;
fn set_prototype_of(
&mut self,
object: &ObjectRef,
prototype: Option<&ObjectRef>,
) -> JsResult<bool>;
fn as_callable(
&mut self,
object: &ObjectRef,
) -> JsResult<Option<CallableRef>>;
fn is_constructor(&mut self, object: &ObjectRef) -> JsResult<bool>;
fn is_array_object(&mut self, object: &ObjectRef) -> JsResult<bool>;
fn is_error_object(&mut self, object: &ObjectRef) -> JsResult<bool>;
fn to_js_string(&mut self, value: &Value) -> JsResult<JsString>;
fn to_number(&mut self, value: &Value) -> JsResult<f64>;
fn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>;
fn type_of(&mut self, value: &Value) -> JsResult<String>;
fn print_value(&mut self, value: &Value) -> JsResult<String>;
fn qjs_print_value_bytes(&mut self, value: &Value) -> JsResult<Vec<u8>>;
fn new_symbol(
&mut self,
description: Option<JsString>,
) -> JsResult<SymbolRef>;
fn symbol_description(
&mut self,
symbol: &SymbolRef,
) -> JsResult<Option<JsString>>;
fn well_known_symbol(
&mut self,
symbol: WellKnownSymbol,
) -> JsResult<SymbolRef>;
fn promise_snapshot(
&mut self,
promise: &ObjectRef,
) -> JsResult<Option<PromiseSnapshot>>;
fn new_promise(&mut self) -> JsResult<PromiseCapability>;
fn promise_then(
&mut self,
promise: &ObjectRef,
on_fulfilled: impl HostFunction<Raw>,
on_rejected: impl HostFunction<Raw>,
) -> JsResult<ObjectRef>;
fn new_array_buffer(&mut self, bytes: &[u8]) -> JsResult<ObjectRef>;
fn array_buffer_len(
&mut self,
buffer: &ObjectRef,
) -> JsResult<Option<usize>>;
fn array_buffer_to_vec(&mut self, buffer: &ObjectRef) -> JsResult<Vec<u8>>;
fn with_array_buffer_bytes<R>(
&mut self,
buffer: &ObjectRef,
f: impl FnOnce(&[u8]) -> R,
) -> JsResult<R>;
fn write_array_buffer(
&mut self,
buffer: &ObjectRef,
offset: usize,
data: &[u8],
) -> JsResult<()>;
fn typed_array_view(
&mut self,
array: &ObjectRef,
) -> JsResult<Option<TypedArrayView>>;
fn new_typed_array(
&mut self,
kind: TypedArrayKind,
buffer: &ObjectRef,
byte_offset: usize,
length: Option<usize>,
) -> JsResult<ObjectRef>;
fn global_object(&mut self) -> JsResult<ObjectRef>;
fn object_prototype(&mut self) -> JsResult<ObjectRef>;
fn array_prototype(&mut self) -> JsResult<ObjectRef>;
fn function_prototype(&mut self) -> JsResult<ObjectRef>;
fn iterator_prototype(&mut self) -> JsResult<ObjectRef>;
fn string_iterator_prototype(&mut self) -> JsResult<ObjectRef>;
fn number_prototype(&mut self) -> JsResult<ObjectRef>;
fn boolean_prototype(&mut self) -> JsResult<ObjectRef>;
fn string_prototype(&mut self) -> JsResult<ObjectRef>;
fn symbol_prototype(&mut self) -> JsResult<ObjectRef>;
fn bigint_prototype(&mut self) -> JsResult<ObjectRef>;
fn function_constructor(&mut self) -> JsResult<CallableRef>;
fn new_native_error(
&mut self,
kind: NativeErrorKind,
message: &str,
) -> JsResult<Value>;
fn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>;
fn new_function<Args>(
&mut self,
options: FunctionOptions,
function: impl HostFunction<Args>,
) -> JsResult<CallableRef>;
fn define_function<Args>(
&mut self,
target: &ObjectRef,
name: &str,
length: u32,
function: impl HostFunction<Args>,
) -> JsResult<CallableRef>;
fn new_host_object<T: 'static>(
&mut self,
value: T,
prototype: Option<&ObjectRef>,
) -> JsResult<ObjectRef>;
fn host_data<T: 'static>(
&mut self,
object: &ObjectRef,
) -> JsResult<Option<Rc<T>>>;
fn throw_error(
&mut self,
kind: NativeErrorKind,
message: &str,
) -> RuntimeError;
}Expand description
Required Methods§
Sourcefn eval(&mut self, source: &str) -> JsResult<Value>
fn eval(&mut self, source: &str) -> JsResult<Value>
Compiles and runs source as a script; the completion value.
fn eval_bytes(&mut self, source: &[u8]) -> JsResult<Value>
fn eval_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<Value>
fn eval_with_options( &mut self, source: &str, options: &EvalOptions, ) -> JsResult<Value>
fn eval_bytes_with_options( &mut self, source: &[u8], options: &EvalOptions, ) -> JsResult<Value>
Sourcefn eval_bytes_with_filename(
&mut self,
source: &[u8],
filename: &str,
) -> JsResult<Value>
fn eval_bytes_with_filename( &mut self, source: &[u8], filename: &str, ) -> JsResult<Value>
Compiles and runs source as a script named filename; the
completion value. A syntax error is thrown (RuntimeError::Exception
with a SyntaxError), as QuickJS’s JS_Eval does.
fn compile(&mut self, source: &str) -> JsResult<FunctionBytecodeRef>
fn compile_bytes(&mut self, source: &[u8]) -> JsResult<FunctionBytecodeRef>
fn compile_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<FunctionBytecodeRef>
fn compile_with_options( &mut self, source: &str, options: &CompileOptions, ) -> JsResult<FunctionBytecodeRef>
fn compile_bytes_with_options( &mut self, source: &[u8], options: &CompileOptions, ) -> JsResult<FunctionBytecodeRef>
Sourcefn compile_bytes_with_filename(
&mut self,
source: &[u8],
filename: &str,
) -> JsResult<FunctionBytecodeRef>
fn compile_bytes_with_filename( &mut self, source: &[u8], filename: &str, ) -> JsResult<FunctionBytecodeRef>
Compiles source as a script named filename. A syntax error is
thrown (RuntimeError::Exception with a SyntaxError). Inside a
host function the code is transient whatever the options say.
Sourcefn execute(&mut self, script: &FunctionBytecodeRef) -> JsResult<Value>
fn execute(&mut self, script: &FunctionBytecodeRef) -> JsResult<Value>
Runs a compiled script with the global object as this.
fn compile_module(&mut self, source: &str) -> JsResult<ModuleBytecodeRef>
fn compile_module_bytes(&mut self, source: &[u8]) -> JsResult<ModuleBytecodeRef>
fn compile_module_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<ModuleBytecodeRef>
fn compile_module_bytes_with_options( &mut self, source: &[u8], options: &CompileOptions, ) -> JsResult<ModuleBytecodeRef>
fn compile_module_bytes_with_filename( &mut self, source: &[u8], filename: &str, ) -> JsResult<ModuleBytecodeRef>
Sourcefn compile_module_bytes_with_import_meta(
&mut self,
source: &[u8],
filename: &str,
import_meta: Vec<(String, Value)>,
) -> JsResult<ModuleBytecodeRef>
fn compile_module_bytes_with_import_meta( &mut self, source: &[u8], filename: &str, import_meta: Vec<(String, Value)>, ) -> JsResult<ModuleBytecodeRef>
Compiles source as the module filename, whose import.meta
starts with import_meta (qjs’s url and main). A syntax error is
thrown.
Sourcefn execute_module(&mut self, module: &ModuleBytecodeRef) -> JsResult<Value>
fn execute_module(&mut self, module: &ModuleBytecodeRef) -> JsResult<Value>
Links and evaluates a compiled module and what it imports; the promise of its evaluation.
fn call( &mut self, callable: &CallableRef, this_value: Value, arguments: &[Value], ) -> JsResult<Value>
fn construct( &mut self, constructor: &CallableRef, arguments: &[Value], ) -> JsResult<Value>
fn construct_with_new_target( &mut self, constructor: &CallableRef, new_target: &CallableRef, arguments: &[Value], ) -> JsResult<Value>
fn new_object(&mut self) -> JsResult<ObjectRef>
fn new_object_with_prototype( &mut self, prototype: Option<&ObjectRef>, ) -> JsResult<ObjectRef>
fn new_array(&mut self) -> JsResult<ObjectRef>
fn new_array_from_values(&mut self, values: Vec<Value>) -> JsResult<ObjectRef>
fn get_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<Option<CompleteOrdinaryPropertyDescriptor>>
fn define_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, descriptor: &OrdinaryPropertyDescriptor, ) -> JsResult<bool>
fn get_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<Value>
fn get_property_with_receiver( &mut self, object: &ObjectRef, key: &PropertyKey, receiver: Value, ) -> JsResult<Value>
fn set_property( &mut self, object: &ObjectRef, key: &PropertyKey, value: Value, ) -> JsResult<bool>
fn set_property_with_receiver( &mut self, object: &ObjectRef, key: &PropertyKey, value: Value, receiver: Value, ) -> JsResult<bool>
fn delete_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>
fn has_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>
fn has_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>
fn own_property_keys( &mut self, object: &ObjectRef, ) -> JsResult<Vec<PropertyKey>>
fn get_prototype_of( &mut self, object: &ObjectRef, ) -> JsResult<Option<ObjectRef>>
fn set_prototype_of( &mut self, object: &ObjectRef, prototype: Option<&ObjectRef>, ) -> JsResult<bool>
Sourcefn as_callable(&mut self, object: &ObjectRef) -> JsResult<Option<CallableRef>>
fn as_callable(&mut self, object: &ObjectRef) -> JsResult<Option<CallableRef>>
The object as a callable reference; None when it is not callable.
fn is_constructor(&mut self, object: &ObjectRef) -> JsResult<bool>
Sourcefn is_array_object(&mut self, object: &ObjectRef) -> JsResult<bool>
fn is_array_object(&mut self, object: &ObjectRef) -> JsResult<bool>
IsArray.
fn is_error_object(&mut self, object: &ObjectRef) -> JsResult<bool>
Sourcefn to_js_string(&mut self, value: &Value) -> JsResult<JsString>
fn to_js_string(&mut self, value: &Value) -> JsResult<JsString>
ToString(value).
Sourcefn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>
fn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>
QuickJS’s JS_DetachArrayBuffer: detaches an ArrayBuffer; anything
else is ignored.
Sourcefn print_value(&mut self, value: &Value) -> JsResult<String>
fn print_value(&mut self, value: &Value) -> JsResult<String>
QuickJS’s JS_PrintValue: what print and an uncaught-exception dump
show. Runs no JavaScript (no accessor, trap or coercion).
Sourcefn qjs_print_value_bytes(&mut self, value: &Value) -> JsResult<Vec<u8>>
fn qjs_print_value_bytes(&mut self, value: &Value) -> JsResult<Vec<u8>>
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.
fn new_symbol(&mut self, description: Option<JsString>) -> JsResult<SymbolRef>
fn symbol_description( &mut self, symbol: &SymbolRef, ) -> JsResult<Option<JsString>>
fn well_known_symbol(&mut self, symbol: WellKnownSymbol) -> JsResult<SymbolRef>
Sourcefn promise_snapshot(
&mut self,
promise: &ObjectRef,
) -> JsResult<Option<PromiseSnapshot>>
fn promise_snapshot( &mut self, promise: &ObjectRef, ) -> JsResult<Option<PromiseSnapshot>>
A promise’s state and result; None when promise is not one.
Sourcefn new_promise(&mut self) -> JsResult<PromiseCapability>
fn new_promise(&mut self) -> JsResult<PromiseCapability>
NewPromiseCapability(%Promise%): a pending promise and its
resolving functions.
Sourcefn promise_then(
&mut self,
promise: &ObjectRef,
on_fulfilled: impl HostFunction<Raw>,
on_rejected: impl HostFunction<Raw>,
) -> JsResult<ObjectRef>
fn promise_then( &mut self, promise: &ObjectRef, on_fulfilled: impl HostFunction<Raw>, on_rejected: impl HostFunction<Raw>, ) -> JsResult<ObjectRef>
promise.then(on_fulfilled, on_rejected) with host functions; the
promise then returns.
Sourcefn new_array_buffer(&mut self, bytes: &[u8]) -> JsResult<ObjectRef>
fn new_array_buffer(&mut self, bytes: &[u8]) -> JsResult<ObjectRef>
A new ArrayBuffer holding a copy of bytes.
Sourcefn array_buffer_len(&mut self, buffer: &ObjectRef) -> JsResult<Option<usize>>
fn array_buffer_len(&mut self, buffer: &ObjectRef) -> JsResult<Option<usize>>
A buffer’s length in bytes; None for a detached buffer or another
object.
Sourcefn array_buffer_to_vec(&mut self, buffer: &ObjectRef) -> JsResult<Vec<u8>>
fn array_buffer_to_vec(&mut self, buffer: &ObjectRef) -> JsResult<Vec<u8>>
A copy of a buffer’s bytes (ArrayBuffer or SharedArrayBuffer);
a detached buffer or another object throws a TypeError.
Sourcefn with_array_buffer_bytes<R>(
&mut self,
buffer: &ObjectRef,
f: impl FnOnce(&[u8]) -> R,
) -> JsResult<R>
fn with_array_buffer_bytes<R>( &mut self, buffer: &ObjectRef, f: impl FnOnce(&[u8]) -> R, ) -> JsResult<R>
Calls f with a buffer’s bytes, borrowed in place for an
ArrayBuffer and copied first for a SharedArrayBuffer. f runs
inside the engine’s borrow, so it cannot call the engine.
Sourcefn write_array_buffer(
&mut self,
buffer: &ObjectRef,
offset: usize,
data: &[u8],
) -> JsResult<()>
fn write_array_buffer( &mut self, buffer: &ObjectRef, offset: usize, data: &[u8], ) -> JsResult<()>
Writes data into a buffer at offset: a TypeError for a
detached buffer or another object, a RangeError past its end.
Sourcefn typed_array_view(
&mut self,
array: &ObjectRef,
) -> JsResult<Option<TypedArrayView>>
fn typed_array_view( &mut self, array: &ObjectRef, ) -> JsResult<Option<TypedArrayView>>
A typed array’s kind, buffer, byte offset and current length; None
for anything but a typed array (a DataView included).
Sourcefn new_typed_array(
&mut self,
kind: TypedArrayKind,
buffer: &ObjectRef,
byte_offset: usize,
length: Option<usize>,
) -> JsResult<ObjectRef>
fn new_typed_array( &mut self, kind: TypedArrayKind, buffer: &ObjectRef, byte_offset: usize, length: Option<usize>, ) -> JsResult<ObjectRef>
new <Kind>Array(buffer, byte_offset, length); without length the
view tracks a resizable buffer’s length.
fn global_object(&mut self) -> JsResult<ObjectRef>
fn object_prototype(&mut self) -> JsResult<ObjectRef>
fn array_prototype(&mut self) -> JsResult<ObjectRef>
fn function_prototype(&mut self) -> JsResult<ObjectRef>
fn iterator_prototype(&mut self) -> JsResult<ObjectRef>
fn string_iterator_prototype(&mut self) -> JsResult<ObjectRef>
fn number_prototype(&mut self) -> JsResult<ObjectRef>
fn boolean_prototype(&mut self) -> JsResult<ObjectRef>
fn string_prototype(&mut self) -> JsResult<ObjectRef>
fn symbol_prototype(&mut self) -> JsResult<ObjectRef>
fn bigint_prototype(&mut self) -> JsResult<ObjectRef>
fn function_constructor(&mut self) -> JsResult<CallableRef>
Sourcefn new_native_error(
&mut self,
kind: NativeErrorKind,
message: &str,
) -> JsResult<Value>
fn new_native_error( &mut self, kind: NativeErrorKind, message: &str, ) -> JsResult<Value>
A new native error object (not thrown).
Sourcefn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>
fn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>
qjs’s print and console.log, scriptArgs, and under std its
load and read.
Sourcefn new_function<Args>(
&mut self,
options: FunctionOptions,
function: impl HostFunction<Args>,
) -> JsResult<CallableRef>
fn new_function<Args>( &mut self, options: FunctionOptions, function: impl HostFunction<Args>, ) -> JsResult<CallableRef>
A function whose body is function: a closure over a Scope
(|scope: &mut Scope<'_>| …), named and shaped by options.
Sourcefn define_function<Args>(
&mut self,
target: &ObjectRef,
name: &str,
length: u32,
function: impl HostFunction<Args>,
) -> JsResult<CallableRef>
fn define_function<Args>( &mut self, target: &ObjectRef, name: &str, length: u32, function: impl HostFunction<Args>, ) -> JsResult<CallableRef>
Js::new_function defined on target as name, writable and
configurable, not enumerable, as QuickJS’s
JS_SetPropertyFunctionList defines a method.
Sourcefn new_host_object<T: 'static>(
&mut self,
value: T,
prototype: Option<&ObjectRef>,
) -> JsResult<ObjectRef>
fn new_host_object<T: 'static>( &mut self, value: T, prototype: Option<&ObjectRef>, ) -> JsResult<ObjectRef>
An object inheriting from prototype (None for null) holding
value, which drops when the object is collected.
Sourcefn host_data<T: 'static>(
&mut self,
object: &ObjectRef,
) -> JsResult<Option<Rc<T>>>
fn host_data<T: 'static>( &mut self, object: &ObjectRef, ) -> JsResult<Option<Rc<T>>>
The value a host object holds; None for an ordinary object or a
value of another type.
Sourcefn throw_error(&mut self, kind: NativeErrorKind, message: &str) -> RuntimeError
fn throw_error(&mut self, kind: NativeErrorKind, message: &str) -> RuntimeError
An error object of kind with message and a stack from
the running frames, as the error to return:
return Err(js.throw_error(NativeErrorKind::Type, "x is required")).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".