Add proto chain inspection to the object interface.
This commit is contained in:
parent
0e59e1c961
commit
983c0fb200
|
@ -105,19 +105,14 @@ fn is_prototype_of<'gc>(
|
|||
Ok(ob) => ob,
|
||||
Err(_) => return Ok(Value::Bool(false).into()),
|
||||
};
|
||||
let mut proto = ob.read().as_script_object().unwrap().prototype().cloned();
|
||||
let mut proto = ob.read().proto();
|
||||
|
||||
while let Some(proto_ob) = proto {
|
||||
if GcCell::ptr_eq(this, proto_ob) {
|
||||
return Ok(Value::Bool(true).into());
|
||||
}
|
||||
|
||||
proto = proto_ob
|
||||
.read()
|
||||
.as_script_object()
|
||||
.unwrap()
|
||||
.prototype()
|
||||
.cloned();
|
||||
proto = proto_ob.read().proto();
|
||||
}
|
||||
|
||||
Ok(Value::Bool(false).into())
|
||||
|
|
|
@ -75,6 +75,13 @@ pub trait Object<'gc>: 'gc + Collect + Debug {
|
|||
/// Returns false if the property cannot be deleted.
|
||||
fn delete(&mut self, name: &str) -> bool;
|
||||
|
||||
/// Retrieve the `__proto__` of a given object.
|
||||
///
|
||||
/// The proto is another object used to resolve methods across a class of
|
||||
/// multiple objects. It should also be accessible as `__proto__` from
|
||||
/// `get`.
|
||||
fn proto(&self) -> Option<ObjectCell<'gc>>;
|
||||
|
||||
/// Checks if the object has a given named property.
|
||||
fn has_property(&self, name: &str) -> bool;
|
||||
|
||||
|
|
|
@ -204,10 +204,6 @@ impl<'gc> ScriptObject<'gc> {
|
|||
self.prototype = Some(prototype);
|
||||
}
|
||||
|
||||
pub fn prototype(&self) -> Option<&ObjectCell<'gc>> {
|
||||
self.prototype.as_ref()
|
||||
}
|
||||
|
||||
pub fn set_type_of(&mut self, type_of: &'static str) {
|
||||
self.type_of = type_of;
|
||||
}
|
||||
|
@ -332,6 +328,10 @@ impl<'gc> Object<'gc> for ScriptObject<'gc> {
|
|||
false
|
||||
}
|
||||
|
||||
fn proto(&self) -> Option<ObjectCell<'gc>> {
|
||||
self.prototype
|
||||
}
|
||||
|
||||
/// Checks if the object has a given named property.
|
||||
fn has_property(&self, name: &str) -> bool {
|
||||
self.has_own_property(name)
|
||||
|
|
Loading…
Reference in New Issue