1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/serde_v8/magic/global.rs
David Sherret 10e4b2e140
chore: update copyright year to 2023 (#17247)
Yearly tradition of creating extra noise in git.
2023-01-02 21:00:42 +00:00

41 lines
918 B
Rust

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::magic::transl8::impl_magic;
use crate::magic::transl8::FromV8;
use crate::magic::transl8::ToV8;
pub struct Global {
pub v8_value: v8::Global<v8::Value>,
}
impl_magic!(Global);
impl From<v8::Global<v8::Value>> for Global {
fn from(v8_value: v8::Global<v8::Value>) -> Self {
Self { v8_value }
}
}
impl From<Global> for v8::Global<v8::Value> {
fn from(v: Global) -> Self {
v.v8_value
}
}
impl ToV8 for Global {
fn to_v8<'a>(
&mut self,
scope: &mut v8::HandleScope<'a>,
) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
Ok(v8::Local::new(scope, self.v8_value.clone()))
}
}
impl FromV8 for Global {
fn from_v8(
scope: &mut v8::HandleScope,
value: v8::Local<v8::Value>,
) -> Result<Self, crate::Error> {
let global = v8::Global::new(scope, value);
Ok(global.into())
}
}