pub struct Scope<'a> { /* private fields */ }Expand description
A host function’s view of the engine: its call, and every operation of
Js. Values it hands out are handles like any other and
outlive the call.
Implementations§
Source§impl Scope<'_>
impl Scope<'_>
Sourcepub fn arg(&mut self, index: usize) -> Value
pub fn arg(&mut self, index: usize) -> Value
Argument index; undefined past Scope::argc.
Sourcepub fn new_target(&mut self) -> Value
pub fn new_target(&mut self) -> Value
new.target; undefined for a call.
Sourcepub fn is_construct(&self) -> bool
pub fn is_construct(&self) -> bool
Whether new called the function.
Sourcepub fn callee(&mut self) -> CallableRef
pub fn callee(&mut self) -> CallableRef
The function object called.
Sourcepub fn data(&mut self, slot: usize) -> Value
pub fn data(&mut self, slot: usize) -> Value
Captured value slot (FunctionOptions::data); undefined past
the last.
Sourcepub fn set_data(&mut self, slot: usize, value: Value) -> JsResult<()>
pub fn set_data(&mut self, slot: usize, value: Value) -> JsResult<()>
Replaces captured value slot, which must exist.
Sourcepub fn this_host_data<T: 'static>(&mut self) -> JsResult<Option<Rc<T>>>
pub fn this_host_data<T: 'static>(&mut self) -> JsResult<Option<Rc<T>>>
The value a host object receiver holds (Js::host_data of
this); None when the receiver is not a host object of T.
Source§impl Scope<'_>
impl Scope<'_>
Sourcepub fn throw_error(
&mut self,
kind: NativeErrorKind,
message: &str,
) -> RuntimeError
pub fn throw_error( &mut self, kind: NativeErrorKind, message: &str, ) -> RuntimeError
Source§impl Scope<'_>
impl Scope<'_>
Sourcepub fn eval(&mut self, source: &str) -> JsResult<Value>
pub fn eval(&mut self, source: &str) -> JsResult<Value>
Compiles and runs source as a script; the completion value.
pub fn eval_bytes(&mut self, source: &[u8]) -> JsResult<Value>
pub fn eval_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<Value>
pub fn eval_with_options( &mut self, source: &str, options: &EvalOptions, ) -> JsResult<Value>
pub fn eval_bytes_with_options( &mut self, source: &[u8], options: &EvalOptions, ) -> JsResult<Value>
Sourcepub fn eval_bytes_with_filename(
&mut self,
source: &[u8],
filename: &str,
) -> JsResult<Value>
pub 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.
pub fn compile(&mut self, source: &str) -> JsResult<FunctionBytecodeRef>
pub fn compile_bytes(&mut self, source: &[u8]) -> JsResult<FunctionBytecodeRef>
pub fn compile_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<FunctionBytecodeRef>
pub fn compile_with_options( &mut self, source: &str, options: &CompileOptions, ) -> JsResult<FunctionBytecodeRef>
pub fn compile_bytes_with_options( &mut self, source: &[u8], options: &CompileOptions, ) -> JsResult<FunctionBytecodeRef>
Sourcepub fn compile_bytes_with_filename(
&mut self,
source: &[u8],
filename: &str,
) -> JsResult<FunctionBytecodeRef>
pub 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.
Sourcepub fn execute(&mut self, script: &FunctionBytecodeRef) -> JsResult<Value>
pub fn execute(&mut self, script: &FunctionBytecodeRef) -> JsResult<Value>
Runs a compiled script with the global object as this.
pub fn compile_module(&mut self, source: &str) -> JsResult<ModuleBytecodeRef>
pub fn compile_module_bytes( &mut self, source: &[u8], ) -> JsResult<ModuleBytecodeRef>
pub fn compile_module_with_filename( &mut self, source: &str, filename: &str, ) -> JsResult<ModuleBytecodeRef>
pub fn compile_module_bytes_with_options( &mut self, source: &[u8], options: &CompileOptions, ) -> JsResult<ModuleBytecodeRef>
pub fn compile_module_bytes_with_filename( &mut self, source: &[u8], filename: &str, ) -> JsResult<ModuleBytecodeRef>
Sourcepub fn compile_module_bytes_with_import_meta(
&mut self,
source: &[u8],
filename: &str,
import_meta: Vec<(String, Value)>,
) -> JsResult<ModuleBytecodeRef>
pub 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.
Sourcepub fn execute_module(&mut self, module: &ModuleBytecodeRef) -> JsResult<Value>
pub fn execute_module(&mut self, module: &ModuleBytecodeRef) -> JsResult<Value>
Links and evaluates a compiled module and what it imports; the promise of its evaluation.
pub fn call( &mut self, callable: &CallableRef, this_value: Value, arguments: &[Value], ) -> JsResult<Value>
pub fn construct( &mut self, constructor: &CallableRef, arguments: &[Value], ) -> JsResult<Value>
pub fn construct_with_new_target( &mut self, constructor: &CallableRef, new_target: &CallableRef, arguments: &[Value], ) -> JsResult<Value>
pub fn new_object(&mut self) -> JsResult<ObjectRef>
pub fn new_object_with_prototype( &mut self, prototype: Option<&ObjectRef>, ) -> JsResult<ObjectRef>
pub fn new_array(&mut self) -> JsResult<ObjectRef>
pub fn new_array_from_values( &mut self, values: Vec<Value>, ) -> JsResult<ObjectRef>
pub fn get_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<Option<CompleteOrdinaryPropertyDescriptor>>
pub fn define_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, descriptor: &OrdinaryPropertyDescriptor, ) -> JsResult<bool>
pub fn get_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<Value>
pub fn get_property_with_receiver( &mut self, object: &ObjectRef, key: &PropertyKey, receiver: Value, ) -> JsResult<Value>
pub fn set_property( &mut self, object: &ObjectRef, key: &PropertyKey, value: Value, ) -> JsResult<bool>
pub fn set_property_with_receiver( &mut self, object: &ObjectRef, key: &PropertyKey, value: Value, receiver: Value, ) -> JsResult<bool>
pub fn delete_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>
pub fn has_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>
pub fn has_own_property( &mut self, object: &ObjectRef, key: &PropertyKey, ) -> JsResult<bool>
pub fn own_property_keys( &mut self, object: &ObjectRef, ) -> JsResult<Vec<PropertyKey>>
pub fn get_prototype_of( &mut self, object: &ObjectRef, ) -> JsResult<Option<ObjectRef>>
pub fn set_prototype_of( &mut self, object: &ObjectRef, prototype: Option<&ObjectRef>, ) -> JsResult<bool>
Sourcepub fn as_callable(
&mut self,
object: &ObjectRef,
) -> JsResult<Option<CallableRef>>
pub fn as_callable( &mut self, object: &ObjectRef, ) -> JsResult<Option<CallableRef>>
The object as a callable reference; None when it is not callable.
pub fn is_constructor(&mut self, object: &ObjectRef) -> JsResult<bool>
Sourcepub fn is_array_object(&mut self, object: &ObjectRef) -> JsResult<bool>
pub fn is_array_object(&mut self, object: &ObjectRef) -> JsResult<bool>
IsArray.
pub fn is_error_object(&mut self, object: &ObjectRef) -> JsResult<bool>
Sourcepub fn to_js_string(&mut self, value: &Value) -> JsResult<JsString>
pub fn to_js_string(&mut self, value: &Value) -> JsResult<JsString>
ToString(value).
Sourcepub fn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>
pub fn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>
QuickJS’s JS_DetachArrayBuffer: detaches an ArrayBuffer; anything
else is ignored.
Sourcepub fn print_value(&mut self, value: &Value) -> JsResult<String>
pub 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).
Sourcepub fn qjs_print_value_bytes(&mut self, value: &Value) -> JsResult<Vec<u8>>
pub 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.
pub fn new_symbol( &mut self, description: Option<JsString>, ) -> JsResult<SymbolRef>
pub fn symbol_description( &mut self, symbol: &SymbolRef, ) -> JsResult<Option<JsString>>
pub fn well_known_symbol( &mut self, symbol: WellKnownSymbol, ) -> JsResult<SymbolRef>
Sourcepub fn promise_snapshot(
&mut self,
promise: &ObjectRef,
) -> JsResult<Option<PromiseSnapshot>>
pub fn promise_snapshot( &mut self, promise: &ObjectRef, ) -> JsResult<Option<PromiseSnapshot>>
A promise’s state and result; None when promise is not one.
Sourcepub fn new_promise(&mut self) -> JsResult<PromiseCapability>
pub fn new_promise(&mut self) -> JsResult<PromiseCapability>
NewPromiseCapability(%Promise%): a pending promise and its
resolving functions.
Sourcepub fn promise_then(
&mut self,
promise: &ObjectRef,
on_fulfilled: impl HostFunction<Raw>,
on_rejected: impl HostFunction<Raw>,
) -> JsResult<ObjectRef>
pub 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.
Sourcepub fn new_array_buffer(&mut self, bytes: &[u8]) -> JsResult<ObjectRef>
pub fn new_array_buffer(&mut self, bytes: &[u8]) -> JsResult<ObjectRef>
A new ArrayBuffer holding a copy of bytes.
Sourcepub fn array_buffer_len(
&mut self,
buffer: &ObjectRef,
) -> JsResult<Option<usize>>
pub 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.
Sourcepub fn array_buffer_to_vec(&mut self, buffer: &ObjectRef) -> JsResult<Vec<u8>>
pub 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.
Sourcepub fn with_array_buffer_bytes<R>(
&mut self,
buffer: &ObjectRef,
f: impl FnOnce(&[u8]) -> R,
) -> JsResult<R>
pub 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.
Sourcepub fn write_array_buffer(
&mut self,
buffer: &ObjectRef,
offset: usize,
data: &[u8],
) -> JsResult<()>
pub 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.
Sourcepub fn typed_array_view(
&mut self,
array: &ObjectRef,
) -> JsResult<Option<TypedArrayView>>
pub 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).
Sourcepub fn new_typed_array(
&mut self,
kind: TypedArrayKind,
buffer: &ObjectRef,
byte_offset: usize,
length: Option<usize>,
) -> JsResult<ObjectRef>
pub 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.
pub fn global_object(&mut self) -> JsResult<ObjectRef>
pub fn object_prototype(&mut self) -> JsResult<ObjectRef>
pub fn array_prototype(&mut self) -> JsResult<ObjectRef>
pub fn function_prototype(&mut self) -> JsResult<ObjectRef>
pub fn iterator_prototype(&mut self) -> JsResult<ObjectRef>
pub fn string_iterator_prototype(&mut self) -> JsResult<ObjectRef>
pub fn number_prototype(&mut self) -> JsResult<ObjectRef>
pub fn boolean_prototype(&mut self) -> JsResult<ObjectRef>
pub fn string_prototype(&mut self) -> JsResult<ObjectRef>
pub fn symbol_prototype(&mut self) -> JsResult<ObjectRef>
pub fn bigint_prototype(&mut self) -> JsResult<ObjectRef>
pub fn function_constructor(&mut self) -> JsResult<CallableRef>
Sourcepub fn new_native_error(
&mut self,
kind: NativeErrorKind,
message: &str,
) -> JsResult<Value>
pub fn new_native_error( &mut self, kind: NativeErrorKind, message: &str, ) -> JsResult<Value>
A new native error object (not thrown).
Sourcepub fn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>
pub fn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>
qjs’s print and console.log, scriptArgs, and under std its
load and read.
Sourcepub fn new_function<Args>(
&mut self,
options: FunctionOptions,
function: impl HostFunction<Args>,
) -> JsResult<CallableRef>
pub 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.
Sourcepub fn define_function<Args>(
&mut self,
target: &ObjectRef,
name: &str,
length: u32,
function: impl HostFunction<Args>,
) -> JsResult<CallableRef>
pub 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.
Trait Implementations§
Source§impl Js for Scope<'_>
impl Js for Scope<'_>
Source§fn eval(&mut self, source: &str) -> JsResult<Value>
fn eval(&mut self, source: &str) -> JsResult<Value>
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>
Source§fn 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>
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>
Source§fn 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>
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>
fn execute(&mut self, script: &FunctionBytecodeRef) -> JsResult<Value>
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>
Source§fn 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>
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>
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>
Source§fn as_callable(&mut self, object: &ObjectRef) -> JsResult<Option<CallableRef>>
fn as_callable(&mut self, object: &ObjectRef) -> JsResult<Option<CallableRef>>
None when it is not callable.fn is_constructor(&mut self, object: &ObjectRef) -> JsResult<bool>
fn is_error_object(&mut self, object: &ObjectRef) -> JsResult<bool>
Source§fn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>
fn detach_array_buffer(&mut self, value: &Value) -> JsResult<()>
JS_DetachArrayBuffer: detaches an ArrayBuffer; anything
else is ignored.Source§fn print_value(&mut self, value: &Value) -> JsResult<String>
fn print_value(&mut self, value: &Value) -> JsResult<String>
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>>
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>
Source§fn promise_snapshot(
&mut self,
promise: &ObjectRef,
) -> JsResult<Option<PromiseSnapshot>>
fn promise_snapshot( &mut self, promise: &ObjectRef, ) -> JsResult<Option<PromiseSnapshot>>
None when promise is not one.Source§fn new_promise(&mut self) -> JsResult<PromiseCapability>
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>
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>
fn new_array_buffer(&mut self, bytes: &[u8]) -> JsResult<ObjectRef>
ArrayBuffer holding a copy of bytes.Source§fn array_buffer_len(&mut self, buffer: &ObjectRef) -> JsResult<Option<usize>>
fn array_buffer_len(&mut self, buffer: &ObjectRef) -> JsResult<Option<usize>>
None for a detached buffer or another
object.Source§fn array_buffer_to_vec(&mut self, buffer: &ObjectRef) -> JsResult<Vec<u8>>
fn array_buffer_to_vec(&mut self, buffer: &ObjectRef) -> JsResult<Vec<u8>>
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>
fn with_array_buffer_bytes<R>( &mut self, buffer: &ObjectRef, f: impl FnOnce(&[u8]) -> R, ) -> JsResult<R>
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<()>
fn write_array_buffer( &mut self, buffer: &ObjectRef, offset: usize, data: &[u8], ) -> JsResult<()>
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>>
fn typed_array_view( &mut self, array: &ObjectRef, ) -> JsResult<Option<TypedArrayView>>
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>
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>
Source§fn new_native_error(
&mut self,
kind: NativeErrorKind,
message: &str,
) -> JsResult<Value>
fn new_native_error( &mut self, kind: NativeErrorKind, message: &str, ) -> JsResult<Value>
Source§fn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>
fn install_qjs_helpers(&mut self, helpers: &QjsHelpers) -> JsResult<()>
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>
fn new_function<Args>( &mut self, options: FunctionOptions, function: impl HostFunction<Args>, ) -> JsResult<CallableRef>
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>
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>
fn new_host_object<T: 'static>( &mut self, value: T, prototype: Option<&ObjectRef>, ) -> JsResult<ObjectRef>
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>>>
fn host_data<T: 'static>( &mut self, object: &ObjectRef, ) -> JsResult<Option<Rc<T>>>
None for an ordinary object or a
value of another type.Source§fn throw_error(&mut self, kind: NativeErrorKind, message: &str) -> RuntimeError
fn throw_error(&mut self, kind: NativeErrorKind, message: &str) -> RuntimeError
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")).