1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::magic::transl8::impl_magic;
use crate::magic::transl8::FromV8;
use crate::magic::transl8::ToV8;
use std::mem::transmute;
pub struct Value<'s> {
pub v8_value: v8::Local<'s, v8::Value>,
}
impl_magic!(Value<'_>);
impl<'s> From<v8::Local<'s, v8::Value>> for Value<'s> {
fn from(v8_value: v8::Local<'s, v8::Value>) -> Self {
Self { v8_value }
}
}
impl<'s> From<Value<'s>> for v8::Local<'s, v8::Value> {
fn from(v: Value<'s>) -> Self {
v.v8_value
}
}
impl ToV8 for Value<'_> {
fn to_v8<'a>(
&mut self,
_scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
Ok(unsafe { transmute(self.v8_value) })
}
}
impl FromV8 for Value<'_> {
fn from_v8(
_scope: &mut v8::HandleScope,
value: v8::Local<v8::Value>,
) -> Result<Self, crate::Error> {
Ok(unsafe { transmute::<Value, Value>(value.into()) })
}
}