0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-27 01:29:19 -05:00
denoland-rusty-v8/src/proxy.rs

60 lines
1.3 KiB
Rust
Raw Normal View History

2020-04-01 17:47:19 -04:00
use crate::Context;
use crate::HandleScope;
2020-04-01 17:47:19 -04:00
use crate::Local;
use crate::Object;
use crate::Proxy;
use crate::Value;
extern "C" {
fn v8__Proxy__New(
context: *const Context,
target: *const Object,
handler: *const Object,
) -> *const Proxy;
fn v8__Proxy__GetHandler(this: *const Proxy) -> *const Value;
fn v8__Proxy__GetTarget(this: *const Proxy) -> *const Value;
fn v8__Proxy__IsRevoked(this: *const Proxy) -> bool;
fn v8__Proxy__Revoke(this: *const Proxy);
2020-04-01 17:47:19 -04:00
}
impl Proxy {
2022-09-20 22:45:33 -04:00
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
target: Local<Object>,
handler: Local<Object>,
) -> Option<Local<'s, Proxy>> {
2020-04-01 17:47:19 -04:00
unsafe {
scope.cast_local(|sd| {
v8__Proxy__New(sd.get_current_context(), &*target, &*handler)
})
2020-04-01 17:47:19 -04:00
}
}
2022-09-20 22:45:33 -04:00
#[inline(always)]
pub fn get_handler<'s>(
&self,
scope: &mut HandleScope<'s>,
) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Proxy__GetHandler(&*self)) }.unwrap()
2020-04-01 17:47:19 -04:00
}
2022-09-20 22:45:33 -04:00
#[inline(always)]
pub fn get_target<'s>(
&self,
scope: &mut HandleScope<'s>,
) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Proxy__GetTarget(&*self)) }.unwrap()
2020-04-01 17:47:19 -04:00
}
2022-09-20 22:45:33 -04:00
#[inline(always)]
pub fn is_revoked(&self) -> bool {
2020-04-01 17:47:19 -04:00
unsafe { v8__Proxy__IsRevoked(self) }
}
2022-09-20 22:45:33 -04:00
#[inline(always)]
pub fn revoke(&self) {
2020-04-01 17:47:19 -04:00
unsafe { v8__Proxy__Revoke(self) };
}
}