Skip to main content

nanvm_lib/vm/function/
partial_eq.rs

1use crate::vm::{Function, IComplex, IVm};
2
3/// Identity: a function is its own value, by reference.
4impl<A: IVm> PartialEq for Function<A> {
5    fn eq(&self, other: &Self) -> bool {
6        self.internal().ptr_eq(other.internal())
7    }
8}
9
10#[cfg(test)]
11mod tests {
12    use crate::{
13        naive::Naive,
14        vm::{Any, Function, IVm, ToArray},
15    };
16
17    type A = Naive;
18
19    fn closure() -> Function<A> {
20        A::static_function(|_, _| Ok(Any::undefined()), 0, [].to_array(), None)
21    }
22
23    /// Two closures from one code are two functions, and a clone is the
24    /// same one: `(() => 1) === (() => 1)` is `false`.
25    #[test]
26    fn closures_by_reference() {
27        let f = closure();
28        assert_ne!(f, closure());
29        assert_eq!(f.clone(), f);
30    }
31}