nanvm_lib/vm/any/not.rs
1use core::ops::Not;
2
3use crate::vm::{Any, IVm, ToAny};
4
5/// `!`. Coerces via `ToBoolean` and negates. Never throws — `ToBoolean`
6/// itself cannot fail — but stays a `Result` to match every other
7/// operator's shape.
8/// <https://tc39.es/ecma262/#sec-logical-not-operator>
9impl<A: IVm> Not for Any<A> {
10 type Output = Result<Any<A>, Any<A>>;
11 fn not(self) -> Self::Output {
12 Ok((!self.to_boolean()).to_any())
13 }
14}