2020-04-01 17:47:19 -04:00
|
|
|
use crate::Context;
|
2020-06-03 01:38:34 -04:00
|
|
|
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(
|
2020-04-13 08:43:56 -04:00
|
|
|
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)]
|
2020-06-03 01:38:34 -04:00
|
|
|
pub fn new<'s>(
|
|
|
|
scope: &mut HandleScope<'s>,
|
2020-04-13 08:43:56 -04:00
|
|
|
target: Local<Object>,
|
|
|
|
handler: Local<Object>,
|
2020-06-03 01:38:34 -04:00
|
|
|
) -> Option<Local<'s, Proxy>> {
|
2020-04-01 17:47:19 -04:00
|
|
|
unsafe {
|
2020-06-25 20:56:24 -04:00
|
|
|
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)]
|
2020-06-03 01:38:34 -04:00
|
|
|
pub fn get_handler<'s>(
|
2020-06-26 08:47:13 -04:00
|
|
|
&self,
|
2020-06-03 01:38:34 -04:00
|
|
|
scope: &mut HandleScope<'s>,
|
|
|
|
) -> Local<'s, Value> {
|
2020-05-31 09:00:23 -04:00
|
|
|
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)]
|
2020-06-03 01:38:34 -04:00
|
|
|
pub fn get_target<'s>(
|
2020-06-26 08:47:13 -04:00
|
|
|
&self,
|
2020-06-03 01:38:34 -04:00
|
|
|
scope: &mut HandleScope<'s>,
|
|
|
|
) -> Local<'s, Value> {
|
2020-05-31 09:00:23 -04:00
|
|
|
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)]
|
2020-06-26 08:47:13 -04:00
|
|
|
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)]
|
2020-06-26 08:47:13 -04:00
|
|
|
pub fn revoke(&self) {
|
2020-04-01 17:47:19 -04:00
|
|
|
unsafe { v8__Proxy__Revoke(self) };
|
|
|
|
}
|
|
|
|
}
|