Skip to main content

v8/
external.rs

1// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
2
3use std::ffi::c_void;
4
5use crate::External;
6use crate::Local;
7use crate::isolate::RealIsolate;
8use crate::scope::PinScope;
9
10unsafe extern "C" {
11  fn v8__External__New(
12    isolate: *mut RealIsolate,
13    value: *mut c_void,
14  ) -> *const External;
15  fn v8__External__Value(this: *const External) -> *mut c_void;
16}
17
18impl External {
19  #[inline(always)]
20  #[allow(clippy::not_unsafe_ptr_arg_deref)]
21  pub fn new<'s>(
22    scope: &PinScope<'s, '_, ()>,
23    value: *mut c_void,
24  ) -> Local<'s, Self> {
25    unsafe {
26      scope.cast_local(|sd| v8__External__New(sd.get_isolate_ptr(), value))
27    }
28    .unwrap()
29  }
30
31  #[inline(always)]
32  pub fn value(&self) -> *mut c_void {
33    unsafe { v8__External__Value(self) }
34  }
35}