diff options
| author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-06-19 08:39:11 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-19 08:39:11 +0530 |
| commit | caaece0d9a62994ef07cf4597d7641762ba8f1ec (patch) | |
| tree | fbcbd553b03c45408950af4c9f78b11c1ae1a16c /serde_v8/magic/global.rs | |
| parent | f564497630d8d12023cd093904bf237ab1079a94 (diff) | |
feat(serde_v8): add serde_v8::Global (#14761)
Diffstat (limited to 'serde_v8/magic/global.rs')
| -rw-r--r-- | serde_v8/magic/global.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/serde_v8/magic/global.rs b/serde_v8/magic/global.rs new file mode 100644 index 000000000..942394067 --- /dev/null +++ b/serde_v8/magic/global.rs @@ -0,0 +1,41 @@ +// Copyright 2018-2022 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>( + &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()) + } +} |
