1use crate::Context;
2use crate::Local;
3use crate::Object;
4use crate::Proxy;
5use crate::Value;
6use crate::scope::PinScope;
7
8unsafe extern "C" {
9 fn v8__Proxy__New(
10 context: *const Context,
11 target: *const Object,
12 handler: *const Object,
13 ) -> *const Proxy;
14 fn v8__Proxy__GetHandler(this: *const Proxy) -> *const Value;
15 fn v8__Proxy__GetTarget(this: *const Proxy) -> *const Value;
16 fn v8__Proxy__IsRevoked(this: *const Proxy) -> bool;
17 fn v8__Proxy__Revoke(this: *const Proxy);
18}
19
20impl Proxy {
21 #[inline(always)]
22 pub fn new<'s>(
23 scope: &PinScope<'s, '_>,
24 target: Local<Object>,
25 handler: Local<Object>,
26 ) -> Option<Local<'s, Proxy>> {
27 unsafe {
28 scope.cast_local(|sd| {
29 v8__Proxy__New(sd.get_current_context(), &*target, &*handler)
30 })
31 }
32 }
33
34 #[inline(always)]
35 pub fn get_handler<'s>(&self, scope: &PinScope<'s, '_>) -> Local<'s, Value> {
36 unsafe { scope.cast_local(|_| v8__Proxy__GetHandler(self)) }.unwrap()
37 }
38
39 #[inline(always)]
40 pub fn get_target<'s>(&self, scope: &PinScope<'s, '_>) -> Local<'s, Value> {
41 unsafe { scope.cast_local(|_| v8__Proxy__GetTarget(self)) }.unwrap()
42 }
43
44 #[inline(always)]
45 pub fn is_revoked(&self) -> bool {
46 unsafe { v8__Proxy__IsRevoked(self) }
47 }
48
49 #[inline(always)]
50 pub fn revoke(&self) {
51 unsafe { v8__Proxy__Revoke(self) };
52 }
53}