1use crate::Context;
2use crate::HandleScope;
3use crate::Local;
4use crate::Object;
5use crate::Proxy;
6use crate::Value;
7
8extern "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 pub fn new<'s>(
22 scope: &mut HandleScope<'s>,
23 target: Local<Object>,
24 handler: Local<Object>,
25 ) -> Option<Local<'s, Proxy>> {
26 unsafe {
27 scope.cast_local(|sd| {
28 v8__Proxy__New(sd.get_current_context(), &*target, &*handler)
29 })
30 }
31 }
32
33 pub fn get_handler<'s>(
34 &self,
35 scope: &mut HandleScope<'s>,
36 ) -> Local<'s, Value> {
37 unsafe { scope.cast_local(|_| v8__Proxy__GetHandler(&*self)) }.unwrap()
38 }
39
40 pub fn get_target<'s>(
41 &self,
42 scope: &mut HandleScope<'s>,
43 ) -> Local<'s, Value> {
44 unsafe { scope.cast_local(|_| v8__Proxy__GetTarget(&*self)) }.unwrap()
45 }
46
47 pub fn is_revoked(&self) -> bool {
48 unsafe { v8__Proxy__IsRevoked(self) }
49 }
50
51 pub fn revoke(&self) {
52 unsafe { v8__Proxy__Revoke(self) };
53 }
54}