2021-02-13 07:31:18 -05:00
|
|
|
// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
|
2020-07-03 08:01:42 -04:00
|
|
|
|
|
|
|
use std::ffi::c_void;
|
|
|
|
|
|
|
|
use crate::External;
|
|
|
|
use crate::HandleScope;
|
|
|
|
use crate::Isolate;
|
|
|
|
use crate::Local;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
fn v8__External__New(
|
|
|
|
isolate: *mut Isolate,
|
|
|
|
value: *mut c_void,
|
|
|
|
) -> *const External;
|
|
|
|
fn v8__External__Value(this: *const External) -> *mut c_void;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl External {
|
2022-09-20 22:45:33 -04:00
|
|
|
#[inline(always)]
|
2022-12-20 18:11:23 -05:00
|
|
|
#[allow(clippy::not_unsafe_ptr_arg_deref)]
|
2020-07-03 08:01:42 -04:00
|
|
|
pub fn new<'s>(
|
2020-07-04 19:36:01 -04:00
|
|
|
scope: &mut HandleScope<'s, ()>,
|
2020-07-03 08:01:42 -04:00
|
|
|
value: *mut c_void,
|
|
|
|
) -> Local<'s, Self> {
|
|
|
|
unsafe {
|
|
|
|
scope.cast_local(|sd| v8__External__New(sd.get_isolate_ptr(), value))
|
|
|
|
}
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2022-09-20 22:45:33 -04:00
|
|
|
#[inline(always)]
|
2020-07-03 08:01:42 -04:00
|
|
|
pub fn value(&self) -> *mut c_void {
|
|
|
|
unsafe { v8__External__Value(self) }
|
|
|
|
}
|
|
|
|
}
|