Skip to main content

Js

Trait Js 

Source
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

The operations Context and a host function’s Scope share, for code generic over where it runs. Sealed; both types also have each as an inherent method, so calling one needs no import.

Required Methods§

Source

fn eval(&mut self, source: &str) -> JsResult<Value>

Compiles and runs source as a script; the completion value.

Source

fn eval_bytes(&mut self, source: &[u8]) -> JsResult<Value>

Source

fn eval_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<Value>

Source

fn eval_with_options( &mut self, source: &str, options: &EvalOptions, ) -> JsResult<Value>

Source

fn eval_bytes_with_options( &mut self, source: &[u8], options: &EvalOptions, ) -> JsResult<Value>

Source

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.

Source

fn compile(&mut self, source: &str) -> JsResult<FunctionBytecodeRef>

Source

fn compile_bytes(&mut self, source: &[u8]) -> JsResult<FunctionBytecodeRef>

Source

fn compile_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<FunctionBytecodeRef>

Source

fn compile_with_options( &mut self, source: &str, options: &CompileOptions, ) -> JsResult<FunctionBytecodeRef>

Source

fn compile_bytes_with_options( &mut self, source: &[u8], options: &CompileOptions, ) -> JsResult<FunctionBytecodeRef>

Source

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.

Source

fn execute(&mut self, script: &FunctionBytecodeRef) -> JsResult<Value>

Runs a compiled script with the global object as this.

Source

fn compile_module(&mut self, source: &str) -> JsResult<ModuleBytecodeRef>

Source

fn compile_module_bytes(&mut self, source: &[u8]) -> JsResult<ModuleBytecodeRef>

Source

fn compile_module_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<ModuleBytecodeRef>

Source

fn compile_module_bytes_with_options( &mut self, source: &[u8], options: &CompileOptions, ) -> JsResult<ModuleBytecodeRef>

Source

fn compile_module_bytes_with_filename( &mut self, source: &[u8], filename: &str, ) -> JsResult<ModuleBytecodeRef>

Source

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.

Source

fn execute_module(&mut self, module: &ModuleBytecodeRef) -> JsResult<Value>

Links and evaluates a compiled module and what it imports; the promise of its evaluation.

Source

fn call( &mut self, callable: &CallableRef, this_value: Value, arguments: &[Value], ) -> JsResult<Value>

Source

fn construct( &mut self, constructor: &CallableRef, arguments: &[Value], ) -> JsResult<Value>

Source

fn construct_with_new_target( &mut self, constructor: &CallableRef, new_target: &CallableRef, arguments: &[Value], ) -> JsResult<Value>

Source

fn new_object(&mut self) -> JsResult<ObjectRef>

Source

fn new_object_with_prototype( &mut self, prototype: Option<&ObjectRef>, ) -> JsResult<ObjectRef>

Source

fn new_array(&mut self) -> JsResult<ObjectRef>

Source

fn new_array_from_values(&mut self, values: Vec<Value>) -> JsResult<ObjectRef>

Source

fn get_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<Option<CompleteOrdinaryPropertyDescriptor>>

Source

fn define_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, descriptor: &OrdinaryPropertyDescriptor, ) -> JsResult<bool>

Source

fn get_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<Value>

Source

fn get_property_with_receiver( &mut self, object: &ObjectRef, key: &PropertyKey, receiver: Value, ) -> JsResult<Value>

Source

fn set_property( &mut self, object: &ObjectRef, key: &PropertyKey, value: Value, ) -> JsResult<bool>

Source

fn set_property_with_receiver( &mut self, object: &ObjectRef, key: &PropertyKey, value: Value, receiver: Value, ) -> JsResult<bool>

Source

fn delete_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>

Source

fn has_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>

Source

fn has_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>

Source

fn own_property_keys( &mut self, object: &ObjectRef, ) -> JsResult<Vec<PropertyKey>>

Source

fn get_prototype_of( &mut self, object: &ObjectRef, ) -> JsResult<Option<ObjectRef>>

Source

fn set_prototype_of( &mut self, object: &ObjectRef, prototype: Option<&ObjectRef>, ) -> JsResult<bool>

Source

fn as_callable(&mut self, object: &ObjectRef) -> JsResult<Option<CallableRef>>

The object as a callable reference; None when it is not callable.

Source

fn is_constructor(&mut self, object: &ObjectRef) -> JsResult<bool>

Source

fn is_array_object(&mut self, object: &ObjectRef) -> JsResult<bool>

IsArray.

Source

fn is_error_object(&mut self, object: &ObjectRef) -> JsResult<bool>

Source

fn to_js_string(&mut self, value: &Value) -> JsResult<JsString>

ToString(value).

Source

fn to_number(&mut self, value: &Value) -> JsResult<f64>

ToNumber(value).

Source

fn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>

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

Source

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

typeof value.

Source

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

Source

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.

Source

fn new_symbol(&mut self, description: Option<JsString>) -> JsResult<SymbolRef>

Source

fn symbol_description( &mut self, symbol: &SymbolRef, ) -> JsResult<Option<JsString>>

Source

fn well_known_symbol(&mut self, symbol: WellKnownSymbol) -> JsResult<SymbolRef>

Source

fn promise_snapshot( &mut self, promise: &ObjectRef, ) -> JsResult<Option<PromiseSnapshot>>

A promise’s state and result; None when promise is not one.

Source

fn new_promise(&mut self) -> JsResult<PromiseCapability>

NewPromiseCapability(%Promise%): a pending promise and its resolving functions.

Source

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.

Source

fn new_array_buffer(&mut self, bytes: &[u8]) -> JsResult<ObjectRef>

A new ArrayBuffer holding a copy of bytes.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

fn global_object(&mut self) -> JsResult<ObjectRef>

Source

fn object_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn array_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn function_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn iterator_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn string_iterator_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn number_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn boolean_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn string_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn symbol_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn bigint_prototype(&mut self) -> JsResult<ObjectRef>

Source

fn function_constructor(&mut self) -> JsResult<CallableRef>

Source

fn new_native_error( &mut self, kind: NativeErrorKind, message: &str, ) -> JsResult<Value>

A new native error object (not thrown).

Source

fn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>

qjs’s print and console.log, scriptArgs, and under std its load and read.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Implementors§

Source§

impl Js for Context

Source§

impl Js for Scope<'_>