0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-03-09 21:47:00 -04:00
rusty-v8/src/proxy.rs
Bert Belder 4e64cefc9c
Remove unnecessary 'DerefMut' impl from 'Local<T>' (#406)
Local handles never need to be mutable. This patch also rounds up the
last few places where we were still asking the user to pass an `&mut T`
to an API method.
2020-06-26 15:05:39 +02:00

54 lines
1.2 KiB
Rust

use crate::Context;
use crate::HandleScope;
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);
}
impl Proxy {
pub fn new<'s>(
scope: &mut HandleScope<'s>,
target: Local<Object>,
handler: Local<Object>,
) -> Option<Local<'s, Proxy>> {
unsafe {
scope.cast_local(|sd| {
v8__Proxy__New(sd.get_current_context(), &*target, &*handler)
})
}
}
pub fn get_handler<'s>(
&self,
scope: &mut HandleScope<'s>,
) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Proxy__GetHandler(&*self)) }.unwrap()
}
pub fn get_target<'s>(
&self,
scope: &mut HandleScope<'s>,
) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Proxy__GetTarget(&*self)) }.unwrap()
}
pub fn is_revoked(&self) -> bool {
unsafe { v8__Proxy__IsRevoked(self) }
}
pub fn revoke(&self) {
unsafe { v8__Proxy__Revoke(self) };
}
}