Struct rquickjs_core::Exception
source · #[repr(transparent)]pub struct Exception<'js>(_);
Expand description
A javascript instance of Error
Will turn into a error when converted to javascript but won’t autmatically be thrown.
Implementations§
source§impl<'js> Exception<'js>
impl<'js> Exception<'js>
sourcepub fn into_object(self) -> Object<'js>
pub fn into_object(self) -> Object<'js>
Turns the exception into the underlying object.
sourcepub fn into_value(self) -> Value<'js>
pub fn into_value(self) -> Value<'js>
Turns the exception into a generic javascript value.
sourcepub fn from_object(obj: Object<'js>) -> Option<Self>
pub fn from_object(obj: Object<'js>) -> Option<Self>
Creates an exception from an object if it is an instance of error.
sourcepub fn from_message(ctx: Ctx<'js>, message: &str) -> Result<Self>
pub fn from_message(ctx: Ctx<'js>, message: &str) -> Result<Self>
Creates a new exception with a give message.
sourcepub fn from_message_location(
ctx: Ctx<'js>,
message: &str,
file: &str,
line: i32
) -> Result<Self>
pub fn from_message_location( ctx: Ctx<'js>, message: &str, file: &str, line: i32 ) -> Result<Self>
Creates a new exception with a give message, file name and line number.
sourcepub fn message(&self) -> Option<String>
pub fn message(&self) -> Option<String>
Returns the message of the error.
Same as retrieving error.message
in javascript.
sourcepub fn file(&self) -> Option<String>
pub fn file(&self) -> Option<String>
Returns the file name from with the error originated..
Same as retrieving error.fileName
in javascript.
sourcepub fn line(&self) -> Option<i32>
pub fn line(&self) -> Option<i32>
Returns the file line from with the error originated..
Same as retrieving error.lineNumber
in javascript.
sourcepub fn stack(&self) -> Option<String>
pub fn stack(&self) -> Option<String>
Returns the error stack.
Same as retrieving error.stack
in javascript.
sourcepub fn throw_message(ctx: Ctx<'js>, message: &str) -> Error
pub fn throw_message(ctx: Ctx<'js>, message: &str) -> Error
Throws a new generic error.
Equivalent to:
let (Ok(e) | Err(e)) = Exception::from_message(ctx, message).map(|x| x.throw());
e
sourcepub fn throw_message_location(
ctx: Ctx<'js>,
message: &str,
file: &str,
line: i32
) -> Error
pub fn throw_message_location( ctx: Ctx<'js>, message: &str, file: &str, line: i32 ) -> Error
Throws a new generic error with a file name and line number.
sourcepub fn throw_syntax(ctx: Ctx<'js>, message: &str) -> Error
pub fn throw_syntax(ctx: Ctx<'js>, message: &str) -> Error
Throws a new syntax error.
sourcepub fn throw_type(ctx: Ctx<'js>, message: &str) -> Error
pub fn throw_type(ctx: Ctx<'js>, message: &str) -> Error
Throws a new type error.
sourcepub fn throw_reference(ctx: Ctx<'js>, message: &str) -> Error
pub fn throw_reference(ctx: Ctx<'js>, message: &str) -> Error
Throws a new reference error.
sourcepub fn throw_range(ctx: Ctx<'js>, message: &str) -> Error
pub fn throw_range(ctx: Ctx<'js>, message: &str) -> Error
Throws a new range error.
sourcepub fn throw_internal(ctx: Ctx<'js>, message: &str) -> Error
pub fn throw_internal(ctx: Ctx<'js>, message: &str) -> Error
Throws a new internal error.
Methods from Deref<Target = Object<'js>>§
sourcepub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<()>where
K: IntoAtom<'js>,
V: AsProperty<'js, P>,
Available on crate feature properties
only.
pub fn prop<K, V, P>(&self, key: K, prop: V) -> Result<()>where K: IntoAtom<'js>, V: AsProperty<'js, P>,
properties
only.Define a property of an object
// Define readonly property without value
obj.prop("no_val", ()).unwrap();
// Define readonly property with value
obj.prop("ro_str", "Some const text").unwrap();
// Define readonly property with value and make it to be writable
obj.prop("ro_str2", Property::from("Some const text").writable()).unwrap();
// Define readonly property using getter and make it to be enumerable
obj.prop("ro_str_get", Accessor::from(|| "Some readable text").enumerable()).unwrap();
// Define readonly property using getter and setter
obj.prop("ro_str_get_set",
Accessor::from(|| "Some text")
.set(|new_val: String| { /* do something */ })
).unwrap();
sourcepub fn init_def<T>(&self) -> Result<()>where
T: ObjectDef,
pub fn init_def<T>(&self) -> Result<()>where T: ObjectDef,
Initialize an object using ObjectDef
sourcepub fn contains_key<K>(&self, k: K) -> Result<bool>where
K: IntoAtom<'js>,
pub fn contains_key<K>(&self, k: K) -> Result<bool>where K: IntoAtom<'js>,
check wether the object contains a certain key.
sourcepub fn set<K: IntoAtom<'js>, V: IntoJs<'js>>(
&self,
key: K,
value: V
) -> Result<()>
pub fn set<K: IntoAtom<'js>, V: IntoJs<'js>>( &self, key: K, value: V ) -> Result<()>
Set a member of an object to a certain value
sourcepub fn keys<K: FromAtom<'js>>(&self) -> ObjectKeysIter<'js, K> ⓘ
pub fn keys<K: FromAtom<'js>>(&self) -> ObjectKeysIter<'js, K> ⓘ
Get own string enumerable property names of an object
sourcepub fn own_keys<K: FromAtom<'js>>(
&self,
filter: Filter
) -> ObjectKeysIter<'js, K> ⓘ
pub fn own_keys<K: FromAtom<'js>>( &self, filter: Filter ) -> ObjectKeysIter<'js, K> ⓘ
Get own property names of an object
sourcepub fn props<K: FromAtom<'js>, V: FromJs<'js>>(&self) -> ObjectIter<'js, K, V> ⓘ
pub fn props<K: FromAtom<'js>, V: FromJs<'js>>(&self) -> ObjectIter<'js, K, V> ⓘ
Get own string enumerable properties of an object
sourcepub fn own_props<K: FromAtom<'js>, V: FromJs<'js>>(
&self,
filter: Filter
) -> ObjectIter<'js, K, V> ⓘ
pub fn own_props<K: FromAtom<'js>, V: FromJs<'js>>( &self, filter: Filter ) -> ObjectIter<'js, K, V> ⓘ
Get own properties of an object
sourcepub fn values<K: FromAtom<'js>>(&self) -> ObjectValuesIter<'js, K> ⓘ
pub fn values<K: FromAtom<'js>>(&self) -> ObjectValuesIter<'js, K> ⓘ
Get own string enumerable property values of an object
sourcepub fn own_values<K: FromAtom<'js>>(
&self,
filter: Filter
) -> ObjectValuesIter<'js, K> ⓘ
pub fn own_values<K: FromAtom<'js>>( &self, filter: Filter ) -> ObjectValuesIter<'js, K> ⓘ
Get own property values of an object
sourcepub fn get_prototype(&self) -> Result<Object<'js>>
pub fn get_prototype(&self) -> Result<Object<'js>>
Get an object prototype
sourcepub fn set_prototype(&self, proto: &Object<'js>) -> Result<()>
pub fn set_prototype(&self, proto: &Object<'js>) -> Result<()>
Set an object prototype
sourcepub fn is_instance_of(&self, class: impl AsRef<Value<'js>>) -> bool
pub fn is_instance_of(&self, class: impl AsRef<Value<'js>>) -> bool
Check instance of object
sourcepub fn instance_of<C: ClassDef>(&self) -> bool
Available on crate feature classes
only.
pub fn instance_of<C: ClassDef>(&self) -> bool
classes
only.Check the object for instance of
Methods from Deref<Target = Value<'js>>§
pub fn is_null(&self) -> bool
pub fn is_undefined(&self) -> bool
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Check if the value is a function
sourcepub unsafe fn ref_string(&self) -> &String<'js>
pub unsafe fn ref_string(&self) -> &String<'js>
sourcepub unsafe fn ref_symbol(&self) -> &Symbol<'js>
pub unsafe fn ref_symbol(&self) -> &Symbol<'js>
sourcepub unsafe fn ref_object(&self) -> &Object<'js>
pub unsafe fn ref_object(&self) -> &Object<'js>
sourcepub unsafe fn ref_function(&self) -> &Function<'js>
pub unsafe fn ref_function(&self) -> &Function<'js>
sourcepub fn as_function(&self) -> Option<&Function<'js>>
pub fn as_function(&self) -> Option<&Function<'js>>
Try reinterprete as
sourcepub unsafe fn ref_big_int(&self) -> &BigInt<'js>
pub unsafe fn ref_big_int(&self) -> &BigInt<'js>
sourcepub fn as_big_int(&self) -> Option<&BigInt<'js>>
pub fn as_big_int(&self) -> Option<&BigInt<'js>>
Try reinterprete as