2020-04-01 23:47:19 +02:00
|
|
|
use crate::Context;
|
|
|
|
use crate::Local;
|
|
|
|
use crate::Object;
|
|
|
|
use crate::Proxy;
|
|
|
|
use crate::ToLocal;
|
|
|
|
use crate::Value;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
fn v8__Proxy__New(
|
2020-04-13 14:43:56 +02: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 23:47:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Proxy {
|
|
|
|
pub fn new<'sc>(
|
|
|
|
scope: &mut impl ToLocal<'sc>,
|
2020-04-13 14:43:56 +02:00
|
|
|
context: Local<Context>,
|
|
|
|
target: Local<Object>,
|
|
|
|
handler: Local<Object>,
|
2020-04-01 23:47:19 +02:00
|
|
|
) -> Option<Local<'sc, Proxy>> {
|
|
|
|
unsafe {
|
2020-04-13 14:43:56 +02:00
|
|
|
let ptr = v8__Proxy__New(&*context, &*target, &*handler);
|
2020-04-01 23:47:19 +02:00
|
|
|
scope.to_local(ptr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_handler<'sc>(
|
|
|
|
&mut self,
|
|
|
|
scope: &mut impl ToLocal<'sc>,
|
|
|
|
) -> Local<'sc, Value> {
|
2020-04-13 14:43:56 +02:00
|
|
|
unsafe { scope.to_local(v8__Proxy__GetHandler(&*self)) }.unwrap()
|
2020-04-01 23:47:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_target<'sc>(
|
|
|
|
&mut self,
|
|
|
|
scope: &mut impl ToLocal<'sc>,
|
|
|
|
) -> Local<'sc, Value> {
|
2020-04-13 14:43:56 +02:00
|
|
|
unsafe { scope.to_local(v8__Proxy__GetTarget(&*self)) }.unwrap()
|
2020-04-01 23:47:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_revoked(&mut self) -> bool {
|
|
|
|
unsafe { v8__Proxy__IsRevoked(self) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn revoke(&mut self) {
|
|
|
|
unsafe { v8__Proxy__Revoke(self) };
|
|
|
|
}
|
|
|
|
}
|