use crate::{
ecmascript::{Agent, ExceptionType, JsResult, Object},
engine::{Bindable, NoGcScope, bindable_handle},
heap::ArenaAccess,
};
use super::{Proxy, data::ProxyHeapData};
#[derive(Debug, Clone, Copy)]
pub(crate) struct NonRevokedProxy<'a> {
pub(crate) target: Object<'a>,
pub(crate) handler: Object<'a>,
}
bindable_handle!(NonRevokedProxy);
pub(crate) fn validate_non_revoked_proxy<'a>(
agent: &mut Agent,
proxy: Proxy,
gc: NoGcScope<'a, '_>,
) -> JsResult<'a, NonRevokedProxy<'a>> {
let ProxyHeapData::NonRevoked {
proxy_handler: handler,
proxy_target: target,
} = proxy.get(agent)
else {
return Err(agent.throw_exception_with_static_message(
ExceptionType::TypeError,
"Proxy target is missing",
gc,
));
};
Ok(NonRevokedProxy {
target: target.bind(gc),
handler: handler.bind(gc),
})
}
pub(crate) fn try_validate_non_revoked_proxy<'a>(
agent: &Agent,
proxy: Proxy,
gc: NoGcScope<'a, '_>,
) -> Option<NonRevokedProxy<'a>> {
let ProxyHeapData::NonRevoked {
proxy_handler: handler,
proxy_target: target,
} = proxy.get(agent)
else {
return None;
};
Some(NonRevokedProxy {
target: target.bind(gc),
handler: handler.bind(gc),
})
}