pub trait Exotic: 'static {
// Provided methods
fn get_own_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
) -> JsResult<Option<Option<Property>>> { ... }
fn define_own_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
_property: &Property,
) -> JsResult<Option<bool>> { ... }
fn has_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
) -> JsResult<Option<bool>> { ... }
fn delete_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
) -> JsResult<Option<bool>> { ... }
fn get_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
_receiver: &Value,
) -> JsResult<Option<Value>> { ... }
fn set_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
_value: &Value,
_receiver: &Value,
) -> JsResult<Option<bool>> { ... }
fn get_prototype(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
) -> JsResult<Option<Option<Gc<JsObject>>>> { ... }
fn set_prototype(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_proto: Option<Gc<JsObject>>,
) -> JsResult<Option<bool>> { ... }
fn is_extensible(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
) -> JsResult<Option<bool>> { ... }
fn prevent_extensions(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
) -> JsResult<Option<bool>> { ... }
}Expand description
The property behaviour a host class may override: the exotic half of JSClassDef.
Every method’s default is “no opinion”, so an implementation names only the traps it
actually wants and everything else keeps the ordinary algorithm. That is what makes
point.c’s class — which has no exotic methods at all — work with an empty impl.
The Option in each answer is the same two-level question JSClassExoticMethods asks:
- outer
None— not my business, run the ordinary algorithm; - outer
Some(None)— this object has no such property; - outer
Some(Some(x))— here is the answer.
§Re-entrancy
A trap receives the interpreter and may call back into it, because a host property can
be a JavaScript getter or a function on another object. It must not re-enter the same
operation on the same object (get_property calling interp.get_property(object, …)
for the key it was asked about), which recurses until the stack ends. The C API has the
identical hazard.
Provided Methods§
Sourcefn get_own_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
) -> JsResult<Option<Option<Property>>>
fn get_own_property( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, _key: &PropertyKey, ) -> JsResult<Option<Option<Property>>>
[[GetOwnProperty]] (JSClassExoticMethods::get_own_property).
Sourcefn define_own_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
_property: &Property,
) -> JsResult<Option<bool>>
fn define_own_property( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, _key: &PropertyKey, _property: &Property, ) -> JsResult<Option<bool>>
[[DefineOwnProperty]] (JSClassExoticMethods::define_own_property).
Sourcefn has_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
) -> JsResult<Option<bool>>
fn has_property( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, _key: &PropertyKey, ) -> JsResult<Option<bool>>
[[HasProperty]] (JSClassExoticMethods::has_property).
Sourcefn delete_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
) -> JsResult<Option<bool>>
fn delete_property( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, _key: &PropertyKey, ) -> JsResult<Option<bool>>
[[Delete]] (JSClassExoticMethods::delete_property).
Sourcefn get_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
_receiver: &Value,
) -> JsResult<Option<Value>>
fn get_property( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, _key: &PropertyKey, _receiver: &Value, ) -> JsResult<Option<Value>>
[[Get]] (JSClassExoticMethods::get_property).
Answers the value, and does its own prototype walk if it wants one; returning
None leaves the read to the ordinary algorithm.
Sourcefn set_property(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_key: &PropertyKey,
_value: &Value,
_receiver: &Value,
) -> JsResult<Option<bool>>
fn set_property( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, _key: &PropertyKey, _value: &Value, _receiver: &Value, ) -> JsResult<Option<bool>>
[[Set]] (JSClassExoticMethods::set_property).
Some(false) is a refusal, which the caller turns into a TypeError in strict code
and silence in sloppy code — exactly like a proxy’s set trap.
Sourcefn get_prototype(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
) -> JsResult<Option<Option<Gc<JsObject>>>>
fn get_prototype( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, ) -> JsResult<Option<Option<Gc<JsObject>>>>
[[GetPrototypeOf]] (JSClassExoticMethods::get_prototype).
Sourcefn set_prototype(
&self,
_interp: &mut Interp<'_>,
_object: &Gc<JsObject>,
_proto: Option<Gc<JsObject>>,
) -> JsResult<Option<bool>>
fn set_prototype( &self, _interp: &mut Interp<'_>, _object: &Gc<JsObject>, _proto: Option<Gc<JsObject>>, ) -> JsResult<Option<bool>>
[[SetPrototypeOf]] (JSClassExoticMethods::set_prototype).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".